How josehelioaraujo/proposta-seguros works
Purpose and entry points
This .NET 10 insurance-proposal system comprises two independently deployable REST microservices: proposal lifecycle management on port 5001 and approved-proposal contracting on port 5002. ASP.NET Core startup, DI composition, Swagger, health checks, and feature-flag adapter selection begin at:
• src/PropostaService/PropostaService.Api/Program.cs
• src/ContratacaoService/ContratacaoService.Api/Program.cs
• docker-compose.yml
Hexagonal service structure
Each service separates framework-free Domain/Application core from API input adapters and Infrastructure output adapters. Domain ports define required persistence, validation, HTTP, and event capabilities; Infrastructure implements them; API binds implementations at runtime.
• src/PropostaService/PropostaService.Domain/Ports/Output/IPropostaRepository.cs
• src/ContratacaoService/ContratacaoService.Domain/Ports/Output/IEventPublisher.cs
• src/ContratacaoService/ContratacaoService.Infrastructure/Extensions/InfrastructureExtensions.cs
Proposal lifecycle
PropostasController exposes create, list, fetch, and status-transition operations. Creation validates request/CPF and delegates product-specific insurance eligibility to IRegraSeguro strategies, then creates a Proposta initially in analysis. Status changes govern approval required by the downstream service.
• src/PropostaService/PropostaService.Api/Controllers/PropostasController.cs
• src/PropostaService/PropostaService.Application/UseCases/CriarProposta/CriarPropostaUseCase.cs
• src/PropostaService/PropostaService.Domain/Entities/Proposta.cs
Product-rule boundary
Insurance products are encoded as domain types and delegated strategies rather than controller conditionals. The application resolves an IRegraSeguro implementation per TipoSeguro; this isolates varying policy validation from proposal orchestration.
• src/PropostaService/PropostaService.Domain/Ports/Output/IRegraSeguro.cs
• src/PropostaService/PropostaService.Domain/Enums/TipoSeguro.cs
• src/PropostaService/PropostaService.Infrastructure/Strategies/SeguroVidaFamiliarRegra.cs
Contracting orchestration
ContratacoesController invokes the contracting use case. It synchronously calls PropostaService through an output port to confirm the referenced proposal exists and is approved, persists Contratacao, then emits a PropostaContratadaEvent. Result objects carry expected business outcomes to HTTP mappings rather than using exceptions for flow control.
• src/ContratacaoService/ContratacaoService.Application/UseCases/ContratarProposta/ContratarPropostaUseCase.cs
• src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Http/HttpPropostaServiceClient.cs
• src/ContratacaoService/ContratacaoService.Domain/Events/PropostaContratadaEvent.cs
Persistence and messaging boundaries
Both services use one PostgreSQL database but separate proposta and contratacao schemas. Repositories can switch between in-memory implementations and Dapper/SQL using Features:UsarBancoDados. RabbitMQ publishing is optional through Features:UsarRabbitMQ; NullEventPublisher preserves successful contracting if messaging is disabled or unavailable.
• src/PropostaService/PropostaService.Infrastructure/Adapters/Output/Database/DapperPropostaRepository.cs
• src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Database/DapperContratacaoRepository.cs
• src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Messaging/RabbitMqEventPublisher.cs
Runtime and delivery
Docker Compose runs the APIs, PostgreSQL 16, and optionally RabbitMQ 4 management; each API has a multi-stage Docker build. Versioned SQL migrations establish the database schemas/tables. CI/CD is defined in GitHub Actions and deployment/operations are script-driven.
• src/PropostaService/Dockerfile
• migrations/V002__create_table_propostas.sql
• .github/workflows/ci-cd.yml
Main entry points: ContratarPropostaUseCase.cs Contract proposal · docker-compose.yml Docker Compose · CriarPropostaUseCase.cs Create proposal · Program.cs Proposal API
Components 19
Proposal service
Proposal lifecycle on port 5001.
- Proposal API · REST input adapter for proposal operations.
src/PropostaService/PropostaService.Api/Program.cs - Proposals controller
src/PropostaService/PropostaService.Api/Controllers/PropostasController.cs - Create proposal · Validates and creates proposals in analysis.
src/PropostaService/PropostaService.Application/UseCases/CriarProposta/CriarPropostaUseCase.cs - Proposal domain · Owns proposal status transitions including approval.
src/PropostaService/PropostaService.Domain/Entities/Proposta.cs - Insurance rule port · Resolves validation by insurance product.
src/PropostaService/PropostaService.Domain/Ports/Output/IRegraSeguro.cs - Life-family rule
src/PropostaService/PropostaService.Infrastructure/Strategies/SeguroVidaFamiliarRegra.cs - Proposal repository · Feature flag can select this or in-memory storage.
src/PropostaService/PropostaService.Infrastructure/Adapters/Output/Database/DapperPropostaRepository.cs
Contracting service
Approved-proposal contracting on port 5002.
- Contracting API · REST input adapter for contracting.
src/ContratacaoService/ContratacaoService.Api/Program.cs - Contract proposal · Confirms approval, persists a contract, and publishes an event.
src/ContratacaoService/ContratacaoService.Application/UseCases/ContratarProposta/ContratarPropostaUseCase.cs - Proposal service client · Synchronously verifies proposal existence and approval.
src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Http/HttpPropostaServiceClient.cs - Contract repository · Feature flag can select this or in-memory storage.
src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Database/DapperContratacaoRepository.cs - Event publisher port · Can be replaced by a null publisher when messaging is disabled.
src/ContratacaoService/ContratacaoService.Domain/Ports/Output/IEventPublisher.cs - RabbitMQ publisher
src/ContratacaoService/ContratacaoService.Infrastructure/Adapters/Output/Messaging/RabbitMqEventPublisher.cs - Proposal contracted event
src/ContratacaoService/ContratacaoService.Domain/Events/PropostaContratadaEvent.cs
Runtime & delivery
- PostgreSQL 16 · Services own separate proposta and contratacao schemas.
docker-compose.yml - RabbitMQ 4 · Optional event transport.
docker-compose.yml - Docker Compose · Runs both APIs, PostgreSQL, and optional RabbitMQ.
docker-compose.yml - Proposal SQL migration · Creates proposal storage.
migrations/V002__create_table_propostas.sql - CI/CD workflow
.github/workflows/ci-cd.yml
Connections 22
- Docker Compose → Proposal API: runs
- Docker Compose → Contracting API: runs
- Docker Compose → PostgreSQL 16: runs
- Docker Compose → RabbitMQ 4: optionally runs
- Proposal API → Proposals controller: routes requests
- Proposals controller → Create proposal: creates proposals
- Create proposal → Proposal domain: creates and transitions
- Create proposal → Insurance rule port: validates product
- Insurance rule port → Life-family rule: implemented by
- Create proposal → Proposal repository: persists
- Proposal repository → PostgreSQL 16: proposta schema
- Contracting API → Contract proposal: invokes
- Contract proposal → Proposal service client: checks approval
- Proposal service client → Proposal API: HTTP
- Contract proposal → Contract repository: persists contract
- Contract repository → PostgreSQL 16: contratacao schema
- Contract proposal → Proposal contracted event: creates
- Contract proposal → Event publisher port: publishes through
- Event publisher port → RabbitMQ publisher: implemented by
- RabbitMQ publisher → RabbitMQ 4: publishes
- Proposal SQL migration → PostgreSQL 16: provisions schema
- CI/CD workflow → Docker Compose: builds and deploys