# srini-code-bytes/ecommerce-platform-mern architecture

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

- Interactive diagram: https://gitdiagram.com/srini-code-bytes/ecommerce-platform-mern
- Repository: https://github.com/srini-code-bytes/ecommerce-platform-mern

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce platform using the MERN stack:
- Frontend: React (Vite, TailwindCSS, Redux Toolkit, Radix UI)
- Backend: Node.js + Express.js with MongoDB via Mongoose
- Features: product catalog, shopping cart, orders, user auth, admin panel, image upload, PayPal payments

##### File Structure
- Top-level:
- client/ — React app
- server/ — Express API
- client/src:
- components/ — reusable UI (admin-view, auth, shopping-view, common, ui)
- pages/ — route-level React pages
- store/ — Redux slices (auth, admin, shop)
- api/ — Axios instance for HTTP calls
- config, context, lib, utils
- server/:
- server.js — main entry point
- routes/ — Express routers (admin, auth, common, shop)
- controllers/ — business logic per domain
- models/ — Mongoose schemas (User, Product, Cart, Order, Review, Address, Feature)
- helpers/ — Cloudinary, PayPal, import utilities

##### Key Insights from README
- Clear three-tier flow: Browser ↔ React Frontend ↔ Express API ↔ MongoDB
- External services: Cloudinary (images), PayPal (payments)
- Authentication: JWT & cookies
- Patterns:
- Frontend: Component-based UI, Redux for state, React Router for navigation
- Backend: MVC-style (Routes → Controllers → Models), helpers for side-effects

##### Main Components
a. User’s Web Browser / Mobile Browser
b. React Frontend
- UI Components (pages, forms, product tiles)
- Redux Store (auth-slice, shop-slices, admin-slices)
- Axios HTTP client
c. Express API Server
- Route Handlers (auth, admin, shop, common)
- Controllers (request logic)
- Mongoose Models (persistent data access)
- Middleware (JWT auth, CORS, cookie parser, multer for file uploads)
- Cloudinary (image storage / upload)
- PayPal (payment processing)
f. DevOps / Deployment
- Vite build & deploy pipeline
- EB config (client/.elasticbeanstalk)
- GitHub Actions workflow

##### Relationships & Data Flow
1) Browser → React Frontend (UI interactions)
2) React → Express (Axios calls over REST API)
3) Express Routes → Controllers → Models
4) Controllers ↔ MongoDB (CRUD via Mongoose)
5) Controllers ↔ Cloudinary (image upload/download)
6) Controllers ↔ PayPal (payment initiation, confirmation)
7) Controllers → send JWT cookies/JSON responses → Frontend
8) Frontend dispatches Redux actions to update UI state

##### Architectural Patterns & Principles
- Separation of concerns: UI vs. API vs. persistence vs. external services
- MVC on server: Routes → Controllers → Models
- Component-based UI on client
- Single source of truth via Redux store
- RESTful API design
- Secure authentication with JWT and cookies
- CI/CD via GitHub Actions and Elastic Beanstalk

