# gitguru826004/greencart architecture

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

- Interactive diagram: https://gitdiagram.com/gitguru826004/greencart
- Repository: https://github.com/gitguru826004/greencart

## Overview

##### Project Type and Purpose
- This is a full-stack e-commerce web application (“GreenCart”) built on the MERN stack (MongoDB, Express, React, Node) with Tailwind CSS styling.
- Purpose: Provide a sustainable shopping platform with product browsing, cart management, secure checkout via Stripe, image uploads via Cloudinary, role-based access, and order management.

##### File Structure Analysis
- Top-level:
- client/ – React (Vite) frontend
- server/ – Node + Express backend
- Frontend (client/src):
- components/ – UI building blocks (e.g., NavBar, ProductCard)
- pages/ – Route-based views (Home, Cart, ProductDetails, Seller pages)
- context/ – Global state (AppContext for cart, user data)
- public/ – Static assets
- Backend (server/):
- configs/ – DB and Cloudinary setup
- controllers/ – Business logic for users, products, cart, orders, sellers
- routes/ – API endpoints mapping
- models/ – Mongoose schemas
- middleware/ – Authentication for users and sellers

##### README Insights
- Layered architecture: clear separation of frontend UI, backend API, and cloud services.
- Deploys both client and server as Vercel serverless functions.
- Integrations: Cloudinary for media, Stripe for payments, MongoDB for data persistence.

##### Main Components
a. Frontend Layer
- React App (Vite)
- Components & Pages
- Context API for state
- Axios (or fetch) calls to API
b. Backend Layer
- Express Server (server.js)
- Route Handlers → Controllers
- Middleware (authUser, authSeller)
- Mongoose Models → MongoDB
c. Data Storage
- MongoDB Atlas (or hosted instance)
d. External Services
- Cloudinary (Image upload & hosting)
- Stripe (Payment processing)
e. Deployment
- Vercel (Frontend + Backend)

##### Component Interactions and Data Flow
- User Browser → HTTP(S) → Frontend (React Router serves pages)
- React Context dispatches actions (add to cart, login) → Axios → API endpoints
- API Controllers handle requests → Middleware (auth checks) → database operations via Mongoose
- Image uploads: Frontend sends file → Backend → Cloudinary SDK → Cloudinary CDN
- Payment: Frontend collects card info with Stripe.js → Backend → Stripe SDK → Payment outcome → Order update in MongoDB
- Frontend polls or listens for order status updates via API
- Deployment pipeline: Git commit → Vercel CI/CD → Separate deployments for client/ and server/

