# lucasbrito3001/ms-wallet-service architecture

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

- Interactive diagram: https://gitdiagram.com/lucasbrito3001/ms-wallet-service
- Repository: https://github.com/lucasbrito3001/ms-wallet-service

## Overview

##### Project Type and Purpose
- The project is a backend application that follows Hexagonal Architecture and Domain-Driven Design (DDD) principles.
- Its main business functions revolve around wallet management and account operations (evident from files like WalletController.ts, AccountRepository.ts, CreateWallet.ts, AddBalance.ts, etc.).
- It also uses messaging for asynchronous events (e.g., RabbitMQ adapters and queue subscribers) and incorporates several infrastructure components (database integration, error handling, logging).

##### Main Components
- Domain Layer:
– Entities: Account, Operation, Wallet (located in src/domain/entities).
– Domain Events: e.g., AccountCreated, OrderItemsApproved.
– Base Domain objects (e.g., Base.ts).

- Application Layer:
– Use Cases: AddBalance, CheckBalance, CreateWallet, PayOrder (under src/application/usecase).
– Controllers: OperationController and WalletController (under src/application/controller).
– Schema/Validation components: Input schemas (defined under src/application/schema/input) and related index.
– Services: JwtService, which may handle authentication or security aspects.

- Infrastructure Layer:
– Repositories: Both Domain repositories under src/application/repository and Infrastructure-specific repository implementations (database and mock versions found under src/infra/repository/database and src/infra/repository/mock).
– Server setup: The main Server (src/infra/Server.ts) responsible for bootstrapping the application, along with the DependencyRegistry for dependency injection.
– Routing: Routers (WalletRouter, OperationRouter) in the infra/router folder that represents the API layer.
– Queue / Messaging: Components under src/infra/queue, including the RabbitMQAdapter and queue subscribers that handle domain event publication/subscription.
– Additional infra: Data Source, Logging (GeneralLogger, Logger), and schema validator (ZodSchemaValidator).

- External Interfaces:
– API requests: The main entry points facilitated by the HTTP server and routers.
– Database: Suggested by init.sql and respective repository implementations.
– Messaging: Usage of RabbitMQ for asynchronous communication.
– Docker support: Deployment and environment configuration with Dockerfile, docker-compose.yaml, and nginx.conf.

##### Architectural Patterns and Design Principles
– The “driving adapters” (e.g., HTTP/REST controllers and queue subscribers) on one side of the core,
– And the “driven adapters” (e.g., repository implementations) on the other.
- Dependency inversion by showing that the Application and Domain layers do not depend directly on the Infrastructure implementations.
- Error handling components and testing (unit and e2e tests) as separate modules (if desired) to indicate robustness in design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Domain Layer"
        D1["Account"]:::domain
        D2["Operation"]:::domain
        D3["Wallet"]:::domain
        D4["Base"]:::domain
        D5["AccountCreated Event"]:::domain
        D6["OrderItemsApproved Event"]:::domain
    end

    subgraph "Application Layer"
        A1["Use Cases: AddBalance, CheckBalance, CreateWallet, PayOrder"]:::application
        A2["Controllers: OperationController, WalletController"]:::application
        A3["Input Schemas & Validators"]:::application
        A4["JwtService"]:::application
    end

    subgraph "Infrastructure Layer"
        I1["Repository Interfaces"]:::infrastructure
        I2["Database Repositories"]:::infrastructure
        I3["In-Memory/Mock Repositories"]:::infrastructure
        I4["Server & DependencyRegistry"]:::infrastructure
        I5["Routers: WalletRouter, OperationRouter"]:::infrastructure
        I6["Queue/Messaging: RabbitMQAdapter, Queue Subscribers"]:::infrastructure
        I7["Data Source"]:::infrastructure
        I8["Logging Modules"]:::infrastructure
        I9["ZodSchemaValidator"]:::infrastructure
        I10["External Config & Deployment Files"]:::infrastructure
    end

    subgraph "External Interfaces"
        EX1["HTTP/API Requests"]:::external
        EX2["Database"]:::external
        EX3["Messaging: RabbitMQ"]:::external
    end

    %% Data Flow Connections
    EX1 -->|"routes"| I5
    I5 -->|"invokes"| A2
    A2 -->|"calls"| A1
    A2 -->|"authenticates"| A4
    A1 -->|"persists"| I1
    A1 -->|"updates"| D1
    A1 -->|"triggers"| D5
    D5 -->|"publishes"| I6
    D6 -->|"publishes"| I6
    I2 -->|"implements"| I1
    I3 -->|"implements"| I1
    I4 -->|"configures"| I5
    I4 -->|"initializes"| I7
    I4 -->|"handles"| I8
    I4 -->|"validates"| I9
    EX2 -->|"stores"| I2
    EX3 -->|"communicates"| I6
    I10 -->|"configures"| I4

    %% Styles for Layers
    classDef domain fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef application fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef infrastructure fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#999900,stroke-width:2px;

    %% Click Events for Domain Layer
    click D1 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/domain/entities"
    click D2 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/domain/entities"
    click D3 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/domain/entities"
    click D4 "https://github.com/lucasbrito3001/ms-wallet-service/blob/main/src/domain/Base.ts"
    click D5 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/domain/event"
    click D6 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/domain/event"

    %% Click Events for Application Layer
    click A1 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/application/usecase"
    click A2 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/application/controller"
    click A3 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/application/schema"
    click A4 "https://github.com/lucasbrito3001/ms-wallet-service/blob/main/src/application/service/JwtService.ts"

    %% Click Events for Infrastructure Layer
    click I1 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/application/repository"
    click I2 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/infra/repository/database"
    click I3 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/infra/repository/mock"
    click I4 "https://github.com/lucasbrito3001/ms-wallet-service/blob/main/src/infra/Server.ts"
    click I5 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/infra/router"
    click I6 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/infra/queue"
    click I7 "https://github.com/lucasbrito3001/ms-wallet-service/blob/main/src/infra/data/DataSource.ts"
    click I8 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/src/infra/log"
    click I9 "https://github.com/lucasbrito3001/ms-wallet-service/blob/main/src/infra/ZodSchemaValidator.ts"
    click I10 "https://github.com/lucasbrito3001/ms-wallet-service/tree/main/Dockerfile"
```
