Work Case study
Duple Labs Invoicer
An admin app for the two of us, a portal for clients, one invoice document that is both the page and the PDF, and billing and reminders that run themselves.
How it fits together
01
The problem
Duple Labs bills clients in two currencies, on retainers and one-offs, and the tools on offer either charged per seat, handled tax we don't collect, or skipped the parts that matter: records that cannot change, a clean PDF, and chasing that happens on its own.
02
What needed to change
An admin app for the two of us, a portal for clients, one invoice document that is both the page and the PDF, and billing and reminders that run themselves.
03
Architecture
A Next.js application over PostgreSQL with Drizzle. The money logic is a pure domain layer with no I/O, imported by the server and the browser alike, so the editor's live total is the total. One React component renders the client portal view and the PDF, which an on-demand Chromium pool prints and caches by content hash. Email goes through Resend with React Email templates, and an idempotent cron endpoint bills retainers and sends overdue reminders.
04
What I built
- Integer money in bigint minor units, rounded once per line, so the printed column always sums to the printed subtotal
- Gapless invoice numbering allocated inside the issuing transaction, verified by a test that fires concurrent issuers at one sequence
- Issued invoices frozen twice: the service layer refuses, and a Postgres trigger rejects any change; corrections go on credit notes
- Payments that belong to a client and allocate across invoices, with an overpayment surfacing as credit instead of vanishing
- A Chromium pool that launches on demand, recycles itself and shuts down when idle, so a quiet container holds no browser on a shared VPS
- Retainer billing and reminders guarded by unique indexes, so at-least-once delivery can never bill a month twice
05
Stack
- Next.js
- React
- TypeScript
- PostgreSQL
- Drizzle ORM
- Chromium
- Resend
- React Email
- Vitest
- Docker
- Coolify
06
Result
Invoices go out branded, numbered and frozen, clients pay from a link without logging in, and retainers bill themselves every month.
07
What I learned
The rules that matter in invoicing are the boring ones: rounding, numbering, immutability. Putting them in a pure module with nearly two hundred unit tests made everything above it simple.