How sajixinc/django-gunicorn-nginx-swagger-rest-api-boilerplate works
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