# merabetmalih/smartcity_backend_rmcs architecture

> Architecture diagram of the GitHub repository merabetmalih/smartcity_backend_rmcs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/merabetmalih/smartcity_backend_rmcs
- Repository: https://github.com/merabetmalih/smartcity_backend_rmcs

## Overview

##### Main Architectural Components

a) External Layer:
- Client Applications (Mobile/Web)
- Payment Gateway (Stripe integration, evident from stripe.js)
- File Storage System (for images in public directory)

b) Application Layer:
- API Gateway/Routes Layer
- Authentication/Authorization Layer
- Controllers Layer
- Services Layer
- Data Access Layer (Models)

##### Key Components

a) Entry Points:
- HTTP REST API endpoints (grouped by functionality):
- Auth routes
- Cart routes
- Category routes
- Order routes
- Product routes
- Search routes
- Store routes
- User routes
- Offer routes

b) Middleware Layer:
- Token Verification
- Data Validation
- Email Handler

c) Business Logic Layer:
- Service Layer Components
- Utility Functions (checkOffer, checkProVarin)

d) Data Models:
- User
- Store
- Product
- Category
- Cart
- Order
- Bill
- Payment
- FlashDeal
- Offer

**External Clients/Systems**
- ↓
**API Gateway (Routes)**
- ↓
**Middleware Layer**
- ↓
**Controllers Layer**
- ↓
**Services Layer**
- ↓
**Models Layer**
- ↓
**Database**

##### Important Relationships to Highlight

Key interactions:
- Authentication flow
- Payment processing flow
- Order processing pipeline
- Product and category management
- Cart and order relationship
- Store and product relationship

##### Additional Elements

Supporting components:
- Environment configuration (.env files)
- Docker container boundaries (Dockerfile presence)
- Public assets management
- External service integrations (Stripe)

##### Specific Implementation Details

Architectural patterns:
- MVC pattern implementation
- Service-oriented architecture
- Repository pattern for data access
- Middleware chain pattern
- Event-driven components (if any)

##### Version/environment management indicators

Remember to:
- Use consistent symbols throughout
- Notes for any non-obvious relationships
- Both synchronous and asynchronous flows
- Scalability points
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Layer"]
        Client["Client Applications"]
        PaymentGW["Payment Gateway"]:::external
        FileStorage["File Storage System"]
    end

    subgraph Routes["API Gateway Layer"]
        direction TB
        AuthR["Auth Routes"]:::route
        CartR["Cart Routes"]:::route
        CategoryR["Category Routes"]:::route
        OrderR["Order Routes"]:::route
        ProductR["Product Routes"]:::route
        SearchR["Search Routes"]:::route
        StoreR["Store Routes"]:::route
        UserR["User Routes"]:::route
        OfferR["Offer Routes"]:::route
    end

    subgraph Middleware["Middleware Layer"]
        TokenVerify["Token Verification"]:::security
        DataValidation["Data Validation"]:::middleware
        EmailHandler["Email Handler"]:::middleware
    end

    subgraph Controllers["Controllers Layer"]
        AuthC["Auth Controller"]:::controller
        CartC["Cart Controller"]:::controller
        CategoryC["Category Controller"]:::controller
        OrderC["Order Controller"]:::controller
        ProductC["Product Controller"]:::controller
        SearchC["Search Controller"]:::controller
        StoreC["Store Controller"]:::controller
        UserC["User Controller"]:::controller
        OfferC["Offer Controller"]:::controller
    end

    subgraph Services["Services Layer"]
        AuthS["Auth Service"]:::service
        CartS["Cart Service"]:::service
        CategoryS["Category Service"]:::service
        OrderS["Order Service"]:::service
        ProductS["Product Service"]:::service
        SearchS["Search Service"]:::service
        StoreS["Store Service"]:::service
        UserS["User Service"]:::service
        OfferS["Offer Service"]:::service
    end

    subgraph Models["Data Models Layer"]
        User["User Model"]:::model
        Store["Store Model"]:::model
        Product["Product Model"]:::model
        Category["Category Model"]:::model
        Cart["Cart Model"]:::model
        Order["Order Model"]:::model
        Bill["Bill Model"]:::model
        Payment["Payment Model"]:::model
        FlashDeal["FlashDeal Model"]:::model
        Offer["Offer Model"]:::model
    end

    subgraph Utils["Utility Components"]
        Stripe["Stripe Integration"]:::util
        OfferChecker["Offer Checker"]:::util
        VariantChecker["Product Variant Checker"]:::util
    end

    Database[(MongoDB)]:::database

    %% Connections
    Client --> Routes
    Routes --> Middleware
    Middleware --> Controllers
    Controllers --> Services
    Services --> Models
    Models --> Database
    Services --> Utils
    PaymentGW --> Stripe
    FileStorage --> Services

    %% Click Events
    click AuthR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/authRoute.js"
    click CartR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/cartRoute.js"
    click CategoryR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/categoryRoute.js"
    click OrderR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/orderRoute.js"
    click ProductR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/productRoute.js"
    click SearchR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/searchRoute.js"
    click StoreR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/storeRoute.js"
    click UserR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/userRoute.js"
    click OfferR "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/routes/offerRoute.js"

    click TokenVerify "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/middleware/verifyToken.js"
    click DataValidation "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/middleware/dataValidation.js"
    click EmailHandler "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/middleware/email.js"

    click AuthC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/authController.js"
    click CartC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/cartController.js"
    click CategoryC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/categoryController.js"
    click OrderC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/orderController.js"
    click ProductC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/productController.js"
    click SearchC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/searchController.js"
    click StoreC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/storeController.js"
    click UserC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/userController.js"
    click OfferC "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/controllers/offerController.js"

    click AuthS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/authService.js"
    click CartS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/cartService.js"
    click CategoryS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/categoryService.js"
    click OrderS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/orderService.js"
    click ProductS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/productService.js"
    click SearchS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/searchService.js"
    click StoreS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/storeService.js"
    click UserS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/userService.js"
    click OfferS "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/services/offerService.js"

    click User "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/User.js"
    click Store "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Store.js"
    click Product "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Product.js"
    click Category "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Category.js"
    click Cart "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Cart.js"
    click Order "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Order.js"
    click Bill "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Bill.js"
    click Payment "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Payment.js"
    click FlashDeal "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/FlashDeal.js"
    click Offer "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/models/Offer.js"

    click Stripe "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/utile/stripe.js"
    click OfferChecker "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/utile/checkOffer.js"
    click VariantChecker "https://github.com/merabetmalih/SmartCity_Backend_RMCS/blob/main/src/utile/checkProVarin.js"

    %% Styling
    classDef external fill:#1E88E5,color:white
    classDef route fill:#4CAF50,color:white
    classDef middleware fill:#FFC107,color:black
    classDef controller fill:#9C27B0,color:white
    classDef service fill:#FF5722,color:white
    classDef model fill:#607D8B,color:white
    classDef database fill:#795548,color:white
    classDef security fill:#F44336,color:white
    classDef util fill:#00BCD4,color:white
```
