Skip to content

Repository files navigation

Transaction Engine

This is a simple transaction engine implemented in Java 21 with Spring Boot. It supports operations such as purchase, installment purchase, withdrawal, and payment, managing accounts and transactions.

The goal of this project is to implement a simple transaction engine that can handle various types of transactions (purchase, installment purchase, withdrawal, payment) while managing accounts and ensuring data integrity. The application should be able to create accounts, perform transactions, and retrieve account details.

This approach was chosen instead of microservices to reduce operational complexity while still allowing future scalability.

For a detailed explanation of design decisions, trade-offs, and system structure, see ARCHITECTURE.md.


Technologies Used

  • Java 21 (as the programming language)
  • Spring Boot (with Spring Data JPA for database interactions and Spring Web for REST API)
  • PostgreSQL (as the relational database)
  • Docker & Docker Compose (for containerization, to facilitate deployment and ensure consistency across environments)
  • JUnit 5 (for unit testing)
  • Mockito (for unit testing)
  • Swagger/OpenAPI (for API documentation)
  • Spring Actuator (for monitoring and health checks)
  • Gradle (build and dependency management)
  • Lombok (to reduce boilerplate code)
  • Flyway (Database Migrations, to facilitate schema management and versioning)

Features

  • Create accounts
  • Perform transactions (purchase, installment purchase, withdrawal, payment)
  • Retrieve account details

Getting Started

Prerequisites

  • Docker
  • Docker Compose

Configuration

This application follows the Externalized Configuration principle from the Twelve-Factor App methodology.

All sensitive and environment-specific configurations (such as database credentials) are managed through environment variables instead of being hardcoded in the application.

A .env file is used for local development convenience and is loaded via Docker Compose.


Setup

To avoid exposing sensitive information, the application uses environment variables.

  1. Create a .env file:
cp env.example .env
  1. Fill in the required values based on .env.example.

Run the Application

docker-compose up --build -d

The application will be available at:

http://localhost:8080

Stop and Cleanup

docker-compose down -v

Testing Strategy

This project follows the Testing Pyramid approach:

  • Unit Tests: Validate individual components in isolation (fast and reliable)
  • Functional Tests: Validate end-to-end behavior simulating real use cases

Run tests

./gradlew test
./gradlew functionalTest

API Overview

Account Endpoints

After starting containers with Docker, you can use Swagger or CURL to test the application manually:

  • POST /accounts — Create an account
    curl -X 'POST' \
      'http://localhost:8080/accounts' \
      -H 'accept: */*' \
      -H 'Content-Type: application/json' \
      -d '{
      "document_number": "12345678900"
    }'
  • GET /accounts/{account_id} — Retrieve an account
    curl -X 'GET' \
      'http://localhost:8080/accounts/{id}' \
      -H 'accept: */*'

Transaction Endpoint

  • POST /transactions — Perform transaction
    curl -X 'POST' \
    'http://localhost:8080/transactions' \
    -H 'accept: */*' \
    -H 'Content-Type: application/json' \
    -d '{
    "account_id": 1,
    "operation_type_id": 1,
    "amount": 100
    }'

Data Model

Account

Account_ID Document_Number
BIGSERIAL VARCHAR(20)

Transaction

Transaction_ID Account_ID OperationType_ID Amount EventDate
BIGSERIAL BIGSERIAL BIGINT Decimal(10,2) TIMESTAMP

Operation Type

OperationType_ID Description
BIGINT VARCHAR(255)

Resources


Possible Improvements

Balance Management

  • Introduce explicit account balance tracking and authorization rules.
  • Implement locking mechanisms (e.g., optimistic or pessimistic locking) to ensure consistency under concurrent access.

Idempotency

  • Add idempotency keys on operations to prevent duplicate transaction creation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages