Skip to content

Implementation of a project using distributed lock concepts and transaction control.

License

Notifications You must be signed in to change notification settings

dalmarcogd/ledger-exp

Repository files navigation

ledger-exp

Table Structure

Table Structure

Application Architecture

Architecture

  • This project uses PostgreSQL as the database solution and Redis for caching and concurrency control (distlock).
  • For observability, the open-source project OpenTelemetry was chosen, allowing for agnostic distribution of metrics and spans to different providers.

Packages

Packages

  • The /cmd directory contains the application bootstrap/main.
  • The /internal directory contains business logic packages:
    1. accounts: Manages poster accounts;
    2. api: Implements HTTP handlers;
    3. balances: Manages account balances, provided by the transactions_balances view;
    4. holders: Manages posters;
    5. statements: Displays account statements based on transactions, separated from the transactions package for better filter autonomy;
    6. transactions: Manages transactions like credits, debits, and transfers between accounts.
  • The /migrations directory contains all SQL scripts (DDL) for database migration.
  • The /pkg directory includes all packages used in the application that are not business-related.

How to Run the Project?

docker-compose --env-file .env-docker up -d

Once all services are up and running, they will be exposed at: Database migration will be executed along with docker-compose startup

How to Run Unit and Integration Tests?

Unit Tests:

go test -json -race -tags=unit ./...

Integration Tests:

go test -json -race -tags=integration ./...

How to Test the API?

You can use the Insomnia exported file, which contains all mapped endpoints with usage examples. File

For a consistent flow, follow these endpoints:

  1. POST /v1/holders
  2. POST /v1/accounts
  3. Create transactions:
    1. POST /v1/transactions/credits -> Credit the account.
    2. POST /v1/transactions/debits -> Debit the account.
    3. POST /v1/transactions/p2p -> Transfer between accounts.
  4. GET /v1/accounts/:accountID/statements -> Account statement.
  5. GET /v1/accounts/:accountID/balances -> Check account balance.

Additional Information

  1. How are mocks generated for tests?
    • In the ./scripts directory, there's a shell file that maps all files/interfaces to generate a mock.
  2. How does database migration work?
    • Database migration is handled by the database-migration service defined in the docker-compose.yml.
  3. How does observability work?
    • The OpenTelemetry Collector service defined in the docker-compose.yml receives all spans and metrics generated by the application and transmits them to Jaeger and Prometheus, respectively.