Case study · April 2026 — now
LIVEDeltern
A multi-tenant sales and distribution ERP: four Flutter apps, one Express API, a PostgreSQL schema per tenant.
- Endpoints
- 761
- Backend modules
- 80
- Test files
- 181
- CI workflows
- 5
Role · Sole engineer — schema, API, apps, deploy
deltern.comContext
Distributors selling fast-moving goods run on three incompatible surfaces: a desktop accounting package, a WhatsApp group, and a warehouse ledger nobody reconciles until month end. An order is taken on paper, typed twice, delivered from a truck whose stock is tracked on a separate sheet.
Deltern is one system for that loop: order capture, dispatch, delivery proof, collections and returns, with a PostgreSQL schema per tenant underneath and Flutter apps for the people holding the phone.
The problem
The field is offline
Warehouses, basements and loading bays have no usable signal. A field app that needs the network is a field app that stops the business at 9 a.m.
Stock disappears between the warehouse and the truck
Van stock lives outside the warehouse ledger, so shrinkage is structurally invisible until someone counts by hand.
Money is reconciled late
Collections at the door, cash handovers and credit notes arrive as separate facts. Reconciling them after the month closes turns every dispute into archaeology.
Constraints
- One engineer, no team, no on-call rotation.
- Each tenant must be isolated at the database level, not by a WHERE clause.
- The app has to work for a rep who has not seen a signal since breakfast.
- Infrastructure cost has to fit under a per-tenant subscription, not a venture budget.
Decisions
The choices that carried most of the system. Each one lists the alternative that was on the table and the bill that came with the choice.
A PostgreSQL schema per tenant, with a per-tenant migrator.
- Not this
- One shared schema with a tenant_id column on every table.
- Why
- Isolation you can prove: a cross-tenant read is a schema error, not a forgotten filter. The migrator tracks applied versions in public.tenant_schema_versions, so each tenant can be moved and verified on its own.
- The cost
- Every migration runs once per tenant and the tooling has to know that a tenant directory is not a schema. It is the single most expensive decision to live with, and it is still the right one.
Offline-first Flutter for the field app: a local SQLite store plus a priority mutation queue.
- Not this
- Online-only client with a retry button.
- Why
- The queue survives process death, retries with backoff, and sends photos through a separate multipart queue so a 4 MB proof-of-delivery never blocks an order.
- The cost
- Every write needs a conflict policy. Server wins for stock and route assignment; money-adjacent writes are append-only with idempotency keys so a replay creates exactly one record.
A modular monolith with BullMQ workers for anything slow.
- Not this
- Microservices split by domain.
- Why
- One deploy, one transaction boundary, one place to look when an order will not save. The jobs that cannot run inside a request — PDFs, photos, sync drains, billing — go to sixteen processors with their own retry and dead-letter behaviour.
- The cost
- Module boundaries are a convention, not a wall. Left alone, a monolith rots into a pile of imports; the discipline has to be enforced in review.
Idempotency keys on every write that can be retried from a phone.
- Not this
- Trusting the client to send a request once.
- Why
- A rep in a dead zone retries. A duplicate order is a trust failure that costs a customer, and no amount of testing finds it before it happens in the field.
- The cost
- Every endpoint that writes carries the header, and the middleware has to no-op correctly — including the case where the first request never reached the database.
How it is put together
- Field, Go, Command, Hub
- Flutter apps and a Next.js portal. Field holds a Drift store and the mutation queue; the rest read the same API contract.
- Express 5 API
- Tenant resolved from the subdomain, never from the token body. Auth, RBAC, idempotency and validation middleware run before any handler.
- PostgreSQL
- A platform schema of 99 models and one schema per tenant: about 84 tables, created and versioned by 68 hand-written migrations.
- BullMQ workers
- Sixteen processors for PDFs, photo processing, sync drains, billing, notifications and e-invoicing, each with retries and a dead-letter path.
- Edges
- Stripe, Cloudflare R2, Brevo, WhatsApp Cloud API, FCM, Google Maps, Socket.IO for live updates, and an observability stack around all of it.
What broke, and what it taught
A case study that only lists wins is a sales page. These are the defects the audit found in my own system, how each surfaced, and what fixing it takes.
Defect
The data model had two heads: 99 Prisma models for the platform, 84 tenant tables reachable only through raw SQL.
Found by
A schema-drift script that compared the two, run during the architecture audit.
Fix
Keep raw SQL for tenant migrations — it handles the batch updates and FEFO joins better — but put the read surface behind reviewed views so application code stops guessing which dialect it is in.
Defect
Three Flutter apps had three different API clients. One had certificate pinning, one had no local database at all.
Found by
Import-graph audit across the package workspace; five of eight shared packages were placeholder directories.
Fix
Extract the proven client from the field app into shared packages, then migrate the others onto it one module at a time. Nothing gets rewritten from scratch.
Defect
Van stock never wrote to the warehouse ledger, so shrinkage between the two was invisible.
Found by
Tracing a delivery end to end through the stock tables.
Fix
Treat the truck as a location with its own ledger entries and reconcile on handover, not at month end.
Defect
Two of the four apps shipped with one test file each, and no mobile release pipeline existed anywhere.
Found by
Counting test files and CI workflows per app rather than trusting the README.
Fix
Backend and field app carry the suite today; the gap is named here because a portfolio that hides it is worth less than one that does not.
Evidence
- 181 test files across backend and apps, gated by 5 CI workflows
- 761 endpoints across 80 backend modules
- Returns and credit-note pipeline covered by 7 test suites
- Live at deltern.com; repository private, walkthrough on request
Checked 30 November 2026. Repository private. A walkthrough is available on request.