# wego11ya/e-commerce-api architecture

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

- Interactive diagram: https://gitdiagram.com/wego11ya/e-commerce-api
- Repository: https://github.com/wego11ya/e-commerce-api

## Overview

##### Main System Components

a) API Layer (Express.js Application)
- Entry point (app.js)
- Routes layer (/routes)
- Controllers layer (/controllers)
- Middleware layer (/middleware)

b) Data Layer
- Models layer (/models)
- Database connection (MongoDB)
- Data utilities (/utils)

c) Security & Authentication
- Authentication middleware
- JWT handling
- Permissions system

##### Component Relationships

- Authentication flow (JWT token generation/verification)
- CRUD operations flow
- Order processing workflow
- Review submission process

##### Detailed Component Breakdown

Authentication System:
**Auth Controller → JWT Utils → User Model → MongoDB**

Product Management:
**Product Routes → Product Controller → Product Model → MongoDB**

Order Processing:
**Order Routes → Order Controller → Order Model → MongoDB**

##### Additional Elements

Include:
- Security layer representation
- External service integrations
- Error handling flow
- Middleware pipeline

Remember to:
- Use clear, consistent naming
- Bidirectional relationships where applicable
- Notes for critical security and performance considerations

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        WEB["Web Client"]
        MOB["Mobile Client"]
    end

    subgraph API["API Gateway Layer"]
        direction TB
        APP["API Entry Point"]:::api
        click APP "https://github.com/wego11ya/E-Commerce-API/blob/main/app.js"
        
        subgraph Routes["Routes Layer"]
            direction TB
            AUTH_R["Auth Routes"]:::route
            PROD_R["Product Routes"]:::route
            ORD_R["Order Routes"]:::route
            REV_R["Review Routes"]:::route
            USER_R["User Routes"]:::route
            click AUTH_R "https://github.com/wego11ya/E-Commerce-API/blob/main/routes/authRoutes.js"
            click PROD_R "https://github.com/wego11ya/E-Commerce-API/blob/main/routes/productRoutes.js"
            click ORD_R "https://github.com/wego11ya/E-Commerce-API/blob/main/routes/orderRoutes.js"
            click REV_R "https://github.com/wego11ya/E-Commerce-API/blob/main/routes/reviewRoutes.js"
            click USER_R "https://github.com/wego11ya/E-Commerce-API/blob/main/routes/userRoutes.js"
        end
    end

    subgraph Core["Application Core"]
        direction TB
        subgraph Controllers["Controllers Layer"]
            direction TB
            AUTH_C["Auth Controller"]:::controller
            PROD_C["Product Controller"]:::controller
            ORD_C["Order Controller"]:::controller
            REV_C["Review Controller"]:::controller
            USER_C["User Controller"]:::controller
            click AUTH_C "https://github.com/wego11ya/E-Commerce-API/blob/main/controllers/authController.js"
            click PROD_C "https://github.com/wego11ya/E-Commerce-API/blob/main/controllers/productController.js"
            click ORD_C "https://github.com/wego11ya/E-Commerce-API/blob/main/controllers/orderController.js"
            click REV_C "https://github.com/wego11ya/E-Commerce-API/blob/main/controllers/reviewController.js"
            click USER_C "https://github.com/wego11ya/E-Commerce-API/blob/main/controllers/userController.js"
        end

        subgraph Security["Security Layer"]
            direction TB
            AUTH_M["Authentication Middleware"]:::security
            FULL_AUTH["Full Authentication"]:::security
            JWT["JWT Utils"]:::security
            PERM["Permissions Check"]:::security
            click AUTH_M "https://github.com/wego11ya/E-Commerce-API/blob/main/middleware/authentication.js"
            click FULL_AUTH "https://github.com/wego11ya/E-Commerce-API/blob/main/middleware/full-auth.js"
            click JWT "https://github.com/wego11ya/E-Commerce-API/blob/main/utils/jwt.js"
            click PERM "https://github.com/wego11ya/E-Commerce-API/blob/main/utils/checkPermissions.js"
        end

        subgraph Error["Error Handling"]
            direction TB
            ERR_H["Error Handler"]:::error
            CUSTOM_ERR["Custom API Errors"]:::error
            NOT_FOUND["Not Found Handler"]:::error
            AUTH_ERR["Authentication Errors"]:::error
            AUTH_ERR2["Authorization Errors"]:::error
            click ERR_H "https://github.com/wego11ya/E-Commerce-API/blob/main/middleware/error-handler.js"
            click CUSTOM_ERR "https://github.com/wego11ya/E-Commerce-API/blob/main/errors/custom-api.js"
            click NOT_FOUND "https://github.com/wego11ya/E-Commerce-API/blob/main/middleware/not-found.js"
            click AUTH_ERR "https://github.com/wego11ya/E-Commerce-API/blob/main/errors/unauthenticated.js"
            click AUTH_ERR2 "https://github.com/wego11ya/E-Commerce-API/blob/main/errors/unauthorized.js"
        end
    end

    subgraph Data["Data Layer"]
        direction TB
        DB_CONN["Database Connection"]:::database
        click DB_CONN "https://github.com/wego11ya/E-Commerce-API/blob/main/db/connect.js"
        
        subgraph Models["Data Models"]
            direction TB
            USER_M["User Model"]:::model
            PROD_M["Product Model"]:::model
            ORD_M["Order Model"]:::model
            REV_M["Review Model"]:::model
            click USER_M "https://github.com/wego11ya/E-Commerce-API/blob/main/models/User.js"
            click PROD_M "https://github.com/wego11ya/E-Commerce-API/blob/main/models/Product.js"
            click ORD_M "https://github.com/wego11ya/E-Commerce-API/blob/main/models/Order.js"
            click REV_M "https://github.com/wego11ya/E-Commerce-API/blob/main/models/Review.js"
        end

        subgraph Utils["Utilities"]
            direction TB
            TOKEN_U["Token User Creation"]:::util
            GEN_U["General Utilities"]:::util
            click TOKEN_U "https://github.com/wego11ya/E-Commerce-API/blob/main/utils/createTokenUser.js"
            click GEN_U "https://github.com/wego11ya/E-Commerce-API/blob/main/utils/index.js"
        end
    end

    %% Relationships
    WEB & MOB --> APP
    APP --> Routes
    Routes --> Controllers
    Controllers --> Security
    Controllers --> Models
    Models --> DB_CONN
    Security --> JWT
    Controllers --> Error
    
    %% Styling
    classDef api fill:#1E88E5,stroke:#0D47A1,color:white
    classDef route fill:#42A5F5,stroke:#1976D2,color:white
    classDef controller fill:#2196F3,stroke:#1976D2,color:white
    classDef security fill:#4CAF50,stroke:#388E3C,color:white
    classDef model fill:#FFC107,stroke:#FFA000,color:black
    classDef database fill:#FF9800,stroke:#F57C00,color:white
    classDef error fill:#F44336,stroke:#D32F2F,color:white
    classDef util fill:#9C27B0,stroke:#7B1FA2,color:white
```
