These instructions are for LLM agents assisting on this Django rebuild project.
- Project: Re-platforming a legacy PHP site to Django + HTMX with modern Docker tooling.
- Current Phase: Phases 0-7 are complete. We are now in Phase 8: Frontend & Final Testing. The data migration is structurally complete but requires rigorous validation. The final phase will be deployment.
- Role: Act as a senior Django engineer specializing in HTMX-driven architectures and robust testing.
- Tone: Concise, actionable guidance; cite official docs when helpful.
- Docker & Compose ≥ v25
- Python 3.12 (containerized)
- 4GB+ RAM, 2GB+ disk space
# Setup
cp .env.example .env
docker-compose up -d --build
# Initial setup inside container
docker-compose exec app bash
python manage.py migrate
python manage.py createsuperuser --noinput- App: http://localhost:8000
- Admin: http://localhost:8000/admin
- Health: http://localhost:8000/healthz
- Metrics: http://localhost:8000/metrics
- Jaeger: http://localhost:16686
- MailHog: http://localhost:8025
- Phase Discipline: Work strictly within the Phase 8 scope: frontend implementation, writing comprehensive tests, and validating the data migration.
- Development Flow:
- Use
docker-compose exec app bashfor all Django commands. - Run
pytestcontinuously. All new frontend interactions and business logic must be covered. - Check
docker-compose logs -f appfor real-time debugging. - Verify CI passes before suggesting merges.
- Use
- Code Changes:
- Provide complete, copy-pastable code snippets for views, templates, and tests.
- Write tests for all new functionality.
- Follow conventional commit messages (
feat:,fix:,test:,chore:).
| Topic | Standard |
|---|---|
| Settings | Split: base.py, dev.py, prod.py, test.py |
| Testing | pytest, pytest-django, ≥95% coverage, factory_boy for fixtures |
| Logging | Structured JSON (prod), human-readable (dev) |
| Observability | OpenTelemetry + Prometheus + Jaeger |
| Commits | Conventional (feat:, fix:, docs:, etc.) |
| Python | 3.12, full type hints, dataclasses, service layer pattern |
| Frontend | HTMX for server-rendered partials, Alpine.js for client-side interactivity |
- Site: Multi-tenant support (e.g.,
lllreptile.com,vistapetsupply.com). - Store: Business configuration per
Site. - User: Custom user model using email for authentication.
- Contact: One-to-one profile with user details.
- Address: Multiple addresses per
Contact. - AccountMeta: QuickBooks IDs and internal business notes.
- AuditLog: Generic logging for tracking model changes.
- [E-commerce Models]: (Via Django Oscar or custom)
Product,Category,Order,Basket, etc. Schema needs verification during testing. - [CMS Models]: (Via Wagtail)
ContentPage,BlogIndexPage,HomePage, etc. Integration with multi-tenant sites needs validation.
- All core models are registered with the Django admin.
- Custom admin views are in place for
Sitemanagement. AuditLogprovides a read-only history of changes.
Business logic is encapsulated in service functions rather than fat models or views. This improves testability and reusability. Services live in app/services.py files.
- Example:
orders.services.place_order(*, user: User, cart: Cart) -> Order
- Views are designed to return either a full page or an HTML fragment based on the
HX-Requestheader. - Use
render_htmxtemplate tags or decorators to simplify logic. - Avoid complex state management on the frontend; keep state on the server.
Reusable template components (e.g., cards, modals, forms) are managed using the django-viewcomponent library. This keeps templates DRY and easier to test.
- Django Coomponents: We have
django-componentsand should make the most use out of it. Components go insrc/[app]/components/[component].{py,html}. The way django components works with htmx is you register the component at a url and you can get the component directly. - Tailwind CSS: Use the
npm run watchcommand (viadocker-compose exec node) to compile CSS during development. - HTMX: All dynamic page updates should be handled via HTMX attributes in templates (
hx-get,hx-post, etc.). - Alpine.js: Use for small, localized UI interactions that don't require a server round-trip (e.g., toggling a dropdown, managing modal visibility). Use the
x-data,x-show, and@clickdirectives. Seedocs/frameworks/alpine-js.md. - Daisy UI: Our primary component library. Use pre-built components whenever possible. See
docs/frameworks/daisyui.md.
The current focus is on integration and end-to-end testing of the frontend and migrated data.
# Run the full test suite
pytest
# Run with coverage report (ensure >=95%)
pytest --cov=src --cov-report=html
# Run tests for a specific app or module
pytest tests/apps/accounts/ -v
# Run frontend-specific tests
pytest tests/frontend/- Migration Validation: Write data integrity tests that compare critical record counts and field values between the legacy DB dump and the new Django models.
- User Journeys: Implement end-to-end tests for key flows (e.g., user registration, login, add-to-cart, checkout).
- HTMX Interactions: Ensure all HTMX-powered UI elements are tested to confirm they render the correct partials and handle user input as expected.
docs/REBUILD.md: Project phases and decisionsdocs/migration-playbook.md: Data migration validation stepsdocs/deploy.md: Deployment procedures (upcoming)docs/frameworks/htmx.md: htmx patterns and pitfallsdocs/frameworks/alpine-js.md: Alpine.js usage patterns- Django 5.0 Documentation: https://docs.djangoproject.com/en/5.0/
- pytest-django: https://pytest-django.readthedocs.io/en/latest/
- OpenTelemetry Django: https://opentelemetry.io/docs/instrumentation/python/django/
Before implementing new features, confirm:
- Does the work align with Phase 8 (Frontend & Testing)?
- Are comprehensive tests included (≥95% coverage)? This is non-negotiable.
- Have you validated the functionality against the migrated data?
- Are environment variables for any new services documented in
.env.example?
When in doubt, focus on testing. Assume nothing works until a test proves it does.
Update this guide when project conventions or requirements change.