# abhishekak411/vmern-ecommerce architecture

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

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

## Overview

##### Project type and purpose
- This is a MERN‐stack (MongoDB, Express, React, Node) e‑commerce prototype.
- Supports two roles:
- Users: browse/search products, add to cart, checkout, view order history.
- Sellers: perform CRUD on products, view/manage their inventory.
- Uses JSON Web Tokens for authentication/authorization, custom email/password validation, and BcryptJS for password hashing.

##### File structure
- Top‐level separation:
- client/ → React front end
- server/ → Node/Express back end
- client/:
- public/ → static HTML, manifest, robots.txt
- src/ → App.js, style files, reportWebVitals, setupTests
- src/Components/ → feature‑grouped React components (Cart, Category, Global, HOC, Helpers, Home, Multiple‑Products, Newest, Product, Single, User)
- src/Context/ → authContext for global auth state
- src/Helpers/apiConfig.js → base URL and HTTP helper
- tailwind.config.js → styling config
- server/:
- index.js → Express app entry point
- controllers/ → prod.cont.js, seller.cont.js, user.cont.js (business logic)
- routes/ → allRoutes.js, prodRoutes.js, sellerRoutes.js, userRoutes.js (routing)
- middlewares/ → sellerAuth.js, userAuth.js (JWT validation)
- models/ → Mongoose schemas: defproduct.js, users.js, orders.js
- utils/ → emailValidator.js, passwordValidator.js
- JSON/products.json → seed data endpoint
- Config & build scripts: .env variables, package.json in both client and server.

##### Key insights from README
- Lists all React routes with their purposes (/, /login, /register, /addProducts, /sellerProducts, /single/:id, /cart, /mens, /womens, /electronics, /newest).
- Defines backend API under base path http://localhost:{port}/app/auth with user, product, seller endpoints.
- Mentions JWT secret, MongoDB URL, and startup scripts for server & client.

##### Step‑by‑step sketch plan
- Middleware layer (userAuth, sellerAuth)
- Routers (userRoutes, prodRoutes, sellerRoutes)
- Controllers
6. Off to the side, show utilities: emailValidator.js, passwordValidator.js, JSON seed loader, indicating controllers call them.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["User/Seller Browser"]:::external
        ReactSPA["React SPA"]:::frontend
        Browser --> ReactSPA

        subgraph "React Application"
            direction TB
            AppShell["App.js & App.css"]:::frontend
            EntryPoint["index.js"]:::frontend
            AuthContext["AuthContext"]:::frontend
            Navbar["Navbar & Navigation"]:::frontend
            Category["Category Components"]:::frontend
            ProductList["Multiple & Newest Products"]:::frontend
            CartComp["Cart Component"]:::frontend
            SingleProd["Single Product View"]:::frontend
            UserAuthComp["Login & Register"]:::frontend

            ReactSPA --> EntryPoint
            ReactSPA --> AppShell
            ReactSPA --> AuthContext
            ReactSPA --> Navbar
            ReactSPA --> Category
            ReactSPA --> ProductList
            ReactSPA --> CartComp
            ReactSPA --> SingleProd
            ReactSPA --> UserAuthComp
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        ExpressAPI["Express API Gateway"]:::backend
        ReactSPA -->|"REST/HTTP + JWT"| ExpressAPI

        subgraph "Middleware Layer"
            direction TB
            UserAuth["userAuth Middleware"]:::backend
            SellerAuth["sellerAuth Middleware"]:::backend
            ExpressAPI --> UserAuth
            ExpressAPI --> SellerAuth
        end

        subgraph "Routing Layer"
            direction TB
            AllRoutes["allRoutes"]:::backend
            ProdRoutes["prodRoutes"]:::backend
            UserRoutes["userRoutes"]:::backend
            SellerRoutes["sellerRoutes"]:::backend
            UserAuth --> AllRoutes
            SellerAuth --> AllRoutes
            AllRoutes --> ProdRoutes
            AllRoutes --> UserRoutes
            AllRoutes --> SellerRoutes
        end

        subgraph "Controller Layer"
            direction TB
            ProdController["prod.cont.js"]:::backend
            UserController["user.cont.js"]:::backend
            SellerController["seller.cont.js"]:::backend
            ProdRoutes --> ProdController
            UserRoutes --> UserController
            SellerRoutes --> SellerController
        end
    end

    %% Database
    subgraph "Database (MongoDB)" 
        direction TB
        UsersColl["users Collection"]:::db
        ProductsColl["products Collection"]:::db
        OrdersColl["orders Collection"]:::db
        OrdersColl & ProductsColl & UsersColl
    end
    ProdController --> ProductsColl
    UserController --> UsersColl
    SellerController --> ProductsColl
    ProdController --> OrdersColl

    %% Utilities
    subgraph "Utilities & Seed"
        direction TB
        EmailVal["emailValidator.js"]:::util
        PassVal["passwordValidator.js"]:::util
        JSONSeed["products.json"]:::util
    end
    ProdController --> EmailVal
    UserController --> PassVal
    ProdController --> JSONSeed

    %% Click Events
    click ReactSPA "https://github.com/abhishekak411/vmern-ecommerce/tree/main/client/src"
    click EntryPoint "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/index.js"
    click AppShell "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/App.js"
    click AppShell "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/App.css"
    click AuthContext "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Context/authContext.jsx"
    click Navbar "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Global/Navbar.jsx"
    click Navbar "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Global/Navigation.jsx"
    click Category "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Category/Electronics.jsx"
    click Category "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Category/Mens.jsx"
    click Category "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Category/Womens.jsx"
    click ProductList "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Multiple-Products/Multiple.jsx"
    click ProductList "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Newest/Newest.jsx"
    click CartComp "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Cart/Cart.jsx"
    click SingleProd "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/Single/Single.jsx"
    click UserAuthComp "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/User/Login.jsx"
    click UserAuthComp "https://github.com/abhishekak411/vmern-ecommerce/blob/main/client/src/Components/User/Register.jsx"
    click AllRoutes "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/routes/allRoutes.js"
    click ProdRoutes "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/routes/prodRoutes.js"
    click UserRoutes "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/routes/userRoutes.js"
    click SellerRoutes "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/routes/sellerRoutes.js"
    click ProdController "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/controllers/prod.cont.js"
    click UserController "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/controllers/user.cont.js"
    click SellerController "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/controllers/seller.cont.js"
    click UserAuth "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/middlewares/userAuth.js"
    click SellerAuth "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/middlewares/sellerAuth.js"
    click EmailVal "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/utils/emailValidator.js"
    click PassVal "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/utils/passwordValidator.js"
    click JSONSeed "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/JSON/products.json"
    click ExpressAPI "https://github.com/abhishekak411/vmern-ecommerce/blob/main/server/index.js"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px
    classDef backend fill:#90ee90,stroke:#000,stroke-width:1px
    classDef db fill:#ffa500,stroke:#000,stroke-width:1px
    classDef util fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef external fill:#ffffff,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
```
