# benfoxyy/django-online-shop architecture

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

- Interactive diagram: https://gitdiagram.com/benfoxyy/django-online-shop
- Repository: https://github.com/benfoxyy/django-online-shop

## Overview

##### Main Components
- Frontend Presentation Layer: Represent the HTML/CSS/JS templates, static files, and client-side interactions that present the user-facing interface (e.g., product lists, cart, checkout, dashboards).
- Django Backend: Highlight the “core” directory as the central hub composed of modular apps:
– Accounts (handles authentication, profiles, and user types)
– Cart (manages shopping cart logic)
– Dashboard (separates admin and customer interfaces)
– Order (order processing and management)
– Payment (integrates with ZarinPal and contains payment client logic)
– Review (customer feedback and review handling)
– Shop (product listing and detail APIs)
– Website (public site pages, sitemap, etc.)
- External Services:
– Cache (Redis for caching operations as noted in the README)
– Object Storage (MinIO for media file storage)
– Payment Gateway (ZarinPal integration)
– Security/Anti-bot service (reCAPTCHA v3)
- Deployment and Infrastructure:
– Docker containers: Separate containers for the backend (Django), the databases (PostgreSQL), the caching layer (Redis), MinIO, as well as for Nginx and Gunicorn in deployment.
– Nginx: As a reverse proxy and static file server.
– Gunicorn: For the WSGI application server.
– Docker compose setups: One for development and one for deployment.
- Additional Tools:
– Django Debug Toolbar (for development diagnostics)
– Pytest (for testing, as managed inside a container)

##### Relationships and Data Flow
- User Requests Flow: Users (of various types – customer, admin, superuser) initiate requests via their browsers. The requests first hit Nginx, which routes them to Gunicorn serving the Django application.
- Internal Module Interactions: Inside Django, modular apps communicate through URL routing (as seen in the file structure under “urls.py” of each module) and shared middleware (perhaps for caching with Redis).
- Data Persistence: The Django app interacts with the PostgreSQL database for core data and utilizes MinIO for media storage.
- Caching and Performance: Redis is used to cache commonly accessed data.
- Payment Process: The payment module communicates with external APIs like ZarinPal.
- Development vs. Production Modes: Note the separate Docker configurations and settings (development using the Django Debug Toolbar and local recaptcha keys versus production with Nginx/Gunicorn and secure settings).

