# alangdp/ibovespadata architecture

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

- Interactive diagram: https://gitdiagram.com/alangdp/ibovespadata
- Repository: https://github.com/alangdp/ibovespadata

## Overview

- API Layer/Entry Point: Start with the “server.ts” and “app.ts” as the point-of-entry for HTTP requests. This represents the web server that listens for incoming simulation-related API calls.
- Routing and Controllers: Include the “routes” and “controllers” directories. For example, there are routes and controllers for specific functionalities like “bazin”, “graham”, “stock”, “simulation”, and “history”. Each controller handles API requests and delegates the work to the use cases.
- Business Logic / Use Cases: Represent the “useCases” directory (e.g., Fetcher, PontuationDatabase, RankingCsv, stockDataBase, and jsonStockDataBase). This layer performs the simulation calculations, manages investment computation logic, and orchestrates the results.
- Domain Entities and Models: Highlight the “Entities” directory and list each entity such as Bazin, Chart, Graham, History, Pontuation, Simulation, Stock, Transaction, and Variable. These entities encapsulate the core data structures utilized by the business logic.
- Interfaces and Types: Note the “interfaces” and “types” directories that define the contracts and data types used throughout the system, ensuring consistency in communication between components.
- Utility and Helper Modules: Include the “utils” directory, which features modules for API fetching, date formatting, caching (e.g., CacheJson), ranking, and other computational utilities. These support the core business logic.
- Global/Shared Components: Mark the “global” folder which includes shared modules (e.g., MacroInfo, Queue, Redis) that are used for caching, queuing, or managing macro information across the system.
- External dependencies: Don’t forget to represent external systems like Redis (noted by “redis.conf” and “src/global/Redis.ts”), Docker (via “Docker-compose.yml”), and any environment files (e.g., “.env.example”).

##### Relationships and Data Flow
- How each Controller calls into specific Use Cases (business logic). For example, the simulation controller calls methods from the simulation use case to process investment models.
- That Use Cases interact with the Entities, using them for data representation and business domain logic.
- Role of the Utility modules, which support the Use Cases with independent functionalities like fetching external data or formatting dates.
- If applicable, represent the queue component (e.g., in “src/queues/StockQueue.ts”) for managing asynchronous processing tasks, with annotations showing how tasks are pushed and processed.

##### Architectural Patterns and Design Principles
- That the overall design follows a layered/MVC approach: the separation of concerns between input (routes/controllers), processing (use cases), and data (entities/models).
- Asynchronous or distributed design elements such as the use of queues and caching (using Redis).
- Mention that the system likely follows strong modular principles with directories clearly demarcated by functional responsibilities, making it easier to extend or swap out components (for example, alternative data fetching methods).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        A1["HTTP Server"]
        A2["Application Setup"]
    end

    %% Routing and Controllers
    subgraph "Routing & Controllers"
        R1["Routes"]
        R2["Controllers"]
    end

    %% Business Logic / Use Cases
    U1["Use Cases"]

    %% Domain Entities and Models
    E1["Entities"]

    %% Interfaces and Types
    subgraph "Data Contracts"
        I1["Interfaces"]
        T1["Types"]
    end

    %% Utility and Helper Modules
    U2["Utilities"]

    %% Global/Shared Components
    G1["Global Services"]

    %% External Dependencies
    subgraph "External Dependencies"
        EX1["Redis Config"]
        EX2["Redis Integration"]
        EX3["Docker Config"]
        EX4["Environment Variables"]
    end

    %% Relationships
    A1 --> R1
    A2 --> R1
    R1 --> R2
    R2 --> U1
    U1 --> E1
    U1 --> I1
    U1 --> T1
    U1 --> U2
    U1 --> G1
    G1 --> EX1
    G1 --> EX2
    A1 --- EX3
    A2 --- EX4

    %% Styles
    class A1,A2 api
    class R1,R2 controller
    class U1 useCase
    class E1 entity
    class I1,T1 interface
    class U2 util
    class G1 global
    class EX1,EX2,EX3,EX4 external

    %% Click Events for API Layer
    click A1 "https://github.com/alangdp/ibovespadata/blob/main/src/server.ts"
    click A2 "https://github.com/alangdp/ibovespadata/blob/main/src/app.ts"

    %% Click Events for Routing and Controllers
    click R1 "https://github.com/alangdp/ibovespadata/tree/main/src/routes"
    click R2 "https://github.com/alangdp/ibovespadata/tree/main/src/controllers"

    %% Click Event for Business Logic / Use Cases
    click U1 "https://github.com/alangdp/ibovespadata/tree/main/src/useCases"

    %% Click Event for Domain Entities and Models
    click E1 "https://github.com/alangdp/ibovespadata/tree/main/src/Entities"

    %% Click Events for Interfaces and Types
    click I1 "https://github.com/alangdp/ibovespadata/tree/main/src/interfaces"
    click T1 "https://github.com/alangdp/ibovespadata/tree/main/src/types"

    %% Click Event for Utility and Helper Modules
    click U2 "https://github.com/alangdp/ibovespadata/tree/main/src/utils"

    %% Click Event for Global/Shared Components
    click G1 "https://github.com/alangdp/ibovespadata/tree/main/src/global"

    %% Click Events for External Dependencies
    click EX1 "https://github.com/alangdp/ibovespadata/blob/main/redis.conf"
    click EX2 "https://github.com/alangdp/ibovespadata/blob/main/src/global/Redis.ts"
    click EX3 "https://github.com/alangdp/ibovespadata/blob/main/Docker-compose.yml"
    click EX4 "https://github.com/alangdp/ibovespadata/blob/main/.env.example"
```
