# sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate architecture

> Architecture diagram of the GitHub repository sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate
- Repository: https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate

## Overview

##### Project type and purpose
- This is a full-stack RESTful API boilerplate built on Django and Django REST Framework (DRF).
- It provides JWT authentication, Swagger documentation, Gunicorn as the WSGI server, Nginx as a reverse proxy/static server, and uses SQLite (by default) or any Django-supported database.

##### File structure
- Top-level:
- manage.py – Django CLI entry point
- gunicorn_config.py – Gunicorn settings
- db.sqlite3 – default database
- yourprojectname/ – Django project (settings, URL conf, WSGI/ASGI)
- yourappname/ – Django app (models, views, URLs, migrations)
- CI/workflow: GitHub Actions for linting (pylint) and main.yml
- Deployment config: gunicorn_config.py, Nginx site config under /etc/nginx/sites-available

##### README for additional insights
- Stack: Django5, DRF, drf-yasg (Swagger), djangorestframework-simplejwt (JWT), Gunicorn, Nginx
- Key flows: API endpoints under /api/, admin under /admin/, Swagger UI at root or /swagger/
- Static files: configured via STATIC_ROOT + collectstatic, served by Nginx in production or Django in DEBUG

a. Components
- Client (browser, mobile, curl)
- Nginx (static files, reverse proxy)
- Gunicorn (WSGI worker pool)
- Django application
– URL Dispatcher
– DRF Views / ViewSets
– JWT Auth middleware
– drf-yasg Swagger generator
– Admin site
- Database (SQLite by default; replaceable with PostgreSQL/MySQL)
- GitHub CI pipeline (pylint, codecov) – optional in architecture

b. Relationships & interactions
1. Client → HTTP(S) request → Nginx
– Static asset requests → Nginx serves from /static/
– Other requests → proxy_pass to Gunicorn
2. Gunicorn → WSGI calls → Django wsgi.application
3. Django request flow
– URLConf routes to yourappname.urls or admin
– DRF dispatches to APIView / ViewSet
– JWT authentication checks token, sets request.user
– Business logic, ORM queries → Database
– Serializer returns JSON response
– drf-yasg introspects Views to serve Swagger JSON/UI at /swagger/
4. Response travels back through Gunicorn → Nginx → Client

c. Architectural patterns & principles
- Layered architecture: Web server → WSGI server → Web framework → ORM → DB
- Separation of concerns: static vs dynamic content
- Pluggable components: DRF for serialization, JWT for auth, drf-yasg for docs
- Twelve-factor app readiness: externalize config (settings, secrets.py), treat logs as streams (Gunicorn)

d. Key technologies/frameworks
- Django 5.x, Django REST Framework
- djangorestframework-simplejwt for JWT
- drf-yasg for Swagger UI
- Gunicorn (gunicorn_config.py)
- Nginx (reverse proxy + static)
- SQLite (default), configurable to any Django-backed DB

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef web fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef app fill:#d4edda,stroke:#333,stroke-width:1px
    classDef data fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef util fill:#e2e3e5,stroke:#333,stroke-width:1px

    subgraph "Web Tier"
        Client["Client"]:::web
        Nginx["Nginx (Port 80)"]:::web
    end

    subgraph "App Tier"
        Gunicorn["Gunicorn (Port 8000)"]:::app
        subgraph "Django Application"
            Dispatcher["URL Dispatcher"]:::app
            Views["DRF Views & ViewSets"]:::app
            JWT["JWT Authentication Middleware"]:::app
            Admin["Django Admin Site"]:::app
            Swagger["Swagger UI (drf-yasg)"]:::util
        end
    end

    subgraph "Data Tier"
        DB["SQLite / PostgreSQL"]:::data
    end

    subgraph "Developer Tools & Config"
        Manage["manage.py"]:::util
        GCfg["gunicorn_config.py"]:::util
        Settings["settings.py"]:::util
        Secrets["secrets.py"]:::util
        URLsPrj["urls.py (project-level)"]:::util
        WSGI["wsgi.py"]:::util
        ASGI["asgi.py"]:::util
        Models["models.py"]:::util
        ViewsFile["views.py"]:::util
        URLsApp["urls.py (app-level)"]:::util
        AdminFile["admin.py"]:::util
        Tests["tests.py"]:::util
        Migrations["migrations/"]:::util
        DBFile["db.sqlite3"]:::data
        MainWF[".github/workflows/main.yml"]:::util
        PylintWF[".github/workflows/pylint.yml"]:::util
        Readme["README.MD"]:::util
    end

    Client -->|"HTTP/HTTPS"| Nginx
    Nginx -->|"static/*"| Client
    Nginx -->|"proxy_pass to Gunicorn"| Gunicorn
    Gunicorn -->|"WSGI call"| Dispatcher
    Dispatcher -->|"routes /api/*"| Views
    Views -->|"JWT token check"| JWT
    JWT -->|"ORM queries"| DB
    Dispatcher -->|"routes /admin/*"| Admin
    Dispatcher -->|"routes /swagger/*"| Swagger

    click Manage "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/manage.py"
    click GCfg "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/gunicorn_config.py"
    click Settings "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourprojectname/settings.py"
    click Secrets "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourprojectname/secrets.py"
    click URLsPrj "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourprojectname/urls.py"
    click WSGI "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourprojectname/wsgi.py"
    click ASGI "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourprojectname/asgi.py"
    click Models "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourappname/models.py"
    click ViewsFile "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourappname/views.py"
    click URLsApp "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourappname/urls.py"
    click AdminFile "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourappname/admin.py"
    click Tests "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/yourappname/tests.py"
    click Migrations "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/tree/main/yourappname/migrations/"
    click DBFile "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/db.sqlite3"
    click MainWF "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/.github/workflows/main.yml"
    click PylintWF "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/.github/workflows/pylint.yml"
    click Readme "https://github.com/sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate/blob/main/README.MD"
```