##### Architectural Patterns and Design Principles
- Layered Architecture: UI, API, Data
- MVC-style on server (Controllers, Models, Views=Routes)
- Component-based front end with Context for global state
- Stateless serverless functions on Vercel
- Secure configuration via .env and Vercel environment variables
- Role-based access control using JWT or session tokens

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client (Frontend)" 
        direction TB
        Browser["User Browser"]:::external
        ReactApp["React App (Vite)"]:::frontend
        Components["UI Components"]:::frontend
        Pages["Route-Based Pages"]:::frontend
        ContextAPI["AppContext (Context API)"]:::frontend
        APIClient["Axios/Fetch"]:::frontend
        FrontendConfig["Frontend Config (.env, vite.config.js, vercel.json)"]:::config
        StaticAssets["Public & Assets"]:::frontend
    end

    %% Server Side
    subgraph "Server (Backend)"
        direction TB
        ExpressAPI["Express Server (server.js)"]:::backend
        Routes["API Routes"]:::backend
        Middleware["Middleware (authUser, authSeller)"]:::backend
        Controllers["Controllers"]:::backend
        Models["Mongoose Models"]:::backend
        DBConfig["DB Config"]:::config
        CloudinaryConfig["Cloudinary Config"]:::config
        MulterConfig["Multer Config"]:::config
        ServerConfig["Server Config (.env, vercel.json)"]:::config
    end

    %% Data & External Services
    subgraph "Data & Services"
        direction TB
        MongoDB["MongoDB Atlas"]:::db
        Cloudinary["Cloudinary"]:::external
        Stripe["Stripe"]:::external
    end

    %% Deployment
    subgraph "Deployment"
        direction TB
        VercelClient["Vercel (Frontend)"]:::external
        VercelServer["Vercel (Backend)"]:::external
    end

    %% Connections
    Browser -->|"HTTPS"| ReactApp
    ReactApp -->|"uses components"| Components
    ReactApp -->|"uses pages"| Pages
    ReactApp -->|"uses context"| ContextAPI
    ReactApp -->|"imports assets"| StaticAssets
    ReactApp -->|"configures via"| FrontendConfig

    ReactApp -->|"HTTP/JSON"| APIClient
    APIClient -->|"calls /api/*"| ExpressAPI

    ExpressAPI -->|"routes requests to"| Routes
    Routes -->|"passes through"| Middleware
    Middleware -->|"invokes"| Controllers
    Controllers -->|"CRUD operations"| Models
    Models -->|"connects to"| MongoDB

    Controllers -->|"uploads via SDK"| Cloudinary
    Controllers -->|"processes payment via SDK"| Stripe

    ExpressAPI -->|"configures DB via"| DBConfig
    ExpressAPI -->|"configures Cloudinary via"| CloudinaryConfig
    ExpressAPI -->|"configures uploads via"| MulterConfig
    ExpressAPI -->|"server env config"| ServerConfig

    ReactApp -->|"deployed on"| VercelClient
    ExpressAPI -->|"deployed on"| VercelServer

    %% Click Events - Frontend
    click ReactApp "https://github.com/gitguru826004/greencart/blob/main/client/src/main.jsx"
    click ReactApp "https://github.com/gitguru826004/greencart/blob/main/client/src/App.jsx"
    click Components "https://github.com/gitguru826004/greencart/tree/main/client/src/components/"
    click Pages "https://github.com/gitguru826004/greencart/tree/main/client/src/pages/"
    click ContextAPI "https://github.com/gitguru826004/greencart/blob/main/client/src/context/AppContext.jsx"
    click StaticAssets "https://github.com/gitguru826004/greencart/tree/main/client/public/"
    click FrontendConfig "https://github.com/gitguru826004/greencart/blob/main/client/vite.config.js"
    click FrontendConfig "https://github.com/gitguru826004/greencart/blob/main/client/.env"
    click FrontendConfig "https://github.com/gitguru826004/greencart/blob/main/client/vercel.json"

    %% Click Events - Server
    click ExpressAPI "https://github.com/gitguru826004/greencart/blob/main/server/server.js"
    click DBConfig "https://github.com/gitguru826004/greencart/blob/main/server/configs/db.js"
    click CloudinaryConfig "https://github.com/gitguru826004/greencart/blob/main/server/configs/cloudinary.js"
    click MulterConfig "https://github.com/gitguru826004/greencart/blob/main/server/configs/multer.js"
    click Middleware "https://github.com/gitguru826004/greencart/blob/main/server/middleware/authUser.js"
    click Middleware "https://github.com/gitguru826004/greencart/blob/main/server/middleware/authSeller.js"
    click Routes "https://github.com/gitguru826004/greencart/tree/main/server/routes/"
    click Controllers "https://github.com/gitguru826004/greencart/tree/main/server/controllers/"
    click Models "https://github.com/gitguru826004/greencart/tree/main/server/models/"
    click ServerConfig "https://github.com/gitguru826004/greencart/blob/main/server/.env"
    click ServerConfig "https://github.com/gitguru826004/greencart/blob/main/server/vercel.json"

    %% Class Definitions
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px,color:#000
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px,color:#000
    classDef db fill:#FFA500,stroke:#333,stroke-width:1px,color:#000
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px,color:#000
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px,color:#000
```
