Skip to content

Challenge-yape-Elxer #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
91de007
Feat: Configuración inicial del proyecto, bajo la arquitectura hexagonal
lucasvalentian Mar 14, 2025
9d8d4d5
Feat: Se realizo la configuración de prima, se migro la tabla a traba…
lucasvalentian Mar 14, 2025
ee7f09f
Feat: Se agrego la funcionalidad para poder almacenar los datos de la…
lucasvalentian Mar 14, 2025
e25d6ab
Feat: Se agrego la funcionalidad para la interacción con kafka
lucasvalentian Mar 14, 2025
2951f7a
Feat: Se intengro la funcionalidad para poder consultar las transacci…
lucasvalentian Mar 15, 2025
bf648cf
Feat: Se agrego la documentación del desarrollo en readme
lucasvalentian Mar 15, 2025
78f9b4e
Feat: add transaction-service
lucasvalentian Mar 16, 2025
8d40873
Fix: Se renovo la carpeta de transaccion
lucasvalentian Mar 16, 2025
9e087be
Feat: Se creo el microservicio para poder procesar toda la secuencia …
lucasvalentian Mar 16, 2025
4b6df54
Fix: Se modifico el archivo docker-compose para poder inicializar los…
lucasvalentian Mar 16, 2025
c8f3c31
Fix: Se modificaron las indicaciones del archivo readme
lucasvalentian Mar 16, 2025
36487ec
Fix: Se modificaron las indicaciones del archivo readme
lucasvalentian Mar 16, 2025
fa0bc19
Feat: Se agregaron los test unitarios al componenete antifraud-service
lucasvalentian Mar 16, 2025
a29afce
Feat: Se agregaron los test al microservicio transaction-service
lucasvalentian Mar 16, 2025
b7e9a22
Fix: agregar ejecución de tests en transaction-service y antifraud-se…
lucasvalentian Mar 16, 2025
b7fcdc6
feat:(transaction-service) habilitar Swagger solo en ambiente de desa…
lucasvalentian Mar 16, 2025
318ef7f
Feat: se realizo la configuracion para el deploy de los microservicio…
lucasvalentian Mar 17, 2025
35a47d8
Fix: se quito el log del controller TransactionController
lucasvalentian Mar 17, 2025
7c669f2
feat: Implementación y mejoras en Antifraud Service y Transaction Ser…
lucasvalentian Apr 22, 2025
3f45ae4
Fix: Se mejoro la documentación en el archivo readme
lucasvalentian Apr 22, 2025
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
104 changes: 0 additions & 104 deletions .gitignore

This file was deleted.

152 changes: 152 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,155 @@ You can use Graphql;
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.

If you have any questions, please let us know.

# API Documentation


This project implements two microservices: Antifraud Service and Transaction Service, designed to validate financial transactions and manage their status through Kafka events. It includes monitoring with Prometheus and Grafana, as well as unit tests to ensure code quality.

## Technologies Used

- **Node.js** – JavaScript runtime environment for building scalable and fast applications.
- **NestJS** – A progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
- **Prisma** – ORM (Object Relational Mapper) for database management and querying.
- **Redis** – In-memory key-value store used for caching.
- **Docker** – Platform for developing, shipping, and running applications in containers.
- **Prometheus** – Monitoring and alerting toolkit for collecting and querying metrics.
- **Grafana** – Visualization and analytics platform for monitoring metrics and logs.
- **PostgreSQL** – Relational database used to store application data, including a `FailedEvent` table for auditing failed Kafka message deliveries.

---

### **FailedEvent Table**

As part of the implementation, a `FailedEvent` table was added to the PostgreSQL database. This table is used to store audit data for messages that fail to be sent to Kafka after multiple retries. The table schema includes the following fields:

- **id**: Auto-incremented primary key.
- **transactionId**: The ID of the transaction associated with the failed message.
- **error**: The error message describing why the message failed.
- **timestamp**: The date and time when the failure occurred.

