# vicenzomartinelli/act-caixa-desafio architecture

> Architecture diagram of the GitHub repository vicenzomartinelli/act-caixa-desafio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vicenzomartinelli/act-caixa-desafio
- Repository: https://github.com/vicenzomartinelli/act-caixa-desafio

## Overview

##### Project type and purpose
- This is a microservices-based financial application (“Act.Caixa”) that handles “Lançamentos” (transactions) and “Consolidações” (daily consolidations).
- It uses an API Gateway to expose endpoints, two independent services for write/read operations, asynchronous event‐driven flows, and a shared domain/library layer.

##### File structure
- Top-level projects:
- Act.Caixa.BuildingBlocks: reusable infra (EF Core DbContext, migrations, message-bus config, HTTP filters)
- Act.Caixa.Domain: core entities, enums, domain events
- Act.Caixa.Services.Lancamento: transaction microservice
- Act.Caixa.Services.Consolidacao: consolidation microservice
- Act.Caixa.Gateway: Ocelot API Gateway
- Act.Caixa.Tests: integration tests with Testcontainers
- compose.yaml/dockerfiles: Docker-based infra (PostgreSQL, RabbitMQ)
- Patterns & infra:
- EF Core + PostgreSQL
- MassTransit + RabbitMQ for event bus
- MediatR (Mediator) for in-process command/query dispatch
- Ocelot for API routing

##### Extract README insights
- CQRS: Services separate commands (writes) and queries (reads) within each service.
- Event-driven: services publish/consume domain events via RabbitMQ.
- API Gateway Pattern: single ingress point.
- Feature-focused structure per service (Commands, Queries, Consumers, ViewModels).
- Docker-compose spins up infra; each service publishes its own Dockerfile.

a. Main components:
- Clients (e.g., browser, mobile, other services)
- API Gateway (Act.Caixa.Gateway)
- Service: Lancamento
- Service: Consolidacao
- Shared Library (BuildingBlocks + Domain) – code dependency, not a runtime component
- PostgreSQL database
- RabbitMQ message broker
- (Optional) In-memory cache inside services
b. Relationships / interactions:
1. Client → HTTP calls → API Gateway
2. Gateway → routes → Lancamento or Consolidacao HTTP endpoints
3. Service receives HTTP → dispatches via MediatR → EF Core writes to PostgreSQL
4. On write commands, service publishes an event to RabbitMQ (e.g., “LancamentoAdded”)
5. Consolidacao service has a MassTransit consumer listening to corresponding queue
6. Consolidacao consumer handles event → updates daily consolidations in its own database schema/table
c. Architectural patterns/design principles:
- API Gateway sits at the front (Ocelot)
- Microservices each own their data (Database per service)
- CQRS inside each service
- Event-driven communication via RabbitMQ + MassTransit
- Mediator (MediatR) for in-proc decoupling
- Shared Building Blocks library for common infra (DbContextFactory, message-bus setup, validation filters)
d. Technologies/frameworks:
- .NET 9.0, C#
- Ocelot (API Gateway)
- MassTransit + RabbitMQ
- Entity Framework Core + PostgreSQL
- MediatR
- Docker / Docker-Compose

