Ledger Service is the core of a financial system implementing double-entry accounting. It acts as a single source of truth for balances and transactions.
- Double-entry accounting (
Σ DEBIT == Σ CREDIT) - Money stored in minor units (
int64, no floats) - Idempotent transactions
- Clean Architecture
- PostgreSQL + SQL migrations
- gRPC API with reflection
- CI with lint, unit and integration tests
make tools
make run
make migrate-up
make testCheck gRPC reflection:
grpcurl -plaintext localhost:8081 listmake tools— install dev toolsmake migrate-up/make migrate-downmake protomake test-unitmake test-integrationmake testmake lintmake lint-cimake check
Environment variables:
DB_DSN— PostgreSQL DSNGRPC_PORT— gRPC port
Example:
DB_DSN=postgres://ledger:ledger@localhost:5432/ledger?sslmode=disable
GRPC_PORT=8081Clean Architecture with explicit responsibility separation.
cmd/ledger
internal/
config/
db/
domain/
repo/postgres/
service/
integration/
transport/grpc/
proto/ledger/v1/
migrations/
test/
domain
- Entities, errors, invariants
service
- Validation
- Business rules
- Idempotency
repo
- PostgreSQL access
- SQL → domain error mapping
transport/grpc
- gRPC API
- Domain → gRPC status mapping
- No business logic
Each transaction contains at least:
DEBITCREDIT
Invariant:
Σ DEBIT == Σ CREDIT
- Stored in minor units
int64- Floats forbidden
Example:
1000 = 10.00 RUB
This project uses Conventional Commits:
feat:new featurefix:bug fixdocs:documentationrefactor:refactoringtest:testsci:CI changeschore:maintenance
Examples:
feat: add balance endpointfix(repo): handle pgx.ErrNoRowsci: add postgres integration job
See CONTRIBUTING.md.
MIT — see LICENSE.