Skip to content

Conversation

@joshnavdev
Copy link

@joshnavdev joshnavdev commented Jun 9, 2025

Yape Code Challenge – Transaction Management with Anti-Fraud Validation

By Joshua Navarro

Hello Yape Team!

Descripción

This PR contains my implementation of the code challenge described in your repository. The solution is designed following microservices architecture using the NestJS framework, Kafka for event-driven communication, GraphQL as the API gateway, and PostgreSQL as the persistent storage. The entire project is built following Clean Architecture principles to ensure modularity, maintainability, and testability.

Services Overview

This project consists of three main services:

  • Transaction Service: Handles creation and persistence of financial transactions, including their status updates based on validation outcomes.
  • Anti-Fraud Service: Validates transactions using predefined business rules (e.g., rejecting those with values greater than 1000), then emits a validation result.
  • API Gateway (GraphQL): Provides a unified entry point to interact with the Transaction Service via a GraphQL API.
  • Optional) RESTful API GatewayI:A lightweight RESTful interface was added for demonstration purposes, showing how the same service could be exposed via REST if needed.

Stack Technology

  • Node.js - The runtime environment for the services.
  • NestJS - A progressive Node.js framework for building efficient and scalable server-side applications.
  • PostgreSQL - The relational database used for storing transaction data.
  • Kafka - A distributed event streaming platform used for communication between services.
  • GraphQL - A query language for APIs that provides a more flexible and efficient way to interact with the services.
  • TypeORM - An ORM for Node.js that provides a way to interact with the PostgreSQL database in an object-oriented manner.
  • Jest - A testing framework used for unit and integration tests to ensure the reliability of the services.
  • Docker & Docker Compose - Containerization and orchestration

Microservices Documentation

Each service has its own README.md with further details:

  • GraphQL Gateway: graphql-gateway/README.md
  • Transaction Service: transaction-service/README.md
  • Anti-Fraud Service: anti-fraud-service/README.md

How to Run the Project

The easiest way to run everything is via Docker Compose. All dependencies and services spin up with a single command.

Note: If you do not have installed docker with docker-compose, please read this How to Install Docker

Once you have installed docker-compose, clone this repository and go to the root directory of the project. Then, run the following command:

$ docker-compose up --build

Warning: Please make sure to have the port 5432, 9092, 3000 and 3005 available to run this project without problems.

Hot to Test the Project

After running the project, you can access the GraphQL playground at http://localhost:3005/graphql

Create Transaction Mutation

mutation createTransaction($createTransactionInput: CreateTransactionInput!) {
  createTransaction(createTransactionData: $createTransactionInput) {
    transactionExternalId
    transactionStatus { id name }
    transactionType { id name }
    transferType { id name }
    value
    createdAt
  }
}

Sample variables:

{
  "createTransactionInput": {
    "accountExternalIdDebit": "28dbd0c5-4ea0-4d05-8fd9-39e8f76aaf13",
    "accountExternalIdCredit": "d6cd54da-8ce3-4f79-abda-bd5be9b19e68",
    "transferTypeId": 1,
    "value": 1000
  }
}

Get Transaction Query

query getTransaction($transactionId: UUID!) {
  getTransaction(id: $transactionId) {
    transactionExternalId
    transactionStatus { id name }
    transactionType { id name }
    transferType { id name }
    value
    createdAt
  }
}

Sample variables:

{
  "transactionId": "28dbd0c5-4ea0-4d05-8fd9-39e8f76aaf13"
}

Scalability Notes (Optional Challenge)

To address high volume scenarios:

  • Kafka decouples services to handle async message processing at scale.
  • Database indexing optimizes lookup queries on frequently queried fields.
  • Horizontal scalability is supported by design through independent service deployment.
  • Future improvements could include CQRS and read replicas for high-read use cases.

Let me know if you have any feedback.

Thanks for reviewing my submission!

joshnavdev added 30 commits June 6, 2025 21:36
- Add Config and Database Module
- Add Create Transaction service
- Add Get Transaction service
@joshnavdev joshnavdev deleted the feat/transaction-service-resolution branch August 11, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants