# 64-hirobyte/django_ec architecture

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

- Interactive diagram: https://gitdiagram.com/64-hirobyte/django_ec
- Repository: https://github.com/64-hirobyte/django_ec

## Overview

##### Project Type and Purpose
- This is a monolithic, full-stack Django e-commerce application, containerized with Docker Compose.
- It provides user account management (accounts), product cataloging and administration (item_management, shop), shopping cart (cart), order processing (purchase), and promotional code capabilities (promotion).

##### File Structure Analysis
- Top-level Docker and deployment configs: Dockerfile, docker-compose.yml, Procfile, .env.
- Django project root under “config/”: ASGI/WGSI entrypoints, settings per environment (base, local, production), URL dispatcher, and shared templates.
- Six Django apps, each representing a business domain:
- accounts (authentication/authorization)
- item_management (CRUD for items)
- shop (public-facing product listing/detail)
- cart (shopping cart lifecycle)
- purchase (order creation, payment, mail, management commands)
- promotion (coupon generation, application)
- Shared static files (CSS/JS) and templates per app, organized under static/ and templates/.
- requirements.txt/runtime.txt define Python dependencies and runtime versions.

##### Key Insights from README
- Uses Postgres, configured via DATABASE_URL in .env.
- Docker Compose orchestrates two services: “web” (Django app) and “db” (Postgres).
- Exposes port 3000 for web; verifies setup via a simple /hello endpoint.

##### Main Components
a. External Clients
- Web Browser (or Mobile App)
b. Web Layer (Docker “web” service)
- Gunicorn/ASGI server
- Django project (config + six apps)
- Static file handler (e.g., WhiteNoise or Django staticfiles)
c. Data Layer
- PostgreSQL Database (Docker “db” service)
d. Environment & Deployment
- Docker Compose network
- Environment variables (.env)
- Procfile (Heroku compatibility)

##### Component Relationships and Data Flows
- Client → HTTP(S) → Gunicorn/ASGI → Django URL router (config/urls.py)
- URL router dispatches to app-specific views (accounts.views, shop.views, etc.)
- Views orchestrate business logic, call models via Django ORM → SQL queries → Postgres
- For order processing, views may invoke management commands (load_prefectures, promotion_code_generate) or send emails via Django’s email backend
- Static assets served directly by WhiteNoise or via a CDN in production
- Docker Compose bridges “web” and “db” on an internal network; web reads DATABASE_URL

##### Architectural Patterns and Principles
- MVC/MVT:
- Models layer under each app/models.py
- Views/controllers under views.py and forms.py
- Templates under templates/…
- Single codebase, well-encapsulated modular apps by domain
- Environment-specific configuration isolation (base/local/production)
- Stateless web containers, state persisted in Postgres
- Batch tasks via Django management commands

