Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a9cf785
chore: update .gitignore
JudaCarrillo Jan 29, 2026
f4a2acd
chore: update docker-compose.yml
JudaCarrillo Jan 29, 2026
81a3dc6
chore: initialize ms-transaction
JudaCarrillo Jan 29, 2026
7e3def7
chore: initialize ms-transaction
JudaCarrillo Jan 29, 2026
1e6d85f
Update ms-transaction/src/main/resources/application-local.yml
JudaCarrillo Jan 29, 2026
e3f5765
Update ms-transaction/devops/docker/Dockerfile.jvm
JudaCarrillo Jan 29, 2026
b29c49b
Update ms-anti-fraud/src/main/avro/Event.avsc
JudaCarrillo Jan 29, 2026
f6913c6
Update ms-anti-fraud/src/main/resources/application-local.yml
JudaCarrillo Jan 29, 2026
d74c79a
chore: add GraphQL sample schemas
JudaCarrillo Jan 29, 2026
e451bb7
chore: correct namespace in Event.avsc
JudaCarrillo Jan 29, 2026
e8b4cc4
chore: update PostgreSQL connection URL
JudaCarrillo Jan 29, 2026
9c4d721
Merge pull request #1 from JudaCarrillo/feature/initialize-project
JudaCarrillo Jan 29, 2026
8ba0644
chore: remove GraphQL schema examples
JudaCarrillo Jan 29, 2026
f6db08e
chore: Add global GraphQL directive and scalar definitions
JudaCarrillo Jan 29, 2026
f2e91d8
chore: Add GraphQL schemas for transaction domain
JudaCarrillo Jan 29, 2026
b3d3d3a
chore: update GraphQL schema configuration in pom.xml
JudaCarrillo Jan 29, 2026
f163d40
Update ms-transaction/src/main/resources/graphql-client/transaction/t…
JudaCarrillo Jan 29, 2026
8fcaac3
Update ms-transaction/src/main/resources/graphql-client/directive.gra…
JudaCarrillo Jan 29, 2026
bf9c18b
Update ms-transaction/src/main/resources/graphql-client/transaction/e…
JudaCarrillo Jan 29, 2026
3185461
Merge pull request #2 from JudaCarrillo/feature/add-graphql-schemas
JudaCarrillo Jan 29, 2026
88daae8
chore: remove AVRO schema example
JudaCarrillo Jan 29, 2026
36565cb
chore: add AVRO schemas for transaction events
JudaCarrillo Jan 29, 2026
516f772
Update ms-transaction/src/main/avro/TransactionCreatedEvent.avsc
JudaCarrillo Jan 29, 2026
b252ebd
Update ms-anti-fraud/src/main/avro/TransactionCreatedEvent.avsc
JudaCarrillo Jan 29, 2026
798cc8b
Update ms-transaction/src/main/avro/TransactionCreatedEvent.avsc
JudaCarrillo Jan 29, 2026
ffd24d1
Update ms-anti-fraud/src/main/avro/TransactionStatusUpdatedEvent.avsc
JudaCarrillo Jan 29, 2026
d6cf2a0
Update ms-transaction/src/main/avro/TransactionStatusUpdatedEvent.avsc
JudaCarrillo Jan 29, 2026
9d456d5
Update ms-anti-fraud/src/main/avro/TransactionCreatedEvent.avsc
JudaCarrillo Jan 29, 2026
67e553a
Update ms-anti-fraud/src/main/avro/TransactionStatusUpdatedEvent.avsc
JudaCarrillo Jan 29, 2026
98df511
Update ms-transaction/src/main/avro/TransactionStatusUpdatedEvent.avsc
JudaCarrillo Jan 29, 2026
949961e
chore: remove transferType field from TransactionCreatedEvent AVRO sc…
JudaCarrillo Jan 29, 2026
919c9dd
chore: update quarkus-junit artifact in pom.xml
JudaCarrillo Jan 29, 2026
1e0fda5
Merge pull request #3 from JudaCarrillo/feature/add-avro-schemas
JudaCarrillo Jan 29, 2026
be1cb60
chore: add Lombok, Redisson, Jackson datatype and Flyway dependencies
JudaCarrillo Jan 30, 2026
57ba42c
feat(ms-transaction): add domain layer with models, repositories and …
JudaCarrillo Jan 30, 2026
9d034ab
feat(ms-transaction): add infrastructure layer with persistence, cach…
JudaCarrillo Jan 30, 2026
53208f0
feat(ms-transaction): add application layer with commands, queries, m…
JudaCarrillo Jan 30, 2026
07c2a18
feat(ms-transaction): add shared layer with exceptions and utilities
JudaCarrillo Jan 30, 2026
575a576
feat(ms-transaction): add GraphQL resolvers for mutations and queries
JudaCarrillo Jan 30, 2026
6e92aa2
feat(ms-transaction): add Flyway database migrations for transaction …
JudaCarrillo Jan 30, 2026
adac30f
feat(ms-transaction): update GraphQL schema with transaction types, i…
JudaCarrillo Jan 30, 2026
dc11a09
feat(ms-transaction): update Avro schemas for transaction events
JudaCarrillo Jan 30, 2026
aad5591
feat(ms-transaction): update application configuration for Kafka, Red…
JudaCarrillo Jan 30, 2026
5608af5
test(ms-transaction): add unit tests for all layers
JudaCarrillo Jan 30, 2026
d617de4
chore(ms-transaction): update pom.xml dependencies and remove Greetin…
JudaCarrillo Jan 30, 2026
0f518d6
feat(ms-anti-fraud): add domain and application layers for transactio…
JudaCarrillo Jan 30, 2026
2772d8d
feat(ms-anti-fraud): add common utilities and constants
JudaCarrillo Jan 30, 2026
669206d
test(ms-anti-fraud): add unit tests for validation and messaging
JudaCarrillo Jan 30, 2026
8b8bc2f
feat(ms-anti-fraud): add Avro schemas for transaction events
JudaCarrillo Jan 30, 2026
6580b10
chore(ms-anti-fraud): update configuration, pom.xml and remove Greeti…
JudaCarrillo Jan 30, 2026
43d0b75
feat(ms-anti-fraud): add SOLUTION.md for Yape Code Challenge overview…
JudaCarrillo Jan 30, 2026
608163e
Merge pull request #6 from JudaCarrillo/feature/implement-create-tran…
JudaCarrillo Jan 30, 2026
2db760b
feat(devops): add multistage Dockerfiles for microservices
JudaCarrillo Jan 30, 2026
5c86aa7
chore(devops): update .dockerignore files
JudaCarrillo Jan 30, 2026
876ccb6
fix(ms-transaction): update application-local.yml with environment va…
JudaCarrillo Jan 30, 2026
5b6d1bb
fix(ms-anti-fraud): update configuration with environment variables a…
JudaCarrillo Jan 30, 2026
83741b3
fix(devops): update docker-compose with proper service configuration
JudaCarrillo Jan 30, 2026
9e98fa3
docs: update Getting Started section for docker-compose setup
JudaCarrillo Jan 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ dist

