# bekzodqodirovdev/nasiya_app_backend architecture

> Architecture diagram of the GitHub repository bekzodqodirovdev/nasiya_app_backend, 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/bekzodqodirovdev/nasiya_app_backend
- Repository: https://github.com/bekzodqodirovdev/nasiya_app_backend

## Overview

##### Main Components
- API Modules: Represent the various API endpoints available in the project. This includes modules like Admin, Auth, Debtor, Debts, Images (both for debtors and debts), Likes, Messages, Payment, Phone Numbers, Sample Messages, Store, and Upload. These are housed inside the “src/api” directory.
- Core Domain Layer: This comprises the entities (domain models) and repositories which implement the data access layer. They are located under “src/core/entity” and “src/core/repository”. These components capture the business objects (like admin, debtor, debt, etc.) and abstract them from the persistence mechanism.
- Common Utilities: Encompassing decorators, guards, enums, etc. (found in “src/common”) these components support cross-cutting concerns such as authorization, data validation, logging, and exception handling.
- Infrastructure & Libraries: This part (e.g., “src/infrastructure/lib/…”) provides additional helper services such as base services, implementations for encryption (Bcrypt), exception filtering, and custom pagination utilities that support the overall operation.
- Configuration & Bootstrap: The “src/config” holds configuration settings necessary for the application while “src/main.ts” handles the application startup.

##### Relationships and Interactions between Components
- Each API module interacts with its respective service (inside its module directory) to manage the domain logic. For instance, the Admin module includes an Admin controller, service, and DTOs which communicate with the underlying repository implementations.
- The service layer (in modules and core) will use the infrastructure components (like exception filters, bcrypt, or pagination helpers) to service client requests effectively.
- The repositories (core layer) will abstract away the data storage concerns, and they may be used by the services across various modules.
- Utilities in the “common” folder (decorators, guards, enums) are used across multiple modules to ensure consistent validation, authorization, and data flow.

##### Architectural Patterns and Design Principles
- Modular Architecture: The project is divided logically into multiple modules representing different business capabilities. Each module is independent — making it easier to scale or reason about each domain.
- Layered Architecture: There is a clear separation between the API/controller layer, the business logic (services), the domain (entities and repositories), and infrastructure layers.
- Use of Dependency Injection: Typical to NestJS, components such as controllers are injected with their respective services, and services use repositories transparently.

##### Relevant Technologies/Frameworks
- NestJS Framework – for structuring modules, controllers, and services.
- TypeScript – used throughout the project.
- PNPM – the package manager used.
- Additional NestJS tools/utilities – for exception handling, JWT authentication (guards like jwt-auth.guard.ts), and decorators.

##### Additional Detail
- If there are any interactions with external services (such as deployment platforms like Mau on AWS mentioned in the README), note these as separate external components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Modules
    subgraph "API Modules"
        Admin["Admin Module"]:::api
        Auth["Auth Module"]:::api
        Debtor["Debtor Module"]:::api
        Debts["Debts Module"]:::api
        ImagesDebtors["Images Debtors"]:::api
        ImagesDebts["Images Debts"]:::api
        Likes["Likes Module"]:::api
        Messages["Messages Module"]:::api
        Payment["Payment Module"]:::api
        PhoneNumbers["Phone Numbers Module"]:::api
        SampleMessages["Sample Messages Module"]:::api
        Store["Store Module"]:::api
        Upload["Upload Module"]:::api
    end

    %% Core Domain Layer
    subgraph "Core Domain"
        Entities["Entities"]:::core
        Repositories["Repositories"]:::core
    end

    %% Common Utilities
    subgraph "Common Utilities"
        Decorators["Decorators"]:::common
        Guards["Guards"]:::common
        Enums["Enums"]:::common
        Interfaces["Interfaces"]:::common
    end

    %% Infrastructure & Libraries
    subgraph "Infrastructure & Libraries"
        BaseService["Base Service"]:::infra
        Bcrypt["Bcrypt Utilities"]:::infra
        Exception["Exception Handling"]:::infra
        Pagination["Pagination"]:::infra
    end

    %% Configuration & Bootstrap
    subgraph "Configuration & Bootstrap"
        Config["Configuration"]:::config
        Bootstrap["Bootstrap"]:::config
    end

    %% Interactions: API Modules to Core Domain
    Admin -->|"calls"| Entities
    Auth -->|"calls"| Entities
    Debtor -->|"calls"| Entities
    Debts -->|"calls"| Entities
    ImagesDebtors -->|"calls"| Entities
    ImagesDebts -->|"calls"| Entities
    Likes -->|"calls"| Entities
    Messages -->|"calls"| Entities
    Payment -->|"calls"| Entities
    PhoneNumbers -->|"calls"| Entities
    SampleMessages -->|"calls"| Entities
    Store -->|"calls"| Entities
    Upload -->|"calls"| Entities

    %% Core Domain internal link
    Entities -->|"uses"| Repositories

    %% API Modules and Core Domain using Common Utilities
    Admin ---|"decorates"| Decorators
    Auth ---|"authorizes"| Guards
    Debtor ---|"defines"| Enums
    Debts ---|"implements"| Interfaces

    %% Core Domain and API Modules use Infrastructure & Libraries
    Entities ---|"utilizes"| BaseService
    Repositories ---|"utilizes"| BaseService
    Admin -->|"exceptions"| Exception
    Auth -->|"encryption"| Bcrypt
    Entities ---|"pagination"| Pagination
    Repositories ---|"pagination"| Pagination

    %% Configuration bootstraps all API Modules
    Config --> Admin
    Config --> Auth
    Config --> Debtor
    Config --> Debts
    Config --> ImagesDebtors
    Config --> ImagesDebts
    Config --> Likes
    Config --> Messages
    Config --> Payment
    Config --> PhoneNumbers
    Config --> SampleMessages
    Config --> Store
    Config --> Upload
    Bootstrap --> Config

    %% Class definitions for colors
    classDef api fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef core fill:#b3ffb3,stroke:#333,stroke-width:2px;
    classDef common fill:#ffcc99,stroke:#333,stroke-width:2px;
    classDef infra fill:#d9d9d9,stroke:#333,stroke-width:2px;
    classDef config fill:#ccffff,stroke:#333,stroke-width:2px;

    %% Click Events for API Modules
    click Admin "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/admin"
    click Auth "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/auth"
    click Debtor "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/debtor"
    click Debts "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/debts"
    click ImagesDebtors "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/images_of_debtors"
    click ImagesDebts "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/images_of_debts"
    click Likes "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/likes"
    click Messages "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/messages"
    click Payment "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/payment"
    click PhoneNumbers "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/phone_numbers"
    click SampleMessages "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/sample_messages"
    click Store "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/store"
    click Upload "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/api/upload"

    %% Click Events for Core Domain
    click Entities "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/core/entity"
    click Repositories "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/core/repository"

    %% Click Events for Common Utilities
    click Decorators "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/common/decorator"
    click Guards "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/common/guard"
    click Enums "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/common/enum"
    click Interfaces "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/common/interfaces"

    %% Click Events for Infrastructure & Libraries
    click BaseService "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/infrastructure/lib/baseService"
    click Bcrypt "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/infrastructure/lib/bcrypt"
    click Exception "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/infrastructure/lib/exception"
    click Pagination "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/infrastructure/lib/pagination"

    %% Click Events for Configuration & Bootstrap
    click Config "https://github.com/bekzodqodirovdev/nasiya_app_backend/tree/main/src/config"
    click Bootstrap "https://github.com/bekzodqodirovdev/nasiya_app_backend/blob/main/src/main.ts"
```
