# quangtrinhhh/minimart-be architecture

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

- Interactive diagram: https://gitdiagram.com/quangtrinhhh/minimart-be
- Repository: https://github.com/quangtrinhhh/minimart-be

## Overview

This project is a NestJS backend application—highly modular and built with scalability in mind. The file structure and README indicate that it is a fully featured server-side application, likely serving as the API and business logic layer for an e-commerce (or similar commerce-integrated) system. With modules covering products, orders, cart, authentication, and even external integrations (like VNPay and Redis), the system is architected according to NestJS best practices.

##### Main Components
- Entry Point & Core: At the heart is the NestJS entry (src/main.ts) which bootstraps the application. The src/app.module.ts ties together the global configuration and imported modules.
- Authentication & Authorization: The auth folder contains controllers, services, DTOs, interfaces, and Passport strategies (JWT, local). It is crucial to highlight authentication guards and roles.
- Feature Modules: There are many modules for the different business domains:
- Assets, Cart, CartItem, Category, Checkout, Coupons, Dashboard, OrderItem, Orders, Product Attributes, Product Variants, Product, Product Assets, Reviews, Users, and VNPay.
Each of these modules has similar patterns with their controllers, services, dtos, and entities—indicating a well-separated domain design.
- External and Common Services:
- The database module (src/database) is likely handling persistence.
- Redis module for caching (src/modules/redis).
- Mail module (with templates) for email functionalities.
- Global configurations, decorators, interceptors, and helpers provide cross-cutting functionality.
- Configuration and Infrastructure: There’s a config folder (e.g., vnpay.config.ts), and common decorators and enums across the application.

##### Out Relationships and Interactions
- That controllers receive HTTP requests and delegate business logic to services, which in turn interact with the database (via entities) and other services (like mail or Redis).
- That authentication middleware (Passport strategies) and guards (like roles.guard.ts) secure the endpoints.
- External integrations:
- A connection between the Redis module and external cache/storage.
- A database component illustrating persistence.
- External email services via the Mail module.

##### Architectural Patterns & Design Principles
- Modular Design: Each feature (or domain) is encapsulated in its own module, promoting separation of concerns.
- Dependency Injection: Controllers depend on services, and services may depend on repositories (entities) and helpers.
- Security Layers: Use of Passport strategies and custom guards to manage authentication/authorization.
- Layered Architecture: Clearly defined layers for controllers (input), services (business logic), and modules/entities (data layer).
- Extensibility: The use of DTOs, decorators, and helpers suggests that the system was designed to be easily extensible.

##### Incorporate Relevant Technologies, Frameworks, or Libraries
- NestJS Framework for building the application.
- TypeScript as the primary language.
- Passport for authentication with JWT and local strategies.
- Likely an ORM (configured in the database module) to manage database entities.
- Redis for caching.
- Mail templating for transactional emails.
- VNPay integration for payment processing.

- Clear labels: Each module should be labeled (e.g., Authentication, Products, Orders, etc.).
- A sectional layout: Group the core application components (main, app module, common utilities) separately from the functional modules and external integrations.
- Additionally, label cross-cutting concerns such as security (auth guards, JWT/LGuard) and configuration (global configuration modules, decorators).