# TernJS port file
.tern-port

# IntelliJ
.idea/

# Quarkus
.quarkus/
260 changes: 260 additions & 0 deletions SOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# Yape Code Challenge - Enterprise Solution :rocket:

[![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange?logo=postman)](https://www.postman.com/me-juda-carrillo/yape-code-challenge/)

## Table of Contents

- [Overview](#overview)
- [Solution Architecture](#solution-architecture)
- [Problem Resolution](#problem-resolution)
- [Why Quarkus?](#why-quarkus)
- [Enterprise Features](#enterprise-features)
- [Technical Stack](#technical-stack)
- [Getting Started](#getting-started)
- [API Usage](#api-usage)
- [Testing](#testing)

---

## Overview

This solution implements a **production-ready microservices architecture** for the Yape Code Challenge, demonstrating how a fintech company would build a scalable transaction processing system.

**Key Highlights:**
- Event-Driven Architecture with Apache Kafka & Avro
- GraphQL API (instead of REST)
- Clean Architecture + CQRS Pattern
- Multi-layer Caching with Redis
- 94% Test Coverage

---

## Solution Architecture

```
┌─────────────────────────────────────────────────────────────────────────────┐
│ CLIENT (GraphQL) │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ MS-TRANSACTION (:18080) │
│ GraphQL → Use Cases → Domain Services → [PostgreSQL, Redis, Kafka] │
└─────────────────────────────────────────────────────────────────────────────┘
┌───────────────────────┴───────────────────────┐
│ transaction.created transaction.status │
▼ ▲
┌─────────────────────────────────────────────────────────────────────────────┐
│ MS-ANTI-FRAUD (:18081) │
│ Kafka Consumer → Validation Service → Kafka Producer │
│ (Reject if value > 1000) │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ PostgreSQL:5432 │ Redis:6379 │ Kafka:9092 │ Schema Registry:8081 │
└─────────────────────────────────────────────────────────────────────────────┘
```

---

## Problem Resolution

| Requirement | Implementation |
|-------------|---------------|
| Create transaction with pending status | ✅ GraphQL mutation saves with `PENDING` status |
| Anti-fraud validation via messaging | ✅ Kafka event to `transaction.created` topic |
| Reject transactions > 1000 | ✅ `AntiFraudValidationService` validates threshold |
| Update status via messaging | ✅ Response via `transaction.status` topic |
| High-volume support | ✅ Redis caching + Kafka async processing |

---

## Why Quarkus?

| Metric | Spring Boot | Quarkus JVM | Quarkus Native |
|--------|-------------|-------------|----------------|
| Startup Time | ~3-5s | ~0.8s | ~15ms |
| Memory (RSS) | ~300MB | ~150MB | ~35MB |
| Docker Image | ~300MB | ~200MB | ~70MB |

**Enterprise Benefits:**
- **Cloud-Native**: Built for Kubernetes & containers
- **Native Compilation**: GraalVM support for serverless
- **Reactive**: Non-blocking Kafka processing
- **Developer Experience**: Live reload with `quarkus:dev`
- **Standards**: MicroProfile, Jakarta EE, Vert.x

---

## Enterprise Features

### Clean Architecture
```
src/main/java/com/yape/services/
├── expose/graphql/ # GraphQL Resolvers
├── transaction/
│ ├── application/ # Use Cases, Commands, Queries
│ ├── domain/ # Models, Repository Interfaces
│ └── infrastructure/ # PostgreSQL, Redis, Kafka
└── shared/exception/ # Error Handling
```

### Event-Driven with Avro Schemas
- Schema evolution with Confluent Schema Registry
- Type-safe serialization
- Request traceability via `requestId`

### Caching Strategy
| Status | TTL | Rationale |
|--------|-----|-----------|
| PENDING | 5 min | Status will change |
| APPROVED/REJECTED | 1 hour | Final state |

---

## Technical Stack

| Component | Technology | Version |
|-----------|------------|---------|
| Framework | Quarkus | 3.31.1 |
| Language | Java | 21 |
| API | SmallRye GraphQL | - |
| Database | PostgreSQL | 14 |
| Cache | Redis | 8 |
| Messaging | Kafka + Avro | 7.9.0 |
| ORM | Hibernate Panache | - |
| Migrations | Flyway | - |

---

## Getting Started

### Prerequisites
- Docker & Docker Compose

### 1. Start All Services
```bash
docker-compose up -d
```

This command starts all services:
- **PostgreSQL** (:5432) - Transaction database
- **Redis** (:6379) - Caching layer
- **Zookeeper** (:2181) - Kafka coordination
- **Kafka** (:9092) - Event streaming
- **Schema Registry** (:8081) - Avro schema management
- **ms-transaction** (:18080) - Transaction microservice
- **ms-anti-fraud** (:18081) - Anti-fraud microservice

### 2. Verify Health
```bash
# Wait ~2 minutes for services to be ready, then:
curl http://localhost:18080/ms-transaction/health
curl http://localhost:18081/ms-anti-fraud/health
```

### 3. Stop Services
```bash
docker-compose down
```

### Development Mode (Optional)
For local development with hot-reload:
```bash
# Start only infrastructure
docker-compose up -d postgres redis zookeeper kafka schema-registry

# Run microservices locally
cd ms-transaction && ./mvnw quarkus:dev
cd ms-anti-fraud && ./mvnw quarkus:dev
```

---

## API Usage

### Step 1: Fetch Transfer Types

```graphql
query {
transferTypes {
transferTypeId
name
}
}
```

![Fetch Transfer Types](assets/01-success-fetch-transfer-types.png)

---

### Step 2: Create Transaction

```graphql
mutation {
createTransaction(input: {
accountExternalIdDebit: "550e8400-e29b-41d4-a716-446655440000"
accountExternalIdCredit: "550e8400-e29b-41d4-a716-446655440001"
transferTypeId: 1
value: "500.00"
}) {
transactionExternalId
transactionStatus { name }
value
createdAt
}
}
```

![Create Transaction](assets/02-success-create-transaction.png)

---

### Step 3: Fetch Transaction

```graphql
query {
transaction(transactionExternalId: "YOUR_TRANSACTION_ID") {
transactionExternalId
transactionType { name }
transactionStatus { name }
value
createdAt
}
}
```

![Fetch Transaction](assets/03-success-fetch-transaction.png)

---

## Testing

### Run Tests
```bash
cd ms-transaction && ./mvnw test
cd ms-anti-fraud && ./mvnw test
```

### Coverage Report
```bash
./mvnw verify
# Report: target/site/jacoco/index.html
```

**ms-transaction: 94% coverage**

| Package | Coverage |
|---------|----------|
| application.usecase | 94% |
| application.query | 100% |
| infrastructure.cache | 100% |
| infrastructure.messaging | 100% |

---

## Author

**Juda Carrillo** - Tech Lead | Senior Backend Developer
📧 [jbcp2006@gmail.com](mailto:jbcp2006@gmail.com)
Binary file added assets/01-success-fetch-transfer-types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/02-success-create-transaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/03-success-fetch-transaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading