Skip to content
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

Beterraba - yaperos codechallenge #446

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
b52f944
initialize anti-fraud service
beterrabaA Feb 6, 2025
7bcdb55
prisma config
beterrabaA Feb 6, 2025
5f15168
Dockerfile
beterrabaA Feb 6, 2025
932e0b7
Dockerfile
beterrabaA Feb 6, 2025
dbeea5b
remove original gitignore
beterrabaA Feb 6, 2025
13cb8c2
add prisma database seeds
beterrabaA Feb 16, 2025
7d66b96
add prisma database migrations
beterrabaA Feb 16, 2025
a2e4de8
create kafka client
beterrabaA Feb 16, 2025
1155efb
relocate files
beterrabaA Feb 16, 2025
8e6fe4b
´.dockerignore´
beterrabaA Feb 16, 2025
a607735
prisma client
beterrabaA Feb 16, 2025
dc608c9
add antifraud service kafka client
beterrabaA Feb 16, 2025
99f66d2
antifraud service `Dockerfile`
beterrabaA Feb 16, 2025
9b08102
transaction service `Dockerfile`
beterrabaA Feb 16, 2025
38f4987
`.gitignore`
beterrabaA Feb 16, 2025
2c75d98
add kafka client `admin` configs
beterrabaA Feb 17, 2025
c9c2c20
`.env` file configs
beterrabaA Feb 17, 2025
26beb14
fix env variable name
beterrabaA Feb 17, 2025
aa27a69
types
beterrabaA Feb 17, 2025
64a0e6b
`package.json`
beterrabaA Feb 17, 2025
4d7835b
`tsconfig` file
beterrabaA Feb 17, 2025
a02faab
`Dockerfile`
beterrabaA Feb 17, 2025
402d490
add antifraud service
beterrabaA Feb 17, 2025
7f0d229
add transaction service
beterrabaA Feb 17, 2025
68d0255
add containers network
beterrabaA Feb 17, 2025
8d889fb
add database service and volume
beterrabaA Feb 17, 2025
dba9146
add kafka zookeeper service
beterrabaA Feb 17, 2025
1562247
add kafka broker service
beterrabaA Feb 17, 2025
6186373
create transaction type table schema
beterrabaA Feb 17, 2025
604fdf2
fix script
beterrabaA Feb 17, 2025
d45ddf3
fix table name and migrations
beterrabaA Feb 17, 2025
8b3b3ed
graphql schemas
beterrabaA Feb 17, 2025
368ecac
graphql resolvers
beterrabaA Feb 17, 2025
eb6d01f
transaction service server
beterrabaA Feb 17, 2025
f0f5d48
setting node env to production
beterrabaA Feb 17, 2025
1b8dfb8
Revert "transaction service server"
beterrabaA Feb 17, 2025
789e2e0
production node
beterrabaA Feb 17, 2025
1139b28
antifraud service server
beterrabaA Feb 17, 2025
436ea1c
antifraud kafka consumer
beterrabaA Feb 17, 2025
1448e92
antifraud kafka producer
beterrabaA Feb 17, 2025
6184dd2
remove console.log
beterrabaA Feb 17, 2025
e2b3b52
update database version
beterrabaA Feb 17, 2025
f660f9c
`docker-compose` development file
beterrabaA Feb 17, 2025
bfe209b
transaction kafka consumer
beterrabaA Feb 17, 2025
d70486c
transaction kafka producer
beterrabaA Feb 17, 2025
f8bad7f
final
beterrabaA Feb 19, 2025
50d682d
`README.md`
beterrabaA Feb 19, 2025
ef15c82
fix indet
beterrabaA Feb 19, 2025
bee6de6
fix fields
beterrabaA Feb 19, 2025
5e61380
fix unsed env
beterrabaA Feb 20, 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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POSTGRES_USER='database_username'
POSTGRES_PASSWORD='database_password'
POSTGRES_PORT=database_external_port
POSTGRES_DB='database_name'
POSTGRES_SSL=database_ssl_status
DATABASE_URL='database_url'
PORT=transaction_service_api_external_port
105 changes: 1 addition & 104 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1 @@
# Logs
logs
*.log
npm-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

# 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
.env
236 changes: 197 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Yape Code Challenge :rocket:

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
Our code challenge will let you marvel us with your Jedi coding skills :smile:.

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

