
Where it came from
I set out to sell my car and ended up touring dealerships. I saw the process from the inside: paper records, photos on someone's phone, prices in dollars and pesos that didn't add up, and a vehicle that could be reserved and listed at the same time. The problem wasn't the sale: it was that nobody knew for sure what was on the lot.
The problem
A mid-sized dealership manages stock, reconditioning costs, documents with expiry dates, trade-ins, reservations and sales opportunities. It almost always does so with shared spreadsheets and WhatsApp groups. The cost doesn't show up in one place: it shows up in the car that has been sitting for ninety days, the margin nobody calculated and the unit that was sold twice.
The solution
A multi-tenant DMS built with spec-driven development: the specifications are the source of truth and the code implements them. It covers the full cycle —vehicle intake, photos and documents, costs and margin, CRM, reservation, trade-in, sale and delivery— with per-organization isolation at the database level and an immutable audit trail of every movement.
What's solved
- Multi-tenancy with Row Level Security in PostgreSQL: isolation lives in the database, not only in application code.
- Dual currency USD/UYU with versioned exchange rates, the way the Uruguayan market actually operates.
- RBAC by role and by branch.
- Vehicle state machine with history and explicit transitions.
- Per-unit costs and real, not estimated, margin calculation.
- Opportunity CRM with activities and WhatsApp link generation.
- Reservation with locking, trade-in, sale, delivery and cancellation.
- Dashboard with a stale-vehicles report, CSV import/export and an audit viewer.
Evidence
- Ten functional verticals (F01–F10) implemented and documented endpoint by endpoint.
- 50 passing e2e tests, including a no-double-sale case under concurrency.
- Production migrations verified by running the API without
synchronize, with the full schema and RLS applied. - Five prior specification phases —research, product, UX and prototype, architecture and plan— versioned in
specs/before the first line of production code.
The hard parts
- A double sale under concurrency is the bug you can't afford: two salespeople reserving the same unit at the same time. It was solved with explicit locking and covered by a concurrent e2e test.
- Row Level Security gives much stronger isolation than filtering by
tenant_idin every query, but it forces you to rethink migrations, connections and database roles. - Dual currency isn't formatting: it runs through cost, margin, reporting and listed price, and each can be pinned to a different currency.
What I learned
- Writing five specification phases before coding looked slow and turned out to be exactly the opposite: the entire backend came out without structural refactors.
- With AI assisting development, the specification becomes the real bottleneck. The more precise it is, the more useful the assistance.
- A test that reproduces a race condition is worth more than twenty happy-path tests.
Next steps
- Next.js frontend wired to the full API.
- Integrations with listing portals and the WhatsApp Cloud API.
- RLS hardening with a restricted role and
SET app.tenant_idper connection.
Other products
Applied learnings