SAB: Distribution & Financial Control System
Immutable-ledger ERP for multi-depot beer distribution
SAB is a beer distribution and financial-control system I built as a freelance engagement for a multi-depot distributor. It's the digital replacement for a manual Excel-and-paper-receipt operation, tracking returnable containers, procurement, sales, deliveries, customer accounts, cash flow, and reconciliation across depots, with financial correctness as the non-negotiable core.
The Core: An Immutable Financial Ledger
The system runs on an append-only, ERPNext-inspired ledger architecture: every stock movement and every cent of money movement is recorded as an immutable entry, and current state (cash balance, stock on hand, customer credit) is a cache derived from that history and kept consistent under optimistic locking. Corrections are reversing entries, never edits; the original record stays forever.
- Money is decimal, never float: every value is exact
decimal(10,2)passed as decimal strings, so totals never drift - Append-only ledgers for stock, customer balances, container custody, and audit, with derived caches that must always agree
- The acceptance test for every feature: does it produce the same numbers the operations manager already sees in their daily report?
What It Manages
- Returnable containers (crates & barrels) with per-container custody tracking and a full deposit lifecycle
- Procurement, sales, and delivery trips: driver assignment, per-trip stock movements, customer returns, and factory-returns of empties
- Customer accounts with credit balances, plus a cash book covering every in/out and bank-to-cash transfers
- Reconciliation (scan-or-count audits), missing-unit liability tracking, and high-value sale approval gates
- OCR receipt scanning: snap a bank receipt and the system extracts the amount and reference automatically, with an LLM fallback for hard scans
- Role-based access control scoped per warehouse, a complete append-only audit trail, and read-only analytics with CSV/JSON export
How It's Built
An Nx monorepo, TypeScript end to end:
- NestJS + Fastify backend on Drizzle + PostgreSQL, BullMQ + Redis for background jobs, MinIO for receipt and attachment storage
- React 19 + Vite frontend consuming a live Swagger/OpenAPI contract generated from the backend's decorators
- JWT auth + RBAC, structured request-scoped logging, and integration tests against real Postgres / Redis / MinIO via Testcontainers
- Fully self-hosted with zero paid SaaS dependencies, auto-deployed via GitHub Actions → container registry → Docker Compose on a VPS
