|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Askbot is a Django-based Q&A forum platform similar to StackOverflow, written in Python. It supports Django 4.2 and Python 3.8+, with PostgreSQL as the recommended database for full-text search capabilities. |
| 8 | + |
| 9 | +Current version: 0.12.x (master branch) |
| 10 | + |
| 11 | +## Development Setup |
| 12 | + |
| 13 | +### Initial Installation |
| 14 | +```bash |
| 15 | +pip install --upgrade pip |
| 16 | +pip install setuptools-rust |
| 17 | +python -m pip install . |
| 18 | +askbot-setup # Creates a Django project, default directory: askbot_site |
| 19 | +cd <root_dir> # Navigate to project root |
| 20 | +python manage.py migrate |
| 21 | +python manage.py migrate # Run twice for askbot and django_authopenid apps |
| 22 | +``` |
| 23 | + |
| 24 | +### Development Environment |
| 25 | +- Test project available at: `testproject/` for development and testing |
| 26 | +- Working site example at: `askbot_site/` |
| 27 | +- Virtual environment typically in: `env/` |
| 28 | + |
| 29 | +### Pre-commit Hooks |
| 30 | +```bash |
| 31 | +pre-commit install # Required before committing |
| 32 | +``` |
| 33 | + |
| 34 | +Pre-commit runs ruff for linting with `--fix` flag. Configuration in `.pre-commit-config.yaml` and `pyproject.toml`. |
| 35 | + |
| 36 | +## Testing |
| 37 | + |
| 38 | +### Running Tests |
| 39 | +```bash |
| 40 | +# Using tox (recommended) |
| 41 | +tox # Runs tests for available Python versions |
| 42 | + |
| 43 | +# Environment variables for database configuration |
| 44 | +DB_TYPE=postgres |
| 45 | +DB_USER=askbot |
| 46 | +DB_PASS=askB0T! |
| 47 | +DB_HOST=localhost |
| 48 | +DB_PORT=5432 |
| 49 | +DB_NAME=askbotfortox |
| 50 | + |
| 51 | +# Direct Django test runner |
| 52 | +cd testproject/ |
| 53 | +python manage.py test --parallel 8 askbot.tests askbot.deps.django_authopenid.tests |
| 54 | + |
| 55 | +# Coverage report |
| 56 | +coverage run --rcfile ../.coveragerc manage.py test --parallel 8 askbot.tests askbot.deps.django_authopenid.tests |
| 57 | +coverage html --rcfile ../.coveragerc |
| 58 | +``` |
| 59 | + |
| 60 | +### Test Configuration |
| 61 | +- Tests located in: `askbot/tests/` |
| 62 | +- Coverage config: `.coveragerc` |
| 63 | +- Tox config: `tox.ini` |
| 64 | +- Uses factory_boy for test fixtures |
| 65 | + |
| 66 | +## Management Commands |
| 67 | + |
| 68 | +Askbot includes numerous custom management commands in `askbot/management/commands/`: |
| 69 | +- `add_admin.py` - Add admin users |
| 70 | +- `askbot_add_test_content.py` - Generate test data |
| 71 | +- `askbot_award_badges.py` - Award badges to users |
| 72 | +- Many others for data migration, cleanup, and maintenance |
| 73 | + |
| 74 | +Run with: `python manage.py <command_name>` |
| 75 | + |
| 76 | +## Architecture |
| 77 | + |
| 78 | +### Django App Structure |
| 79 | +``` |
| 80 | +askbot/ |
| 81 | +├── models/ # Core data models |
| 82 | +├── views/ # View controllers (readers.py, writers.py, commands.py, users.py) |
| 83 | +├── forms.py # Form definitions (large, 63KB+) |
| 84 | +├── urls.py # URL routing with translatable patterns |
| 85 | +├── conf/ # Livesettings configuration system |
| 86 | +├── deps/ # Bundled dependencies |
| 87 | +│ ├── django_authopenid/ # Forked authentication system |
| 88 | +│ └── group_messaging/ # Group messaging functionality |
| 89 | +├── skins/ # Template system |
| 90 | +├── utils/ # Utility modules |
| 91 | +├── middleware/ # Custom middleware |
| 92 | +├── deployment/ # Deployment scripts and validators |
| 93 | +└── startup_procedures.py # Validation on startup |
| 94 | +``` |
| 95 | + |
| 96 | +### Core Models (askbot/models/) |
| 97 | +- **Post** (`post.py`) - Base class for questions/answers/comments |
| 98 | +- **Thread/Question** (`question.py`) - Question threads and views |
| 99 | +- **User** (`user.py`, `user_profile.py`) - Extended user model with reputation |
| 100 | +- **Tag** (`tag.py`) - Tag system with synonyms and categories |
| 101 | +- **Badges** (`badges.py`) - Badge award system |
| 102 | +- **Repute** (`repute.py`) - Reputation tracking |
| 103 | + |
| 104 | +### Configuration System (Livesettings) |
| 105 | +Askbot uses django-livesettings3 for runtime-editable settings stored in the database. Configuration modules in `askbot/conf/` define settings groups: |
| 106 | +- `site_settings.py`, `email.py`, `moderation.py`, etc. |
| 107 | +- Settings accessed via: `from askbot.conf import settings as askbot_settings` |
| 108 | +- Wrapper in: `askbot/conf/settings_wrapper.py` |
| 109 | + |
| 110 | +### Template System |
| 111 | +- Uses Jinja2 (not Django templates) |
| 112 | +- Custom Jinja2 environment in `askbot/skins/jinja2_environment.py` |
| 113 | +- Template backends in `askbot/skins/template_backends.py` |
| 114 | +- Skin system allows theme customization |
| 115 | + |
| 116 | +### URL Routing |
| 117 | +- Translatable URLs using `pgettext()` when `ASKBOT_TRANSLATE_URL` is enabled |
| 118 | +- Configurable base URLs: `ASKBOT_MAIN_PAGE_BASE_URL`, `ASKBOT_QUESTION_PAGE_BASE_URL` |
| 119 | +- Complex regex patterns for questions with filters (scope, sort, tags, author, page) |
| 120 | + |
| 121 | +### Authentication |
| 122 | +Bundled fork of `django_authopenid` in `askbot/deps/`: |
| 123 | +- Supports multiple auth providers (OAuth, OpenID, LDAP, CAS, Okta) |
| 124 | +- Custom user model extensions patch Django's `auth_user` table |
| 125 | +- **Important**: Migrations automatically add missing columns but won't overwrite existing ones |
| 126 | + |
| 127 | +## Recent Changes |
| 128 | + |
| 129 | +### Markdown Parser Migration (Current Branch: markdown-upgrade) |
| 130 | +Recent commit migrated from markdown2 to markdown_it: |
| 131 | +- Changed in: `askbot/utils/markup.py` |
| 132 | +- Uses: `markdown-it-py`, `mdit-py-plugins`, `linkify-it-py` |
| 133 | +- Function: `get_md_converter()` returns configured MarkdownIt instance |
| 134 | +- PostRevision.html property uses markdown input converter |
| 135 | + |
| 136 | +Key behavior: |
| 137 | +- Users trusted by reputation or admins can post links |
| 138 | +- Anonymous users cannot post links |
| 139 | +- Link detection for spam prevention in `User.assert_can_post_text()` |
| 140 | + |
| 141 | +## Important Development Considerations |
| 142 | + |
| 143 | +### Multi-language Support |
| 144 | +Three language modes configured via `ASKBOT_LANGUAGE_MODE`: |
| 145 | +- `'single-lang'` - Single language site |
| 146 | +- `'url-lang'` - Language prefix in URLs |
| 147 | +- `'user-lang'` - User-selected language |
| 148 | + |
| 149 | +Check mode: `askbot.is_multilingual()` |
| 150 | + |
| 151 | +### Database Considerations |
| 152 | +- PostgreSQL recommended for full-text search and relevance sorting |
| 153 | +- Supports MySQL 5.6+ and SQLite |
| 154 | +- Database engine check: `askbot.get_database_engine_name()` |
| 155 | + |
| 156 | +### Search System |
| 157 | +Multiple search backends in `askbot/search/`: |
| 158 | +- `postgresql/` - PostgreSQL full-text search |
| 159 | +- `haystack/` - Haystack integration |
| 160 | + |
| 161 | +### Email System |
| 162 | +- Complex email alert system in `askbot/mail/` |
| 163 | +- Supports instant and delayed alerts with tag filtering |
| 164 | +- Email parsing for reply-by-email functionality |
| 165 | + |
| 166 | +### Celery Tasks |
| 167 | +Async task processing configured in `askbot/tasks.py`: |
| 168 | +- Badge awarding |
| 169 | +- Email sending |
| 170 | +- Other background operations |
| 171 | + |
| 172 | +### Static Files and Media |
| 173 | +- Node.js dependencies in `askbot/media/node_modules/` |
| 174 | +- ESLint configuration for JavaScript |
| 175 | +- Static files collected via Django's collectstatic |
| 176 | + |
| 177 | +### Code Quality Tools |
| 178 | +- **Ruff**: Primary linter (configuration in `pyproject.toml`) |
| 179 | +- **Pylint**: Available but currently disabled in pre-commit |
| 180 | +- Many rules are TODO for gradual adoption |
| 181 | +- Migrations excluded from linting |
| 182 | + |
| 183 | +## Key Files to Review |
| 184 | + |
| 185 | +- `askbot/__init__.py` - Version, requirements, utility functions |
| 186 | +- `askbot/startup_procedures.py` - Deployment validation on startup |
| 187 | +- `askbot/conf/__init__.py` - Settings system initialization |
| 188 | +- `askbot/forms.py` - Large file with all form definitions |
| 189 | +- `askbot/signals.py` - Django signal handlers |
| 190 | +- `testproject/testproject/settings.py` - Example settings configuration |
| 191 | + |
| 192 | +## Admin Tags Feature |
| 193 | +Recent work on admin tags system: |
| 194 | +- Admin tags stored in a root category |
| 195 | +- Setting: `ASKBOT_USER_CAN_MANAGE_ADMIN_TAGS_FUNCTION` |
| 196 | +- Defaults to admins or moderators |
| 197 | +- Category tree editing updates admin tags setting |
| 198 | + |
| 199 | +## Installation Paths |
| 200 | + |
| 201 | +Function `askbot.get_install_directory()` returns askbot package location. |
| 202 | +Function `askbot.get_askbot_module_path(relative_path)` constructs paths within askbot. |
0 commit comments