# ishan678-code/grocery-management-system architecture

> Architecture diagram of the GitHub repository ishan678-code/grocery-management-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ishan678-code/grocery-management-system
- Repository: https://github.com/ishan678-code/grocery-management-system

## Overview

##### Project Type and Purpose
- Full-stack Grocery Management System
- Frontend: React (Vite), handles UI for users and sellers
- Backend: Node.js + Express API, handles routing, business logic, persistence
- Database: MongoDB (via Mongoose)
- External Services: Cloudinary for image hosting, Vercel for deployment

##### File Structure Analysis
- Top-level separation into “client” and “server” directories
- client/
- public, src (components, pages, context, assets)
- Vite config, ESLint, React entry points
- .env for API base URL or feature flags
- server/
- configs (db connection, multer, Cloudinary)
- routes → controllers → models (MVC-style)
- middleware for user/seller authentication
- server.js as Express app bootstrap
- .env for secrets (DB URI, Cloudinary keys, JWT secrets)

##### README Insights
- Simple one-line description and live link
- All architectural knowledge comes from directory layout

##### Main Components and Interactions
a. Client Application (React/Vite)
- Pages & Components consume REST API
- AppContext for global state (cart, user session)
- Login screens for users and sellers
b. API Server (Express)
- Routes layer (addressRoute, cartRoute, etc.)
- Controllers implement business logic (cartController, orderController, etc.)
- Middleware handles JWT checks (authUser, authSeller)
- Config modules for DB and Cloudinary setup
c. Database (MongoDB)
- Collections: users, products, orders, addresses
- Mongoose models for schema definitions
d. External Service (Cloudinary)
- Image upload pipeline via multer → Cloudinary SDK
e. Deployment Platforms
- Vercel hosting for frontend and backend (via serverless functions or separate deployments)