##### Technologies & Frameworks to Label
- React 18, Vite, TailwindCSS, Radix UI, Redux Toolkit, Axios
- Node.js, Express.js, Mongoose, MongoDB
- bcryptjs, jsonwebtoken, cookie-parser, multer, cors, dotenv
- Cloudinary, PayPal
- ESLint, PostCSS, Autoprefixer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    A["User’s Web Browser"]:::external
    click A "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/index.html"

    %% Frontend Layer
    subgraph "Frontend (React)" 
        direction TB
        FE_ROOT["App Entry (main.jsx & App.jsx)"]:::frontend
        click FE_ROOT "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/main.jsx"
        click FE_ROOT "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/App.jsx"

        subgraph "UI Components" 
            direction TB
            UI_COMP["components/"]:::frontend
            click UI_COMP "https://github.com/srini-code-bytes/ecommerce-platform-mern/tree/main/client/src/components"
            PAGES["pages/"]:::frontend
            click PAGES "https://github.com/srini-code-bytes/ecommerce-platform-mern/tree/main/client/src/pages"
        end

        subgraph "State Management (Redux)" 
            direction TB
            STORE["store.js"]:::frontend
            click STORE "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/store/store.js"
            AUTH_SLICE["auth-slice"]:::frontend
            click AUTH_SLICE "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/store/auth-slice/index.js"
            SHOP_SLICES["shop-slices"]:::frontend
            click SHOP_SLICES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/store/shop/**/index.js"
            ADMIN_SLICES["admin-slices"]:::frontend
            click ADMIN_SLICES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/store/admin/**/index.js"
        end

        AXIOS["Axios HTTP Client"]:::frontend
        click AXIOS "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/api/axiosInstance.js"

        subgraph "Config & Utils" 
            direction TB
            VITE_CFG["vite.config.js"]:::frontend
            click VITE_CFG "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/vite.config.js"
            TAILWIND_CFG["tailwind.config.js"]:::frontend
            click TAILWIND_CFG "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/tailwind.config.js"
            ENV[".env"]:::frontend
            click ENV "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/.env"
            UTILS["utils/"]:::frontend
            click UTILS "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/lib/utils.js"
            click UTILS "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/utils/file-validation.js"
            SNACKBAR["SnackbarContext"]:::frontend
            click SNACKBAR "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/src/context/SnackbarContext.jsx"
        end
    end

    %% Backend Layer
    subgraph "Backend (Express API)" 
        direction TB
        SERVER["server.js"]:::backend
        click SERVER "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/server.js"

        subgraph "Middleware & Config" 
            direction TB
            MIDDLEWARE["CORS, cookie-parser, multer, JWT"]:::backend
        end

        subgraph "Routes" 
            direction TB
            AUTH_ROUTES["auth-routes"]:::backend
            click AUTH_ROUTES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/routes/auth/auth-routes.js"
            ADMIN_ROUTES["admin-routes"]:::backend
            click ADMIN_ROUTES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/routes/admin/**-routes.js"
            COMMON_ROUTES["feature-routes"]:::backend
            click COMMON_ROUTES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/routes/common/feature-routes.js"
            SHOP_ROUTES["shop-routes"]:::backend
            click SHOP_ROUTES "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/routes/shop/**-routes.js"
        end

        subgraph "Controllers" 
            direction TB
            AUTH_CTRL["auth-controller"]:::backend
            click AUTH_CTRL "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/controllers/auth/auth-controller.js"
            ADMIN_CTRL["admin-controllers"]:::backend
            click ADMIN_CTRL "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/controllers/admin/**-controller.js"
            COMMON_CTRL["feature-controller"]:::backend
            click COMMON_CTRL "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/controllers/common/feature-controller.js"
            SHOP_CTRL["shop-controllers"]:::backend
            click SHOP_CTRL "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/controllers/shop/**-controller.js"
        end

        subgraph "Models (Mongoose)" 
            direction TB
            MODELS["User,Product,Cart,Order,Review,Address,Feature"]:::backend
            click MODELS "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/models/*.js"
        end

        subgraph "Helpers / External Integrations" 
            direction TB
            CLOUD_HELPER["Cloudinary Helper"]:::external
            click CLOUD_HELPER "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/helpers/cloudinary.js"
            PAYPAL_HELPER["PayPal Helper"]:::external
            click PAYPAL_HELPER "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/helpers/paypal.js"
            IMPORT_UTIL["Import Products"]:::backend
            click IMPORT_UTIL "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/server/helpers/import-products.js"
        end
    end

    %% Data Store
    DB["MongoDB"]:::database

    %% External Services
    CLOUD["Cloudinary"]:::external
    PAYPAL["PayPal"]:::external

    %% DevOps / Deployment
    subgraph "DevOps / CI-CD" 
        direction TB
        GH_ACTIONS["GitHub Actions Workflow"]:::devops
        click GH_ACTIONS "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/.github/workflows/deploy-mern-fullstack.yml"
        EB_CFG["EB Config"]:::devops
        click EB_CFG "https://github.com/srini-code-bytes/ecommerce-platform-mern/blob/main/client/.elasticbeanstalk/config.yml"
        PROCFILE["Procfile"]:::devops
        click PROCFILE "https://github.com/srini-code-bytes/ecommerce-platform-mern/tree/main/client/Procfile"
    end

    %% Relationships
    A -->|"Interacts with UI"| FE_ROOT
    FE_ROOT -->|"Dispatches actions"| STORE
    FE_ROOT -->|"Renders components"| UI_COMP
    FE_ROOT -->|"Navigates pages"| PAGES
    FE_ROOT -->|"Makes HTTP calls"| AXIOS
    AXIOS -->|"REST API calls"| SERVER

    SERVER -->|"Uses middleware"| MIDDLEWARE
    SERVER -->|"Routes requests"| AUTH_ROUTES
    SERVER -->|"Routes requests"| ADMIN_ROUTES
    SERVER -->|"Routes requests"| COMMON_ROUTES
    SERVER -->|"Routes requests"| SHOP_ROUTES

    AUTH_ROUTES --> AUTH_CTRL
    ADMIN_ROUTES --> ADMIN_CTRL
    COMMON_ROUTES --> COMMON_CTRL
    SHOP_ROUTES --> SHOP_CTRL

    AUTH_CTRL -->|"CRUD via Mongoose"| MODELS
    ADMIN_CTRL --> MODELS
    COMMON_CTRL --> MODELS
    SHOP_CTRL --> MODELS

    AUTH_CTRL -->|"Handles images"| CLOUD
    SHOP_CTRL -->|"Processes payment"| PAYPAL
    CLOUD_HELPER --> CLOUD
    PAYPAL_HELPER --> PAYPAL

    MODELS --> DB
    SERVER --> DB
    SERVER --> CLOUD_HELPER
    SERVER --> PAYPAL_HELPER

    DB -->|"Query results"| SHOP_CTRL

    GH_ACTIONS --> SERVER
    GH_ACTIONS --> FE_ROOT

    %% Styles
    classDef frontend fill:#D0EBFF,stroke:#1E90FF,color:#000
    classDef backend fill:#D6F5D6,stroke:#28A745,color:#000
    classDef database fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef external fill:#F0E6FF,stroke:#800080,color:#000
    classDef devops fill:#F5F5F5,stroke:#808080,color:#000
```
