Django + Next.js Architecture for Production SaaS
Separation of concerns
Rep Cloud splits Django REST Framework for business logic and Next.js for UX. TanStack Query on the frontend keeps server state predictable; JWT auth flows through httpOnly cookies on production.
Multi-tenancy
Tenant isolation lives at the database row level with middleware-enforced tenant context on every queryset. Background Celery tasks inherit tenant ID from job metadata to prevent cross-tenant leaks.
Async work
Invoicing PDFs, QuickBooks sync, and email notifications run in Celery workers. Beat schedules recurring jobs like report generation and subscription renewals.
Deployment
Docker Compose for staging; production uses containerized API + worker pools with PostgreSQL and Redis as managed services. Media switches between local disk and S3 via environment config.