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
142 changes: 53 additions & 89 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,68 @@
# compiled output
/dist
/node_modules
/build
/postgres
**/node_modules
**/dist
**/build
**/logs
**/coverage
**/.nyc_output
**/.idea
**/.project
**/.classpath
transaction-ms/postgres
antifraud-ms/postgres

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

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# 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

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
160 changes: 107 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,136 @@
# Yape Code Challenge :rocket:
# Yape Reto - Transaction & Antifraud Microservices

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
This project consists of two microservices: Transaction Management and Antifraud Detection.

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

- [Problem](#problem)
- [Tech Stack](#tech_stack)
- [Send us your challenge](#send_us_your_challenge)
- Node.js (LTS version recommended)
- pnpm package manager
- Docker and Docker Compose

# Problem
## Installation

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:
### 1. Install Antifraud Microservice

<ol>
<li>pending</li>
<li>approved</li>
<li>rejected</li>
</ol>
```bash
cd antifraud-ms
pnpm install
```

### 2. Install Transaction Microservice

```bash
cd transaction-ms
pnpm install
```

### 3. Start Docker Services

From the root directory, start the required Docker containers:

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

### 4. Configure Environment Variables

Copy the environment template file to create your local configuration:

```bash
cd transaction-ms
cp .env.template .env
```

## Running the Application

Start both microservices in development mode:

Every transaction with a value greater than 1000 should be rejected.
### Terminal 1 - Antifraud Microservice
```bash
cd antifraud-ms
pnpm run start:dev
```

```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)]
### Terminal 2 - Transaction Microservice
```bash
cd transaction-ms
pnpm run start:dev
```

# Tech Stack
## Testing the API

Once both services are running, navigate to the GraphQL playground:

<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>
```
http://localhost:3000/graphql
```

We do provide a `Dockerfile` to help you get started with a dev environment.
### Available Operations

You must have two resources:
#### 1. Create Transaction Mutation

1. Resource to create a transaction that must containt:
First, use this mutation to create a new transaction:

```graphql
mutation Mutation($createTransactionInput: CreateTransactionInput!) {
createTransaction(createTransactionInput: $createTransactionInput) {
accountExternalIdCredit
accountExternalIdDebit
createdAt
status
transactionExternalId
value
}
}
```

**Variables:**
```json
{
"accountExternalIdDebit": "Guid",
"accountExternalIdCredit": "Guid",
"tranferTypeId": 1,
"value": 120
"createTransactionInput": {
"accountExternalIdDebit": "550e8400-e29b-41d4-a716-446655440000",
"accountExternalIdCredit": "9f1a8a23-3c7b-4b9f-9e29-17d1f8e41e76",
"value": 999,
"transferTypeId": 1
}
}
```

2. Resource to retrieve a transaction
> **Note:** Copy the `transactionExternalId` from the response, you'll need it for the next query.

#### 2. Query Transaction

Use this query to retrieve the transaction details using the `transactionExternalId` obtained from the create mutation:

```graphql
query Transaction($transactionExternalId: String!) {
transaction(transactionExternalId: $transactionExternalId) {
status
accountExternalIdCredit
accountExternalIdDebit
status
transactionExternalId
}
}
```

**Variables:**
```json
{
"transactionExternalId": "Guid",
"transactionType": {
"name": ""
},
"transactionStatus": {
"name": ""
},
"value": 120,
"createdAt": "Date"
"transactionExternalId": "<USE THE transactionExternalId FROM THE CREATE MUTATION RESPONSE>"
}
```

## Optional

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?

You can use Graphql;
## Troubleshooting

# Send us your challenge
- Ensure all Docker containers are running: `docker-compose ps`
- Check if ports 3000 and other required ports are available
- Verify environment variables are properly configured in `.env` file
- Check logs of each service for any errors

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

If you have any questions, please let us know.
This project implements a microservices architecture with:
- **Transaction Microservice**: Handles transaction creation and management
- **Antifraud Microservice**: Validates transactions for fraud detection
- **GraphQL API**: Provides a unified interface for client interactions
Loading