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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"prisma.pinToPrisma6": true
}
181 changes: 136 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,173 @@
# Yape Code Challenge :rocket:
# 🏦 Transaction Processing System (Code Challenge)

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
This project is a solution to the Yape Code Challenge.

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

- [Problem](#problem)
- [Tech Stack](#tech_stack)
- [Send us your challenge](#send_us_your_challenge)
This project implements a simple **event-driven architecture** using Node.js, Kafka, and PostgreSQL.

# Problem
The system processes financial transactions and validates them through an anti-fraud microservice.

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>
## 🧱 Architecture

Every transaction with a value greater than 1000 should be rejected.
The solution is composed of two microservices:

```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)]
```
* **transaction-service**

* Creates transactions
* Stores them in PostgreSQL
* Publishes events to Kafka
* Consumes validation results

* **anti-fraud-service**

* Consumes transaction events
* Applies validation rules
* Publishes transaction status updates

---

## 🔄 Flow

# Tech Stack
1. A transaction is created via API
2. It is stored with status `pending`
3. An event `transaction.created` is sent to Kafka
4. Anti-fraud service consumes the event
5. Applies rule:

<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>
* If value > 1000 → `rejected`
* Else → `approved`
6. Publishes `transaction.validated`
7. Transaction service consumes and updates status

We do provide a `Dockerfile` to help you get started with a dev environment.
---

You must have two resources:
## 🧪 API Endpoints

1. Resource to create a transaction that must containt:
### ➤ Create Transaction

**POST /transactions**

```json
{
"accountExternalIdDebit": "Guid",
"accountExternalIdCredit": "Guid",
"accountExternalIdDebit": "string",
"accountExternalIdCredit": "string",
"tranferTypeId": 1,
"value": 120
}
```

2. Resource to retrieve a transaction
**Response:**

```json
{
"transactionExternalId": "Guid",
"transactionId": "uuid",
"status": "pending"
}
```

---

### ➤ Get Transaction

**GET /transactions/:id**

**Response:**

```json
{
"transactionExternalId": "uuid",
"transactionType": {
"name": ""
"name": "transfer"
},
"transactionStatus": {
"name": ""
"name": "approved"
},
"value": 120,
"createdAt": "Date"
"createdAt": "date"
}
```

## Optional
---

## ⚙️ Tech Stack

* Node.js (NestJS)
* PostgreSQL (Prisma ORM)
* Kafka (KafkaJS)
* Docker

---

## 🚀 How to Run

### 1. Start infrastructure

```bash
docker-compose up -d
```

---

### 2. Run transaction-service

```bash
cd transaction-service
npm install
npm run start:dev
```

---

### 3. Run anti-fraud-service

```bash
cd anti-fraud-service
npm install
npm run start:dev
```

---

## 📡 Kafka Topics

* `transaction.created`
* `transaction.validated`

---

## 🧠 Design Decisions

* Event-driven architecture for decoupling services
* Asynchronous validation to improve scalability
* Prisma ORM for type-safe database access
* Kafka for reliable message delivery

---

## ⚡ Scalability Considerations

To handle high load scenarios:

* Horizontal scaling of consumers (Kafka consumer groups)
* Partitioned topics for parallel processing
* Database indexing on transaction ID
* Potential use of caching (e.g., Redis)

---

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?
## ✅ Status

You can use Graphql;
✔ Transaction creation
✔ Anti-fraud validation
✔ Kafka communication
✔ Transaction status update
✔ Transaction query by ID

# Send us your challenge
---

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.
## 👨‍💻 Author

If you have any questions, please let us know.
Christian Pulache
25 changes: 25 additions & 0 deletions anti-fraud-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',
},
};
35 changes: 35 additions & 0 deletions anti-fraud-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# compiled output
/dist
/node_modules

# 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
4 changes: 4 additions & 0 deletions anti-fraud-service/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
73 changes: 73 additions & 0 deletions anti-fraud-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ npm install
```

## Running the app

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

## Test

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).
8 changes: 8 additions & 0 deletions anti-fraud-service/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading