# rohitkeshri803/e-com-app architecture

> Architecture diagram of the GitHub repository rohitkeshri803/e-com-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohitkeshri803/e-com-app
- Repository: https://github.com/rohitkeshri803/e-com-app

## Overview

##### Project Type & Purpose
- Full-stack MERN (MongoDB / Express / React / Node.js) e-commerce app.
- Features: JWT-based auth, product/category management, shopping cart, payment integration, admin dashboard.

##### File Structure
- Top-Level:
- client/ → React frontend (Vite, JSX, CSS/Tailwind, contexts, hooks, pages, components)
- config/db.js → MongoDB connection
- controllers/ → Express route handlers (auth, category, product)
- middlewares/ → auth checks (JWT)
- models/ → Mongoose schemas (User, Product, Category, Order)
- routes/ → Express routers
- server.js → Entry point for backend
- Dependencies: dotenv, bcrypt, JWT, Axios on client, react-router.

##### Read README Insights
- Tech Stack confirms separation of concerns: React + React Router + Axios for UI/API calls; Express + JWT + Mongoose on the server.
- User vs Admin flows.

##### Main Components
a. Frontend (Browser/React App)
- Pages & Components grouped (Auth pages, Product pages, Cart, Admin dashboard)
- Contexts: AuthContext, CartContext, SearchContext
- API layer: Axios HTTP client
b. Backend API (Node.js/Express)
- Express Server → routes → controllers → models → MongoDB
- Middleware: JWT auth, role checks
c. Database
- MongoDB (hosted; shown as a single node or cluster)
d. External Services
- Payment gateway (Stripe/PayPal)
- Email service (if applicable)
e. Dev/Others
- dotenv for config
- ESLint/Vite in build/deploy pipeline

##### Relationships & Data Flow
- User Action → React UI → Axios → Express API endpoint
→ Middleware (auth/role) → Controller logic → Mongoose Model → MongoDB
← Data ← Mongoose Model ← Controller → JSON → React
- Cart & Auth state are stored in React Context providers.
- Admin requests follow same HTTP pipeline but hit admin-only routes.

##### Architectural Patterns & Principles
- Separation of Concerns:
- Presentation (React) vs Business Logic (Express controllers) vs Data Access (Mongoose)
- Layered Architecture (API layer, Service layer, Data layer)
- Token-based Authentication (JWT in headers)
- Component-based UI (React)
- Context API for state management (cart, auth, search)

