# shagor-mia/multivendor-e-commerce-backend- architecture

> Architecture diagram of the GitHub repository shagor-mia/multivendor-e-commerce-backend-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shagor-mia/multivendor-e-commerce-backend-
- Repository: https://github.com/shagor-mia/multivendor-e-commerce-backend-

## Overview

##### Project Type and Purpose
- This is a backend RESTful API for a multivendor e-commerce platform.
- Built with Node.js, Express, TypeScript and MongoDB; integrates with Stripe for payments and Cloudinary for image uploads.

##### File Structure
- Entry Point: src/index.ts
- Configuration: src/config (stripe.ts, database URI)
- Routing Layer: src/routes (separate route files per resource)
- Middleware Layer: src/middleware (authentication, rate limiting, file uploads)
- Controller Layer: src/controllers (business logic per domain: auth, user, product, order, payment, etc.)
- Data Layer: src/models (Mongoose schemas for User, Product, Order, Payment, Category, Cart, ReviewRating)
- Utilities & Validation: src/utils (OTP, JWT token functions), src/validation (Joi or Zod schemas)
- Database Connection: src/database/connect.ts
- Environment / Types: src/types/environment.d.ts

##### README for Insights
- Role-based access control (Admin, Vendor, User)
- Stripe payment intent creation and webhook handling
- MongoDB as primary data store

##### Main Components & Their Relationships
a. Client Applications
– Web or Mobile front-ends consuming the API over HTTP(S).
b. API Gateway / Express Server
– Entry point (index.ts)
– Global middleware (authMiddleware, rateLimiters)
– Route definitions → Controller handlers
c. Controllers (Business Logic)
– Handle requests for auth, user management, product/catalog, cart, orders, payments, reviews, vendor operations.
– Token generation (JWT), OTP sending, Cloudinary upload, Stripe SDK calls
e. Data Access Layer (Models)
– Mongoose models mapping to MongoDB collections
f. Database
– MongoDB cluster (cloud or local)
g. External Services
– Stripe (payment intents, webhooks)
– Cloudinary or local file store (image uploads)

