# philip-d21/learnly architecture

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

- Interactive diagram: https://gitdiagram.com/philip-d21/learnly
- Repository: https://github.com/philip-d21/learnly

## Overview

##### Main Components
- Application Core: Begin with the main entry point (src/main.ts) and the primary Nest application module (src/app.module.ts), which is responsible for assembling the different feature modules.
- Account Module (src/core/account): Includes the controller, service, DTOs, and schema for account management.
- Auth Module (src/core/auth): Handles authentication logic with its own controller, service, DTOs, and schema.
- Transaction Module (src/core/transaction): Manages transaction-related operations with similar subdivisions.
- Common Utilities: Include supporting libraries such as guards, decorators (located in src/common/guard and its subdirectories), and interfaces (src/common/interface) that provide cross-cutting functionality.
- Infrastructure Components: Even though the repository doesn’t explicitly show a database configuration file, the presence of schema files (for each module) suggests the use of a database layer. Indicate that controllers and services interact with a data storage mechanism (e.g., MongoDB, PostgreSQL, or another database that the project might be configured to use).
- Docker & Deployment: Incorporate the containerization aspect shown by files like dockerfile, docker-compose.yml, and .dockerignore. Show that the app is potentially containerized and can be deployed as a service.

##### Relationships and Interactions
- For each feature module, illustrate that:
- The Controller (e.g., src/core/account/account.controller.ts) acts as the entry point for handling HTTP requests.
- The Controller forwards requests to the corresponding Service (e.g., src/core/account/account.service.ts), where the business logic is implemented.
- The Service interacts with the data layer (schemas in src/core/account/schema) and possibly a database (you might note “DB” as an external component) to perform CRUD operations.
- Application’s dependency flow from the App Module to each feature module and how the Common utilities (guards, decorators) are integrated for cross-cutting concerns like authentication, authorization, and response formatting.

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize how the application is structured into discrete modules (account, auth, transaction) promoting separation of concerns.
- MVC-like Approach: Within each module, note the use of controllers, services, and schemas, which is akin to an MVC (or modular layered) architecture.
- Dependency Injection: Point out that NestJS leverages dependency injection, allowing for loosely coupled components.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Entities
    Client("Client/External API Consumer"):::client

    %% Application Core
    subgraph "Application Core"
        MainEntry("Main Entry (main.ts)"):::appCore
        AppModule("App Module (app.module.ts)"):::appCore
        MainEntry -->|"initialize"| AppModule
    end

    %% Feature Modules
    subgraph "Feature Modules"
        %% Account Module
        subgraph "Account Module"
            AccountModule("Account Module"):::module
            AccountController("Account Controller"):::module
            AccountService("Account Service"):::module
            AccountDTO("Account DTO"):::module
            AccountSchema("Account Schema"):::module
            AccountModule -->|"routes"| AccountController
            AccountController -->|"calls"| AccountService
            AccountController -->|"validates"| AccountDTO
            AccountService -->|"persists"| AccountSchema
        end

        %% Auth Module
        subgraph "Auth Module"
            AuthModule("Auth Module"):::module
            AuthController("Auth Controller"):::module
            AuthService("Auth Service"):::module
            AuthDTO("Auth DTO"):::module
            AuthSchema("Auth Schema"):::module
            AuthModule -->|"routes"| AuthController
            AuthController -->|"calls"| AuthService
            AuthController -->|"validates"| AuthDTO
            AuthService -->|"persists"| AuthSchema
        end

        %% Transaction Module
        subgraph "Transaction Module"
            TransactionModule("Transaction Module"):::module
            TransactionController("Transaction Controller"):::module
            TransactionService("Transaction Service"):::module
            TransactionDTO("Transaction DTO"):::module
            TransactionSchema("Transaction Schema"):::module
            TransactionModule -->|"routes"| TransactionController
            TransactionController -->|"calls"| TransactionService
            TransactionController -->|"validates"| TransactionDTO
            TransactionService -->|"persists"| TransactionSchema
        end
    end

    %% Common Utilities
    subgraph "Common Utilities"
        CommonResponse("Response Handler"):::common
        AuthGuard("Auth Guard"):::common
        RolesGuard("Roles Guard"):::common
        PublicDecorator("Public Decorator"):::common
        RolesDecorator("Roles Decorator"):::common
        MainInterface("Main Interface"):::common
    end

    %% Infrastructure (Database)
    subgraph "Infrastructure"
        Database["Database"]:::database
    end

    %% Docker & Deployment
    subgraph "Docker & Deployment"
        Dockerfile("Dockerfile"):::docker
        DockerCompose("docker-compose.yml"):::docker
        DockerIgnore(".dockerignore"):::docker
    end

    %% Testing
    subgraph "Testing"
        TestSuite("Test Suite"):::test
    end

    %% Relationships
    Client -->|"request"| AccountController
    Client -->|"request"| AuthController
    Client -->|"request"| TransactionController

    AppModule -->|"includes"| AccountModule
    AppModule -->|"includes"| AuthModule
    AppModule -->|"includes"| TransactionModule

    AccountSchema -->|"data access"| Database
    AuthSchema -->|"data access"| Database
    TransactionSchema -->|"data access"| Database

    %% Common Utilities applied to Controllers
    CommonResponse -.->|"usedby"| AccountController
    CommonResponse -.->|"usedby"| AuthController
    CommonResponse -.->|"usedby"| TransactionController
    AuthGuard -.->|"protects"| AuthController
    RolesGuard -.->|"protects"| AccountController
    RolesGuard -.->|"protects"| TransactionController

    %% Docker linking to Application Core
    AppModule -->|"containerized"| Dockerfile
    AppModule --> DockerCompose
    AppModule --> DockerIgnore

    %% Testing linking
    TestSuite -->|"tests"| AppModule

    %% Click Events for Application Core
    click MainEntry "https://github.com/philip-d21/learnly/blob/master/src/main.ts"
    click AppModule "https://github.com/philip-d21/learnly/blob/master/src/app.module.ts"

    %% Click Events for Account Module
    click AccountModule "https://github.com/philip-d21/learnly/blob/master/src/core/account/account.module.ts"
    click AccountController "https://github.com/philip-d21/learnly/blob/master/src/core/account/account.controller.ts"
    click AccountService "https://github.com/philip-d21/learnly/blob/master/src/core/account/account.service.ts"
    click AccountDTO "https://github.com/philip-d21/learnly/blob/master/src/core/account/dto/account.dto.ts"
    click AccountSchema "https://github.com/philip-d21/learnly/blob/master/src/core/account/schema/account.schema.ts"

    %% Click Events for Auth Module
    click AuthModule "https://github.com/philip-d21/learnly/blob/master/src/core/auth/auth.module.ts"
    click AuthController "https://github.com/philip-d21/learnly/blob/master/src/core/auth/auth.controller.ts"
    click AuthService "https://github.com/philip-d21/learnly/blob/master/src/core/auth/auth.service.ts"
    click AuthDTO "https://github.com/philip-d21/learnly/blob/master/src/core/auth/dto/auth.dto.ts"
    click AuthSchema "https://github.com/philip-d21/learnly/blob/master/src/core/auth/schema/auth.schema.ts"

    %% Click Events for Transaction Module
    click TransactionModule "https://github.com/philip-d21/learnly/blob/master/src/core/transaction/transaction.module.ts"
    click TransactionController "https://github.com/philip-d21/learnly/blob/master/src/core/transaction/transaction.controller.ts"
    click TransactionService "https://github.com/philip-d21/learnly/blob/master/src/core/transaction/transaction.service.ts"
    click TransactionDTO "https://github.com/philip-d21/learnly/blob/master/src/core/transaction/dto/transaction.dto.ts"
    click TransactionSchema "https://github.com/philip-d21/learnly/blob/master/src/core/transaction/schema/transaction.schema.ts"

    %% Click Events for Common Utilities
    click CommonResponse "https://github.com/philip-d21/learnly/blob/master/src/common/brc.response.ts"
    click AuthGuard "https://github.com/philip-d21/learnly/blob/master/src/common/guard/auth.guard.ts"
    click RolesGuard "https://github.com/philip-d21/learnly/blob/master/src/common/guard/roles.guard.ts"
    click PublicDecorator "https://github.com/philip-d21/learnly/blob/master/src/common/guard/decorator/public.decorator.ts"
    click RolesDecorator "https://github.com/philip-d21/learnly/blob/master/src/common/guard/decorator/roles.decorator.ts"
    click MainInterface "https://github.com/philip-d21/learnly/blob/master/src/common/interface/main.interface.ts"

    %% Click Events for Docker & Deployment
    click Dockerfile "https://github.com/philip-d21/learnly/tree/master/dockerfile"
    click DockerCompose "https://github.com/philip-d21/learnly/blob/master/docker-compose.yml"
    click DockerIgnore "https://github.com/philip-d21/learnly/blob/master/.dockerignore"

    %% Click Event for Testing
    click TestSuite "https://github.com/philip-d21/learnly/tree/master/test"

    %% Styles
    classDef client fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef appCore fill:#a9d0f5,stroke:#333,stroke-width:2px;
    classDef module fill:#c1e1c1,stroke:#333,stroke-width:2px;
    classDef common fill:#d3bae8,stroke:#333,stroke-width:2px;
    classDef docker fill:#e0e0e0,stroke:#333,stroke-width:2px;
    classDef test fill:#ffe0e0,stroke:#333,stroke-width:2px;
    classDef database fill:#f5c7c7,stroke:#333,stroke-width:2px;
```
