# tuanvupresent/drf-template architecture

> Architecture diagram of the GitHub repository tuanvupresent/drf-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tuanvupresent/drf-template
- Repository: https://github.com/tuanvupresent/drf-template

## Overview

##### Project Type and Purpose
- This is a backend web application built with Django and Django REST Framework. Its purpose includes providing RESTful APIs for client consumption along with user authentication, health checks, and core utilities.
- The project also integrates asynchronous task processing using Celery and uses Docker to containerize various components for development, beta, and production environments.

##### Analyzing the File Structure
- Core Application Code: The code is organized in the “apps” folder with submodules such as “authentication”, “core” and “health_check”. Each of these modules handles distinct aspects of the business logic – for example, authentication handles JWT authentication and migration, core provides utility functions like logging, permissions, pagination, and the health_check app is likely used for status endpoints.
- Configuration: The “config” directory holds the main Django configuration (settings, URLs, ASGI/WGI, celery configuration) indicating central control for environment and routing.
- Container & Deployment Files: The Dockerfiles (in docker/app and docker/nginx) and docker-compose files (docker-compose.yml, docker-compose-prod.yml, docker-compose-beta.yml) indicate containerization and reverse proxy usage alongside CI/CD scripts (e.g., Jenkinsfile and GitHub workflows).
- Celery Integration: The README and the celery setup in the config/celery.py indicate scheduled tasks and asynchronous processing via Redis as Broker and Result Backend.

a. Client Interface:
- External clients (web browsers, mobile apps, or API consumers) that send HTTP requests.
b. Nginx Reverse Proxy:
- Nginx container (from docker/nginx) that receives incoming traffic and passes it to the Django application container.
c. Django Application:
- Authentication Module: Manages user authentication (JWT, migrations, serializers, views, etc.).
- Core App: Provides the common utilities (logging, pagination, middleware, custom authentication backend, etc.).
- Health Check: Exposes endpoints for system health monitoring.
- Django URLs routing from config/urls.py to these apps.
d. Celery Worker:
- A separate Celery worker container that picks up scheduled tasks from the task queue. Detail that this uses Celery and a Redis service as the broker and results backend.
e. Redis Service:
- Redis, which is used as the message broker for Celery. Indicate its relationship with the Celery worker.
f. (Optional) Database Layer:
- Although not explicitly visible in the file tree, note that Django projects usually integrate with a relational database. If a database is configured elsewhere (e.g., via environment configurations), include a placeholder block for your database (PostgreSQL, MySQL, etc.).

##### Relationships and Interactions
- Client requests flowing from external clients to the Nginx container.
- Traffic passing from Nginx into the Django application.
- The Django app querying or updating the database.
- Django application sending asynchronous tasks to the Celery worker via Redis.
- Celery worker picking tasks and possibly returning results back to the Django application if needed.

##### Architectural Patterns and Technologies
- Micro-layer separation by having distinct blocks for each major component (e.g., authentication, core, health_check).
- Rectangles for application components.
- That the architecture leverages containerization (Docker), asynchronous task handling (Celery + Redis), and REST API design (Django REST Framework).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("External Clients"):::client
    Nginx("Nginx Reverse Proxy"):::reverse
    DjangoApp("Django Application"):::django
    Database("Database"):::database
    Redis("Redis Service"):::redis
    CeleryWorker("Celery Worker"):::celery

    Client -->|"HTTP_API"| Nginx
    Nginx -->|"HTTP_API"| DjangoApp
    DjangoApp -->|"DB_Query"| Database
    DjangoApp -->|"Task_Enqueue"| Redis
    Redis -->|"Task_Dispatch"| CeleryWorker

    subgraph "Django Internal Modules"
        DjangoRouting("Django Routing"):::module
        ManagePy("Manage.py"):::module
        Settings("Settings"):::module
        WSGI("WSGI/ASGI"):::module
        Authentication("Authentication Module"):::module
        Core("Core Module"):::module
        HealthCheck("Health Check Module"):::module
    end

    DjangoRouting -->|"routes_to"| Authentication
    DjangoRouting -->|"routes_to"| Core
    DjangoRouting -->|"routes_to"| HealthCheck

    %% Click Events
    click Nginx "https://github.com/tuanvupresent/drf-template/tree/master/docker/nginx/Dockerfile"
    click DjangoRouting "https://github.com/tuanvupresent/drf-template/blob/master/config/urls.py"
    click ManagePy "https://github.com/tuanvupresent/drf-template/blob/master/manage.py"
    click Settings "https://github.com/tuanvupresent/drf-template/blob/master/config/settings.py"
    click WSGI "https://github.com/tuanvupresent/drf-template/blob/master/config/asgi.py"
    click Authentication "https://github.com/tuanvupresent/drf-template/tree/master/apps/authentication"
    click Core "https://github.com/tuanvupresent/drf-template/tree/master/apps/core"
    click HealthCheck "https://github.com/tuanvupresent/drf-template/tree/master/apps/health_check"
    click CeleryWorker "https://github.com/tuanvupresent/drf-template/blob/master/config/celery.py"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef reverse fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef django fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef module fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef redis fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef celery fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef database fill:#AFEEEE,stroke:#333,stroke-width:2px;
```
