Skip to content

Diego Ortiz - Challenge Transaction #474

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

Conversation

DiegoOrtizS
Copy link

Candidate Name: Diego Ortiz

Execution

Running the Application

docker-compose up -d --build

Creating a Transaction

Execute approved transaction use case

docker exec -it app-nodejs-codechallenge-transaction-service-1 curl -X POST http://localhost:3000/transactions \
     -H "Content-Type: application/json" \
     -d '{
           "accountExternalIdDebit": "ab865bf7-079d-43b3-80f8-cd6dc35ba33b",
           "accountExternalIdCredit": "fe219ec9-3e32-4d41-9add-66bef431179c",
           "tranferTypeId": 1,
           "value": 100
         }'

Execute approved transaction use case

docker exec -it app-nodejs-codechallenge-transaction-service-1 curl -X POST http://localhost:3000/transactions \
     -H "Content-Type: application/json" \
     -d '{
           "accountExternalIdDebit": "ab865bf7-079d-43b3-80f8-cd6dc35ba33b",
           "accountExternalIdCredit": "fe219ec9-3e32-4d41-9add-66bef431179c",
           "tranferTypeId": 1,
           "value": 1001
         }'

Retrieving a Transaction

Execute get transaction use case

docker exec -it app-nodejs-codechallenge-transaction-service-1 curl -X GET http://localhost:3000/transactions/{transactionExternalId}

🧰 Technologies Used

The project was built using modern backend technologies to ensure scalability, maintainability, and performance:

  • NestJS – Progressive Node.js framework for building efficient and scalable server-side applications.
  • TypeScript – Adds static typing and better developer tooling for JavaScript.
  • Kafka – Message broker used to communicate between the transaction service and the anti-fraud microservice asynchronously.
  • PostgreSQL – Relational database used to persist transaction records.
  • Prisma – Type-safe ORM used for database access and migrations.
  • Fastify – Fast and low-overhead HTTP server, used as the NestJS platform adapter.
  • Swagger – Used to automatically generate API documentation. Accessible at http://localhost:3000/docs.
  • Docker – Used to containerize the app and run all services locally via docker-compose.

📁 Project Structure

The project follows a modular and layered architecture inspired by Clean Architecture and Domain-Driven Design. Here's a breakdown:

src/
├── application/               # Business logic (services)
├── domain/                    # Entities and domain models
│   ├── entities/
│   └── value-objects/
├── dto/                       # Data Transfer Objects
├── infrastructure/            # External layers (DB, Kafka)
│   └── repositories/          # Repositories using Prisma
├── interface/                 # Controllers and transport logic
│   └── controllers/
├── main.ts                    # App bootstrap and setup
└── app.module.ts              # Root application module

🧠 Architecture

The application follows a layered architecture inspired by Clean Architecture and Domain-Driven Design principles:

  • Domain Layer: Contains the core business logic in the form of entities, enums, and interfaces. It’s isolated and has no external dependencies.
  • Application Layer: Implements the use cases of the system. It coordinates between the domain and infrastructure layers.
  • Infrastructure Layer: Responsible for external concerns such as Kafka messaging and database persistence.
  • Presentation Layer: The REST API (controllers) that handles HTTP requests and responses.
[ Controller Layer (interface) ]
           |
[ Application Layer (services) ]
           |
[ Domain Layer (entities, value objects) ]
           |
[ Infrastructure Layer (DB, Kafka, Prisma) ]

📌 Noteworthy Features

  • Validation: Input data is validated using class-validator and NestJS’s ValidationPipe, ensuring proper error handling and 400 responses for malformed requests.
  • Microservice Integration: Kafka is used to asynchronously send transaction creation events to the anti-fraud service and receive status updates.
  • Status Management: Transaction status is initially set to pending, and updated based on messages from the anti-fraud service.
  • Scalability Considerations: The system is designed with scalability in mind—Kafka for decoupling services, PostgreSQL for reliable storage, and Fastify for efficient HTTP handling.

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.

1 participant