# premgchavan/fs-18-webfundamentals architecture

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

- Interactive diagram: https://gitdiagram.com/premgchavan/fs-18-webfundamentals
- Repository: https://github.com/premgchavan/fs-18-webfundamentals

## Overview

##### Project Type and Purpose
- At the root this repo is a catch-all for MERN-stack class materials (HTML/CSS/JS, React, Node/Express).
- Among dozens of mini-apps, the folder “ecommerceProject” exemplifies a full-stack MERN application with: user auth, product catalog, cart, coupons, file uploads, protected routes.

##### File Structure of ecommerceProject
- ecommerceProject/
- backend/
– controllers/ (userController.js, productController.js, cartController.js, couponController.js)
– models/ (userModel.js, productModel.js, cartModel.js, couponModel.js)
– routes/ (authRoutes.js, productRoutes.js, cartRoutes.js, couponRoutes.js, ecomRoutes.js)
– middlewares/ (authMiddleware.js, upload.js)
– services/ (cloudinaryUpload.js, tokenGenerate.js)
– utils/ (generateRandomCrypto.js)
– index.js (Express app entry point)
- frontend/
– public/ (index.html, static assets)
– src/
· App.jsx, ProtectedRoute.jsx, axiosConfig.js
· components/ (Header, Footer, DisplayProducts, etc.)
· pages/ (Home.jsx, Cart.jsx, Login.jsx, SingleProduct.jsx, Wishlist.jsx)
– tailwind.config.js, postcss.config.js, vite.config.js

##### README Insights
- This lab is part of a MERN-stack curriculum.

- React Client (Browser)
- Express API Server
- MongoDB Database
- Cloudinary (External File-Storage Service)
- JWT Auth Service (token generation/validation)
- React → Express (HTTPS calls via Axios)
- Express Controllers → Models (Mongoose) → MongoDB
- Express File-upload Endpoint → Cloudinary SDK
- AuthMiddleware intercepts API calls → verifies JWT → forwards to controller
- React ProtectedRoute reads token → blocks/unblocks UI routes
c. Architectural Patterns & Principles:
- Frontend: SPA, component-based, client-side routing, protected routes
- Backend: MVC-style (Routes → Middleware → Controllers → Models), service layer for cross-cutting concerns
- Separation of concerns: file-upload and token logic in “services”
d. Technologies & Frameworks:
- Frontend: React (Vite), Tailwind CSS, Axios
- Backend: Node.js, Express.js, Mongoose (MongoDB ORM)
- Auth: JSON Web Tokens
- File Storage: Cloudinary