##### Architectural Patterns and Principles
- MVC-inspired layering on the server
- Clear separation of concerns: UI vs. API vs. persistence
- Context API in React for cross-component state
- Shared environment configuration via .env files
- Stateless RESTful endpoints, JWT auth

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "React Client"
        direction TB
        RC["React Client"]:::frontend
        MP["main.jsx"]:::frontend
        AC["App.jsx"]:::frontend
        CT["AppContext.jsx"]:::frontend
        CM["UI Components"]:::frontend
        SB["Seller Components"]:::frontend
        CP["Client Pages"]:::frontend
        SP["Seller Pages"]:::frontend
        PA["Public Assets"]:::frontend
        VC["vite.config.js"]:::frontend
        ESL["eslint.config.js"]:::frontend
        CENV[".env (Client)"]:::frontend

        RC --> MP
        MP --> AC
        AC --> CT
        AC --> CM
        CM --> SB
        AC --> CP
        CP --> SP
    end

    %% Backend Layer
    subgraph "Express API Server"
        direction TB
        ES["Express API"]:::api
        ServerEnv[".env (Server)"]:::api

        subgraph "Configs"
            direction TB
            DBConf["db.js"]:::api
            CLConf["cloudinary.js"]:::api
            MUConf["multer.js"]:::api
        end

        subgraph "Middleware"
            direction TB
            AuthU["authUser.js"]:::api
            AuthS["authSeller.js"]:::api
        end

        subgraph "Routes"
            direction TB
            AR["addressRoute.js"]:::api
            CR["cartRoute.js"]:::api
            ORt["orderRoute.js"]:::api
            PR["productRoute.js"]:::api
            UR["userRoute.js"]:::api
            SR["sellerRoute.js"]:::api
        end

        subgraph "Controllers"
            direction TB
            ACt["addressController.js"]:::api
            CC["cartController.js"]:::api
            OC["orderController.js"]:::api
            PC["productController.js"]:::api
            UC["userController.js"]:::api
            SC["sellerController.js"]:::api
        end

        subgraph "Models"
            direction TB
            MAdr["Address.js"]:::db
            MOrd["Order.js"]:::db
            MProd["product.js"]:::db
            MUsr["user.js"]:::db
        end

        ES --> ServerEnv
        ES --> DBConf
        ES --> CLConf
        ES --> MUConf
        ES --> AuthU
        ES --> AuthS
        ES --> AR
        ES --> CR
        ES --> ORt
        ES --> PR
        ES --> UR
        ES --> SR

        AR --> ACt
        CR --> CC
        ORt --> OC
        PR --> PC
        UR --> UC
        SR --> SC

        ACt --> MAdr
        CC --> MOrd
        OC --> MOrd
        PC --> MProd
        UC --> MUsr
        SC --> MUsr
    end

    %% External Services and Data Stores
    DB["MongoDB Atlas"]:::database
    CL["Cloudinary"]:::external
    VercelF["Vercel (Frontend)"]:::deploy
    VercelB["Vercel (Backend)"]:::deploy

    %% Data Flows
    Browser["Browser"]:::external
    Browser -->|uses| RC
    RC -->|REST API calls| ES
    ES -->|CRUD operations| DB
    ES -->|Image upload/download| CL
    RC -->|deployed on| VercelF
    ES -->|deployed on| VercelB

    %% Click Events
    click RC "https://github.com/ishan678-code/grocery-management-system/tree/main/client/"
    click MP "https://github.com/ishan678-code/grocery-management-system/blob/main/client/src/main.jsx"
    click AC "https://github.com/ishan678-code/grocery-management-system/blob/main/client/src/App.jsx"
    click CT "https://github.com/ishan678-code/grocery-management-system/blob/main/client/src/context/AppContext.jsx"
    click CM "https://github.com/ishan678-code/grocery-management-system/tree/main/client/src/components/"
    click SB "https://github.com/ishan678-code/grocery-management-system/tree/main/client/src/components/seller/"
    click CP "https://github.com/ishan678-code/grocery-management-system/tree/main/client/src/pages/"
    click SP "https://github.com/ishan678-code/grocery-management-system/tree/main/client/src/pages/seller/"
    click PA "https://github.com/ishan678-code/grocery-management-system/tree/main/client/public/"
    click VC "https://github.com/ishan678-code/grocery-management-system/blob/main/client/vite.config.js"
    click ESL "https://github.com/ishan678-code/grocery-management-system/blob/main/client/eslint.config.js"
    click CENV "https://github.com/ishan678-code/grocery-management-system/blob/main/client/.env"
    click ES "https://github.com/ishan678-code/grocery-management-system/blob/main/server/server.js"
    click ServerEnv "https://github.com/ishan678-code/grocery-management-system/blob/main/server/.env"
    click DBConf "https://github.com/ishan678-code/grocery-management-system/blob/main/server/configs/db.js"
    click CLConf "https://github.com/ishan678-code/grocery-management-system/blob/main/server/configs/cloudinary.js"
    click MUConf "https://github.com/ishan678-code/grocery-management-system/blob/main/server/configs/multer.js"
    click AuthU "https://github.com/ishan678-code/grocery-management-system/blob/main/server/middleware/authUser.js"
    click AuthS "https://github.com/ishan678-code/grocery-management-system/blob/main/server/middleware/authSeller.js"
    click AR "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/addressRoute.js"
    click CR "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/cartRoute.js"
    click ORt "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/orderRoute.js"
    click PR "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/productRoute.js"
    click UR "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/userRoute.js"
    click SR "https://github.com/ishan678-code/grocery-management-system/blob/main/server/routes/sellerRoute.js"
    click ACt "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/addressController.js"
    click CC "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/cartController.js"
    click OC "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/orderController.js"
    click PC "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/productController.js"
    click UC "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/userController.js"
    click SC "https://github.com/ishan678-code/grocery-management-system/blob/main/server/controllers/sellerController.js"
    click MAdr "https://github.com/ishan678-code/grocery-management-system/blob/main/server/models/Address.js"
    click MOrd "https://github.com/ishan678-code/grocery-management-system/blob/main/server/models/Order.js"
    click MProd "https://github.com/ishan678-code/grocery-management-system/blob/main/server/models/product.js"
    click MUsr "https://github.com/ishan678-code/grocery-management-system/blob/main/server/models/user.js"
    click VercelF "https://github.com/ishan678-code/grocery-management-system/blob/main/client/vercel.json"
    click VercelB "https://github.com/ishan678-code/grocery-management-system/blob/main/server/vercel.json"

    %% Styles
    classDef frontend fill:#DCEEFB,stroke:#0366D6,stroke-width:1px
    classDef api fill:#E6FFFA,stroke:#038C6C,stroke-width:1px
    classDef database fill:#FFF4E5,stroke:#DD6B20,stroke-width:1px
    classDef external fill:#F3E8FF,stroke:#805AD5,stroke-width:1px
    classDef deploy fill:#EDF2F7,stroke:#4A5568,stroke-width:1px
    classDef db fill:#FFF4E5,stroke:#DD6B20,stroke-width:1px
```
