# lucasscheere/cobranca architecture

> Architecture diagram of the GitHub repository lucasscheere/cobranca, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lucasscheere/cobranca
- Repository: https://github.com/lucasscheere/cobranca

## Overview

Cobrança API is a REST service for managing business clients, receivables, customer-service interactions, and users. Its main workflow starts with an HTTP request, passes through a domain controller and service, and reads or writes through a repository; creating accounts and interactions also checks the referenced client. Account status is computed during creation. PostgreSQL persistence and Flyway schema migrations are documented, but configuration and migration wiring were not excerpted, so those links rely on README evidence.

Main entry points: [`src/main/kotlin/br/net/cobranca/client/ClientRepository.kt`](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientRepository.kt) (Client repository), [`src/main/kotlin/br/net/cobranca/account/AccountService.kt`](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountService.kt) (Account service), [`src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt`](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt) (Interaction service), [`src/main/kotlin/br/net/cobranca/client/ClientService.kt`](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientService.kt) (Client service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_client_controller["Client endpoints"]
  node_account_controller["Account endpoints"]
  node_interaction_controller["Interaction endpoints"]
  node_user_controller["User endpoints<br/>[UserController.kt]"]
  node_application["Spring application"]
  node_exception_handler["Global error handler"]
end

subgraph group_billing["Clients and Billing"]
  node_client_service["Client service<br/>[ClientService.kt]"]
  node_client_model["Client model and DTOs<br/>[Client.kt]"]
  node_client_repository["Client repository"]
  node_account_service["Account service<br/>[AccountService.kt]"]
  node_account_model["Account model and enums<br/>[Account.kt]"]
  node_account_dto["Account DTOs"]
  node_account_repository["Account repository"]
end

subgraph group_engagement["Customer Engagement"]
  node_interaction_service["Interaction service"]
  node_interaction_model["Interaction model<br/>[Interaction.kt]"]
  node_interaction_dto["Interaction DTOs"]
  node_interaction_repository["Interaction repository"]
end

subgraph group_identity["User Management"]
  node_user_service["User service<br/>[UserService.kt]"]
  node_user_model["User model<br/>[User.kt]"]
  node_user_repository["User repository<br/>[UserRepository.kt]"]
end

subgraph group_persistence["Persistence and Errors"]
  node_database[("PostgreSQL")]
  node_migrations["Schema migrations"]
end

node_caller(("API caller"))

node_caller -->|"requests clients"| node_client_controller
node_caller -->|"requests accounts"| node_account_controller
node_caller -->|"requests interactions"| node_interaction_controller
node_caller -->|"requests users"| node_user_controller
node_client_controller -->|"delegates to"| node_client_service
node_account_controller -->|"delegates to"| node_account_service
node_interaction_controller -->|"delegates to"| node_interaction_service
node_user_controller -->|"delegates to"| node_user_service
node_client_service -->|"reads and saves"| node_client_repository
node_account_service -->|"reads and saves"| node_account_repository
node_account_service -->|"checks client"| node_client_repository
node_interaction_service -->|"reads and saves"| node_interaction_repository
node_interaction_service -->|"checks client"| node_client_repository
node_user_service -->|"reads and saves"| node_user_repository
node_client_repository -->|"persists"| node_client_model
node_account_repository -->|"persists"| node_account_model
node_interaction_repository -->|"persists"| node_interaction_model
node_user_repository -->|"persists"| node_user_model
node_account_service -->|"maps data"| node_account_dto
node_interaction_service -->|"maps data"| node_interaction_dto
node_client_service -->|"maps data"| node_client_model
node_client_repository -->|"stores records"| node_database
node_account_repository -->|"stores records"| node_database
node_interaction_repository -->|"stores records"| node_database
node_user_repository -->|"stores records"| node_database
node_migrations -->|"versions schema"| node_database

click node_client_controller "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientController.kt"
click node_account_controller "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountController.kt"
click node_interaction_controller "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionController.kt"
click node_user_controller "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserController.kt"
click node_application "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/CobrancaApplication.kt"
click node_client_service "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientService.kt"
click node_client_model "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/Client.kt"
click node_client_repository "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientRepository.kt"
click node_account_service "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountService.kt"
click node_account_model "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/Account.kt"
click node_account_dto "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/dto/AccountRequestDTO.kt"
click node_account_repository "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountRepository.kt"
click node_interaction_service "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt"
click node_interaction_model "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/Interaction.kt"
click node_interaction_dto "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/dto/InteractionRequestDTO.kt"
click node_interaction_repository "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionRepository.kt"
click node_user_service "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserService.kt"
click node_user_model "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/User.kt"
click node_user_repository "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserRepository.kt"
click node_exception_handler "https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/exception/GlobalExceptionHandler.kt"
click node_migrations "https://github.com/lucasscheere/cobranca/blob/main/src/main/resources/db/migration/V1__create_clients.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_controller,node_account_controller,node_interaction_controller,node_user_controller,node_application,node_exception_handler toneBlue
class node_client_service,node_client_model,node_client_repository,node_account_service,node_account_model,node_account_dto,node_account_repository toneAmber
class node_interaction_service,node_interaction_model,node_interaction_dto,node_interaction_repository,node_caller toneMint
class node_user_service,node_user_model,node_user_repository toneRose
class node_database,node_migrations toneIndigo
```

## Components

### REST API

- [Client endpoints](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientController.kt): `src/main/kotlin/br/net/cobranca/client/ClientController.kt`
- [Account endpoints](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountController.kt): `src/main/kotlin/br/net/cobranca/account/AccountController.kt`
- [Interaction endpoints](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionController.kt): `src/main/kotlin/br/net/cobranca/interaction/InteractionController.kt`
- [User endpoints](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserController.kt): `src/main/kotlin/br/net/cobranca/user/UserController.kt`
- [Spring application](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/CobrancaApplication.kt): `src/main/kotlin/br/net/cobranca/CobrancaApplication.kt`
- [Global error handler](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/exception/GlobalExceptionHandler.kt): `src/main/kotlin/br/net/cobranca/exception/GlobalExceptionHandler.kt`

### Clients and Billing

- [Client service](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientService.kt): `src/main/kotlin/br/net/cobranca/client/ClientService.kt`
- [Client model and DTOs](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/Client.kt): `src/main/kotlin/br/net/cobranca/client/Client.kt`
- [Client repository](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/client/ClientRepository.kt): `src/main/kotlin/br/net/cobranca/client/ClientRepository.kt`
- [Account service](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountService.kt): `src/main/kotlin/br/net/cobranca/account/AccountService.kt`
- [Account model and enums](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/Account.kt): `src/main/kotlin/br/net/cobranca/account/Account.kt`
- [Account DTOs](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/dto/AccountRequestDTO.kt): `src/main/kotlin/br/net/cobranca/account/dto/AccountRequestDTO.kt`
- [Account repository](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/account/AccountRepository.kt): `src/main/kotlin/br/net/cobranca/account/AccountRepository.kt`

### Customer Engagement

- [Interaction service](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt): `src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt`
- [Interaction model](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/Interaction.kt): `src/main/kotlin/br/net/cobranca/interaction/Interaction.kt`
- [Interaction DTOs](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/dto/InteractionRequestDTO.kt): `src/main/kotlin/br/net/cobranca/interaction/dto/InteractionRequestDTO.kt`
- [Interaction repository](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/interaction/InteractionRepository.kt): `src/main/kotlin/br/net/cobranca/interaction/InteractionRepository.kt`

### User Management

- [User service](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserService.kt): `src/main/kotlin/br/net/cobranca/user/UserService.kt`
- [User model](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/User.kt): `src/main/kotlin/br/net/cobranca/user/User.kt`
- [User repository](https://github.com/lucasscheere/cobranca/blob/main/src/main/kotlin/br/net/cobranca/user/UserRepository.kt): `src/main/kotlin/br/net/cobranca/user/UserRepository.kt`

### Persistence and Errors

- **PostgreSQL**
- [Schema migrations](https://github.com/lucasscheere/cobranca/blob/main/src/main/resources/db/migration/V1__create_clients.sql): `src/main/resources/db/migration/V1__create_clients.sql`

### Other components

- **API caller**

## Connections

- API caller → Client endpoints: requests clients (evidence: `README.md`)
- API caller → Account endpoints: requests accounts (evidence: `README.md`)
- API caller → Interaction endpoints: requests interactions (evidence: `README.md`)
- API caller → User endpoints: requests users (evidence: `README.md`)
- Client endpoints → Client service: delegates to (evidence: `src/main/kotlin/br/net/cobranca/client/ClientController.kt`)
- Account endpoints → Account service: delegates to (evidence: `src/main/kotlin/br/net/cobranca/account/AccountController.kt`)
- Interaction endpoints → Interaction service: delegates to (evidence: `src/main/kotlin/br/net/cobranca/interaction/InteractionController.kt`)
- User endpoints → User service: delegates to (evidence: `src/main/kotlin/br/net/cobranca/user/UserController.kt`)
- Client service → Client repository: reads and saves (evidence: `src/main/kotlin/br/net/cobranca/client/ClientService.kt`)
- Account service → Account repository: reads and saves (evidence: `src/main/kotlin/br/net/cobranca/account/AccountService.kt`)
- Account service → Client repository: checks client (evidence: `src/main/kotlin/br/net/cobranca/account/AccountService.kt`)
- Interaction service → Interaction repository: reads and saves (evidence: `src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt`)
- Interaction service → Client repository: checks client (evidence: `src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt`)
- User service → User repository: reads and saves (evidence: `src/main/kotlin/br/net/cobranca/user/UserService.kt`)
- Client repository → Client model and DTOs: persists (evidence: `src/main/kotlin/br/net/cobranca/client/ClientRepository.kt`)
- Account repository → Account model and enums: persists (evidence: `src/main/kotlin/br/net/cobranca/account/AccountRepository.kt`)
- Interaction repository → Interaction model: persists (evidence: `src/main/kotlin/br/net/cobranca/interaction/InteractionRepository.kt`)
- User repository → User model: persists (evidence: `src/main/kotlin/br/net/cobranca/user/UserRepository.kt`)
- Account service → Account DTOs: maps data (evidence: `src/main/kotlin/br/net/cobranca/account/AccountService.kt`)
- Interaction service → Interaction DTOs: maps data (evidence: `src/main/kotlin/br/net/cobranca/interaction/InteractionService.kt`)
- Client service → Client model and DTOs: maps data (evidence: `src/main/kotlin/br/net/cobranca/client/ClientService.kt`)
- Client repository → PostgreSQL: stores records (evidence: `README.md`)
- Account repository → PostgreSQL: stores records (evidence: `README.md`)
- Interaction repository → PostgreSQL: stores records (evidence: `README.md`)
- User repository → PostgreSQL: stores records (evidence: `README.md`)
- Schema migrations → PostgreSQL: versions schema (evidence: `README.md`)