##### Detail but Maintain Clarity
- JWT flow: Login → Token issuance → Authorization header on subsequent calls → AuthMiddleware.
- File-upload flow: React FileUpload component → /api/products/upload → cloudinaryUpload service → Cloudinary.
- Boundary with the technology in use (e.g. “Axios (HTTPS)”, “Mongoose”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes
    subgraph "Frontend (React)" 
        direction TB
        RC["React Client (Browser)"]:::frontend
        App["App.jsx"]:::frontend
        PR["ProtectedRoute.jsx"]:::frontend
        AX["axiosConfig.js"]:::api
        DP["DisplayProducts.jsx"]:::frontend
        HD["Header.jsx"]:::frontend
        FT["Footer.jsx"]:::frontend
        PG["Products.jsx"]:::frontend
        RG["Register.jsx"]:::frontend
        SB["Sidebar.jsx"]:::frontend
        HP["Home.jsx"]:::frontend
        CP["Cart.jsx"]:::frontend
        LP["Login.jsx"]:::frontend
        SP["SingleProduct.jsx"]:::frontend
        WL["Wishlist.jsx"]:::frontend

        RC -->|renders| App
        App -->|"uses"| PR
        App -->|"configures Axios"| AX
        App -->|includes| HD
        App -->|includes| FT
        App -->|routes to pages| HP
        App -->|routes to pages| CP
        App -->|routes to pages| LP
        App -->|routes to pages| SP
        App -->|routes to pages| WL
        HP -->|shows| DP
        HP -->|lists| PG
        RG -->|form| App
        SB -->|navigation| App

    end

    subgraph "Backend (Express API)" 
        direction TB
        EX["Express API Server"]:::api
        IR["index.js"]:::api
        SR["ecomRoutes.js"]:::api
        AR["authRoutes.js"]:::api
        PRoR["productRoutes.js"]:::api
        CR["cartRoutes.js"]:::api
        CoR["couponRoutes.js"]:::api
        AMW["authMiddleware.js"]:::api
        UMW["upload.js"]:::api
        UC["userController.js"]:::api
        PC["productController.js"]:::api
        CC["cartController.js"]:::api
        COC["couponController.js"]:::api
        CS1["cloudinaryUpload.js"]:::util
        CS2["tokenGenerate.js"]:::util
        UT["generateRandomCrypto.js"]:::util
        UM["userModel.js"]:::db
        PM["productModel.js"]:::db
        CaM["cartModel.js"]:::db
        CoM["couponModel.js"]:::db

        IR -->|loads routes| SR
        SR --> AR
        SR --> PRoR
        SR --> CR
        SR --> CoR

        AR --> AMW
        AR --> UC
        PRoR --> PC
        CR --> CC
        CoR --> COC

        UC --> CS2
        PC --> UMW
        UMW --> CS1
        CC --> UT
        COC --> UT

        UC --> UM
        PC --> PM
        CC --> CaM
        COC --> CoM

        %% Controllers talk to DB
        UM -->|Mongoose| DB[(MongoDB)]:::db
        PM -->|Mongoose| DB
        CaM -->|Mongoose| DB
        CoM -->|Mongoose| DB

    end

    %% Cross-Layer Interactions
    App -->|HTTPS Axios calls| EX
    AX -->|baseURL /api| EX
    PR -->|checks JWT| AMW
    AR -->|POST /api/auth/login| UC
    UC -->|issues JWT| CS2
    PR -->|blocks/unblocks routes| App

    SP -->|GET /api/products/:id| PRoR
    DP -->|GET /api/products| PRoR

    CP -->|POST /api/cart| CR
    CP -->|GET /api/cart| CR

    LP -->|POST /api/auth/login| AR
    RG -->|POST /api/auth/register| AR

    SP -->|POST /api/coupons| CoR

    DP -->|POST /api/products/upload| PRoR
    DP -->|file upload| UMW
    UMW -->|calls| CS1
    CS1 -->|uploads to| Cloudinary[(Cloudinary)]:::ext

    %% Click Events
    click RC "https://github.com/premgchavan/fs-18-webfundamentals/tree/main/ecommerceProject/frontend"
    click App "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/App.jsx"
    click PR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/ProtectedRoute.jsx"
    click AX "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/axiosConfig.js"
    click DP "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/DisplayProducts.jsx"
    click HD "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/Header.jsx"
    click FT "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/Footer.jsx"
    click PG "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/Products.jsx"
    click RG "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/Register.jsx"
    click SB "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/components/Sidebar.jsx"
    click HP "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/pages/Home.jsx"
    click CP "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/pages/Cart.jsx"
    click LP "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/pages/Login.jsx"
    click SP "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/pages/SingleProduct.jsx"
    click WL "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/frontend/src/pages/Wishlist.jsx"
    click IR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/index.js"
    click SR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/routes/ecomRoutes.js"
    click AR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/routes/authRoutes.js"
    click PRoR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/routes/productRoutes.js"
    click CR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/routes/cartRoutes.js"
    click CoR "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/routes/couponRoutes.js"
    click AMW "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/middlewares/authMiddleware.js"
    click UMW "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/middlewares/upload.js"
    click UC "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/controllers/userController.js"
    click PC "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/controllers/productController.js"
    click CC "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/controllers/cartController.js"
    click COC "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/controllers/couponController.js"
    click CS1 "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/services/cloudinaryUpload.js"
    click CS2 "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/services/tokenGenerate.js"
    click UT "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/utils/generateRandomCrypto.js"
    click UM "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/models/userModel.js"
    click PM "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/models/productModel.js"
    click CaM "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/models/cartModel.js"
    click CoM "https://github.com/premgchavan/fs-18-webfundamentals/blob/main/ecommerceProject/backend/models/couponModel.js"

    %% Styles
    classDef frontend fill:#e3f2fd,stroke:#42a5f5,color:#0d47a1;
    classDef api fill:#e1f5fe,stroke:#0288d1,color:#01579b;
    classDef db fill:#e8f5e9,stroke:#43a047,color:#1b5e20;
    classDef util fill:#eeeeee,stroke:#9e9e9e,color:#424242;
    classDef ext fill:#fff3e0,stroke:#fb8c00,color:#e65100;
    classDef api stroke-dasharray: 4 2;
```