##### Technologies and Frameworks
- Python/Django (with apps for each bounded context)
- Gunicorn or Uvicorn ASGI server
- PostgreSQL
- Docker & Docker Compose
- WhiteNoise (static files) or external CDN in production
- HTML/CSS/JS for front-end delivered via Django templates

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        browser["Web Browser"]:::actor
    end

    %% CDN and Email
    CDN["CDN (Static Assets)"]:::infra
    SMTP["Email SMTP Server"]:::infra

    %% Docker Compose Boundary
    subgraph "Docker Compose Network" 
        direction TB
        subgraph "Service: db" 
            style dbContainer fill:#E8F8F5,stroke:#1ABC9C
            db["PostgreSQL Database"]:::db
        end

        subgraph "Service: web"
            style webContainer fill:#E8F8,stroke:#27AE60
            webServer["Gunicorn/ASGI Server & Django"]:::container

            %% Config & Entrypoints
            subgraph "Config & Entrypoints"
                asgi["ASGI Entry Point"]:::module
                wsgi["WSGI Entry Point"]:::module
                urls["URL Router"]:::module
                baseSettings["Base Settings"]:::module
                localSettings["Local Settings"]:::module
                prodSettings["Production Settings"]:::module
                templatesHello["Shared Template: hello.html"]:::module
            end

            %% Django Apps
            subgraph "Django Apps"
                accountsApp["accounts (User Management)"]:::module
                itemMgmtApp["item_management (Product CRUD)"]:::module
                shopApp["shop (Public Catalog)"]:::module
                cartApp["cart (Shopping Cart)"]:::module
                purchaseApp["purchase (Orders & Payments)"]:::module
                promoApp["promotion (Coupons & Discounts)"]:::module
            end

            %% Static Handler
            staticHandler["WhiteNoise Static Handler"]:::module

            %% Management Commands
            subgraph "Management Commands"
                loadPref["load_prefectures"]:::module
                genPromo["promotion_code_generate"]:::module
            end

            %% Project Entrypoint
            manage["manage.py"]:::module

            %% Deployment & Environment
            subgraph "Env & Deployment"
                dockerfile["Dockerfile"]:::infra
                compose["docker-compose.yml"]:::infra
                procfile["Procfile"]:::infra
                envFile[".env"]:::infra
            end
        end
    end

    %% Connections
    browser -->|"HTTP(S) Request"| webServer
    webServer -->|routes via URL Router| urls
    urls --> accountsApp
    urls --> itemMgmtApp
    urls --> shopApp
    urls --> cartApp
    urls --> purchaseApp
    urls --> promoApp

    webServer -->|serves static| staticHandler
    staticHandler --> CDN
    CDN --> browser

    webServer -->|ORM queries| db
    loadPref --> db
    genPromo --> db

    purchaseApp -->|sends email| SMTP

    %% Entrypoints to Core
    webServer --> asgi
    webServer --> wsgi
    webServer --> baseSettings
    webServer --> localSettings
    webServer --> prodSettings
    webServer --> templatesHello

    %% Entrypoint script
    webServer --> manage

    %% Deployment files connected
    webServer --> dockerfile
    webServer --> compose
    webServer --> procfile
    webServer --> envFile

    %% Click Events
    click dockerfile "https://github.com/64-hirobyte/django_ec/tree/main/Dockerfile"
    click compose "https://github.com/64-hirobyte/django_ec/blob/main/docker-compose.yml"
    click procfile "https://github.com/64-hirobyte/django_ec/tree/main/Procfile"
    click envFile "https://github.com/64-hirobyte/django_ec/blob/main/.env"
    click asgi "https://github.com/64-hirobyte/django_ec/blob/main/config/asgi.py"
    click wsgi "https://github.com/64-hirobyte/django_ec/blob/main/config/wsgi.py"
    click urls "https://github.com/64-hirobyte/django_ec/blob/main/config/urls.py"
    click baseSettings "https://github.com/64-hirobyte/django_ec/blob/main/config/settings/base.py"
    click localSettings "https://github.com/64-hirobyte/django_ec/blob/main/config/settings/local.py"
    click prodSettings "https://github.com/64-hirobyte/django_ec/blob/main/config/settings/production.py"
    click templatesHello "https://github.com/64-hirobyte/django_ec/blob/main/config/templates/hello.html"
    click accountsApp "https://github.com/64-hirobyte/django_ec/blob/main/accounts/apps.py"
    click itemMgmtApp "https://github.com/64-hirobyte/django_ec/blob/main/item_management/apps.py"
    click shopApp "https://github.com/64-hirobyte/django_ec/blob/main/shop/apps.py"
    click cartApp "https://github.com/64-hirobyte/django_ec/blob/main/cart/apps.py"
    click purchaseApp "https://github.com/64-hirobyte/django_ec/blob/main/purchase/apps.py"
    click promoApp "https://github.com/64-hirobyte/django_ec/blob/main/promotion/apps.py"
    click loadPref "https://github.com/64-hirobyte/django_ec/blob/main/purchase/management/commands/load_prefectures.py"
    click genPromo "https://github.com/64-hirobyte/django_ec/blob/main/promotion/management/commands/promotion_code_generate.py"
    click manage "https://github.com/64-hirobyte/django_ec/blob/main/manage.py"

    %% Styles
    classDef actor fill:#ADD8E6,stroke:#0366d6
    classDef container fill:#90EE90,stroke:#2E8B57
    classDef module fill:#FFA500,stroke:#CD7F32
    classDef infra fill:#D3D3D3,stroke:#7F8C8D
    classDef db fill:#A2D9CE,stroke:#117A65
```
