Case study · Personal · Production
Sunrise
A read-only ledger that reconciles an exchange account, a staking position and on-chain wallets into one auditable record, and says 'absent' instead of guessing zero.
- Decision records
- 192
- docs/DECISIONS.md in the private original, counted 2026-11-01; the public copy stops at D-172
- Tests passing
- 1,044
- Latest count in the decision log (D-161); the suite spans 264 test files
- Dashboard plus health render
- 25.4 s → 616 ms
- Warm, after moving the integrity check off the request path (D-054)
- Page-loader CPU time
- −25 to −52%
- One read connection and memoised config, 2026-09-30 (D-149)
The problem
One person's crypto exposure sat in five places: an exchange account, a staking position, EVM and Solana wallets, dust across several chains, and a hand-kept spreadsheet journal. The sources report different concepts and cannot simply be added up. Exchange balances carry no reliable cost basis, staked principal would be counted twice against wallet balances, and dust buries the figures that matter.
Sunrise normalises them into one ledger with weighted-average cost, and shows for every figure where it came from and how fresh it is.
Constraints
- Read-only by construction: no trading, signing, claiming or withdrawals, and the exchange key must hold no withdrawal permission.
- The web process binds to 127.0.0.1 only. The host is a type literal in the config, so an environment variable cannot change it. Public access is nginx over loopback.
- Exactly one web process and one worker. The worker is the only writer, and a deploy must never run two copies.
- Exact decimals only; no floating-point financial maths.
- The exchange exposes only 90 days of fill history, so older cost basis comes from a reviewed export or stays visibly incomplete.
- The staking protocol publishes no contract or indexer. Its RPC returns four account totals, which is the permanent boundary.
- One VPS disk shared with eleven other services. The database reached 2,479 MB in about four weeks, which forced retention and backup rules.
Decisions
A figure that cannot be established is absent, never zero
The staking RPC returns null for fields it does not disclose. Printing 0 would assert a balance the chain never gave and silently understate equity, so every unknown figure is shown as absent. Rejected: zero-filling so the grid looks complete.
Weighted-average cost, with every fill and lot kept
One defensible method for version 1 without discarding the raw events another method would need. FIFO and LIFO are deferred, which is why the lots are retained.
Journal notes link to ledger subjects by plain text, not a foreign key
Ledger subjects are re-ingested. A cascading foreign key would delete a hand-written note on resync, and a restrict would block the resync. The note is the irreplaceable half, so an orphaned link renders as unresolved instead.
Retention prunes telemetry, never a financial record
Ledger entries, cost lots, realized P&L, fills and transfers are the account's history. Raw payloads (30 days), full snapshots (14), sync runs (30), resolved alerts (90) and chart points (thinned past 90) are caches or audit trail. Rejected: keeping everything, and deleting raw rows outright, which would let re-fetched events be counted twice.
Going public kept the loopback bind
The app never listens on a routable interface, so a proxy mistake cannot expose the dashboard. Rejected: binding to 0.0.0.0 behind a firewall.
Migration timestamps must strictly increase, and a test asserts it
The Drizzle migrator skips a migration whose timestamp is not newer than the newest recorded one, and still reports success. One migration was dated two days ahead, and its tables silently never appeared.
What broke
A one-millisecond bug that hid a cost basis
The exchange's fee token, credited by dust sweeps, was permanently reported as having no cost basis, so real cost was left out of realized P&L. The accounting code matched a sweep's outbound legs to its inbound credit by an exact millisecond match on the timestamp, and one sweep logged the credit 1 ms late (…791 against …790).
My first conclusion, recorded as decision D-132, was that the flag was a correct statement about the data and not a bug. D-133 reverses it, after reading the production database directly (read-only) with a temporary script that was deleted afterwards.
The fix snaps an outbound leg's timestamp to the nearest inbound dust credit for the same account within 5 seconds before the carried cost is keyed. A test fails before (cost null, status incomplete) and passes after (cost 5, status complete). Data that was already synced corrects itself, because accounting is rebuilt from the raw ledger on the next sync.
Result
Performance work is measured, not asserted. The integrity check (a 25-second PRAGMA quick_check on a 2.3 GB database) used to run on page render. Moving it off the request path cut dashboard-plus-health render from 25.4 s to 616 ms warm. Sharing one read connection and memoising config cut page-loader CPU time by 25 to 52% (Overview 243 to 170 ms).
Gaps are recorded too. When the one-second page target was set, seven of eight pages met it and Overview did not (D-075). Disk pressure was real: backups reached 24 GB with 15 GB abandoned (D-041), which is why the retention and backup rules exist.
Acceptance against the PRD was verified on 2026-09-13 (build, types and 192 tests); by 2026-09-26 the suite was 671 tests, and 1,044 by D-161. The live instance is private and the public copy ships no seed data, so there is no demo to open. The public copy holds the source, the tests and the decision log through D-172.
Stack
Figures checked against their sources on 2026-11-01. Each figure names the file or readout it came from.