# m0hit5/django-ecommerce architecture

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

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

## Overview

##### Project Type and Purpose
- This is a monolithic Django-based full-stack e-commerce web application.
- Key features: user accounts, product categories, shopping cart, orders, payments, reviews, email notifications, static/media asset management.
- Deployed on AWS Elastic Beanstalk (EB), likely using RDS (PostgreSQL/MySQL), S3 for media, and SMTP for email.

##### Main Architectural Tiers
A. Presentation Layer (Client)
– Web browser or mobile client
– Static assets (CSS, JS, fonts, images) delivered via CDN or EB’s static file host
B. Application Layer (Django Monolith)
– WSGI/ASGI server (Gunicorn/Uvicorn) running Django project “greatkart”
– Django apps as logical sub‐components:
- accounts (authentication, profiles, email verification)
- store (product listing, variations, gallery, reviews)
- category (product categorization, context processors)
- carts (add/remove items, context data)
- orders (checkout, payment processing, order lifecycle, invoices)
– Templates & Context Processors for dynamic HTML generation
C. Data Layer
– Relational Database (PostgreSQL/MySQL) for models in each app
– File Storage (AWS S3 or local MEDIA_ROOT) for product images, user avatars
D. External Services
– SMTP Email Service (Gmail SMTP or AWS SES) for order notifications, password resets
– Payment Gateway (Stripe/PayPal) invoked in orders/forms and views
– AWS Elastic Beanstalk for hosting, ELB/ALB for load balancing, Auto Scaling

##### Component Relationships & Data Flow
1. Client → Load Balancer → WSGI/ASGI Server
2. WSGI/ASGI → Django URL Router → App Views → Business Logic (models/forms)
3. Business Logic ↔ Database (ORM)
4. Business Logic ↔ File Storage (media files)
5. Views → Templates → HTML → Client
6. Cart updates, order placements trigger:
– Database writes (CartItem, Order, OrderProduct)
– Email Service call (send_mail)
– Payment Gateway API call
7. Static files served directly from CDN/S3

##### Architectural Patterns & Design Principles
- MVC (MTV) pattern via Django’s Model–Template–View separation
- Modular “apps” structure: each domain (accounts, store, carts, orders, category) encapsulates its own models, views, URLs, templates
- Context processors for injecting cart and category data into all templates
- Settings module for environment (SECRET_KEY, DEBUG, email credentials)
- Migrations for schema evolution

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    Client["Web Browser / Mobile Client"]:::frontend
    CDN["CDN / Static File Host"]:::frontend

    %% Load Balancer
    LB["AWS ALB / ELB"]:::internal

    %% Application Layer
    subgraph "Django Monolith" 
        direction TB
        AppServer["Gunicorn / Uvicorn"]:::internal
        subgraph "Django Project Configuration"
            direction TB
            Config["greatkart/"]:::internal
        end
        subgraph "Django Apps"
            direction TB
            Accounts["Accounts App"]:::internal
            Store["Store App"]:::internal
            Category["Category App"]:::internal
            Carts["Carts App"]:::internal
            Orders["Orders App"]:::internal
        end
        subgraph "Templates & Static"
            direction TB
            Templates["templates/"]:::internal
            StaticFiles["static/"]:::internal
            MediaFiles["media/"]:::internal
        end
        Config -->|loads settings| AppServer
        AppServer --> Accounts
        AppServer --> Store
        AppServer --> Category
        AppServer --> Carts
        AppServer --> Orders
        AppServer --> Templates
        Templates --> StaticFiles
        Templates --> MediaFiles
    end

    %% Data Layer
    DB["RDS (PostgreSQL/MySQL)"]:::storage
    S3["S3 Bucket (Media)"]:::storage

    %% External Services
    SMTP["SMTP Email Service"]:::external
    Payment["Payment Gateway API"]:::external

    %% Data Flows
    Client -->|HTTPS| LB
    LB -->|HTTPS| AppServer
    AppServer -->|SQL| DB
    AppServer -->|S3 API| S3
    AppServer -->|SMTP| SMTP
    AppServer -->|REST API| Payment
    Client -->|HTTP GET static| CDN
    CDN --> StaticFiles

    %% Config & Env
    Env[".env-sample"]:::config
    Req["requirements.txt"]:::config
    Readme["README.md"]:::config
    Env --> Config
    Req --> Config
    Readme --> Config

    %% Click Events
    click Config "https://github.com/m0hit5/django-ecommerce/blob/main/greatkart/settings.py"
    click StaticFiles "https://github.com/m0hit5/django-ecommerce/tree/main/greatkart/static/"
    click StaticFiles "https://github.com/m0hit5/django-ecommerce/tree/main/static/"
    click MediaFiles "https://github.com/m0hit5/django-ecommerce/tree/main/media/"
    click Accounts "https://github.com/m0hit5/django-ecommerce/tree/main/accounts/"
    click Store "https://github.com/m0hit5/django-ecommerce/tree/main/store/"
    click Category "https://github.com/m0hit5/django-ecommerce/tree/main/category/"
    click Carts "https://github.com/m0hit5/django-ecommerce/tree/main/carts/"
    click Orders "https://github.com/m0hit5/django-ecommerce/tree/main/orders/"
    click Templates "https://github.com/m0hit5/django-ecommerce/tree/main/templates/"
    click Env "https://github.com/m0hit5/django-ecommerce/blob/main/.env-sample"
    click Req "https://github.com/m0hit5/django-ecommerce/blob/main/requirements.txt"
    click Readme "https://github.com/m0hit5/django-ecommerce/blob/main/README.md"

    %% Styles
    classDef frontend fill:#D0E6F7,stroke:#4A90E2,color:#4A90E2;
    classDef internal fill:#E2F7D0,stroke:#7ED321,color:#7ED321;
    classDef storage fill:#F7E2D0,stroke:#F5A623,color:#F5A623,stroke-dasharray: 5 5;
    classDef external fill:#F7D0D0,stroke:#D0021B,color:#D0021B,stroke-dasharray: 5 5;
    classDef config fill:#F2F2F2,stroke:#9B9B9B,color:#9B9B9B;
```
