# jaideepbose51/theverse-hackon5-ecotrustpay architecture

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

- Interactive diagram: https://gitdiagram.com/jaideepbose51/theverse-hackon5-ecotrustpay
- Repository: https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay

## Overview

##### Project type and purpose
- This is a full-stack, multi-tenant e-commerce platform (“EcoCommerce”) with three separate React-based SPAs (Customer, Seller, Admin) talking to a central Node.js/Express REST API.
- Purpose: Enable three roles—end users (shopping), sellers (product management), and administrators (platform management)—to interact via authenticated API endpoints backed by MongoDB and Cloudinary.

##### File structure
- Top-level directories:
– backend: Express app subdivided into config, controller, middleware, model, routes, utils
– frontend: Customer SPA (React + Vite + Tailwind + Context API)
– seller: Seller SPA (React + Vite + Tailwind)
– admin: Admin SPA (React + Vite + Tailwind)
- Patterns:
– Backend follows MVC-style separation: routes → controllers → models (Mongoose).
– Shared middleware for authentication (JWT), error-handling, file uploads (Multer).
– Frontends each follow component/page hierarchy under src/, use React Router, global state or context for user sessions.
- Config & deployment files: .env references for backend URL, Cloudinary, MongoDB, JWT secret; Vite configs, Tailwind configs.

##### README for additional insights
- RESTful API endpoints grouped by role (/api/user, /api/seller, /api/admin)
- JWT-based auth flows, role-based middleware (authUser, authSeller, authAdmin)
- Third-party integration: Cloudinary for image storage
- Feature set: Cart, orders, eco-stats, product verification, report export

a. Main components
1) Customer SPA (React/Vite)
2) Seller SPA (React/Vite)
3) Admin SPA (React/Vite)
4) API Server (Node.js/Express)
– Routes & Controllers
– Middleware (Auth, Error Handler, Multer)
– Models (Mongoose schemas)
5) Database: MongoDB (hosted)
6) External service: Cloudinary (image upload/storage)

b. Relationships & interactions
– Each SPA communicates over HTTPS to the API Server’s REST endpoints.
– API Server persists and retrieves data from MongoDB.
– For file uploads (product images, seller docs), API Server uses Multer → Cloudinary SDK.
– JWT tokens are issued by the API Server upon login and attached by SPAs on subsequent calls.

c. Architectural patterns & design principles
– Separation of Concerns: SPAs vs. API vs. Data layer
– MVC-style organization in the backend
– Role-based access control enforced by middleware
– API contracts documented in README for consistency
– Client-side state management (Context API in Customer SPA)

d. Key technologies, frameworks, libraries
– Backend: Node.js, Express, Mongoose, Multer, jsonwebtoken, Cloudinary SDK
– Frontends: React, Vite, Tailwind CSS, React Router, Context API
– Database: MongoDB (URI via ENV)
– Auth: JWT, role-based middleware

