# sarishtshreshth0/ecommerce architecture

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

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

## Overview

##### Project Type & Purpose
- This is a full‑stack Flask e‑commerce web application with user authentication, profile management, contact/ticket features, and email OTP verification. It uses MongoDB for persistence and Gmail SMTP for email services.

##### File Structure Analysis
- Top-level:
- app.py – main Flask application and route definitions
- requirements.txt, Procfile – dependencies & deployment hints
- templates/ – Jinja2 HTML views (login, signup, product list, cart, profile, contact, OTP, reset password, etc.)

- No separate “static” folder implies CSS/JS may be inlined or served elsewhere; templates drive the UI.

##### Key Technologies & Patterns
- Flask (request routing, session management via Flask-Session)
- MongoDB (via PyMongo) with three collections: db_user, db_otp, db_contact
- Flask‑Mail for SMTP email
- MVC‑style:
- Views = HTML templates
- Controllers = Flask route functions in app.py
- Model = MongoDB collections

##### Main Components for the Flowchart
A. User Browser (UI)
B. Flask Application Server
– Route Handlers (login, signup, verify, contact, ticket raise, settings)
– OTP & Email Functions (send_otp, send_mail)
C. MongoDB
– db_user, db_otp, db_contact
D. External Email Service
– Gmail SMTP

##### Component Interactions & Data Flows
1. User → HTTP Request → Flask Route
2. Flask Route ↔ MongoDB (read/write user, OTP, contact data)
3. OTP route → send_otp() → store OTP in db_otp → send_mail() → Gmail SMTP → User Email
4. Contact form route → store message in db_contact → send_mail() (optional)
5. Flask → HTTP Response → User Browser

##### Architectural Patterns & Design Principles
- Stateless HTTP with session cookies stored by Flask-Session
- Separation of concerns: routing, business logic, data access
- Use environment variables for secrets (not hard‑coded)
- Simple MVC in a monolithic service

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        Browser["User Browser (UI)"]:::rectangle
        Templates["Jinja2 Templates"]:::rectangle
        NoteUI["Templates: login, signup, product, cart, profile, contact, OTP, reset"]:::note
    end

    %% Application Layer
    subgraph "Application Layer"
        FlaskApp["Flask Application Server"]:::rectangle
        NoteApp["Libraries: Flask-Mail, PyMongo, Flask-Session"]:::note
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoDB[("MongoDB\n(db_user, db_otp, db_contact)")]:::cylinder
    end

    %% External Services
    subgraph "External Services"
        Gmail["Gmail SMTP"]:::cloud
    end

    %% Connections
    Browser -->|"1. HTTP Request\n(e.g., POST /login)"| FlaskApp
    FlaskApp -->|"2. HTTP Response"| Browser
    FlaskApp -->|"3. MongoDB find()/insert()"| MongoDB
    FlaskApp -->|"4. store OTP"| MongoDB
    FlaskApp -->|"5. SMTP send"| Gmail
    Gmail -->|"6. deliver OTP email"| Browser

    %% Click Events
    click FlaskApp "https://github.com/sarishtshreshth0/ecommerce/blob/main/app.py"
    click Templates "https://github.com/sarishtshreshth0/ecommerce/tree/main/templates/"
    click MongoDB "https://github.com/sarishtshreshth0/ecommerce/blob/main/app.py"
    click Gmail "https://github.com/sarishtshreshth0/ecommerce/blob/main/app.py"
    click Requirements "https://github.com/sarishtshreshth0/ecommerce/blob/main/requirements.txt"
    click Procfile "https://github.com/sarishtshreshth0/ecommerce/tree/main/Procfile"
    click README "https://github.com/sarishtshreshth0/ecommerce/blob/main/README.md"

    %% Styles
    classDef rectangle fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef cylinder fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef cloud fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef note fill:#f9f,stroke:#333,stroke-width:1px,stroke-dasharray:5 5;
    class NoteUI,NoteApp note
```
