# lechiluan/ecommerce architecture

> Architecture diagram of the GitHub repository lechiluan/ecommerce, 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/lechiluan/ecommerce
- Repository: https://github.com/lechiluan/ecommerce

## Overview

##### Project Overview & Architecture
- This project is a full-stack e-commerce system built with Python and Django. It is divided into multiple Django apps – primarily "customer", "dashboard", and "main" – each responsible for different aspects of the overall system.
- Its purpose is to provide a comprehensive online shopping experience: customers can browse, search, order products and interact with an integrated chatbot; administrators manage products, orders, customers, and see analytics.
- The system uses standard Django architecture (MTV pattern) with clearly separated frontend and backend logic.

##### Primary System Components
a. Client/Browser:
- Represents users interacting with the system.
- Both “Customer” and “Administrator” roles.
b. Web Server / Django Application:
- Consists of several Django apps:
▪ Customer App: Contains views, templates, and static files designed for customer-facing pages (shopping, cart, checkout, registration, login, product filtering, etc.).
▪ Dashboard App: Provides the administrator interface for managing products, orders, payments, customers, sales statistics, and chatbot management.
▪ Main App: Contains core functionalities, user registration, and shared components like contextual processors.
- The central project configuration is managed through the “ecommerce” directory (settings, URL configurations, WSGI/ASGI) which routes requests appropriately.
c. Database:
- The application uses PostgreSQL in production (Heroku) but also includes a local SQLite database for development/testing (db.sqlite3).
d. External Services & Cloud Integration:
- Cloudinary: For image storage.
- Email Service: For password resets, account verifications and notifications.
- reCaptcha: To verify human users during login/registration.
- Chatbot Integration: Managed through Dialogflow via the dashboard.
- Deployment Platforms: Heroku (primary) and Railway (backup).
e. Static & Media Files:
- Static assets are segmented into static directories (per app and central staticfiles) covering CSS, JavaScript, and images.
- Media directory holds uploaded images like brand logos, product images, and customer images.

##### Relationships and Data Flow
- Client requests travel via the Django routing (configured in ecommerce/urls.py, main/urls.py, customer/urls.py, dashboard/urls.py) and are handled by the relevant app’s views.
- Business logic in each Django app interacts with models that persist data to the database.
- For customer functions (product browsing, cart management, checkout), interactions flow from the browser, through the customer or main app, and update the database.
- Administrative functions (managing products, orders, reviews, chatbot) are processed in the dashboard app and access the same central database.
- External interactions include sending emails (triggered upon registration or order placement) and transferring images to Cloudinary.

##### Architectural Patterns & Design Principles
- Adoption of the Django MTV (Model-Template-View) pattern.
- Separation of concerns: distinct Django apps are deployed to isolate customer versus admin functionalities.
- Environment variable configuration (.env file for sensitive data) for external services (email, database, Cloudinary).
- Use of version control (Git) and deployment pipelines (Procfile, runtime.txt for Heroku).

##### Final Touches
- Frontend (client/browser interfaces)
- Backend services (Django apps, business logic)
- Databases and external integrations
- Detailed interfaces showing how a customer flow (like placing an order) and an admin flow (like viewing sales statistics or managing products) traverse multiple components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients"
        CB["Customer Browser"]:::frontend
        AB["Admin Browser"]:::frontend
    end

    %% Web Server / Django Application Layer
    subgraph "Web Server / Django Application"
        DP["Django Project (ecommerce)"]:::backend
        CA["Customer App"]:::backend
        DA["Dashboard App"]:::backend
        MA["Main App"]:::backend
    end

    %% Database Layer
    DB["PostgreSQL/SQLite"]:::database

    %% External Services Layer
    subgraph "External Services"
        CL["Cloudinary"]:::external
        ES["Email Service"]:::external
        RC["reCaptcha"]:::external
        CBOT["Chatbot Integration"]:::external
    end

    %% Deployment Platforms Layer
    subgraph "Deployment Platforms"
        H["Heroku"]:::external
        R["Railway"]:::external
    end

    %% Static & Media Files Layer
    subgraph "Static & Media Files"
        SF["Static Files"]:::backend
        MF["Media Files"]:::backend
    end

    %% Deployment Configuration Nodes
    DC1["Procfile"]:::backend
    DC2["runtime.txt"]:::backend

    %% Data Flow and Relationships
    CB -->|"HTTP_requests"| DP
    AB -->|"HTTP_requests"| DP

    DP -->|"RoutesTo"| CA
    DP -->|"RoutesTo"| DA
    DP -->|"RoutesTo"| MA

    CA -->|"UpdatesDB"| DB
    DA -->|"UpdatesDB"| DB
    MA -->|"UpdatesDB"| DB

    CA -->|"UploadsImages"| CL
    CA -->|"SendsEmail"| ES

    DA -->|"DisplaysChatbot"| CBOT

    CB -->|"reCaptchaCheck"| RC
    AB -->|"reCaptchaCheck"| RC

    DP -->|"DeployedOn"| H
    DP -->|"DeployedOn"| R

    DP -->|"Serves"| SF
    DP -->|"Serves"| MF

    DP -->|"ConfiguredWith"| DC1
    DP -->|"ConfiguredWith"| DC2

    %% Click Events for Component Mapping
    click CA "https://github.com/lechiluan/ecommerce/tree/main/customer/"
    click DA "https://github.com/lechiluan/ecommerce/tree/main/dashboard/"
    click MA "https://github.com/lechiluan/ecommerce/tree/main/main/"
    click DP "https://github.com/lechiluan/ecommerce/tree/main/ecommerce/"
    click DB "https://github.com/lechiluan/ecommerce/blob/main/db.sqlite3"
    click CL "https://github.com/lechiluan/ecommerce/tree/main/staticfiles/cloudinary/"
    click ES "https://github.com/lechiluan/ecommerce/blob/main/ecommerce/settings.py"
    click CBOT "https://github.com/lechiluan/ecommerce/tree/main/dashboard/templates/dashboard/chatbot/"
    click DC1 "https://github.com/lechiluan/ecommerce/tree/main/Procfile"
    click DC2 "https://github.com/lechiluan/ecommerce/blob/main/runtime.txt"
    click SF "https://github.com/lechiluan/ecommerce/tree/main/static/"
    click MF "https://github.com/lechiluan/ecommerce/tree/main/media/"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
```
