# yurysidyakin/top-api architecture

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

- Interactive diagram: https://gitdiagram.com/yurysidyakin/top-api
- Repository: https://github.com/yurysidyakin/top-api

## Overview

##### Main Components
- NestJS Application Core – Represented by the main.ts and app.module.ts files initializing the server.
- Modular Components – Each module in the “src” directory should be its own component:
- Auth Module: Handles authentication flows using JWT (with its controllers, services, strategies, guards, and DTOs).
- Product Module: Manages product-related operations.
- Review Module: Manages reviews, including its controller, service, and model.
- Top-Page Module: Likely handles content for a top-page (with its dedicated controller, DTOs, and service).
- Users Module: Handles user-specific functionalities.
- Configurations – Modules like the “configs” directory (with jwt.config.ts and mongo.config.ts) indicate configuration components, especially for JWT security and MongoDB connectivity.
- Testing & DevOps – Presence of the “test” directory and CI/CD workflows (.github/workflows/main.yml) highlights testing and deployment considerations.

##### Relationships and Data Flow
- Client Requests to API Gateway: Start with a client (web/mobile or any HTTP consumer) making REST API calls.
- Controllers: Each module (auth, product, review, top-page, users) has a controller that receives client requests.
- Services: Controllers delegate operations to their respective services, which handle the business logic.
- Database: Based on the existence of mongo.config.ts, use a database block (likely MongoDB) that services interact with for data retrieval and persistence.
- Authentication Flow: Clearly illustrate the JWT strategy starting at the Auth Controller, which passes through guards/strategies to validate user credentials, and then hands over valid requests to the appropriate modules.
- Configuration and Environment: Include a component for configuration management (using configuration files and environment variables) that interacts with the NestJS core.

##### Architectural Patterns and Design Principles
- Dependency Injection: Emphasize the use of DI within NestJS that connects controllers to services.
- Statelessness: Highlight REST/HTTP principles ensuring each request is independently authenticated and handled.
- Security Using JWT: Mark the specific flow for authentication using tokens with guards and strategies.
- Containerization: Reinforce that deployment is managed via Docker and docker-compose, ensuring the app and its services can run in isolated containers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    C("Client"):::external
    Core("NestJS Application Core"):::core
    Config("Configurations"):::config
    DB("MongoDB"):::config

    %% Client to Core and Config injection
    C -->|"HTTP request"| Core
    Config -->|"injects env/config"| Core

    %% Auth Module
    subgraph "Auth Module"
        A_ctrl("Auth Controller"):::module
        A_sec("JWT Guards/Strategy"):::module
        A_serv("Auth Service"):::module
        A_ctrl -->|"uses"| A_sec
        A_sec -->|"validates"| A_serv
    end

    %% Product Module
    subgraph "Product Module"
        P_ctrl("Product Controller"):::module
        P_serv("Product Service"):::module
        P_ctrl -->|"calls"| P_serv
    end

    %% Review Module
    subgraph "Review Module"
        R_ctrl("Review Controller"):::module
        R_serv("Review Service"):::module
        R_ctrl -->|"calls"| R_serv
    end

    %% Top-Page Module
    subgraph "Top-Page Module"
        T_ctrl("Top-Page Controller"):::module
        T_serv("Top-Page Service"):::module
        T_ctrl -->|"calls"| T_serv
    end

    %% Users Module
    subgraph "Users Module"
        U_serv("Users Service"):::module
    end

    %% Connections from Core to Modules
    Core --> A_ctrl
    Core --> P_ctrl
    Core --> R_ctrl
    Core --> T_ctrl
    Core --> U_serv

    %% Services to Database
    A_serv -->|"data ops"| DB
    P_serv -->|"data ops"| DB
    R_serv -->|"data ops"| DB
    T_serv -->|"data ops"| DB
    U_serv -->|"data ops"| DB

    %% Deployment subgraph
    subgraph "Deployment"
        D1("Dockerfile"):::infra
        D2("docker-compose.yml"):::infra
    end

    %% Deployment to Core
    D1 -->|"containerizes"| Core
    D2 -->|"orchestrates"| Core

    %% Testing & DevOps subgraph
    subgraph "Testing & DevOps"
        T1("Tests"):::infra
        T2("CI/CD Config"):::infra
    end

    %% DevOps supports deployment
    T1 -->|"verifies"| D1
    T1 -->|"verifies"| D2
    T2 -->|"triggers"| D1
    T2 -->|"triggers"| D2

    %% Class definitions for styling
    classDef core fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef module fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef config fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef infra fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef external fill:#cccccc,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;

    %% Click Events
    click Core "https://github.com/yurysidyakin/top-api/blob/main/src/main.ts"
    click Core "https://github.com/yurysidyakin/top-api/blob/main/src/app.module.ts"
    click A_ctrl "https://github.com/yurysidyakin/top-api/tree/main/src/auth"
    click P_ctrl "https://github.com/yurysidyakin/top-api/tree/main/src/product"
    click R_ctrl "https://github.com/yurysidyakin/top-api/tree/main/src/review"
    click T_ctrl "https://github.com/yurysidyakin/top-api/tree/main/src/top-page"
    click U_serv "https://github.com/yurysidyakin/top-api/tree/main/src/users"
    click Config "https://github.com/yurysidyakin/top-api/tree/main/src/configs"
    click T1 "https://github.com/yurysidyakin/top-api/tree/main/test"
    click T2 "https://github.com/yurysidyakin/top-api/blob/main/.github/workflows/main.yml"
    click D1 "https://github.com/yurysidyakin/top-api/tree/main/Dockerfile"
    click D2 "https://github.com/yurysidyakin/top-api/blob/main/docker-compose.yml"
```