Expand Down Expand Up @@ -30,53 +30,211 @@ Every transaction with a value greater than 1000 should be rejected.
Transaction -- Update transaction Status event--> transactionDatabase[(Database)]
```

# Tech Stack
# Solution

<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>
### Set up environment variables

We do provide a `Dockerfile` to help you get started with a dev environment.
Create a `.env` file in the root directory and add any required environment variables (e.g., API keys, database URLs). Check `.env.example` for a template.

You must have two resources:
```env
POSTGRES_USER='database_username'
POSTGRES_PASSWORD='database_password'
POSTGRES_PORT=database_external_port
POSTGRES_DB='database_name'
POSTGRES_SSL=database_ssl_status
DATABASE_URL='database_url'
PORT=transaction_service_api_external_port
```

1. Resource to create a transaction that must containt:
## Database

```json
{
"accountExternalIdDebit": "Guid",
"accountExternalIdCredit": "Guid",
"tranferTypeId": 1,
"value": 120
}
```
### Database structure

2. Resource to retrieve a transaction

```json
{
"transactionExternalId": "Guid",
"transactionType": {
"name": ""
},
"transactionStatus": {
"name": ""
},
"value": 120,
"createdAt": "Date"
}
```
![database](db_diagram.png)

### Seeds

## Optional
Eight different transfer types were previously seeded into the database.

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?
```javascript
[
{ 1: "ATM" },
{ 2: "Charge" },
{ 3: "Check" },
{ 4: "Deposit" },
{ 5: "Online" },
{ 6: "POS" },
{ 7: "Transfer" },
{ 8: "Withdrawal" },
];
```

You can use Graphql;
## Starting application

# Send us your challenge
### Running docker compose script

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.
```bash
docker compose -f 'docker-compose.yml' up -d --build
```

If you have any questions, please let us know.
## Services

- Antifraud: Intended to check all transactions
- Transaction: The API server is responsible for creating new transactions and manipulate.
- Database: Intended to persiste all data
- Kafka broker: Working with boths(Transaction and Antifraud) services listening events
- Zookeeper: Responsible for overseeing and managing Kafka brokers.

## API

The api will be running on [http://localhost:{4000}/graphql](http://localhost:4000/graphql).
_In this example, port 4000 is used, it can be any port of your choice._

### Using Graphql client

#### Creating new transactions

Allows create new transactions

- **Graphql query**:

```graphql
mutation {
createTransaction(
input: {
accountExternalIdDebit: "Guid"
accountExternalIdCredit: "Guid"
tranferTypeId: 5
value: 500.87
}
) {
transactionExternalId
transactionType {
name
}
transactionStatus {
name
}
value
createdAt
}
}
```

- **Response**:

```graphql
{
data: {
createTransaction: {
transactionExternalId: "01951fd9-b7f0-71d0-9402-985e5ddf972d",
transactionType: {
name: "Deposit"
},
transactionStatus: {
name: "pending"
},
value: 500.87,
createdAt: "1739996116976"
}
}
}
```

#### Listing transactions

Allows list all transactions created
. _All field are optionals(id,idDebit,idCredit,transferId,status,value,createdAt)_

- **Graphql query**:

```graphql
query {
getTransactions {
id
idDebit
idCredit
transferId
status
value
createdAt
}
}
```

- **Response**:

```graphql
{
data: {
getTransactions: [
{
id: "019515de-b304-76a0-a15d-954286f5eeaf",
idDebit: "01951fea-3522-7625-991a-830cff56177a",
idCredit: "01951fea-7b78-742c-9007-8710135ce31b",
transferId: 8,
status: "REJECTED",
value: 1205.48,
createdAt: "1739828671236"
},
{
id: "01951fd9-b7f0-71d0-9402-985e5ddf972d",
idDebit: "01951fea-ac02-702d-bc82-068d5a6c8b04",
idCredit: "01951fea-f4b3-7d79-bf1a-282931aea271",
transferId: 3,
status: "ACCEPTED",
value: 482.91,
createdAt: "1739996116976"
},
{
id: "01951feb-2f41-7e37-8db6-2dd8286be601",
idDebit: "01951feb-2f41-7323-861a-ca44d3309ff9",
idCredit: "01951feb-beda-7ae0-a513-2447e7b8fe5a",
transferId: 6,
status: "REJECTED",
value: 1000.87,
createdAt: "1739996356039"
}
]
}
}
```

#### Getting a especific transactions using Id

Allows search transactions by Id
. _All field are optionals(id,idDebit,idCredit,transferId,status,value,createdAt)_

- **Graphql query**:

```graphql
query {
getTransaction(id: "019515de-b304-76a0-a15d-954286f5eeaf") {
id
idDebit
idCredit
transferId
status
value
createdAt
}
}
```

- **Response**:

```graphql
{
data: {
getTransactions: {
id: "019515de-b304-76a0-a15d-954286f5eeaf",
idDebit: "3dfbe8b2-564f-4275-8d76-f47c9db3cf53",
idCredit: "3da480a2-4319-4cc5-81f3-f05c378b78a3",
transferId: 5,
status: "ACCEPTED",
value: 999.99,
createdAt: "1740000991"
}
}
}
```
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
3 changes: 3 additions & 0 deletions antifraud-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
.dist
11 changes: 11 additions & 0 deletions antifraud-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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