# nhtbao101/be-accessories-store architecture

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

- Interactive diagram: https://gitdiagram.com/nhtbao101/be-accessories-store
- Repository: https://github.com/nhtbao101/be-accessories-store

## Overview

##### Main Components
- NestJS Framework Core – Represent the NestJS application at the heart of the system.
- Modular Components – Break down the application into its primary modules:
- Auth Module: Handles authentication including the strategies, guards, controllers, and DTOs.
- Admin Module: Manages administrative functionalities, including sub-modules like the user management portion under admin.
- User, Product, and Categories Modules: These are cleanly separated to encapsulate domain logic.
- Database Layer – Represent Prisma as the ORM tool with its schema (prisma/schema.prisma) and migration structure.
- Shared Module – Contains configuration, helper functions, and standardized response handling which can be used across modules.
- Infrastructure Components – Include deployment, CI/CD configurations (GitHub Actions in .github/workflows and other configuration files like .prettierrc, .eslintrc.js).

##### Relationships and Interactions
- Controllers interact with Services: Each module has its own controller that receives API requests and passes them to service components.
- Services call upon Repositories or Prisma Service: For data persistence and complex business logic, services either use specific repository patterns (e.g., in the Auth module) or leverage the centralized Prisma module (src/prisma).
- Module Dependencies: Although modules are isolated, they might interact (for instance, the Auth module might be utilised by other modules for access control via guards and interceptors).
- Integration with External Tools: Highlight CI/CD workflows from GitHub Actions and potential deployment tools like Mau mentioned in the README.

##### Architectural Patterns and Design Principles
- Modular Architecture: Each domain (auth, admin, user, product, categories) is self-contained, promoting separation of concerns.
- Dependency Injection: NestJS relies extensively on dependency injection which is central in wiring controllers, services, and repositories.
- Clean Layering: The system layers (controller → service → data access) are clearly delineated.
- Use of DTOs and Guards: For input validation and role-based access control, reinforcing security and data integrity.

##### Relevant Technologies, Frameworks, and Libraries
- NestJS: The core framework.
- TypeScript: The language used for type safety.
- Prisma: For ORM and managing database migrations.
- Testing Tools: Jest for unit and e2e tests.
- CI/CD: GitHub Actions workflows for continuous integration.
- Linting & Formatting: ESLint and Prettier for code consistency.

##### Elements
- Use clear labels for each module and component (e.g., Auth Module, Admin Module, User Module, etc.).
- API/Presentation Components (Controllers)
- Business Logic Components (Services, Strategies, Guards)
- Data Layer Components (Repositories/Prisma Service, Database)
- Cross-cutting Concerns (Shared Modules, Configurations)
- Optionally, indicate the testing and CI/CD pipeline as side components that facilitate the development and deployment process.

## Diagram (Mermaid)

```mermaid
graph TD
    NestCore["NestJS Core"]:::core

    subgraph "Modules"
        AuthMod["Auth Module\n(Controller,Service,Repository)"]:::module
        AdminMod["Admin Module"]:::module
        AdminUserSub["Admin User Submodule"]:::module
        UserMod["User Module"]:::module
        ProductMod["Product Module"]:::module
        CategoriesMod["Categories Module"]:::module
    end

    NestCore -->|"routes"| AuthMod
    NestCore -->|"routes"| AdminMod
    NestCore -->|"routes"| UserMod
    NestCore -->|"routes"| ProductMod
    NestCore -->|"routes"| CategoriesMod

    AdminMod -->|"includes"| AdminUserSub

    AuthMod -->|"uses"| PrismaService
    AdminMod -->|"uses"| PrismaService
    UserMod -->|"uses"| PrismaService
    ProductMod -->|"uses"| PrismaService
    CategoriesMod -->|"uses"| PrismaService

    AuthMod -->|"utilizes"| SharedUtil
    AdminMod -->|"utilizes"| SharedUtil
    UserMod -->|"utilizes"| SharedUtil
    ProductMod -->|"utilizes"| SharedUtil
    CategoriesMod -->|"utilizes"| SharedUtil

    subgraph "Database Layer"
        PrismaSchema["Prisma Schema"]:::db
        PrismaService["Prisma Service\n(prisma.module.ts, service)"]:::db
        PrismaService -->|"defines"| PrismaSchema
    end

    SharedUtil["Shared Utilities"]:::shared

    subgraph "Infrastructure"
        CICD["CI/CD Workflows"]:::infra
        ConfigFiles["Config Files"]:::infra
        CICD -.->|"deploys"| NestCore
        ConfigFiles -.->|"configs"| NestCore
    end

    click NestCore "https://github.com/nhtbao101/be-accessories-store/blob/main/src/app.module.ts"
    click AuthMod "https://github.com/nhtbao101/be-accessories-store/tree/main/src/auth"
    click AdminMod "https://github.com/nhtbao101/be-accessories-store/tree/main/src/modules/admin"
    click AdminUserSub "https://github.com/nhtbao101/be-accessories-store/tree/main/src/modules/admin/user"
    click UserMod "https://github.com/nhtbao101/be-accessories-store/tree/main/src/modules/user"
    click ProductMod "https://github.com/nhtbao101/be-accessories-store/tree/main/src/modules/product"
    click CategoriesMod "https://github.com/nhtbao101/be-accessories-store/tree/main/src/modules/categories"
    click PrismaSchema "https://github.com/nhtbao101/be-accessories-store/blob/main/prisma/schema.prisma"
    click PrismaService "https://github.com/nhtbao101/be-accessories-store/tree/main/src/prisma"
    click SharedUtil "https://github.com/nhtbao101/be-accessories-store/tree/main/src/shared"
    click CICD "https://github.com/nhtbao101/be-accessories-store/tree/main/.github/workflows"
    click ConfigFiles "https://github.com/nhtbao101/be-accessories-store/blob/main/.eslintrc.js"

    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef module fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef db fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef shared fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef infra fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
