# huyhoangbcvt/django_rest_template architecture

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

- Interactive diagram: https://gitdiagram.com/huyhoangbcvt/django_rest_template
- Repository: https://github.com/huyhoangbcvt/django_rest_template

## Overview

##### Project Type and Purpose
- This is a monolithic full‐stack web application built with Django and Django REST Framework.
- It serves both server‐rendered HTML pages (templates in each app) and RESTful JSON APIs (in each app’s `apis/` and serializers).
- Main domains:
- user_app: authentication, profile management, admin docs
- catalog_app: product & category CRUD, comments, contact forms
- upload_app: file/image upload and display

##### High‐Level Architecture Overview
- Client Layer
- Web browsers or mobile frontends
- Load HTML (templates + static assets) and invoke REST endpoints (AJAX/fetch)
- Web / Application Layer (Django monolith)
- Reverse proxy (e.g., Nginx) → WSGI/ASGI server (Gunicorn/Daphne)
- Django project `django_rest_template`: settings, URL dispatch, middleware
- Three Django apps (user_app, catalog_app, upload_app)
– Each app provides: models, views (Django views + DRF viewsets or function‐based views in `apis/`), serializers, URLs
– Modules subfolders (form controllers, view controllers) implement MVC separation internally
- API Documentation via drf‐yasg (Swagger / Redoc) under `/api/swagger/` and `/api/redoc/`
- Data Storage Layer
- PostgreSQL for relational data (accounts, products, categories, uploaded file metadata)
- Local file system (or object storage) for media uploads (`media/` directory)
- Static files served from `static/` directory (CSS/JS frameworks, CKEditor, Bootstrap, jQuery plugins)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Client["Browser / Mobile"]:::frontend
    end

    %% Reverse Proxy and App Server
    Nginx["Nginx (Reverse Proxy)"]:::backend
    ApplicationServer["Gunicorn / Daphne"]:::backend

    %% Django Monolith
    subgraph "Backend Layer"
        direction TB
        DjangoMonolith["Django Monolith"]:::backend

        URLDispatcher["URL Dispatcher"]:::backend
        TemplateEngine["Template Engine & Static Handler"]:::backend
        APIDocs["Swagger / Redoc (/api/swagger/, /api/redoc/)"]:::backend

        subgraph "Django Apps"
            direction TB
            subgraph "user_app"
                direction TB
                UserApp["user_app"]:::backend
                AuthService["services_auth.py"]:::backend
                UserSerializers["serializers/"]:::backend
                UserURLs["urls.py"]:::backend
                UserModules["modules/"]:::backend
                UserTemplates["templates/"]:::backend
            end
            subgraph "catalog_app"
                direction TB
                CatalogApp["catalog_app"]:::backend
                CategoryWS["apis/category_ws.py"]:::backend
                ProductWS["apis/product_ws.py"]:::backend
                CatalogSerializers["serializers/"]:::backend
                CatalogURLs["urls.py"]:::backend
                CatalogModules["modules/"]:::backend
                CatalogTemplates["templates/"]:::backend
                CatalogUtil["util/"]:::backend
            end
            subgraph "upload_app"
                direction TB
                UploadApp["upload_app"]:::backend
                UploadViews["views.py"]:::backend
                UploadForms["forms.py"]:::backend
                UploadURLs["urls.py"]:::backend
                UploadTemplates["templates/upload_app/"]:::backend
            end
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PostgreSQL["PostgreSQL"]:::data
        MediaStorage["Media Storage (media/)"]:::data
        StaticFiles["Static Files (static/)"]:::data
    end

    %% Connections
    Client -->|HTTP/HTTPS| Nginx
    Nginx -->|Pass to WSGI/ASGI| ApplicationServer
    ApplicationServer -->|WSGI/ASGI| URLDispatcher
    URLDispatcher -->|Routes to Views/API| UserApp
    URLDispatcher -->|Routes to Views/API| CatalogApp
    URLDispatcher -->|Routes to Views/API| UploadApp
    TemplateEngine -->|Render HTML| Client
    TemplateEngine -->|Serve assets| Client
    APIDocs -->|Serve docs| Client

    %% Data flows
    UserApp -->|ORM SQL| PostgreSQL
    CatalogApp -->|ORM SQL| PostgreSQL
    UploadApp -->|Save Files| MediaStorage
    Client -->|Fetch Static| StaticFiles
    Client -->|AJAX JSON| UserApp
    Client -->|AJAX JSON| CatalogApp
    Client -->|AJAX JSON| UploadApp

    %% Click Events
    click URLDispatcher "https://github.com/huyhoangbcvt/django_rest_template/blob/main/django_rest_template/urls.py"
    click ApplicationServer "https://github.com/huyhoangbcvt/django_rest_template/blob/main/django_rest_template/wsgi.py"
    click ApplicationServer "https://github.com/huyhoangbcvt/django_rest_template/blob/main/django_rest_template/asgi.py"
    click UserApp "https://github.com/huyhoangbcvt/django_rest_template/tree/main/user_app/"
    click AuthService "https://github.com/huyhoangbcvt/django_rest_template/blob/main/user_app/api/services_auth.py"
    click UserSerializers "https://github.com/huyhoangbcvt/django_rest_template/tree/main/user_app/serializers/"
    click UserURLs "https://github.com/huyhoangbcvt/django_rest_template/blob/main/user_app/urls.py"
    click UserModules "https://github.com/huyhoangbcvt/django_rest_template/tree/main/user_app/modules/"
    click UserTemplates "https://github.com/huyhoangbcvt/django_rest_template/tree/main/user_app/templates/"
    click CatalogApp "https://github.com/huyhoangbcvt/django_rest_template/tree/main/catalog_app/"
    click CategoryWS "https://github.com/huyhoangbcvt/django_rest_template/blob/main/catalog_app/apis/category_ws.py"
    click ProductWS "https://github.com/huyhoangbcvt/django_rest_template/blob/main/catalog_app/apis/product_ws.py"
    click CatalogSerializers "https://github.com/huyhoangbcvt/django_rest_template/tree/main/catalog_app/serializers/"
    click CatalogURLs "https://github.com/huyhoangbcvt/django_rest_template/blob/main/catalog_app/urls.py"
    click CatalogModules "https://github.com/huyhoangbcvt/django_rest_template/tree/main/catalog_app/modules/"
    click CatalogTemplates "https://github.com/huyhoangbcvt/django_rest_template/tree/main/catalog_app/templates/"
    click CatalogUtil "https://github.com/huyhoangbcvt/django_rest_template/tree/main/catalog_app/util/"
    click UploadApp "https://github.com/huyhoangbcvt/django_rest_template/tree/main/upload_app/"
    click UploadViews "https://github.com/huyhoangbcvt/django_rest_template/blob/main/upload_app/views.py"
    click UploadForms "https://github.com/huyhoangbcvt/django_rest_template/blob/main/upload_app/forms.py"
    click UploadURLs "https://github.com/huyhoangbcvt/django_rest_template/blob/main/upload_app/urls.py"
    click UploadTemplates "https://github.com/huyhoangbcvt/django_rest_template/tree/main/upload_app/templates/upload_app/"
    click MediaStorage "https://github.com/huyhoangbcvt/django_rest_template/tree/main/media/"
    click StaticFiles "https://github.com/huyhoangbcvt/django_rest_template/tree/main/static/"

    %% Styles
    classDef frontend fill:#D6E9FE,stroke:#333,stroke-width:1px
    classDef backend fill:#DFF2BF,stroke:#333,stroke-width:1px
    classDef data fill:#FEEFB3,stroke:#333,stroke-width:1px
```
