# cristianorc/fluxo-de-caixa architecture

> Architecture diagram of the GitHub repository cristianorc/fluxo-de-caixa, 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/cristianorc/fluxo-de-caixa
- Repository: https://github.com/cristianorc/fluxo-de-caixa

## Overview

- End Users accessing the Web App.
- External services for PDF rendering (Gotenberg), caching (Redis), and messaging (RabbitMQ).
- Third-party or cloud-based infrastructure (if any are used, e.g., Azure cloud components).
- Use clear labels to note that the system supports user wallet creation, transactions, and end-of-day reporting.

- Web Application (App): A React-based front-end that serves the user interface.
- API (FluxoDeCaixa.Api): A .NET backend service handling transactions, wallet management, and exposing RESTful endpoints. It is structured according to Domain-Driven Design (with layers like Domain, Application, and Infrastructure), as evidenced by directories such as Domain, Application, Infra, and UnitTest.
- API Report (FluxoDeCaixa.Api.Report): An Azure Functions-based service that generates daily reports by consuming data and orchestrating PDF generation.
- Databases: PostgreSQL is used for transactional and wallet data. MongoDB is also listed in the README for local setups, so include it where appropriate.
- Infrastructure Dependencies:
- RabbitMQ (as configured in the Infra/MessageBus folder) for event-driven messaging.
- Redis for distributed locks and caching (as noted in the local setup instructions).
- Gotenberg for PDF processing (port 3000), used by the API Report service.
- The Web App communicates with both the API and API Report via HTTP.
- The API interacts with the databases for transaction persistence.
- The API and possibly the API Report publish or subscribe to events via RabbitMQ.
- The API Report calls the PDF rendering service, which in turn may send back generated PDFs.

- Within the API container:
- Controllers (e.g., BalanceController, BookEntryController) handling HTTP requests.
- Application Services (under Api/FluxoDeCaixa.Application/Services) orchestrating business use cases such as processing transactions and handling distributed locks.
- Domain Layer (entities, value objects, domain services) and how it interacts with Infrastructure (repositories and EF configurations in Api/FluxoDeCaixa.Infra).
- For the API Report container:
- HTTPTrigger and QueueTrigger functions that serve as entry points.
- How these functions delegate work to Report Services (like IReportService/ReportService) and how they use external HTTP calls (for example, to the PDFRenderService in the Infra folder).

##### Technologies and Frameworks
- Container/component with the underlying technology:
- Frontend: React, npm (with Vite).
- Backend API: .NET 7, ASP.NET Core, Entity Framework.
- API Report: .NET 7, Azure Functions.
- Infrastructure: PostgreSQL, MongoDB, RabbitMQ, Redis, Gotenberg.
- CI/CD: Docker, GitHub Actions.
- Mention that Docker containers are used (evidenced by Dockerfiles and docker-compose.yaml), which helps in visualizing the deployment architecture.

## Diagram (Mermaid)

```mermaid
graph TD
    %% System Context
    subgraph "System Context"
        EU["End Users"]:::external
        FDCS["Fluxo De Caixa System\n(User Wallet, Transactions, Reporting)"]:::system
        EXT_GOT["Gotenberg (PDF Rendering)"]:::external
        EXT_RED["Redis (Caching/Locking)"]:::external
        EXT_RMQ["RabbitMQ (Messaging)"]:::external
        EU -->|"accesses"| FDCS
        FDCS -->|"integrates with"| EXT_GOT
        FDCS -->|"integrates with"| EXT_RED
        FDCS -->|"integrates with"| EXT_RMQ
    end

    %% Container Diagram
    subgraph "Containers"
        WApp["Web Application (React)"]:::frontend
        API["API Backend (.NET)"]:::backend
        ARS["API Report Service (Azure Functions)"]:::backend
        PG["PostgreSQL Database"]:::database
        MDB["MongoDB Database"]:::database
        CON_RMQ["RabbitMQ (Messaging)"]:::external
        CON_RED["Redis (Caching)"]:::external
        CON_GOT["Gotenberg (PDF Rendering)"]:::external
        
        %% Inter-container communications
        WApp -->|"HTTP"| API
        WApp -->|"HTTP"| ARS
        API -->|"Read/Write"| PG
        API -->|"Read/Write\n(Optional local setup)"| MDB
        API -->|"Publish/Subscribe"| CON_RMQ
        API -->|"Caching/Locking"| CON_RED
        ARS -->|"Publish/Subscribe"| CON_RMQ
        ARS -->|"Caching"| CON_RED
        ARS -->|"Calls PDF Rendering"| CON_GOT
    end

    %% Component Diagram for API Backend
    subgraph "API Components"
        CONT["Controllers\n(BalanceController, BookEntryController)"]:::component
        APPSVC["Application Services"]:::component
        DOMAIN["Domain Layer\n(Entities, Value Objects, Domain Services)"]:::component
        INFRA["Infrastructure\n(Repositories & EF Configurations)"]:::component
        CONT -->|"delegates to"| APPSVC
        APPSVC -->|"domain logic"| DOMAIN
        DOMAIN -->|"persists via"| INFRA
    end

    %% Component Diagram for API Report Service
    subgraph "API Report Components"
        HTTP_TRIG["HTTP Trigger"]:::component
        QUEUE_TRIG["Queue Trigger"]:::component
        REPORT_SVC["Report Service\n(and Idempotency)"]:::component
        PDF_CLIENT["PDFRenderService Client"]:::component
        HTTP_TRIG -->|"invokes"| REPORT_SVC
        QUEUE_TRIG -->|"invokes"| REPORT_SVC
        REPORT_SVC -->|"calls"| PDF_CLIENT
    end

    %% Click Events for Component Mapping
    click WApp "https://github.com/cristianorc/fluxo-de-caixa/tree/main/App/"
    click API "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api/FluxoDeCaixa.Api/"
    click ARS "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api.Report/FluxoDeCaixa.Api.Report/"
    click DOMAIN "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api/FluxoDeCaixa.Domain/"
    click APPSVC "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api/FluxoDeCaixa.Application/"
    click INFRA "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api/FluxoDeCaixa.Infra/"
    click CON_RMQ "https://github.com/cristianorc/fluxo-de-caixa/tree/main/Api/FluxoDeCaixa.Infra/MessageBus/"
    click PDF_CLIENT "https://github.com/cristianorc/fluxo-de-caixa/blob/main/Api.Report/FluxoDeCaixa.Api.Report.Infra/Http/PdfRenderService.cs"

    %% Style Definitions
    classDef external fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef system fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef frontend fill:#577590,stroke:#000,stroke-width:2px,color:#fff;
    classDef backend fill:#43aa8b,stroke:#000,stroke-width:2px,color:#fff;
    classDef database fill:#f94144,stroke:#000,stroke-width:2px,color:#fff;
    classDef component fill:#f3722c,stroke:#000,stroke-width:2px,color:#fff;
```
