How drmacsika/fastapi-django-combo works
Project type and purpose
• This is a full-stack Python web application that “combines FastAPI and Django” into a single production-ready monorepo.
• It provides:
• A classic Django-powered site (HTML templates, Django Admin, ORM, all-auth)
• A FastAPI-powered REST/async API layer (CRUD for blog, contacts, JWT auth)
• Shared database models (via Django ORM) and shared user-accounts logic
File structure
Top-level directories:
• core/ ← project bootstrap, ASGI/WSGI entrypoints, URL/router configuration, settings
• accounts/ ← custom user model, serializers, views, forms, endpoints, migrations
• blog/ ← blog Post and Category models, DRF-style schemas, FastAPI endpoints (api_crud/endpoints)
• contact/ ← Contact model, managers, FastAPI endpoints
• templates/ ← Django HTML templates (accounts pages, blog home/about, base.html)
Configuration & scripts:
• manage.py, core/asgi.py, core/wsgi.py
• requirements.txt (Django, DRF, FastAPI, Pydantic, Uvicorn, Gunicorn, all-auth, JWT, CORS)
README for additional insights
• Confirms hybrid architecture (Django + FastAPI)
• Mentions key tools: Django ORM/Admin, DRF, FastAPI, Pydantic, JWT, Uvicorn/Gunicorn, CORS
• Sample blog and contact CRUD, asynchronous endpoints, JWT auth
a. Main components
• Client (Web browser or REST API client)
• HTTP Server tier (Uvicorn/Gunicorn on ASGI)
• ASGI application “core.asgi” that mounts two sub-apps:
– Django application (templates, Admin, DRF auth endpoints)
– FastAPI application (blog, contact, account APIs)
• Shared Database (PostgreSQL/MySQL/SQLite via Django ORM)
• External services (SMTP email for confirmation, optional Redis/Caching)
b. Relationships & interactions
1. Client → HTTP Server (port 8000)
2. HTTP Server dispatches to ASGI router
3. ASGI router: based on URL prefix (/api/, /admin/, /, /accounts/) forwards to FastAPI or Django
4. FastAPI handlers use Pydantic schemas & call Django ORM via async adapters for CRUD
5. Django views/templates use Django ORM to read/write same database
6. Both apps share accounts.models.User and JWT auth logic (via DRF & all-auth)
7. Database migrations (Django manage.py migrate) keep schemas in sync
c. Architectural patterns & design principles
• Monorepo “hybrid-monolith” with two frameworks mounted on the same ASGI interface
• MVC pattern for Django (models, views, templates, admin)
• Router-controller-schema pattern for FastAPI (routers → endpoints → Pydantic schemas)
• Shared domain layer (Django ORM models) for consistency
• Separation of concerns: web UI vs. REST API
d. Key technologies & libraries
• Django + Django Rest Framework (ORM, Admin, Forms, Serializers, JWT auth, all-auth)
• FastAPI + Pydantic (async endpoints, validation)
• Uvicorn/Gunicorn (ASGI server)
• PostgreSQL/MySQL/SQLite (via Django ORM)
• CORS middleware, JWT Authentication
Capturing essential architectural elements
• Don’t just show “Backend” — split into Django and FastAPI components
• Core/asgi.py as the bridging router
• Authentication subsystem (DRF tokens/JWT) as a reusable module