- 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.
- The
/cmd
directory contains the application bootstrap/main. - The
/internal
directory contains business logic packages:- accounts: Manages poster accounts;
- api: Implements HTTP handlers;
- balances: Manages account balances, provided by the transactions_balances view;
- holders: Manages posters;
- statements: Displays account statements based on transactions, separated from the transactions package for better filter autonomy;
- 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.
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
- ledger-exp-api -> localhost:8080
- postgres -> localhost:5432
- redis-commander -> localhost:8081 root - root
- jaeger -> localhost:16686
- prometheus -> localhost:9090
Unit Tests:
go test -json -race -tags=unit ./...
Integration Tests:
go test -json -race -tags=integration ./...
You can use the Insomnia exported file, which contains all mapped endpoints with usage examples. File
For a consistent flow, follow these endpoints:
- POST /v1/holders
- POST /v1/accounts
- Create transactions:
- POST /v1/transactions/credits -> Credit the account.
- POST /v1/transactions/debits -> Debit the account.
- POST /v1/transactions/p2p -> Transfer between accounts.
- GET /v1/accounts/:accountID/statements -> Account statement.
- GET /v1/accounts/:accountID/balances -> Check account balance.
- How are mocks generated for tests?
- In the
./scripts
directory, there's a shell file that maps all files/interfaces to generate a mock.
- In the
- How does database migration work?
- Database migration is handled by the
database-migration
service defined in the docker-compose.yml.
- Database migration is handled by the
- 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.