##### Elements
- Another for “Messaging infrastructure”
- Another for “Persistence”
- Ports, queue names, topic/exchange names.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Layers
    subgraph "Ingress Layer"
        direction TB
        Clients["Clients"]:::ingress
        APIGW["API Gateway"]:::ingress
        Clients -->|"HTTP"| APIGW
    end

    %% API Gateway internals
    APIGW -->|"routes"| LancHTTP
    subgraph "API Gateway Configuration"
        direction TB
        LancHTTP["Ocelot.json"]:::config
        GWProgram["Program.cs"]:::config
    end

    %% Microservices
    APIGW -->|"HTTP 5168"| LanSvc
    APIGW -->|"HTTP 5259"| ConSvc

    subgraph "Lancamento Service" 
        direction TB
        LanEntry["Program.cs"]:::micro
        LanProj["Act.Caixa.Services.Lancamento.csproj"]:::micro
        LanRoutes["Routes.cs"]:::micro
        subgraph "CQRS Write"
            direction TB
            AddCmd["AddLancamentoCommand.cs"]:::micro
            DelCmd["DeleteLancamentoCommand.cs"]:::micro
        end
        subgraph "CQRS Read"
            direction TB
            FindById["FindLancamentoByIdQuery.cs"]:::micro
            FindAll["FindLancamentosQuery.cs"]:::micro
            VM["LancamentoViewModel.cs"]:::micro
        end
        LanEntry --> LanProj --> LanRoutes
        LanRoutes --> AddCmd & DelCmd & FindById & FindAll
        AddCmd --> VM
        FindAll --> VM
    end

    subgraph "Consolidacao Service"
        direction TB
        ConEntry["Program.cs"]:::micro
        ConProj["Act.Caixa.Services.Consolidacao.csproj"]:::micro
        ConRoutes["Routes.cs"]:::micro
        subgraph "Event Bridge"
            direction TB
            ConQuery["AddLancamentoCommand.cs"]:::micro
        end
        subgraph "Consumer"
            direction TB
            Consumer["AtualizaConsolidacaoDiariaConsumer.cs"]:::micro
        end
        VMCon["ConsolidacaoDiariaViewModel.cs"]:::micro
        ConEntry --> ConProj --> ConRoutes
        ConRoutes --> ConQuery --> Consumer --> VMCon
    end

    %% Messaging
    subgraph "Messaging Infrastructure"
        direction TB
        RabbitMQ["RabbitMQ"]:::messaging
    end
    AddCmd -.->|"Publishes event"| RabbitMQ
    RabbitMQ -.->|"Consumes event"| Consumer

    %% Persistence
    subgraph "Persistence"
        direction TB
        DBLan["PostgreSQL (Lancamento)"]:::persistence
        DBCon["PostgreSQL (Consolidacao)"]:::persistence
    end
    AddCmd -->|"writes"| DBLan
    Consumer -->|"writes"| DBCon

    %% Shared Libraries
    subgraph "Shared Libraries"
        direction TB
        BBProj["Act.Caixa.BuildingBlocks.csproj"]:::shared
        DomainProj["Act.Caixa.Domain.csproj"]:::shared
        BBProj --> CaixaDb["CaixaDbContext.cs"]:::shared
        BBProj --> Validation["ValidationFilter.cs"]:::shared
        BBProj --> MsgBus["AddMessageBus.cs"]:::shared
        DomainProj --> Entities["Entities\\*.cs"]:::shared
        DomainProj --> Events["LancamentoDiaAtualizadoEvent.cs"]:::shared
    end

    %% Click Events
    click LancHTTP "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Gateway/ocelot.json"
    click GWProgram "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Gateway/Program.cs"
    click LanEntry "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Program.cs"
    click LanProj "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Act.Caixa.Services.Lancamento.csproj"
    click LanRoutes "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Routes.cs"
    click AddCmd "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Features/Lancamentos/Commands/AddLancamentoCommand.cs"
    click DelCmd "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Features/Lancamentos/Commands/DeleteLancamentoCommand.cs"
    click FindById "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Features/Lancamentos/Queries/FindLancamentoByIdQuery.cs"
    click FindAll "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Features/Lancamentos/Queries/FindLancamentosQuery.cs"
    click VM "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Lancamento/Features/Lancamentos/ViewModels/LancamentoViewModel.cs"
    click ConEntry "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Program.cs"
    click ConProj "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Act.Caixa.Services.Consolidacao.csproj"
    click ConRoutes "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Routes.cs"
    click ConQuery "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Features/Consolidacao/Queries/AddLancamentoCommand.cs"
    click Consumer "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Features/Consolidacao/Consumers/AtualizaConsolidacaoDiariaConsumer.cs"
    click VMCon "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Services.Consolidacao/Features/Consolidacao/ViewModels/ConsolidacaoDiariaViewModel.cs"
    click BBProj "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.BuildingBlocks/Act.Caixa.BuildingBlocks.csproj"
    click CaixaDb "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.BuildingBlocks/Infra/Db/CaixaDbContext.cs"
    click Validation "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.BuildingBlocks/Infra/Http/ValidationFilter.cs"
    click MsgBus "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.BuildingBlocks/Infra/MessageBus/Configuration/AddMessageBus.cs"
    click DomainProj "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Domain/Act.Caixa.Domain.csproj"
    click Events "https://github.com/vicenzomartinelli/act-caixa-desafio/blob/main/Act.Caixa.Domain/Events/LancamentoDiaAtualizadoEvent.cs"

    %% Styles
    classDef ingress fill:#f9f,stroke:#333,stroke-width:1px
    classDef config fill:#fc9,stroke:#333,stroke-width:1px
    classDef micro fill:#bbf,stroke:#333,stroke-width:1px
    classDef messaging fill:#ff9,stroke:#333,stroke-width:1px
    classDef persistence fill:#bfb,stroke:#333,stroke-width:1px
    classDef shared fill:#cff,stroke:#333,stroke-width:1px
```