##### Details
- Be as detailed as possible while maintaining clarity. Break down the system into distinct components rather than lumping them all together.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Components
    subgraph "Core Components"
        MAIN["Entry Point (src/main.ts)"]:::core
        APP["App Module (src/app.module.ts)"]:::core
        MAIN --> APP
    end

    %% API Modules
    subgraph "API Modules"
        AUTH["Authentication & Authorization"]:::auth
        subgraph "Feature Modules"
            ASSETS["Assets Module"]:::feature
            CART["Cart Module"]:::feature
            CARTITEM["CartItem Module"]:::feature
            CATEGORY["Category Module"]:::feature
            CHECKOUT["Checkout Module"]:::feature
            COUPONS["Coupons Module"]:::feature
            DASHBOARD["Dashboard Module"]:::feature
            ORDERITEM["OrderItem Module"]:::feature
            ORDERS["Orders Module"]:::feature
            PATTR["Product Attributes Module"]:::feature
            PVAR["Product Variants Module"]:::feature
            PRODUCT["Product Module"]:::feature
            PASSET["Product Assets Module"]:::feature
            REVIEWS["Reviews Module"]:::feature
            USERS["Users Module"]:::feature
            VNPay["VNPay Module"]:::feature
        end
        APP --> AUTH
        APP --> ASSETS
        APP --> CART
        APP --> CARTITEM
        APP --> CATEGORY
        APP --> CHECKOUT
        APP --> COUPONS
        APP --> DASHBOARD
        APP --> ORDERITEM
        APP --> ORDERS
        APP --> PATTR
        APP --> PVAR
        APP --> PRODUCT
        APP --> PASSET
        APP --> REVIEWS
        APP --> USERS
        APP --> VNPay
    end

    %% External Systems
    subgraph "External Systems"
        DB["Database Module"]:::external
        REDIS["Redis Module"]:::external
        MAIL["Mail Module"]:::external
        CONFIG["Configuration & External Integrations"]:::external
        PAYMENT["Payment Gateway"]:::external
    end

    %% Global & Common Services
    GLOBAL["Global & Common Services"]:::common

    %% Relationships
    AUTH -->|"uses"| GLOBAL
    ASSETS -->|"CRUDoperations"| DB
    CART -->|"CRUDoperations"| DB
    CARTITEM -->|"CRUDoperations"| DB
    CATEGORY -->|"CRUDoperations"| DB
    CHECKOUT -->|"processes"| DB
    COUPONS -->|"appliestodiscount"| DB
    DASHBOARD -->|"reads/writes"| DB
    ORDERITEM -->|"CRUDoperations"| DB
    ORDERS -->|"CRUDoperations"| DB
    PATTR -->|"CRUDoperations"| DB
    PVAR -->|"CRUDoperations"| DB
    PRODUCT -->|"CRUDoperations"| DB
    PASSET -->|"CRUDoperations"| DB
    REVIEWS -->|"CRUDoperations"| DB
    USERS -->|"CRUDoperations"| DB
    VNPay -->|"sendsPayment"| PAYMENT

    GLOBAL -->|"configs"| CONFIG
    MAIL -->|"sendsEmails"| USERS
    USERS -->|"triggersEmails"| MAIL
    CART -->|"cachesData"| REDIS
    ORDERS -->|"cachesData"| REDIS

    %% Click Events
    click MAIN "https://github.com/quangtrinhhh/minimart-be/blob/master/src/main.ts"
    click APP "https://github.com/quangtrinhhh/minimart-be/blob/master/src/app.module.ts"
    click AUTH "https://github.com/quangtrinhhh/minimart-be/tree/master/src/auth"
    click ASSETS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/assets"
    click CART "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/cart"
    click CARTITEM "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/cartitem"
    click CATEGORY "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/category"
    click CHECKOUT "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/checkout"
    click COUPONS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/coupons"
    click DASHBOARD "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/dashboard"
    click ORDERITEM "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/orderitem"
    click ORDERS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/orders"
    click PATTR "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/product-attribute"
    click PVAR "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/product-variant"
    click PRODUCT "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/product"
    click PASSET "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/productasset"
    click REVIEWS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/review"
    click USERS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/users"
    click VNPay "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/vnpay"
    click DB "https://github.com/quangtrinhhh/minimart-be/tree/master/src/database"
    click REDIS "https://github.com/quangtrinhhh/minimart-be/tree/master/src/modules/redis"
    click MAIL "https://github.com/quangtrinhhh/minimart-be/tree/master/src/mail"
    click CONFIG "https://github.com/quangtrinhhh/minimart-be/tree/master/src/config"
    click GLOBAL "https://github.com/quangtrinhhh/minimart-be/tree/master/src/common"

    %% Styles
    classDef core fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef auth fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef feature fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef common fill:#ead1dc,stroke:#b8549f,stroke-width:2px;
```
