# saurabhtbj1201/megabasket architecture

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

- Interactive diagram: https://gitdiagram.com/saurabhtbj1201/megabasket
- Repository: https://github.com/saurabhtbj1201/megabasket

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce platform (“MegaBasket”) built on the MERN stack (MongoDB, Express, React, Node.js).
- It serves two main user groups: shoppers (browsing products, adding to cart, checking out) and administrators (managing products, categories, orders, users, banners, promotions).

##### File Structure
- Top level:
- .github/workflows—CI/CD pipeline (runs tests or deployments)
- backend/—API server and business logic
- frontend/—React single-page application (SPA)
- backend/:
- config/db.js—database connection setup
- controllers/—request handlers (adminController, authController, productController, etc.)
- models/—Mongoose schemas for Users, Products, Orders, Banners, Offers, etc.
- routes/—Express routers mapping HTTP endpoints to controllers
- middleware/—authMiddleware (JWT verification), uploadMiddleware (file handling)
- utils/—token generation, PayU integration, email sending
- server.js—entry point that wires middleware, routes, DB, and starts the server
- frontend/:
- src/:
– components/—reusable UI widgets (Header, Footer, ProductCard, Modals, etc.)
– pages/—route-driven views (HomePage, ProductDetailPage, CartPage, AdminDashboardPage, etc.)
– layouts/—wrappers for public vs. admin routes
– context/—React Contexts (AuthContext, LoadingContext)
– utils/—helper functions (cacheUtils, formatCurrency)
– App.jsx & main.jsx—React router setup and root rendering
- vite.config.js—dev server proxy to backend
- There’s a vercel.json for frontend deployment, and .github/workflows for CI.

##### README for Additional Insights
- Confirms MERN stack, JWT and Google OAuth for auth, AWS S3 for image hosting, PayU for payments.
- Describes features: search, filter, cart, checkout, admin dashboard, CRUD operations, email notifications.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Browser["Client Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        SPA["React SPA (Vite)"]:::frontend
        App["App.jsx"]:::frontend
        Main["main.jsx"]:::frontend
        Public["Static Assets (public/)"]:::frontend
        Layouts["Layouts (public vs admin)"]:::frontend
        Context["React Contexts"]:::frontend
        Config["Vite.config.js & vercel.json"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API Server)"
        direction TB
        Server["server.js"]:::backend
        DBConn["db.js (MongoDB Connection)"]:::backend
        subgraph "Models"
            Models["Mongoose Schemas"]:::backend
        end
        subgraph "Routes"
            Routes["Express Routes"]:::backend
        end
        subgraph "Controllers"
            Controllers["Controllers"]:::backend
        end
        subgraph "Middleware"
            AuthMid["authMiddleware.js"]:::backend
            UploadMid["uploadMiddleware.js"]:::backend
        end
        subgraph "Utils"
            GenerateToken["generateToken.js"]:::backend
            PayuUtils["payuUtils.js"]:::backend
            SendEmail["sendEmail.js"]:::backend
        end
        subgraph "Email Module"
            EmailCtrl["emailController.js"]:::backend
            EmailRoutes["emailRoutes.js"]:::backend
        end
    end

    %% Data Stores & External Services
    subgraph "Data Stores & Services"
        direction TB
        DB["MongoDB"]:::database
        S3["AWS S3"]:::database
        AuthProvider["Google OAuth & JWT"]:::external
        PayU["PayU Payment Gateway"]:::external
        EmailService["SMTP / AWS SES"]:::external
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        direction TB
        CI["GitHub Actions"]:::external
        DeployF["Vercel (Frontend)"]:::external
        DeployB["Node Host (Backend)"]:::external
    end

    %% Connections
    Browser -->|Uses| SPA
    SPA -->|Calls API| Server
    SPA -->|Loads Assets| Public
    SPA --> App
    SPA --> Main
    SPA --> Layouts
    SPA --> Context
    SPA --> Config

    Server --> DBConn
    Server --> Models
    Server --> Routes
    Server --> Controllers
    Server --> AuthMid
    Server --> UploadMid
    Server --> GenerateToken
    Server --> PayuUtils
    Server --> SendEmail
    Server --> EmailCtrl
    Server --> EmailRoutes

    Server -->|Reads/Writes| DB
    Server -->|Upload/Download| S3
    Server -->|Verifies Auth| AuthProvider
    Server -.->|Async Payment| PayU
    Server -.->|Async Email| EmailService

    CI -->|Build/Test/Deploy| DeployF
    CI -->|Build/Test/Deploy| DeployB

    %% Click Events
    click SPA "https://github.com/saurabhtbj1201/megabasket/tree/master/frontend/src/"
    click App "https://github.com/saurabhtbj1201/megabasket/blob/master/frontend/src/App.jsx"
    click Main "https://github.com/saurabhtbj1201/megabasket/blob/master/frontend/src/main.jsx"
    click Public "https://github.com/saurabhtbj1201/megabasket/tree/master/frontend/public/"
    click Layouts "https://github.com/saurabhtbj1201/megabasket/tree/master/frontend/src/layouts/"
    click Context "https://github.com/saurabhtbj1201/megabasket/tree/master/frontend/src/context/"
    click Config "https://github.com/saurabhtbj1201/megabasket/blob/master/frontend/vite.config.js"
    click Config "https://github.com/saurabhtbj1201/megabasket/blob/master/frontend/vercel.json"
    click Server "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/server.js"
    click DBConn "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/config/db.js"
    click Models "https://github.com/saurabhtbj1201/megabasket/tree/master/backend/models/"
    click Routes "https://github.com/saurabhtbj1201/megabasket/tree/master/backend/routes/"
    click Controllers "https://github.com/saurabhtbj1201/megabasket/tree/master/backend/controllers/"
    click AuthMid "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/middleware/authMiddleware.js"
    click UploadMid "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/middleware/uploadMiddleware.js"
    click GenerateToken "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/utils/generateToken.js"
    click PayuUtils "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/utils/payuUtils.js"
    click SendEmail "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/utils/sendEmail.js"
    click EmailCtrl "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/controllers/emailController.js"
    click EmailRoutes "https://github.com/saurabhtbj1201/megabasket/blob/master/backend/routes/emailRoutes.js"
    click CI "https://github.com/saurabhtbj1201/megabasket/blob/master/.github/workflows/master_megabasket.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef database fill:#FFD700,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
