# drmacsika/fastapi-django-combo architecture

> Architecture diagram of the GitHub repository drmacsika/fastapi-django-combo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/drmacsika/fastapi-django-combo
- Repository: https://github.com/drmacsika/fastapi-django-combo

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client layer
    Browser["Web Browser"]:::external
    APIClient["API Client"]:::external

    %% Infrastructure
    HTTPServer["Uvicorn/Gunicorn (ASGI Server)"]:::infra
    ASGI["core/asgi.py\nASGI Router"]:::infra
    click ASGI "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/asgi.py"
    WSGI["core/wsgi.py"]:::infra
    click WSGI "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/wsgi.py"

    %% Django App
    subgraph "Django Application" 
        Settings["core/settings.py"]:::web
        click Settings "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/settings.py"
        URLs["core/urls.py"]:::web
        click URLs "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/urls.py"
        FormsViews["accounts/forms.py & views.py"]:::web
        click FormsViews "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/forms.py"
        click FormsViews "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/views.py"
        AdminUI["templates/"]:::web
        click AdminUI "https://github.com/drmacsika/fastapi-django-combo/tree/master/templates/"
        TemplatesBase["templates/base.html"]:::web
        click TemplatesBase "https://github.com/drmacsika/fastapi-django-combo/blob/master/templates/base.html"
        TemplatesAccounts["templates/accounts/"]:::web
        click TemplatesAccounts "https://github.com/drmacsika/fastapi-django-combo/tree/master/templates/accounts/"
        TemplatesPagesHome["templates/pages/home.html"]:::web
        click TemplatesPagesHome "https://github.com/drmacsika/fastapi-django-combo/blob/master/templates/pages/home.html"
        TemplatesPagesAbout["templates/pages/about.html"]:::web
        click TemplatesPagesAbout "https://github.com/drmacsika/fastapi-django-combo/blob/master/templates/pages/about.html"
    end

    %% FastAPI App
    subgraph "FastAPI Application"
        APIRouter["core/api_router.py"]:::api
        click APIRouter "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/api_router.py"
        BaseCRUD["core/base_crud.py"]:::api
        click BaseCRUD "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/base_crud.py"
        Utils["core/utils.py"]:::api
        click Utils "https://github.com/drmacsika/fastapi-django-combo/blob/master/core/utils.py"
        BlogEndpoints["blog/endpoints.py"]:::api
        click BlogEndpoints "https://github.com/drmacsika/fastapi-django-combo/blob/master/blog/endpoints.py"
        BlogCRUD["blog/api_crud.py"]:::api
        click BlogCRUD "https://github.com/drmacsika/fastapi-django-combo/blob/master/blog/api_crud.py"
        BlogSchemas["blog/schemas.py"]:::api
        click BlogSchemas "https://github.com/drmacsika/fastapi-django-combo/blob/master/blog/schemas.py"
        ContactEndpoints["contact/endpoints.py"]:::api
        click ContactEndpoints "https://github.com/drmacsika/fastapi-django-combo/blob/master/contact/endpoints.py"
        ContactCRUD["contact/api_crud.py"]:::api
        click ContactCRUD "https://github.com/drmacsika/fastapi-django-combo/blob/master/contact/api_crud.py"
        ContactSchemas["contact/schemas.py"]:::api
        click ContactSchemas "https://github.com/drmacsika/fastapi-django-combo/blob/master/contact/schemas.py"
        AccountsAdapter["accounts/adapter.py"]:::api
        click AccountsAdapter "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/adapter.py"
        AccountsSchemas["accounts/schemas.py"]:::api
        click AccountsSchemas "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/schemas.py"
    end

    %% Domain Model Shared
    subgraph "Domain Models & Auth"
        UserModel["accounts/models.py"]:::domain
        click UserModel "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/models.py"
        Managers["accounts/managers.py"]:::domain
        click Managers "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/managers.py"
        Serializers["accounts/serializers.py"]:::domain
        click Serializers "https://github.com/drmacsika/fastapi-django-combo/blob/master/accounts/serializers.py"
        BlogModel["blog/models.py"]:::domain
        click BlogModel "https://github.com/drmacsika/fastapi-django-combo/blob/master/blog/models.py"
        BlogManagers["blog/managers.py"]:::domain
        click BlogManagers "https://github.com/drmacsika/fastapi-django-combo/blob/master/blog/managers.py"
        ContactModel["contact/models.py"]:::domain
        click ContactModel "https://github.com/drmacsika/fastapi-django-combo/blob/master/contact/models.py"
        ContactManagers["contact/managers.py"]:::domain
        click ContactManagers "https://github.com/drmacsika/fastapi-django-combo/blob/master/contact/managers.py"
    end

    %% External Services
    Database["Relational Database"]:::storage
    SMTP["SMTP Email Service"]:::infra

    %% Management
    Manage["manage.py"]:::infra
    click Manage "https://github.com/drmacsika/fastapi-django-combo/blob/master/manage.py"

    %% Connections
    Browser -->|HTTP| HTTPServer
    APIClient -->|HTTP/JSON| HTTPServer
    HTTPServer --> ASGI

    ASGI -->|mounts| URLs
    ASGI -->|mounts /api| APIRouter

    %% Django flows
    URLs -->|routes| FormsViews
    URLs -->|routes| AdminUI
    FormsViews -->|ORM queries| UserModel
    FormsViews -->|ORM queries| BlogModel
    AdminUI -->|renders| TemplatesBase
    AdminUI -->|renders| TemplatesAccounts

    UserModel -->|SQL| Database
    BlogModel -->|SQL| Database
    ContactModel -->|SQL| Database

    %% FastAPI flows
    APIRouter -->|forwards /blog| BlogEndpoints
    APIRouter -->|forwards /contact| ContactEndpoints
    APIRouter -->|forwards /accounts| AccountsAdapter

    BlogEndpoints -->|uses| BlogSchemas
    BlogEndpoints -->|CRUD| BlogCRUD
    BlogCRUD -->|ORM| BlogModel

    ContactEndpoints -->|uses| ContactSchemas
    ContactEndpoints -->|CRUD| ContactCRUD
    ContactCRUD -->|ORM| ContactModel

    AccountsAdapter -->|uses| AccountsSchemas
    AccountsAdapter -->|calls| UserModel

    BaseCRUD -->|shared logic| BlogCRUD
    BaseCRUD -->|shared logic| ContactCRUD
    Utils -->|JWT/CORS| APIRouter

    UserModel -->|auth logic| Serializers
    Serializers -->|JWT| Utils

    %% External interactions
    FormsViews -->|email| SMTP
    AccountsAdapter -->|email| SMTP

    %% Styles
    classDef web fill:#cfe2f3,stroke:#2a7ab9,color:#000000
    classDef api fill:#d9ead3,stroke:#6aa84f,color:#000000
    classDef domain fill:#f9cb9c,stroke:#e69138,color:#000000
    classDef storage fill:#fce5cd,stroke:#e06666,color:#000000
    classDef infra fill:#d0d0d0,stroke:#999999,color:#000000
    classDef external fill:#ffffff,stroke:#666666,color:#000000
```