This ensures that failed messages are logged for further analysis or reprocesamiento.

---

### Prerequisites

Ensure you have the following installed:

- [Node.js](https://nodejs.org/)
- [Docker](https://www.docker.com/)
- [Redis](https://www.memurai.com/get-memurai)

---

### Steps to Install and Run

## Ejecución del Proyecto

1. **Clona el repositorio**:
```bash
git clone https://github.com/lucasvalentian/app-nodejs-codechallenge.git
cd yape-codechallenge

docker-compose up --build
```

## API Endpoints

### Crear una Transacción
```bash
curl --location 'http://localhost:3000/transaction' \
--header 'Content-Type: application/json' \
--data '{
"accountExternalIdDebit": "a1f4e567-b8f4-4d72-b3de-97b8e6d33a8d",
"accountExternalIdCredit": "d1b5f423-458b-4b2d-a6f0-16e8c999a57d",
"tranferTypeId": 1,
"value": 2000
}'
```

### Get Transaction by ID

```bash
curl --location 'http://localhost:3000/transaction?transactionId=a1f4e567-b8f4-4d72-b3de-97b8e6d33a8d' \
--header 'Content-Type: application/json'
```

```json
{
"code": 200,
"message": "OK",
"data": [
{
"transactionExternalId": "d6208b72-0a3f-4bf9-aaf3-b7e8758387b2",
"transactionType": {
"name": "TRANSFER"
},
"transactionStatus": {
"name": "REJECTED"
},
"value": 2000,
"createdAt": "2025-03-15T00:32:20.426Z"
}
]
}
```

## Access

- **Transaction service Swagger**: [http://localhost:3000/api/docs](http://localhost:3000/api/docs) - Interactive API documentation for the transaction service.
- **Kafka UI**: [http://localhost:8080](http://localhost:8080) - Graphical interface to monitor Kafka topics and messages.
- **Prometheus**: [http://localhost:9090](http://localhost:9090) - Tool for monitoring system metrics.
- **Grafana**: [http://localhost:3001](http://localhost:3001) - Platform for visualizing metrics and logs.
- **User**: admin
- **Password**: admin

## Pruebas Unitarias

Para ejecutar las pruebas unitarias de ambos microservicios, sigue estos pasos:

1. **Antifraud Service**:
- Navega a la carpeta del microservicio `antifraud-service`:
```bash
cd antifraud-service
```
- Ejecuta las pruebas unitarias:
```bash
npm run test
```

2. **Transaction Service**:
- Navega a la carpeta del microservicio [transaction-service](http://_vscodecontentref_/2):
```bash
cd transaction-service
```
- Ejecuta las pruebas unitarias:
```bash
npm run test
```

### **Notas**:
- Asegúrate de que todas las dependencias estén instaladas antes de ejecutar las pruebas:
```bash
npm install
```

---

## Exposed Metrics

- **Antifraud Service**:
- `antifraud_kafka_messages_sent_total`: Total number of messages successfully sent to Kafka.
- `antifraud_kafka_messages_failed_total`: Total number of messages that failed to send to Kafka.
- `antifraud_transactions_validated_total`: Total number of validated transactions.
- `antifraud_transactions_validation_errors_total`: Total number of errors during transaction validation.

- **Transaction Service**:
- `transactions_created_total`: Total number of successfully created transactions.
- `transactions_creation_errors_total`: Total number of errors while attempting to create transactions.
- `transactions_retrieved_total`: Total number of retrieved transactions.

---


2 changes: 2 additions & 0 deletions antifraud-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.dist
25 changes: 25 additions & 0 deletions antifraud-service/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
56 changes: 56 additions & 0 deletions antifraud-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions antifraud-service/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
12 changes: 12 additions & 0 deletions antifraud-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:22.14-alpine3.21

WORKDIR /usr/src/app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

CMD ["sh", "-c", "npm run build && npm start"]

Loading