Sistema enterprise de processamento de pagamentos implementando Event Sourcing, CQRS e Saga Pattern com Spring Boot.
- Todos os eventos de domínio são armazenados no Event Store
- Estado do agregado é reconstruído a partir do histórico de eventos
- Auditoria completa e time-travel debugging
- Commands:
PaymentCommandService- Operações de escrita - Queries:
PaymentQueryService- Operações de leitura - Separação clara entre modelos de escrita e leitura
- Orquestração de transações distribuídas
- Fluxo de pagamento: Create → Validate → Authorize → Capture → Complete
- Compensating transactions em caso de falha
- Aggregate Root:
Payment - Domain Events:
PaymentCreatedEvent,PaymentAuthorizedEvent, etc. - Value Objects e Entities bem definidos
payment-processor/
├── src/main/java/com/portfolio/payment/
│ ├── domain/ # Domain Layer (DDD)
│ │ ├── Payment.java # Aggregate Root
│ │ ├── PaymentStatus.java # Value Object
│ │ └── events/ # Domain Events
│ │ ├── DomainEvent.java
│ │ └── PaymentEvents.java
│ │
│ ├── application/ # Application Layer (Use Cases)
│ │ ├── commands/ # CQRS Commands
│ │ ├── dto/ # Data Transfer Objects
│ │ └── services/
│ │ ├── PaymentCommandService.java
│ │ └── PaymentQueryService.java
│ │
│ ├── infrastructure/ # Infrastructure Layer
│ │ ├── eventstore/
│ │ │ └── EventStore.java # Event Store Implementation
│ │ └── persistence/
│ │ ├── EventStoreEntity.java
│ │ └── EventStoreRepository.java
│ │
│ ├── api/ # Presentation Layer
│ │ ├── PaymentController.java # REST API
│ │ └── GlobalExceptionHandler.java
│ │
│ └── PaymentProcessorApplication.java
│
├── src/test/java/ # Tests
│ ├── domain/
│ │ └── PaymentTest.java # Unit Tests
│ └── api/
│ └── PaymentControllerIntegrationTest.java
│
├── pom.xml # Maven Dependencies
├── Dockerfile # Docker Image
├── docker-compose.yml # Orchestration
└── README.md
| Categoria | Tecnologia |
|---|---|
| Framework | Spring Boot 3.2 |
| Language | Java 17 |
| Build Tool | Maven |
| ORM | Spring Data JPA / Hibernate |
| Database | H2 (in-memory) |
| Validation | Jakarta Validation |
| Documentation | SpringDoc OpenAPI (Swagger) |
| Utilities | Lombok, Apache Commons |
| Testing | JUnit 5, Mockito, AssertJ |
| Containerization | Docker |
- Java 17+
- Maven 3.9+
- Docker (opcional)
# Compilar o projeto
mvn clean install
# Executar a aplicação
mvn spring-boot:run
# Executar testes
mvn test# Build e executar
docker-compose up --build
# Parar
docker-compose down# Build
mvn clean package
# Executar
java -jar target/payment-processor-1.0.0.jarBase URL: http://localhost:8080/api/v1
POST /payments
Content-Type: application/json
{
"customerId": "CUST-123",
"amount": 100.00,
"currency": "USD",
"description": "Payment for order #456"
}Resposta:
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"customerId": "CUST-123",
"amount": 100.00,
"currency": "USD",
"description": "Payment for order #456",
"status": "PENDING",
"version": 0
}POST /payments/{paymentId}/processExecuta o fluxo completo:
- Valida
- Autoriza
- Captura
- Completa
GET /payments/{paymentId}GET /payments/{paymentId}/historyResposta:
{
"paymentId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"currentStatus": "COMPLETED",
"events": [
{
"eventId": "evt-001",
"eventType": "PaymentCreated",
"version": 0,
"occurredAt": "2024-01-20T10:00:00Z",
"payload": "{...}"
},
{
"eventType": "PaymentValidated",
"version": 1
},
...
]
}POST /payments/{paymentId}/refund
{
"refundAmount": 50.00,
"reason": "Customer request"
}GET /payments/eventsAcesse após iniciar a aplicação:
- Swagger UI: http://localhost:8080/swagger-ui.html
- API Docs: http://localhost:8080/api-docs
mvn testmvn test jacoco:report- Unit Tests: Testes de domínio (Aggregate)
- Integration Tests: Testes de API (Controllers)
- Event Sourcing Tests: Reconstrução de estado
PENDING → VALIDATED → AUTHORIZED → CAPTURED → COMPLETED
↓
REFUNDED
(qualquer etapa pode ir para) → FAILED
✅ Event Sourcing - Histórico completo de eventos
✅ CQRS - Separação de Commands e Queries
✅ Saga Pattern - Orquestração de transações
✅ Domain-Driven Design - Aggregates, Entities, Value Objects
✅ Repository Pattern - Abstração de persistência
✅ Single Responsibility
✅ Open/Closed
✅ Liskov Substitution
✅ Interface Segregation
✅ Dependency Inversion
✅ Layered Architecture
✅ Aggregate Root
✅ Domain Events
✅ Event Store
✅ Eventual Consistency
- Commands alteram o estado criando Domain Events
- Events são persistidos no Event Store
- Estado atual é reconstruído a partir dos eventos
- Time-travel: Podemos ver o estado em qualquer ponto no tempo
- ✅ Auditoria completa
- ✅ Debug temporal
- ✅ Replay de eventos
- ✅ Análise de comportamento
- ✅ Event-driven architecture ready
- Implementar projections (read models)
- Adicionar snapshots para performance
- Integração com Kafka/RabbitMQ
- Implementar idempotência
- Circuit Breaker para external services
- API de compensação (undo)
- Métricas e monitoring (Micrometer)
| Aspecto | Biblioteca (Antigo) | Payment Processor (Novo) |
|---|---|---|
| Arquitetura | Simples 3-layer | Event Sourcing + CQRS + DDD |
| Patterns | Básicos | Enterprise (10+ patterns) |
| Persistência | Arquivo TXT | Event Store (JPA) |
| Histórico | Não tem | Completo (Event Sourcing) |
| Testes | Não tem | Unit + Integration (JUnit 5) |
| API | CLI | REST (Spring Boot) |
| Docs | Básico | Swagger/OpenAPI |
| Docker | Não | Sim |
| Complexidade | Júnior | Pleno/Sênior |
Este projeto demonstra:
- Arquitetura Enterprise - Event Sourcing, CQRS, Saga
- Domain-Driven Design - Aggregates, Events, Bounded Contexts
- Spring Ecosystem - Boot, Data JPA, Web, Validation
- Testes Automatizados - TDD, Integration Tests
- Clean Code - SOLID, Design Patterns
- DevOps Ready - Docker, CI/CD ready
Nível: Pleno/Sênior
Tempo de desenvolvimento: 8-12 horas
Impacto no portfólio: ⭐⭐⭐⭐⭐
MIT License
Desenvolvido como projeto de portfólio demonstrando expertise em:
- Java Enterprise
- Spring Framework
- Event-Driven Architecture
- Domain-Driven Design
- Microservices Patterns