# ramon-mateus/contamente-api architecture

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

- Interactive diagram: https://gitdiagram.com/ramon-mateus/contamente-api
- Repository: https://github.com/ramon-mateus/contamente-api

## Overview

##### Project type and purpose
- This is a RESTful backend API for a personal finance management system (“ContaMente”).
- Built with ASP.NET Core (C#/.NET), Entity Framework Core for data access, and designed to run in Docker with a Postgres (or SQL Server) database.
- Exposes endpoints for user authentication, categories, financial movements, installments, recurrence, and payment types.

##### File structure and infer architecture
- Top-level files:
- Program.cs & launchSettings.json: ASP.NET Core startup and hosting.
- appsettings.json(es): configuration (DB connection, JWT, SMTP, etc.).
- dockerfile: containerization.
- Folders:
- Controllers: HTTP entry points (API layer).
- Services (+Interfaces): business logic layer.
- Repositories (+Interfaces): data access layer (EF Core DbContext in Contexts/ApplicationDbContext.cs).
- Models: EF Core entities.
- Migrations: schema evolution scripts.
- Contexts: DbContext definition.
- Properties: environment-specific settings.

##### README insights
- Project uses Swagger for API docs.
- Demonstrates class relationships (Movimentacao ↔ Categoria, TipoPagamento, Parcela, Recorrencia).
- Instructions for EF CLI, Docker (Postgres container), and migration workflow.
- Front-end exists separately.

##### Main components
a. API Layer
- Controllers (AuthController, CategoriaController, MovimentacaoController, ParcelaController, RecorrenciaController, TipoPagamentoController)
- Swagger UI (documentation)
b. Business Logic Layer
- Services (CategoriaService, MovimentacaoService, ParcelaService, RecorrenciaService, TipoPagamentoService, EmailService)
c. Data Access Layer
- Repositories (CategoriaRepository, MovimentacaoRepository, ParcelaRepository, RecorrenciaRepository, TipoPagamentoRepository)
- Interfaces for each repository/service
- Context: ApplicationDbContext (EF Core)
d. Persistence
- Postgres (or SQL Server) database container
- Migrations subsystem
e. External Services
- SMTP/email provider (used by EmailService)
- Docker host

##### Relationships and interactions
- HTTP Request → Controller → corresponding Service → corresponding Repository → DbContext → Database.
- Service may also invoke EmailService for notifications.
- Repositories abstract EF Core calls; DbContext manages entity tracking & migrations.
- Controllers leverage DTOs to decouple API contract from domain models.

##### Architectural patterns and design principles
- Layered architecture (Presentation / Business / Data).
- Dependency inversion via interfaces (Services and Repositories injected via DI).
- Repository pattern + Unit of Work (via EF Core DbContext).
- DTO pattern for data transfer.
- Containerization for infra consistency (Docker).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        direction TB
        AuthController["AuthController"]:::api
        CategoriaController["CategoriaController"]:::api
        MovimentacaoController["MovimentacaoController"]:::api
        ParcelaController["ParcelaController"]:::api
        RecorrenciaController["RecorrenciaController"]:::api
        TipoPagamentoController["TipoPagamentoController"]:::api
        SwaggerUI["Swagger UI"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Layer"
        direction TB
        ICategoriaService["ICategoriaService"]:::service
        IMovimentacaoService["IMovimentacaoService"]:::service
        IParcelaService["IParcelaService"]:::service
        IRecorrenciaService["IRecorrenciaService"]:::service
        ITipoPagamentoService["ITipoPagamentoService"]:::service
        IEmailService["IEmailService"]:::service

        CategoriaService["CategoriaService"]:::service
        MovimentacaoService["MovimentacaoService"]:::service
        ParcelaService["ParcelaService"]:::service
        RecorrenciaService["RecorrenciaService"]:::service
        TipoPagamentoService["TipoPagamentoService"]:::service
        EmailService["EmailService"]:::service
    end

    %% Data Access Layer
    subgraph "Data Layer"
        direction TB
        ICategoriaRepository["ICategoriaRepository"]:::repo
        IMovimentacaoRepository["IMovimentacaoRepository"]:::repo
        IParcelaRepository["IParcelaRepository"]:::repo
        IRecorrenciaRepository["IRecorrenciaRepository"]:::repo
        ITipoPagamentoRepository["ITipoPagamentoRepository"]:::repo

        CategoriaRepository["CategoriaRepository"]:::repo
        MovimentacaoRepository["MovimentacaoRepository"]:::repo
        ParcelaRepository["ParcelaRepository"]:::repo
        RecorrenciaRepository["RecorrenciaRepository"]:::repo
        TipoPagamentoRepository["TipoPagamentoRepository"]:::repo

        ApplicationDbContext["ApplicationDbContext"]:::dbcontext
    end

    %% Persistence & Infra
    subgraph "Persistence & Infra"
        direction TB
        Migrations["EF Migrations"]:::infra
        Database["Postgres DB"]:::db
        DockerHost["Docker Container"]:::infra
        Configuration["Configuration (appsettings)"]:::infra
    end

    %% External Services
    SMTP["SMTP / Email Provider"]:::external

    %% Flows
    %% Controllers to Services
    AuthController -->|calls| IEmailService
    AuthController -->|uses| CategoriaService
    CategoriaController -->|calls| ICategoriaService
    MovimentacaoController -->|calls| IMovimentacaoService
    ParcelaController -->|calls| IParcelaService
    RecorrenciaController -->|calls| IRecorrenciaService
    TipoPagamentoController -->|calls| ITipoPagamentoService

    %% Services to Repositories
    CategoriaService -->|depends on| ICategoriaRepository
    MovimentacaoService -->|depends on| IMovimentacaoRepository
    ParcelaService -->|depends on| IParcelaRepository
    RecorrenciaService -->|depends on| IRecorrenciaRepository
    TipoPagamentoService -->|depends on| ITipoPagamentoRepository
    EmailService -->|sends via| SMTP

    %% Repositories to DbContext
    CategoriaRepository -->|uses| ApplicationDbContext
    MovimentacaoRepository -->|uses| ApplicationDbContext
    ParcelaRepository -->|uses| ApplicationDbContext
    RecorrenciaRepository -->|uses| ApplicationDbContext
    TipoPagamentoRepository -->|uses| ApplicationDbContext

    %% DbContext to Database & Migrations
    ApplicationDbContext -->|migrates| Migrations
    ApplicationDbContext -->|reads/writes| Database
    Migrations -->|applies to| Database

    %% Docker and Config
    DockerHost -->|hosts| ApplicationDbContext
    DockerHost -->|runs| Database
    Configuration -->|provides settings to| ApplicationDbContext
    Configuration -->|provides settings to| DockerHost
    SwaggerUI -->|configured in| Program.cs

    %% Click Events
    click AuthController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/AuthController.cs"
    click CategoriaController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/CategoriaController.cs"
    click MovimentacaoController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/MovimentacaoController.cs"
    click ParcelaController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/ParcelaController.cs"
    click RecorrenciaController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/RecorrenciaController.cs"
    click TipoPagamentoController "https://github.com/ramon-mateus/contamente-api/blob/master/Controllers/TipoPagamentoController.cs"
    click SwaggerUI "https://github.com/ramon-mateus/contamente-api/blob/master/Program.cs"
    click CategoriaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/CategoriaService.cs"
    click MovimentacaoService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/MovimentacaoService.cs"
    click ParcelaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/ParcelaService.cs"
    click RecorrenciaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/RecorrenciaService.cs"
    click TipoPagamentoService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/TipoPagamentoService.cs"
    click EmailService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/EmailService.cs"
    click ICategoriaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/ICategoriaService.cs"
    click IMovimentacaoService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/IMovimentacaoService.cs"
    click IParcelaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/IParcelaService.cs"
    click IRecorrenciaService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/IRecorrenciaService.cs"
    click ITipoPagamentoService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/ITipoPagamentoService.cs"
    click IEmailService "https://github.com/ramon-mateus/contamente-api/blob/master/Services/Interfaces/IEmailService.cs"
    click CategoriaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/CategoriaRepository.cs"
    click MovimentacaoRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/MovimentacaoRepository.cs"
    click ParcelaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/ParcelaRepository.cs"
    click RecorrenciaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/RecorrenciaRepository.cs"
    click TipoPagamentoRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/TipoPagamentoRepository.cs"
    click ICategoriaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/Interfaces/ICategoriaRepository.cs"
    click IMovimentacaoRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/Interfaces/IMovimentacaoRepository.cs"
    click IParcelaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/Interfaces/IParcelaRepository.cs"
    click IRecorrenciaRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/Interfaces/IRecorrenciaRepository.cs"
    click ITipoPagamentoRepository "https://github.com/ramon-mateus/contamente-api/blob/master/Repositories/Interfaces/ITipoPagamentoRepository.cs"
    click ApplicationDbContext "https://github.com/ramon-mateus/contamente-api/blob/master/Contexts/ApplicationDbContext.cs"
    click Migrations "https://github.com/ramon-mateus/contamente-api/blob/master/Migrations/20250427182424_CreateTables.cs"
    click Configuration "https://github.com/ramon-mateus/contamente-api/blob/master/appsettings.json"
    click DockerHost "https://github.com/ramon-mateus/contamente-api/tree/master/dockerfile"

    %% Styles
    classDef api fill:#D0E7FF,stroke:#3399FF,color:#000
    classDef service fill:#E0FFE0,stroke:#33CC33,color:#000
    classDef repo fill:#FFF5CC,stroke:#FFCC00,color:#000
    classDef dbcontext fill:#FFE0CC,stroke:#FF9933,color:#000
    classDef db fill:#FFCCCC,stroke:#FF6666,color:#000
    classDef infra fill:#F0F0F0,stroke:#999999,color:#000
    classDef external fill:#FDE2FF,stroke:#CC33CC,color:#000
```