##### Detail without over-complication
- Every major component and its dependencies: frontends, API modules, DB, external services.
- Don’t hesitate to break the backend into sub-components (e.g., Auth, Catalogue, User Controllers) if it improves clarity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        subgraph "Customer SPA"
            direction TB
            CEntry["main.jsx"]:::customer
            CApp["App.jsx"]:::customer
            CPages["pages/"]:::customer
            CComponents["components/"]:::customer
        end
        subgraph "Seller SPA"
            direction TB
            SEntry["main.jsx"]:::seller
            SApp["App.jsx"]:::seller
            SPages["pages/"]:::seller
            SComponents["components/"]:::seller
        end
        subgraph "Admin SPA"
            direction TB
            AEntry["main.jsx"]:::admin
            AApp["App.jsx"]:::admin
            APages["pages/"]:::admin
            AComponents["components/"]:::admin
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        APIServer["API Server\n(Node.js/Express)"]:::backend
        subgraph "API Internals"
            direction TB
            subgraph "Routes"
                URoute["userRoute.js"]:::backend
                SRoute["sellerRoute.js"]:::backend
                ARoute["adminRoute.js"]:::backend
            end
            subgraph "Controllers"
                UController["userController.js"]:::backend
                SeController["sellerController.js"]:::backend
                AdController["adminController.js"]:::backend
                CController["catalogueController.js"]:::backend
            end
            subgraph "Models"
                UModel["userModel.js"]:::backend
                SeModel["sellerModel.js"]:::backend
                CModel["catalogueModel.js"]:::backend
            end
            subgraph "Middleware"
                Auth["auth.js"]:::backend
                AuthU["authUser.js"]:::backend
                AuthS["authSeller.js"]:::backend
                AuthA["authAdmin.js"]:::backend
                Err["errorHandler.js"]:::backend
                Multer["multer.js"]:::backend
                ValID["validateObjectIds.js"]:::backend
            end
            subgraph "Config"
                MongoCfg["mongodb.js"]:::backend
                CloudCfg["cloudinary.js"]:::backend
            end
            subgraph "Utils"
                CloudUtil["cloudinaryUpload.js"]:::backend
            end
        end
    end

    %% Data and External
    subgraph "Data & External Services"
        direction TB
        MongoDB[(MongoDB)]:::database
        Cloudinary((Cloudinary)):::external
    end

    %% Connections
    CComponents -->|interacts via REST| APIServer
    SPages -->|interacts via REST| APIServer
    APages -->|interacts via REST| APIServer

    APIServer --> URoute
    URoute --> UController
    SRoute --> SeController
    ARoute --> AdController
    UController --> UModel
    SeController --> SeModel
    AdController --> CModel
    CController --> CModel

    UController --> AuthU
    SeController --> AuthS
    AdController --> AuthA
    URoute --> Auth
    UController --> Multer
    Multer --> CloudUtil
    CloudUtil --> Cloudinary

    APIServer --> MongoDB

    %% Click Events
    click CEntry "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/frontend/src/main.jsx"
    click CApp "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/frontend/src/App.jsx"
    click CPages "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/frontend/src/pages/"
    click CComponents "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/frontend/src/components/"
    click SEntry "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/seller/src/main.jsx"
    click SApp "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/seller/src/App.jsx"
    click SPages "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/seller/src/pages/"
    click SComponents "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/seller/src/components/"
    click AEntry "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/admin/src/main.jsx"
    click AApp "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/admin/src/App.jsx"
    click APages "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/admin/src/pages/"
    click AComponents "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/tree/main/admin/src/components/"
    click APIServer "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/server.js"
    click URoute "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/routes/userRoute.js"
    click SRoute "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/routes/sellerRoute.js"
    click ARoute "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/routes/adminRoute.js"
    click UController "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/controller/userController.js"
    click SeController "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/controller/sellerController.js"
    click AdController "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/controller/adminController.js"
    click CController "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/controller/catalogueController.js"
    click UModel "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/model/userModel.js"
    click SeModel "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/model/sellerModel.js"
    click CModel "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/model/catalogueModel.js"
    click Auth "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/auth.js"
    click AuthU "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/authUser.js"
    click AuthS "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/authSeller.js"
    click AuthA "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/authAdmin.js"
    click Err "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/errorHandler.js"
    click Multer "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/multer.js"
    click ValID "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/middleware/validateObjectIds.js"
    click MongoCfg "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/config/mongodb.js"
    click CloudCfg "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/config/cloudinary.js"
    click CloudUtil "https://github.com/jaideepbose51/theverse-hackon5-ecotrustpay/blob/main/backend/utils/cloudinaryUpload.js"

    %% Styles
    classDef customer fill:#cce5ff,stroke:#004085,color:#004085
    classDef seller fill:#d4edda,stroke:#155724,color:#155724
    classDef admin fill:#fff3cd,stroke:#856404,color:#856404
    classDef backend fill:#e2e3e5,stroke:#818182,color:#343a40
    classDef database fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef external fill:#d1ecf1,stroke:#0c5460,color:#0c5460
```