##### Architectural Patterns & Design Principles
- Layered (Presentation → Middleware → Controllers → Models → Database)
- MVC-inspired: Routes map to Controllers, Controllers invoke Models
- Separation of concerns: Authentication/authorization isolated in middleware
- Dependency injection via config modules (e.g., stripe key, DB URI)
- Event-driven webhook handling for Stripe

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Web/Mobile)"]:::external

    subgraph "Layer 1: API Gateway & Middleware"
        API["Express Server"]:::internal
        Config["Config (Stripe & Env)"]:::config
        DBConn["DB Connection"]:::internal
        AuthMW["Auth Middleware"]:::internal
        RateMW["Rate Limiting Middleware"]:::internal
        UploadCloud["Upload to Cloudinary Middleware"]:::internal
        UploadServer["Upload to Server Middleware"]:::internal
    end

    subgraph "Layer 2: Routing & Controllers"
        subgraph Routing
            AuthR["Auth Routes"]:::internal
            AdminR["Admin Routes"]:::internal
            UserR["User Routes"]:::internal
            ProdR["Product Routes"]:::internal
            CatR["Category Routes"]:::internal
            CartR["Cart Routes"]:::internal
            OrderR["Order Routes"]:::internal
            PaymentR["Payment Routes"]:::internal
            ReviewR["Review & Rating Routes"]:::internal
        end
        subgraph Controllers
            AuthC["Auth Controller"]:::internal
            AdminC["Admin Controller"]:::internal
            UserC["User Controller"]:::internal
            ProdC["Product Controller"]:::internal
            CatC["Category Controller"]:::internal
            CartC["Cart Controller"]:::internal
            OrderC["Order Controller"]:::internal
            PaymentC["Payment Controller"]:::internal
            VendorC["Vendor Controller"]:::internal
            WebhookC["Webhook Controller"]:::internal
            ReviewC["ReviewRating Controller"]:::internal
        end
    end

    subgraph "Layer 3: Services & Models"
        subgraph Services
            OTP["OTP Generation"]:::internal
            TokenUtil["JWT Token Utilities"]:::internal
        end
        subgraph Models
            UserM["User Model"]:::internal
            ProdM["Product Model"]:::internal
            OrderM["Order Model"]:::internal
            PaymentM["Payment Model"]:::internal
            CatM["Category Model"]:::internal
            CartM["Cart Model"]:::internal
            ReviewM["ReviewRating Model"]:::internal
        end
        Validation["Validation Schemas"]:::internal
        Types["Env Types"]:::config
    end

    subgraph "Layer 4: Database & External"
        DB["MongoDB"]:::database
        Stripe["Stripe"]:::external
        Cloudinary["Cloudinary"]:::external
    end

    Client -->|"HTTP Request"| API
    API --> Config
    API --> DBConn
    API --> AuthMW
    API --> RateMW
    API --> UploadCloud
    API --> UploadServer

    AuthMW --> AuthR
    RateMW --> AuthR
    UploadCloud --> ProdR
    UploadServer --> ProdR

    AuthMW --> AdminR
    AuthMW --> UserR
    AuthMW --> CartR
    AuthMW --> OrderR
    AuthMW --> PaymentR
    AuthMW --> ReviewR
    AuthMW --> ProdR
    AuthMW --> CatR

    AuthR --> AuthC
    AdminR --> AdminC
    UserR --> UserC
    ProdR --> ProdC
    CatR --> CatC
    CartR --> CartC
    OrderR --> OrderC
    PaymentR --> PaymentC
    ReviewR --> ReviewC

    ProdC --> ProdM
    ProdC --> UploadCloud
    ProdC --> UploadServer
    CatC --> CatM
    CartC --> CartM
    OrderC --> OrderM
    PaymentC --> PaymentM
    PaymentC --> Stripe
    AuthC --> UserM
    AuthC --> TokenUtil
    AuthC --> OTP
    AdminC --> UserM
    AdminC --> CatM
    AdminC --> ProdM
    UserC --> UserM
    VendorC --> ProdM
    WebhookC --> Stripe
    WebhookC --> OrderM
    WebhookC --> PaymentM
    ReviewC --> ReviewM

    UserM --> DB
    ProdM --> DB
    OrderM --> DB
    PaymentM --> DB
    CatM --> DB
    CartM --> DB
    ReviewM --> DB
    DBConn --> DB

    classDef internal fill:#4682B4,stroke:#000,color:#fff
    classDef external fill:#FFA500,stroke:#000,color:#fff
    classDef database fill:#3CB371,stroke:#000,color:#fff
    classDef config fill:#D3D3D3,stroke:#000,color:#000

    click API "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/index.ts"
    click Config "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/config/stripe.ts"
    click DBConn "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/database/connect.ts"
    click AuthMW "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/middleware/authMiddleware.ts"
    click RateMW "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/middleware/rateLimmiters.ts"
    click UploadCloud "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/middleware/uploadToCloudinary.ts"
    click UploadServer "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/middleware/uploadToServer.ts"
    click AuthR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/authRoutes.ts"
    click AdminR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/adminRoutes.ts"
    click UserR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/userRoutes.ts"
    click ProdR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/productRoutes.ts"
    click CatR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/categoryRoutes.ts"
    click CartR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/cartRoute.ts"
    click OrderR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/orderRoute.ts"
    click PaymentR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/paymentRoutes.ts"
    click ReviewR "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/routes/reviewRatting.ts"
    click AuthC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/authController.ts"
    click AdminC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/adminController.ts"
    click UserC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/userController.ts"
    click ProdC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/productController.ts"
    click CatC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/categoryController.ts"
    click CartC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/cartController.ts"
    click OrderC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/orderController.ts"
    click PaymentC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/paymentController.ts"
    click ReviewC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/reviewRatingController.ts"
    click VendorC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/vendorController.ts"
    click WebhookC "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/controllers/webhookController.ts"
    click UserM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/User.ts"
    click ProdM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/Product.ts"
    click OrderM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/Order.ts"
    click PaymentM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/Payment.ts"
    click CatM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/Category.ts"
    click CartM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/Cart.ts"
    click ReviewM "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/models/ReviewRating.ts"
    click OTP "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/utils/otp.ts"
    click TokenUtil "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/utils/token.ts"
    click Validation "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/validation/userSchema.ts"
    click Types "https://github.com/shagor-mia/multivendor-e-commerce-backend-/blob/main/src/types/environment.d.ts"
```