##### Final Recommendations
- Both happy and error flows (e.g., unauthorized → 401).
- Related endpoints (products, categories, orders) inside the API block.
- Where environment variables are used (DB URI, JWT secret).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    UserBrowser["User Browser"]:::actor

    %% Frontend Layer
    subgraph "Frontend (React App)"
        direction TB
        Pages["Pages"]:::frontend
        Components["Components"]:::frontend
        Contexts["Context Providers"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        Styles["Stylesheets"]:::frontend
        EntryIndex["index.jsx"]:::frontend
        EntryMain["main.jsx"]:::frontend
        AdminRoute["AdminRoute.jsx"]:::frontend
        PrivateRoute["Private.jsx"]:::frontend
        Axios["API Layer (Axios)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        Server["Express Server"]:::backend
        DBConfig["MongoDB Config (db.js)"]:::backend
        subgraph "Routes"
            AuthRoute["authRoute.js"]:::backend
            CategoryRoute["categoryRoutes.js"]:::backend
            ProductRoute["productRoute.js"]:::backend
        end
        subgraph "Controllers"
            AuthController["authController.js"]:::backend
            CategoryController["categoryController.js"]:::backend
            ProductController["productController.js"]:::backend
        end
        Middleware["authMiddleware.js"]:::backend
        Helper["authHelper.js"]:::backend
        subgraph "Models"
            UserModel["userModels.js"]:::backend
            ProductModel["productModel.js"]:::backend
            CategoryModel["categoryModel.js"]:::backend
            OrderModel["orderModel.js"]:::backend
        end
    end

    %% External Services & Database
    MongoDB["MongoDB"]:::database
    PaymentGateway["Payment Gateway\n(Stripe/PayPal)"]:::external
    EnvFront[".env (client)"]:::config
    EnvBack[".env (root)"]:::config
    PackageFront["package.json (client)"]:::config
    PackageBack["package.json (root)"]:::config

    %% Data Flows
    UserBrowser -->|navigates| Pages
    UserBrowser -->|interacts| Components
    UserBrowser -->|state via| Contexts
    Contexts -->|uses| Hooks
    Pages -->|calls| Axios
    Components -->|calls| Axios
    Axios -->|HTTP Requests| Server
    Server -->|loads config| DBConfig
    Server -->|uses| AuthRoute
    Server -->|uses| CategoryRoute
    Server -->|uses| ProductRoute
    AuthRoute -->|calls| Middleware
    CategoryRoute -->|calls| Middleware
    ProductRoute -->|calls| Middleware
    Middleware -->|invokes| AuthController
    AuthController -->|reads/writes| UserModel
    CategoryController -->|reads/writes| CategoryModel
    ProductController -->|reads/writes| ProductModel
    UserModel -->|queries| MongoDB
    CategoryModel -->|queries| MongoDB
    ProductModel -->|queries| MongoDB
    OrderModel -->|queries| MongoDB
    Pages -->|checkout POST| PaymentGateway
    PaymentGateway -.->|webhook| Server

    %% Config & Manifests
    EnvFront --- EntryIndex
    EnvBack --- Server
    PackageFront --- EntryMain
    PackageBack --- Server

    %% Click Events
    click Pages "https://github.com/rohitkeshri803/e-com-app/tree/main/client/src/pages/"
    click Components "https://github.com/rohitkeshri803/e-com-app/tree/main/client/src/components/"
    click Contexts "https://github.com/rohitkeshri803/e-com-app/tree/main/client/src/context/"
    click Hooks "https://github.com/rohitkeshri803/e-com-app/tree/main/client/src/hooks/"
    click Styles "https://github.com/rohitkeshri803/e-com-app/tree/main/client/src/styles/"
    click EntryIndex "https://github.com/rohitkeshri803/e-com-app/blob/main/client/src/index.jsx"
    click EntryMain "https://github.com/rohitkeshri803/e-com-app/blob/main/client/src/main.jsx"
    click AdminRoute "https://github.com/rohitkeshri803/e-com-app/blob/main/client/src/components/Routes/AdminRoute.jsx"
    click PrivateRoute "https://github.com/rohitkeshri803/e-com-app/blob/main/client/src/components/Routes/Private.jsx"
    click Server "https://github.com/rohitkeshri803/e-com-app/blob/main/server.js"
    click DBConfig "https://github.com/rohitkeshri803/e-com-app/blob/main/config/db.js"
    click AuthRoute "https://github.com/rohitkeshri803/e-com-app/blob/main/routes/authRoute.js"
    click CategoryRoute "https://github.com/rohitkeshri803/e-com-app/blob/main/routes/categoryRoutes.js"
    click ProductRoute "https://github.com/rohitkeshri803/e-com-app/blob/main/routes/productRoute.js"
    click AuthController "https://github.com/rohitkeshri803/e-com-app/blob/main/controllers/authController.js"
    click CategoryController "https://github.com/rohitkeshri803/e-com-app/blob/main/controllers/categoryController.js"
    click ProductController "https://github.com/rohitkeshri803/e-com-app/blob/main/controllers/productController.js"
    click Middleware "https://github.com/rohitkeshri803/e-com-app/blob/main/middlewares/authMiddleware.js"
    click Helper "https://github.com/rohitkeshri803/e-com-app/blob/main/helpers/authHelper.js"
    click UserModel "https://github.com/rohitkeshri803/e-com-app/blob/main/models/userModels.js"
    click ProductModel "https://github.com/rohitkeshri803/e-com-app/blob/main/models/productModel.js"
    click CategoryModel "https://github.com/rohitkeshri803/e-com-app/blob/main/models/categoryModel.js"
    click OrderModel "https://github.com/rohitkeshri803/e-com-app/blob/main/models/orderModel.js"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#42A5F5
    classDef backend fill:#E8F5E9,stroke:#66BB6A
    classDef database fill:#FFF3E0,stroke:#FFA726
    classDef external fill:#EEEEEE,stroke:#9E9E9E,stroke-dasharray: 5 5
    classDef actor fill:#F3E5F5,stroke:#AB47BC
    classDef config fill:#F5F5F5,stroke:#BDBDBD,stroke-dasharray: 2 2
```
