Personal · finance backend · 2026In progress
Ledger API
A ledger API I built in phases to practise writing money code properly: layered TypeScript and Express, storage that moved from JSON to SQLite through a migration, and authentication hardened step by step.
Who wrote whatI used an AI tutor to explain concepts while learning; I wrote the code.
- helmet, CORS allow-list, rate limit on /auth
- JWT middleware + revoked-token check
- Controller
- Service and validation
- TransactionRepository interface
- JSON or SQLite adapter
The idea
Money code should be boring, traceable and secure. This started as a command-line expense tracker. Each phase added one thing and a document explaining why.
What's in it
Controllers call a service, and the service talks to a TransactionRepository interface. Both a JSON file and SQLite implement it, so I swapped storage with a migration script instead of a rewrite. Every query is scoped to the signed-in user. SQLite runs in WAL mode with foreign keys on.
Auth
Passwords are hashed with bcrypt. Access tokens last 15 minutes and carry an ID, so logout can revoke them. Refresh tokens last 7 days, rotate on every use, and are stored only as SHA-256 hashes, so a database leak doesn't hand out sessions. Auth routes are rate-limited, and helmet and a CORS allow-list sit in front of everything.
Next
Store amounts as whole pesewas instead of floats, add idempotency keys so a retried request can't record a payment twice, write an OpenAPI spec, add CI and deploy a demo.