# khoaxuandang/python-django-ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/khoaxuandang/python-django-ecommerce
- Repository: https://github.com/khoaxuandang/python-django-ecommerce

## Overview

##### Project type and purpose
- This is a monolithic, full-stack Django e-commerce application.
- Purpose: allow users to browse products (by category), manage their cart, place orders, and handle user accounts (registration, login, password reset).

##### File structure
- Top-level Django project: greatkart/ (contains settings.py, urls.py, ASGI/WSGI entry points).
- Five domain apps under project root:
- accounts (user management)
- carts (shopping-cart logic)
- category (product categorization)
- orders (order processing, payments)
- store (product listing and detail)
- Shared resources:
- templates/ (HTML with Django template inheritance)
- static/ & greatkart/static/ (CSS, JS, fonts, images)
- Configuration files: manage.py, .gitignore

##### README for additional insights
- Confirms feature set: product browsing, cart, checkout, admin panel.
- Uses Django’s ORM, built-in admin, context processors, forms, and email for notifications.

##### Architectural pattern and layers
The project follows Django’s MTV (Model-Template-View) pattern within a layered architecture. We’ll further subdivide into six layers:

A. Presentation (UI) Layer
- Templates (templates/*.html)
- Static assets (CSS, JS, fonts, images in static/ and greatkart/static/)

B. Web Framework Layer
- URL Dispatcher (greatkart/urls.py + each app’s urls.py)
- Middleware & Context Processors (e.g., carts/context_processors.py, category/context_processors.py)
- Request/Response Handling (ASGI/WSGI entry points)

C. Application (Service) Layer
- Views (accounts/views.py, store/views.py, orders/views.py, etc.)
- Forms (accounts/forms.py, orders/forms.py, store/forms.py)
- Business Logic orchestrating models and external calls

D. Domain (Model) Layer
- Models (accounts/models.py, carts/models.py, etc.)
- Migrations (app/migrations/)

E. Data Access Layer
- Django ORM (database connection via settings.py)
- QuerySets, model managers

F. Infrastructure & External Services
- Database (PostgreSQL/MySQL/SQLite configured in settings.py)
- Static file storage (local filesystem or CDN)
- Email server (SMTP for password reset & order notifications)
- Optional: Payment gateway API (integrated via orders app)

##### Main components & interactions
1. Web Browser (client)
– Sends HTTP(S) requests
– Renders HTML/CSS/JS
2. Load Balancer / Web Server (optional in deployment)
– Routes to the Django application
3. Django Application
– URL Dispatcher → Middleware → Views
– Views invoke Forms & Models
– Models persist or fetch data via ORM
4. Database
– Stores user, product, cart, order, category data
5. Static File Server / CDN
– Serves CSS, JS, images, fonts
6. Email Service (SMTP)
– Sends verification, password reset, order emails
7. (Optional) Payment Gateway
– Processes payments during checkout

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["Web Browser"]:::external

    %% Deployment
    LB["Load Balancer / Web Server"]:::infra

    %% A. Presentation Layer
    subgraph "A. Presentation Layer"
        Templates["Templates (templates/*.html)"]:::template
        StaticProj["Project Static (static/)"]:::template
        StaticApp["App Static (greatkart/static/)"]:::template
    end

    %% B. Web Framework Layer
    subgraph "B. Web Framework Layer"
        ASGI["ASGI Entry"]:::service
        WSGI["WSGI Entry"]:::service
        URLsRoot["Root URLs"]:::service
        URLsAcc["accounts URLs"]:::service
        URLsCarts["carts URLs"]:::service
        URLsCat["category URLs"]:::service
        URLsOrders["orders URLs"]:::service
        URLsStore["store URLs"]:::service
        CP_Carts["carts Context Processor"]:::service
        CP_Cat["category Context Processor"]:::service
    end

    %% C. Application (Service) Layer
    subgraph "C. Application (Service) Layer"
        ViewsAcc["accounts Views"]:::service
        ViewsCarts["carts Views"]:::service
        ViewsCat["category Views"]:::service
        ViewsOrders["orders Views"]:::service
        ViewsStore["store Views"]:::service
        FormsAcc["accounts Forms"]:::service
        FormsOrders["orders Forms"]:::service
        FormsStore["store Forms"]:::service
    end

    %% D. Domain (Model) Layer
    subgraph "D. Domain (Model) Layer"
        ModelsAcc["accounts Models"]:::model
        ModelsCarts["carts Models"]:::model
        ModelsCat["category Models"]:::model
        ModelsOrders["orders Models"]:::model
        ModelsStore["store Models"]:::model
        MigrationsAcc["accounts Migrations"]:::model
        MigrationsCarts["carts Migrations"]:::model
        MigrationsCat["category Migrations"]:::model
        MigrationsOrders["orders Migrations"]:::model
        MigrationsStore["store Migrations"]:::model
    end

    %% E. Data Access Layer
    subgraph "E. Data Access Layer"
        ORM["Django ORM & DB Settings"]:::service
    end

    %% F. Infrastructure & External Services
    subgraph "F. Infrastructure & External Services"
        DB["Database"]:::db
        StaticServer["Static File Server / CDN"]:::infra
        SMTP["Email Service (SMTP)"]:::external
        Payment["Payment Gateway API"]:::external
        Manage["manage.py"]:::infra
        GitIgnore[".gitignore"]:::infra
        Readme["README.md"]:::infra
    end

    %% Connections
    Client --> LB
    LB --> ASGI
    LB --> WSGI
    ASGI --> URLsRoot
    WSGI --> URLsRoot
    URLsRoot --> URLsAcc
    URLsRoot --> URLsCarts
    URLsRoot --> URLsCat
    URLsRoot --> URLsOrders
    URLsRoot --> URLsStore
    URLsRoot --> CP_Carts
    URLsRoot --> CP_Cat
    URLsRoot --> ViewsAcc
    URLsRoot --> ViewsCarts
    URLsRoot --> ViewsCat
    URLsRoot --> ViewsOrders
    URLsRoot --> ViewsStore
    ViewsAcc --> FormsAcc
    ViewsAcc --> ModelsAcc
    ViewsCarts --> FormsAcc
    ViewsCarts --> ModelsCarts
    ViewsCat --> ModelsCat
    ViewsOrders --> FormsOrders
    ViewsOrders --> ModelsOrders
    ViewsStore --> FormsStore
    ViewsStore --> ModelsStore
    ModelsAcc --> ORM
    ModelsCarts --> ORM
    ModelsCat --> ORM
    ModelsOrders --> ORM
    ModelsStore --> ORM
    ORM --> DB
    Client --> StaticServer
    StaticServer --> StaticProj
    StaticServer --> StaticApp
    ViewsOrders --> SMTP
    ViewsOrders --> Payment

    %% Click Events
    click Templates "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/templates/"
    click StaticProj "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/static/"
    click StaticApp "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/greatkart/static/"
    click URLsRoot "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/greatkart/urls.py"
    click URLsAcc "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/accounts/urls.py"
    click URLsCarts "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/carts/urls.py"
    click URLsCat "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/category/urls.py"
    click URLsOrders "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/orders/urls.py"
    click URLsStore "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/store/urls.py"
    click ASGI "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/greatkart/asgi.py"
    click WSGI "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/greatkart/wsgi.py"
    click CP_Carts "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/carts/context_processors.py"
    click CP_Cat "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/category/context_processors.py"
    click ViewsAcc "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/accounts/views.py"
    click ViewsCarts "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/carts/views.py"
    click ViewsCat "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/category/views.py"
    click ViewsOrders "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/orders/views.py"
    click ViewsStore "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/store/views.py"
    click FormsAcc "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/accounts/forms.py"
    click FormsOrders "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/orders/forms.py"
    click FormsStore "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/store/forms.py"
    click ModelsAcc "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/accounts/models.py"
    click ModelsCarts "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/carts/models.py"
    click ModelsCat "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/category/models.py"
    click ModelsOrders "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/orders/models.py"
    click ModelsStore "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/store/models.py"
    click MigrationsAcc "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/accounts/migrations/"
    click MigrationsCarts "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/carts/migrations/"
    click MigrationsCat "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/category/migrations/"
    click MigrationsOrders "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/orders/migrations/"
    click MigrationsStore "https://github.com/khoaxuandang/python-django-ecommerce/tree/main/store/migrations/"
    click ORM "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/greatkart/settings.py"
    click Manage "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/manage.py"
    click GitIgnore "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/.gitignore"
    click Readme "https://github.com/khoaxuandang/python-django-ecommerce/blob/main/README.md"

    %% Styles
    classDef template fill:#ffeb3b,stroke:#333,stroke-width:1px
    classDef service fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef model fill:#90caf9,stroke:#333,stroke-width:1px
    classDef db fill:#a5d6a7,stroke:#333,stroke-width:1px
    classDef external fill:#ffe082,stroke:#333,stroke-width:1px
    classDef infra fill:#fff59d,stroke:#333,stroke-width:1px
```
