StackMoth/Work/Invitrack

Financial software

Financial integrity enforced in the database, not the application

Receivables, vehicle-log PDF ingestion, approved hire summaries and driver payroll for C S Tours (CSTT).

~36,000Lines of code
32Forward migrations
313Tests across 43 suites
0Floating-point money ops

A buggy or compromised client still cannot mutate an issued financial record.

Vehicle-log PDF to bank payout pipeline
Monthly Vehicle-Log PDFs (pdfjs-dist) │ ▼ Pure Rational & Money Engine (zero I/O, zero floats) │ ├──► Approved Hire-Summary Workbooks (.xlsx via exceljs) ├──► Immutable Versioned Invoice PDFs (verified via pdf-lib) └──► Driver Advance Reconciliation ──► Production Bank Payout File

Engineering notes

Architecture & guarantees

01Facts
Client
C S Tours (CSTT), a GTel subsidiary
Scale
~36,000 lines, 58 commits
Database
Supabase PostgreSQL, RLS on all tables, 32 forward-only migrations
Stack
Next.js 16 App Router, React 19, strict TypeScript, PGlite
Tests
313 tests across 43 suites (PGlite workflows & real-PostgreSQL RLS)
Access
Private, staff sign-in only
02Where the rules live

Row-level security is enabled across every table and backed by PostgreSQL workflow functions, triggers and append-only ledger rules. The application holds no special privileges that make it trusted. Accounting is strictly append-only: voids never delete rows, and issued documents are never overwritten.

03Zero floating-point math anywhere near money

Currency amounts are fixed-precision integer cents (money.ts), and intermediate vehicle-hire calculations stay in pure, I/O-free BigInt rational fractions (rational.ts) until an invoice or display boundary. Summing unrounded fractions and rounding half away from zero only at the final line matches spreadsheet and tax-invoice rules without a single float entering the pipeline.

04From raw vehicle-log PDFs to bank payout files

Instead of re-keying monthly fleet logs by hand, the system parses source PDFs, applies contracted slab and rate rules inside the rational engine, generates client-approved Excel workbooks, reconciles driver advances against trip totals, and emits production bank payout files from the same verified numbers.

05An invoice number is never recycled

Numbering is two-phase: a number is reserved, then finalised, with idempotency keys so a retry cannot consume two. A reservation that does not complete moves to a failed terminal state and that number stays permanently burned.

Draft PDF preflight runs before reserve_invoice_issue, so a draft render failure never spends a permanent number. After reservation, the numbered snapshot is rendered and verified with pdf-lib; issued invoice PDFs are archived as immutable versioned snapshots, whereas on-demand working-sheet .xlsx downloads (api/hire/working-sheets) compute and stream bytes from current inputs.

06CI that proves the database contracts
  • Replays all 32 forward-only migrations onto a clean PostgreSQL instance.
  • Runs PGlite workflow tests alongside real-PostgreSQL integration tests impersonating Admin, Finance and Viewer JWTs to verify privilege denial as observed behaviour.
  • Gates migration syntax against the real PostgreSQL parser rather than regular expressions.

AI-assisted, human-accountable. AI tools contributed significantly to the implementation described here. The specification, the review of every change, the production operation and the accountability are mine.

Next case study

Land evaluation engine