# ngtrnhao/obeyclothing architecture

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

- Interactive diagram: https://gitdiagram.com/ngtrnhao/obeyclothing
- Repository: https://github.com/ngtrnhao/obeyclothing

## Overview

##### Main Components
- Frontend:
- That it uses React.js, CSS Modules, and React Router.

- Backend:
● Controllers (for example, auth, product, order, voucher, user, etc.)
● Routes linking to each controller module (e.g., /api/auth, /api/products, etc.)
● Middleware (e.g., JWT authentication, file upload via Multer, and role-based access control).
● Models representing MongoDB collections (User, Product, Order, etc.)
● Services and utilities (PDF generation, email service, cron jobs, state factories for order and delivery states).

- Database:
- A “Database” component representing MongoDB.

- External Services:
- Integrations with third-party services such as:
● Cloudinary (for image uploads).
● PayPal (for payment processing).
● Email Service (likely for authentication and notifications).
● Possibly a file storage mechanism for uploads.

##### Relationships & Data Flow
● Routes invoke Controllers.
● Controllers use Services to perform business logic.
● Models are used by services/controllers to retrieve and store data in the Database.

##### Architectural Patterns & Design Principles
- The separation of Frontend and Backend indicates a clear separation-of-concerns.
- The use of controllers, routes, models, middleware, and services suggests an MVC (or layered) architecture on the backend.
- The modular file layout in the frontend (components, contexts, pages, layouts) supports a component-based architecture driven by React.
- Cloud integration and external API usage are design decisions worth noting.

##### Relevant Technologies and Frameworks
- Frontend: React, React Router, Axios, CSS Modules.
- Backend: Node.js, Express, MongoDB, Mongoose, JWT, Multer, PDFKit, Node-cron.
- DevOps: Git, npm, and deployment configurations (vercel.json files).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE_App["React App"]:::frontend
        FE_UI["UI Components"]:::frontend
        FE_Pages["Pages"]:::frontend
        FE_Router["Layouts & Routing"]:::frontend
        FE_Context["State Management & Contexts"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE_Api["API Server"]:::backend
        BE_Routes["Routes"]:::backend
        BE_Controllers["Controllers"]:::backend
        BE_Middleware["Middleware"]:::middleware
        BE_Models["Models"]:::model
        BE_Services["Services & Utilities"]:::service
        BE_StateFactories["State Factories"]:::service
        BE_Config["External Configurations"]:::backend
    end

    %% Database Node
    DB["Database (MongoDB)"]:::db

    %% External Services
    subgraph "External Services"
        EXT_Cloud["Cloudinary"]:::external
        EXT_Paypal["PayPal"]:::external
        EXT_Email["Email Service"]:::external
        EXT_File["File Storage"]:::external
    end

    %% Frontend Internal Relationships
    FE_UI --> FE_App
    FE_Pages --> FE_App
    FE_Router --> FE_App
    FE_Context --> FE_App

    %% Frontend to Backend Connection
    FE_App -->|"API_Calls"| BE_Api
    FE_App -->|"Payment_Integration"| EXT_Paypal

    %% Backend Internal Relationships
    BE_Api --> BE_Routes
    BE_Routes --> BE_Middleware
    BE_Routes --> BE_Controllers
    BE_Controllers --> BE_Services
    BE_Controllers --> BE_Models
    BE_Controllers --> BE_StateFactories
    BE_Controllers --> BE_Config
    BE_Services --> BE_Models

    %% Database Connections
    BE_Models -->|"Mongoose_ODM"| DB
    BE_Services -->|"Interacts_with"| DB

    %% External Services Connections from Backend
    BE_Services --> EXT_Cloud
    BE_Services --> EXT_Paypal
    BE_Services --> EXT_Email
    BE_Middleware --> EXT_File

    %% State Design Pattern Relationship
    BE_StateFactories -->|"Manages_State"| BE_Controllers

    %% Click Events for Frontend
    click FE_App "https://github.com/ngtrnhao/obeyclothing/tree/main/frontend/src"
    click FE_UI "https://github.com/ngtrnhao/obeyclothing/tree/main/frontend/src/components"
    click FE_Pages "https://github.com/ngtrnhao/obeyclothing/tree/main/frontend/src/pages"
    click FE_Router "https://github.com/ngtrnhao/obeyclothing/tree/main/frontend/src/layouts"
    click FE_Router "https://github.com/ngtrnhao/obeyclothing/blob/main/frontend/src/AppRoutes.js"
    click FE_Context "https://github.com/ngtrnhao/obeyclothing/tree/main/frontend/src/contexts"

    %% Click Events for Backend
    click BE_Api "https://github.com/ngtrnhao/obeyclothing/blob/main/backend/server.js"
    click BE_Controllers "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/controllers"
    click BE_Routes "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/routes"
    click BE_Middleware "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/middleware"
    click BE_Models "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/models"
    click BE_Services "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/services"
    click BE_Services "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/utils"
    click BE_StateFactories "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/factories"
    click BE_StateFactories "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/states"
    click BE_Config "https://github.com/ngtrnhao/obeyclothing/tree/main/backend/config"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef middleware fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef model fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef service fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef db fill:#A3E4D7,stroke:#16A085,stroke-width:2px;
```
