# kuldeeprec/weggsapi architecture

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

- Interactive diagram: https://gitdiagram.com/kuldeeprec/weggsapi
- Repository: https://github.com/kuldeeprec/weggsapi

## Overview

##### Main components
- API Server: Represented by the entry points (app.js and index.js) that bootstrap the server.
- Routes: Group the route files (Admin.js, Order.js, Payment.js, Product.js, User.js, WhereToBuy.js) into a “Routes” block. These components direct incoming HTTP requests to the proper controllers.
- Middlewares: Create a component labeled “Middlewares” that includes functions like bigPromise, verifyJwtToken, and whereClause. These sit between the requests and the controllers for tasks such as authentication, error-handling, or request validation.
- Models: Setup a “Models” component that contains database schema representations (order, otp, product, user, wheretobuy). This block implies linkages with a database.
- External Dependencies: Although not explicitly detailed in the tree, note the presence of package.json which implies third-party dependencies (for example, express, jwt libraries for token verification, etc.). Optionally, add an “External Services” block for services such as payment gateways if they are integrated (inferred from the paymentController and Payment route).

##### Relationships and interactions
- Client-side interactions initiating HTTP requests that hit the Routes layer.
- Middleware functions should be shown intercepting requests before they reach the controllers. Illustrate these as filters or checkpoints between the Routes block and Controllers.

##### Architectural patterns and design principles
- Separation of concerns: Routes (request routing), Controllers (business logic), Middlewares (pre/post processing like JWT verification), and Models (data access).
- That the system is designed around modularity, where different endpoints (admin, order, payment, product, user, wheretobuy) are handled independently.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Node
    subgraph "Client Layer"
        client["Client"]:::client
    end

    %% API Server Layer with Entry Points
    subgraph "API Server"
        app["app.js"]:::server
        index["index.js"]:::server
    end

    %% External Dependencies
    external["package.json"]:::external

    %% Routes Layer
    subgraph "Routes"
        adminRoute["Admin Routes"]:::routes
        orderRoute["Order Routes"]:::routes
        paymentRoute["Payment Routes"]:::routes
        productRoute["Product Routes"]:::routes
        userRoute["User Routes"]:::routes
        whereToBuyRoute["WhereToBuy Routes"]:::routes
    end

    %% Middlewares Layer
    subgraph "Middlewares"
        bigPromise["bigPromise"]:::middleware
        verifyJwt["verifyJwtToken"]:::middleware
        whereClause["whereClause"]:::middleware
    end

    %% Controllers Layer
    subgraph "Controllers"
        adminCtrl["adminController"]:::controller
        orderCtrl["orderController"]:::controller
        paymentCtrl["paymentController"]:::controller
        productCtrl["productController"]:::controller
        userCtrl["userController"]:::controller
        whereToBuyCtrl["whereToBuyController"]:::controller
    end

    %% Models Layer
    subgraph "Models"
        orderModel["Order Model"]:::model
        otpModel["OTP Model"]:::model
        productModel["Product Model"]:::model
        userModel["User Model"]:::model
        whereToBuyModel["WhereToBuy Model"]:::model
    end

    %% Configuration and Database
    configuration["DB Config"]:::config
    database["Database"]:::database

    %% Data Flow Connections
    client -->|"HTTP_Request"| app
    client -->|"HTTP_Request"| index

    app -->|"Initializes"| external
    index -->|"Initializes"| external

    app -->|"Forwards_to"| adminRoute
    app -->|"Forwards_to"| orderRoute
    app -->|"Forwards_to"| paymentRoute
    app -->|"Forwards_to"| productRoute
    app -->|"Forwards_to"| userRoute
    app -->|"Forwards_to"| whereToBuyRoute

    index -->|"Forwards_to"| adminRoute
    index -->|"Forwards_to"| orderRoute
    index -->|"Forwards_to"| paymentRoute
    index -->|"Forwards_to"| productRoute
    index -->|"Forwards_to"| userRoute
    index -->|"Forwards_to"| whereToBuyRoute

    %% Routes pass requests to Middlewares
    adminRoute -->|"Uses"| bigPromise
    orderRoute -->|"Uses"| verifyJwt
    paymentRoute -->|"Uses"| whereClause
    productRoute -->|"Uses"| bigPromise
    userRoute -->|"Uses"| verifyJwt
    whereToBuyRoute -->|"Uses"| whereClause

    %% Middlewares hand over to Controllers
    bigPromise -->|"Calls"| adminCtrl
    verifyJwt -->|"Calls"| orderCtrl
    whereClause -->|"Calls"| paymentCtrl
    bigPromise -->|"Calls"| productCtrl
    verifyJwt -->|"Calls"| userCtrl
    whereClause -->|"Calls"| whereToBuyCtrl

    %% Controllers invoke Models for CRUD operations
    adminCtrl -->|"CRUD"| orderModel
    orderCtrl -->|"CRUD"| otpModel
    paymentCtrl -->|"CRUD"| productModel
    productCtrl -->|"CRUD"| userModel
    userCtrl -->|"CRUD"| whereToBuyModel
    whereToBuyCtrl -->|"CRUD"| orderModel

    %% Models connect to Database via Configuration
    orderModel --> configuration
    otpModel --> configuration
    productModel --> configuration
    userModel --> configuration
    whereToBuyModel --> configuration

    configuration -->|"Connects"| database

    %% Click Events
    click app "https://github.com/kuldeeprec/weggsapi/blob/main/app.js"
    click index "https://github.com/kuldeeprec/weggsapi/blob/main/index.js"
    click external "https://github.com/kuldeeprec/weggsapi/blob/main/package.json"
    
    click adminCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/adminController.js"
    click orderCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/orderController.js"
    click paymentCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/paymentController.js"
    click productCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/productController.js"
    click userCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/userController.js"
    click whereToBuyCtrl "https://github.com/kuldeeprec/weggsapi/blob/main/controllers/whereToBuyController.js"
    
    click adminRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/Admin.js"
    click orderRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/Order.js"
    click paymentRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/Payment.js"
    click productRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/Product.js"
    click userRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/User.js"
    click whereToBuyRoute "https://github.com/kuldeeprec/weggsapi/blob/main/routes/WhereToBuy.js"
    
    click bigPromise "https://github.com/kuldeeprec/weggsapi/blob/main/middlewares/bigPromise.js"
    click verifyJwt "https://github.com/kuldeeprec/weggsapi/blob/main/middlewares/verifyJwtToken.js"
    click whereClause "https://github.com/kuldeeprec/weggsapi/blob/main/middlewares/whereClause.js"
    
    click orderModel "https://github.com/kuldeeprec/weggsapi/blob/main/models/order.js"
    click otpModel "https://github.com/kuldeeprec/weggsapi/blob/main/models/otp.js"
    click productModel "https://github.com/kuldeeprec/weggsapi/blob/main/models/product.js"
    click userModel "https://github.com/kuldeeprec/weggsapi/blob/main/models/user.js"
    click whereToBuyModel "https://github.com/kuldeeprec/weggsapi/blob/main/models/wheretobuy.js"
    
    click configuration "https://github.com/kuldeeprec/weggsapi/blob/main/config/db.js"

    %% Style Definitions
    classDef client fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef server fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef routes fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef middleware fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef controller fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef model fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef config fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