##### Architectural Patterns and Technologies
- Modular/Django “Apps” Pattern: Each functional aspect (accounts, cart, etc.) is in its own Django app.
- MVC (or MVT in Django): Separate the concerns with models, templated views, and controllers.
- Containerized Deployment: Using Docker containers to isolate services (backend, database, cache, media store, proxy server).
- API Layer: Some modules (like the accounts and shop modules) include API endpoints (e.g., under “api/v1”), which indicates RESTful design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    subgraph "User Interaction"
        User["User (Customer/Admin)"]:::user
    end

    %% Edge Services
    subgraph "Edge Services"
        Nginx["Nginx (Reverse Proxy)"]:::infra
        Gunicorn["Gunicorn (WSGI Server)"]:::infra
    end

    User -->|"request"| Nginx
    Nginx -->|"forwards"| Gunicorn

    %% Django Application with Core Engine and Modules
    subgraph "Django Application"
        Core["Core Engine"]:::django
        CoreManage["manage.py"]:::django
        %% Link manage.py to Core Engine
        CoreManage --> Core

        subgraph "API Modules"
            Accounts["Accounts Module"]:::django
            Cart["Cart Module"]:::django
            Dashboard["Dashboard Module"]:::django
            Order["Order Module"]:::django
            Payment["Payment Module"]:::django
            PaymentClient["zarinpal_client.py"]:::django
            Review["Review Module"]:::django
            Shop["Shop Module"]:::django
            Website["Website Module"]:::django
        end

        %% Core Engine connects to each module
        Core --> Accounts
        Core --> Cart
        Core --> Dashboard
        Core --> Order
        Core --> Payment
        Core --> Review
        Core --> Shop
        Core --> Website
        PaymentClient --> Payment
    end

    Gunicorn -->|"executes"| Core

    %% Frontend Presentation Layer
    subgraph "Frontend Presentation Layer"
        Templates["Templates"]:::frontend
        Static["Static Files"]:::frontend
    end

    Templates -.->|"renders"| Core
    Static -.->|"provides-assets"| Core

    %% External Services
    subgraph "External Services"
        DB["PostgreSQL Database"]:::external
        Cache["Redis Cache"]:::external
        Storage["MinIO (Object Storage)"]:::external
        PaymentGW["ZarinPal Payment Gateway"]:::external
        reCAPTCHA["reCAPTCHA v3"]:::external
    end

    Core -->|"reads/writes"| DB
    Core -->|"caches"| Cache
    Core -->|"stores-media"| Storage
    Payment -->|"calls"| PaymentGW
    Core -->|"uses"| reCAPTCHA

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        DockerComposeDev["Docker Compose (Dev)"]:::infra
        DockerComposeProd["Docker Compose (Prod)"]:::infra
        DockerfileDev["Dockerfile (Dev)"]:::infra
        DockerfileProd["Dockerfile (Prod)"]:::infra
        NginxConf["Nginx Config"]:::infra
    end

    Nginx -->|"configured-by"| NginxConf
    DockerComposeDev -->|"orchestrates"| Nginx
    DockerComposeDev --> Core
    DockerComposeProd -->|"orchestrates"| Nginx
    DockerComposeProd --> Core
    DockerfileDev --> DockerComposeDev
    DockerfileProd --> DockerComposeProd

    %% Additional Tools
    subgraph "Additional Tools"
        DebugToolbar["Django Debug Toolbar"]:::tools
        Pytest["Pytest & Linters"]:::tools
    end

    Core -->|"debugs-using"| DebugToolbar
    Core -->|"testing-with"| Pytest

    %% Click Events for Component Mapping
    click Templates "https://github.com/benfoxyy/django-online-shop/tree/main/core/templates"
    click Static "https://github.com/benfoxyy/django-online-shop/tree/main/core/static"
    click Core "https://github.com/benfoxyy/django-online-shop/tree/main/core/core"
    click CoreManage "https://github.com/benfoxyy/django-online-shop/blob/main/core/manage.py"
    click Accounts "https://github.com/benfoxyy/django-online-shop/tree/main/core/accounts"
    click Cart "https://github.com/benfoxyy/django-online-shop/tree/main/core/cart"
    click Dashboard "https://github.com/benfoxyy/django-online-shop/tree/main/core/dashboard"
    click Order "https://github.com/benfoxyy/django-online-shop/tree/main/core/order"
    click Payment "https://github.com/benfoxyy/django-online-shop/tree/main/core/payment"
    click PaymentClient "https://github.com/benfoxyy/django-online-shop/blob/main/core/payment/zarinpal_client.py"
    click Review "https://github.com/benfoxyy/django-online-shop/tree/main/core/review"
    click Shop "https://github.com/benfoxyy/django-online-shop/tree/main/core/shop"
    click Website "https://github.com/benfoxyy/django-online-shop/tree/main/core/website"
    click DockerComposeDev "https://github.com/benfoxyy/django-online-shop/blob/main/docker-compose.yml"
    click DockerComposeProd "https://github.com/benfoxyy/django-online-shop/blob/main/docker-compose-deployment.yml"
    click DockerfileDev "https://github.com/benfoxyy/django-online-shop/tree/main/dockerfiles/development/django/Dockerfile"
    click DockerfileProd "https://github.com/benfoxyy/django-online-shop/tree/main/dockerfiles/deployment/django/Dockerfile"
    click NginxConf "https://github.com/benfoxyy/django-online-shop/blob/main/default.conf"
    click Pytest "https://github.com/benfoxyy/django-online-shop/blob/main/core/pytest.ini"
    click DebugToolbar "https://github.com/benfoxyy/django-online-shop/tree/main/core/static/debug_toolbar"

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef django fill:#ccf,stroke:#333,stroke-width:2px;
    classDef external fill:#bfb,stroke:#333,stroke-width:2px;
    classDef infra fill:#fbb,stroke:#333,stroke-width:2px;
    classDef tools fill:#ffc,stroke:#333,stroke-width:2px;
```
