How victorm0nteiro/wallet-go- works
wallet-go is a digital-wallet API whose balance is derived from an append-only, double-entry ledger. Its main workflow is an authenticated HTTP request through application use cases to PostgreSQL: transfers are validated, executed atomically with scoped idempotency, and recorded with ledger entries and an outbox event; balance and statement reads query the ledger. The README documents optional read-only API keys, per-key rate limiting, two selectable concurrency strategies, and a separate at-least-once relay. Connections for unsampled HTTP middleware and relay internals are limited to documented behavior.
Main entry points: main.go Wallet server · transfer.go Transfer and idempotency · handler.go Request handlers · account.go Account use cases
Components 21
HTTP API
- Wallet server
cmd/wallet/main.go - HTTP router
internal/adapters/http/router.go - Request handlers
internal/adapters/http/handler.go - Auth and rate limit
internal/adapters/http/middleware.go - HTTP error mapping
internal/adapters/http/errors.go
Wallet use cases
- Account use cases
internal/app/account.go - Deposit and withdrawal
internal/app/cash.go - Transfer and idempotency
internal/app/transfer.go - Use-case ports
internal/app/model.go
PostgreSQL persistence
- Account repository
internal/adapters/postgres/account_repository.go - Ledger repository
internal/adapters/postgres/entry_repository.go - Locking executor
internal/adapters/postgres/transfer_executor.go - Serializable executor
internal/adapters/postgres/serializable_executor.go - Strategy selection
internal/adapters/postgres/strategy.go - PostgreSQL
Outbox delivery
- Relay process
cmd/relay/main.go - Outbox poller
internal/adapters/postgres/relay.go - Outbox storage
internal/adapters/postgres/outbox.go - Log publisher
internal/adapters/postgres/relay.go
Domain model
- Money and account rules
internal/domain/money.go
Other components
- API client
Connections 31
- API client → Wallet server: sends requests
README.md - Wallet server → HTTP router: configures
cmd/wallet/main.go - HTTP router → Request handlers: routes requests
README.md - HTTP router → Auth and rate limit: applies middleware
README.md - Request handlers → Account use cases: calls account use cases
internal/adapters/http/handler.go - Request handlers → Deposit and withdrawal: calls cash use cases
internal/adapters/http/handler.go - Request handlers → Transfer and idempotency: calls transfer use case
internal/adapters/http/handler.go - Request handlers → HTTP error mapping: maps errors
internal/adapters/http/errors.go - Account use cases → Use-case ports: uses persistence ports
internal/app/account.go - Account use cases → Money and account rules: uses domain types
internal/app/account.go - Deposit and withdrawal → Transfer and idempotency: models cash as transfers
README.md - Transfer and idempotency → Use-case ports: uses transfer port
internal/app/transfer.go - Transfer and idempotency → Money and account rules: validates amounts
internal/app/transfer.go - Wallet server → Account use cases: constructs service
cmd/wallet/main.go - Wallet server → Deposit and withdrawal: constructs service
cmd/wallet/main.go - Wallet server → Transfer and idempotency: constructs service
cmd/wallet/main.go - Wallet server → Account repository: constructs repository
cmd/wallet/main.go - Wallet server → Ledger repository: constructs repository
cmd/wallet/main.go - Wallet server → Strategy selection: selects executor
cmd/wallet/main.go - Strategy selection → Locking executor: selects strategy
README.md - Strategy selection → Serializable executor: selects strategy
README.md - Locking executor → PostgreSQL: locks and writes transfers
internal/adapters/postgres/transfer_executor.go - Serializable executor → PostgreSQL: executes serializable transactions
internal/adapters/postgres/serializable_executor.go - Account repository → PostgreSQL: reads and writes accounts
internal/adapters/postgres/account_repository.go - Ledger repository → PostgreSQL: reads and writes ledger
internal/adapters/postgres/entry_repository.go - Ledger repository → PostgreSQL: derives balance by sum
internal/adapters/postgres/entry_repository.go - Transfer and idempotency → Outbox storage: appends completion event
README.md - Relay process → Outbox poller: polls batches
cmd/relay/main.go - Outbox poller → PostgreSQL: reads and marks events
README.md - Relay process → Log publisher: passes publisher
cmd/relay/main.go - Outbox poller → Log publisher: delivers events
README.md