# mmt20/full-e-commerce-restful-apis architecture

> Architecture diagram of the GitHub repository mmt20/full-e-commerce-restful-apis, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mmt20/full-e-commerce-restful-apis
- Repository: https://github.com/mmt20/full-e-commerce-restful-apis

## Overview

##### Main Components Identification

a) API Layer (Express.js Server)
b) Service Layer
c) Data Access Layer (MongoDB)
d) External Services
e) Middleware Layer
f) Utility Components

##### Component Relationships

a) Client Requests Flow:
**Client → API Routes → Middlewares → Services → Models → Database**

b) Authentication Flow:
**Client → Auth Routes → JWT Validation → Protected Resources**

c) File Upload Flow:
**Client → Upload Middleware (Multer) → Image Processing (Sharp) → File Storage**

##### Detailed Component Breakdown

A. Routes Layer (Blue)
- Route groups: auth, products, orders, etc.
- To respective service handlers

B. Middleware Layer (Yellow)
- Error handling
- Validation
- Image upload processing
- Authentication checking

C. Services Layer (Blue)
- Business logic modules
- External service integrations
- Data processing

D. Models Layer (Green)
- User
- Product
- Order
- Cart
- Category
- Review
- Coupon

E. External Integrations (Red)
- Stripe Payment Gateway
- Email Service (Gmail SMTP)

##### Additional Elements

- API versioning if applicable
- Security layers (JWT, input validation)
- Database indexes and relationships
- Caching mechanisms (if implemented)
- Error handling flow
- File storage structure

##### Performance and Scalability Indicators

Show:
- Database connection pooling
- Asynchronous operations
- File storage optimization
- Payment processing flow

Remember to indicate the asynchronous nature of Node.js operations and how the different components interact with each other through Promises and async/await patterns.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Clients
        WB[Web Browser]
        MA[Mobile App]
    end

    subgraph "API Layer"
        API[Express.js Server]:::server
        click API "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/server.js"

        subgraph "Route Handlers"
            AR["Auth Routes"]:::route
            PR["Product Routes"]:::route
            OR["Order Routes"]:::route
            CR["Category Routes"]:::route
            UR["User Routes"]:::route
            RR["Review Routes"]:::route
            CAR["Cart Routes"]:::route

            click AR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/authRoute.js"
            click PR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/productRoute.js"
            click OR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/orderRoute.js"
            click CR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/categoryRoute.js"
            click UR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/userRoute.js"
            click RR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/reviewRoute.js"
            click CAR "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/routes/cartRoute.js"
        end
    end

    subgraph "Middleware Layer"
        EH["Error Handler"]:::middleware
        FU["File Upload"]:::middleware
        VAL["Validator"]:::middleware

        click EH "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/middlewares/errorMiddleware.js"
        click FU "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/middlewares/uploadImageMiddleware.js"
        click VAL "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/middlewares/validatorMiddleware.js"
    end

    subgraph "Service Layer"
        AS["Auth Service"]:::service
        PS["Product Service"]:::service
        OS["Order Service"]:::service
        US["User Service"]:::service
        CS["Cart Service"]:::service
        HF["Handlers Factory"]:::service

        click AS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/authService.js"
        click PS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/productService.js"
        click OS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/orderService.js"
        click US "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/userService.js"
        click CS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/cartService.js"
        click HF "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/services/handlersFactory.js"
    end

    subgraph "Data Models"
        UM["User Model"]:::model
        PM["Product Model"]:::model
        OM["Order Model"]:::model
        CM["Cart Model"]:::model
        CATM["Category Model"]:::model
        RM["Review Model"]:::model
        COUM["Coupon Model"]:::model

        click UM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/userModel.js"
        click PM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/productModel.js"
        click OM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/orderModel.js"
        click CM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/cartModel.js"
        click CATM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/categoryModel.js"
        click RM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/reviewModel.js"
        click COUM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/models/couponModel.js"
    end

    subgraph "Utility Services"
        AF["API Features"]:::util
        AE["API Error"]:::util
        TM["Token Management"]:::util
        ES["Email Service"]:::util
        DS["Data Sanitization"]:::util

        click AF "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/apiFeatures.js"
        click AE "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/apiError.js"
        click TM "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/createToken.js"
        click ES "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/sendEmail.js"
        click DS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/sanitizeData.js"
    end

    subgraph "Validators"
        AV["Auth Validator"]:::validator
        PV["Product Validator"]:::validator
        CV["Category Validator"]:::validator
        UV["User Validator"]:::validator

        click AV "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/validators/authValidator.js"
        click PV "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/validators/productValidator.js"
        click CV "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/validators/categoryValidator.js"
        click UV "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/utils/validators/userValidator.js"
    end

    subgraph "External Services"
        ST["Stripe Payment"]:::external
        SMTP["Gmail SMTP"]:::external
    end

    subgraph "Storage"
        DB[(MongoDB)]:::database
        FS["File Storage"]:::storage

        click DB "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/blob/main/config/database.js"
        click FS "https://github.com/mmt20/Full-E-Commerce-RESTful-APIs/tree/main/uploads/products"
    end

    WB & MA --> API
    API --> AR & PR & OR & CR & UR & RR & CAR
    AR & PR & OR & CR & UR & RR & CAR --> EH & FU & VAL
    EH & FU & VAL --> AS & PS & OS & US & CS
    AS & PS & OS & US & CS --> HF
    HF --> UM & PM & OM & CM & CATM & RM & COUM
    UM & PM & OM & CM & CATM & RM & COUM --> DB
    AS & PS & OS & US & CS --> AF & AE & TM & ES & DS
    AR --> AV
    PR --> PV
    CR --> CV
    UR --> UV
    OS --> ST
    ES --> SMTP
    FU --> FS

    classDef server fill:#1E88E5,stroke:#0D47A1,color:white
    classDef route fill:#42A5F5,stroke:#1976D2,color:white
    classDef middleware fill:#FDD835,stroke:#F9A825,color:black
    classDef service fill:#29B6F6,stroke:#0288D1,color:white
    classDef model fill:#66BB6A,stroke:#388E3C,color:white
    classDef util fill:#78909C,stroke:#455A64,color:white
    classDef validator fill:#BA68C8,stroke:#7B1FA2,color:white
    classDef external fill:#EF5350,stroke:#D32F2F,color:white
    classDef database fill:#26A69A,stroke:#00796B,color:white
    classDef storage fill:#8D6E63,stroke:#5D4037,color:white
```
