Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/app-nodejs-codechallenge.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

231 changes: 185 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,221 @@
# Yape Code Challenge :rocket:
# Transaction Service

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
Microservicio desarrollado con Spring Boot para la gestión de transacciones financieras y validación antifraude.

Don't forget that the proper way to submit your work is to fork the repo and create a PR :wink: ... have fun !!
---

- [Problem](#problem)
- [Tech Stack](#tech_stack)
- [Send us your challenge](#send_us_your_challenge)
## 🚀 Tecnologías Utilizadas

# Problem
- Java 21
- Spring Boot 3.2.5
- Spring Data JPA
- H2 Database (Base de datos en memoria)
- Maven
- Lombok
- OpenAPI / Swagger

Every time a financial transaction is created it must be validated by our anti-fraud microservice and then the same service sends a message back to update the transaction status.
For now, we have only three transaction statuses:
---

<ol>
<li>pending</li>
<li>approved</li>
<li>rejected</li>
</ol>
## 🏗 Arquitectura

Every transaction with a value greater than 1000 should be rejected.
El proyecto sigue una arquitectura en capas:

```mermaid
flowchart LR
Transaction -- Save Transaction with pending Status --> transactionDatabase[(Database)]
Transaction --Send transaction Created event--> Anti-Fraud
Anti-Fraud -- Send transaction Status Approved event--> Transaction
Anti-Fraud -- Send transaction Status Rejected event--> Transaction
Transaction -- Update transaction Status event--> transactionDatabase[(Database)]
```
controller → service → repository → entity → dto
```

Estructura principal:

```
src
└─ main
├─ java
│ └─ com.yape.transactionservice
│ ├─ controller
│ ├─ service
│ ├─ repository
│ ├─ entity
│ └─ dto
└─ resources
```

---

## ▶️ Cómo Ejecutar el Proyecto

### 1️⃣ Compilar el proyecto

```bash
mvn clean install
```

### 2️⃣ Ejecutar la aplicación

```bash
mvn spring-boot:run
```

La aplicación se ejecutará en:

```
http://localhost:8081/api
```

---

## 🗄 Base de Datos

# Tech Stack
Se utiliza H2 en memoria.

<ol>
<li>Node. You can use any framework you want (i.e. Nestjs with an ORM like TypeOrm or Prisma) </li>
<li>Any database</li>
<li>Kafka</li>
</ol>
### Consola H2

We do provide a `Dockerfile` to help you get started with a dev environment.
```
http://localhost:8081/api/h2-console
```

Credenciales:

```
JDBC URL: jdbc:h2:mem:transactiondb
User: sa
Password: (vacío)
```

La base de datos se reinicia cada vez que la aplicación se detiene.

---

You must have two resources:
## 📚 Documentación Swagger

1. Resource to create a transaction that must containt:
Una vez levantada la aplicación:

```
http://localhost:8081/api/swagger-ui/index.html
```

Swagger permite:
- Visualizar endpoints
- Probar requests
- Ver modelos de request y response

---

# 📌 Endpoints

## 🔹 1. Crear Transacción

**POST** `/api/transactions`

### Request

```json
{
"accountExternalIdDebit": "Guid",
"accountExternalIdCredit": "Guid",
"accountExternalIdDebit": 1001,
"accountExternalIdCredit": 2001,
"tranferTypeId": 1,
"value": 120
"amount": 120.50
}
```

2. Resource to retrieve a transaction
### Response

```json
{
"transactionExternalId": "Guid",
"transactionExternalId": 1,
"transactionType": {
"name": ""
"id": 1,
"name": "TRANSFER"
},
"transactionStatus": {
"name": ""
"id": 1,
"name": "PENDING"
},
"value": 120,
"createdAt": "Date"
"amount": 120.50,
"createdAt": "2026-03-02T17:00:00"
}
```

## Optional
---

## 🔹 2. Obtener Transacción

**GET** `/api/transactions/{id}`

### Ejemplo

```
GET /api/transactions/1
```

### Response

```json
{
"transactionExternalId": 1,
"transactionType": {
"id": 1,
"name": "TRANSFER"
},
"transactionStatus": {
"id": 2,
"name": "APPROVED"
},
"amount": 120.50,
"createdAt": "2026-03-02T17:00:00"
}
```

---

## 🔹 3. Validar Transacción (AntiFraud)

**POST** `/api/transactions/validate/{id}`

### Ejemplo

```
POST /api/transactions/validate/1
```

### Response

```json
{
"transactionId": 1,
"status": "APPROVED"
}
```

---

# 🛡 Reglas de Negocio (Ejemplo AntiFraude)

- La aprobación o rechazo producto de la validación es aleatoria para efectos de éste reto técnico
- El estado inicial de una transacción es PENDING

---

# 🧪 Testing

Para ejecutar pruebas (si existen):

```bash
mvn test
```

---

# 📈 Mejoras Futuras

You can use any approach to store transaction data but you should consider that we may deal with high volume scenarios where we have a huge amount of writes and reads for the same data at the same time. How would you tackle this requirement?
- Migración a PostgreSQL
- Implementación de Docker
- Manejo global de excepciones (@ControllerAdvice)
- Logs estructurados
- Pruebas unitarias y de integración

You can use Graphql;
---

# Send us your challenge
# 👨‍💻 Autor

When you finish your challenge, after forking a repository, you **must** open a pull request to our repository. There are no limitations to the implementation, you can follow the programming paradigm, modularization, and style that you feel is the most appropriate solution.
Proyecto desarrollado como parte de un reto técnico backend.

If you have any questions, please let us know.
8 changes: 8 additions & 0 deletions transaction-service.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$/transaction-service" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/transaction-service/src/main/resources" type="java-resource" />
</content>
</component>
</module>
Loading