Work / Case study · Published · 2026-10-15
ProfitLab
Marketplace unit economics with exact decimal arithmetic and pass/fail gates.

The problem
A reseller deciding what to list needs projected profit per product after every fee, shipping cost and overhead share, and a clear yes/no against minimum profit and margin. Rounding drift or a blank cost silently treated as $0 makes a losing product look like a winner.
What it does
- Editable product table with costs, prices, percentage and fixed fees, promoted-listing share and monthly units; sorting, filtering and bulk edit.
- Qualification gates (minimum net profit and margin); rows with missing inputs are marked incomplete and can never qualify or be ranked.
- Break-even price per product, optional markup-retention pricing, explicit overhead allocation.
- Scenarios compared side by side; CSV import with line-by-line validation; CSV and JSON export.
- Local persistence with schema validation, corruption recovery and a cross-tab notice.
Engineering choices
- Money as decimal strings (decimal.js), each fee line rounded half-up to the cent, gates compared exactly: a displayed 15.00% that is really 14.996% must not pass.
- Break-even found by an exact scan of the price band that per-line cent rounding can affect, so the lowest qualifying cent is exact even at high fee rates.
- A blank cost means unknown, never zero; ranking only among qualifying rows.
- zod only at the persistence boundary; a small, fully tested CSV parser instead of a dependency.
Significant challenge: Proving the money math
The test suite re-implements the economics with BigInt integer cents, sharing no code with the decimal engine, and compares randomized scenarios and break-even cases against it. The independent review found break-even errors at high fee rates and CSV round-trip problems; each was fixed with a regression test.
Tested results
- 55 Vitest tests, including 1,500-scenario and 400 break-even BigInt-oracle suites.
- 10 Playwright tests against the production build under /profit-lab/.
- Independent acceptance review: 9 defects found and fixed with regression tests.
- Published 2026-10-15: GitHub Actions CI green on Ubuntu, GitHub Pages deployed, live check passed.
Last recorded verification 2026-10-15; latest recorded commit 214668e. The full commands and outcomes are in the repository's docs/test-report.md.


Stack
Candid limitations
- Projections only: no realized profit and no live marketplace data.
- Built-in fee tiers are illustrative examples, not an official fee schedule.
- Data stays in one browser (localStorage).
How it was made
Directed and reviewed by the owner; specification, code, tests and documentation written with Claude Code (AI). A separate Claude Code session that did not write the code then re-ran every check and fixed what it found; that is an AI review, not a human code audit. See the repository's AI_ASSISTANCE.md.