All work

Vector

A multi-tenant ERP for road haulage. Planning, fleet, drivers, sub-carriers, fuel, invoicing and cash flow in one system.

What
Web platform
When
April 2026 to August 2026
Stack
React, Express, PostgreSQL, PGlite, Docker, Ollama
backend/db.jsVector
// '?' (SQLite/node:sqlite style, positional, in order) -> '$1', '$2', ... (pg style).
function toPgPlaceholders(sql) {
  let i = 0
  return sql.replace(/\?/g, () => `$${++i}`)
}

The problem

A road haulage company runs on a dozen disconnected surfaces: a planning spreadsheet, a fuel-card portal, a separate invoicing tool, and a lot of institutional memory. Nobody can answer “did this trip make money?” without half an hour of cross-referencing, and by then the week has moved on.

What I built

One operational platform covering the full cycle, from planning a trip on Monday to reconciling the invoice for it six weeks later.

  • Weekly planning: a trip grid by week with states (Confirmed, In Progress, Completed, Cancelled), driver and vehicle assignment, CSV import and margin per trip
  • Driver and sub-carrier portals: separate logins where drivers see their own runs and documents, and sub-carriers follow the work assigned to them live
  • Fleet, drivers and suppliers: tractors and trailers with deadlines and fixed costs, attendance and salaries, workshops and parts orders
  • Clients and reconciliation: shipper contracts, sub-carrier pre-invoices, disputes and penalties, checked against what was actually run
  • Money: a cash-flow ledger with a payment schedule, fuel-card and toll imports per vehicle and driver, and client payment tracking
  • Documents and chat: engagement letters, pre-invoices and attendance reports as PDFs, and a team chat with direct messages

Updates propagate between open tabs over server-sent events, so two dispatchers working the same week see each other’s changes immediately. An AI assistant answers questions about the company’s own data through a local Ollama model, so nothing leaves the server.

Notes on the hard part

One install, many companies. Each client company is a tenant with its own Postgres schema, picked from the request’s hostname (acme.vector.app is tenant acme). After the middleware opens the scope, SELECT * FROM viaggi reads that company’s trips and nobody else’s, and the routers never know tenants exist.

I chose schemas over a tenant_id column with row-level security on purpose. RLS is ignored by superusers, and development and tests run on PGlite as a superuser, so isolation would be switched off exactly where it is verified. A tenant_id column only isolates if every query remembers its WHERE, a promise dozens of route files would have to keep forever. With schemas, a mistake fails closed: with no tenant selected, the table isn’t there. Session tokens carry the tenant they were issued in, so a token from one company never verifies on another’s host. Isolation is covered by tests at the database and the HTTP level.

Moving to Postgres without a cutover. The backend started on SQLite. The new db.js keeps the exact call shape every route already used and rewrites SQLite’s ? placeholders into Postgres’s $1, $2, so a ported route changed what it awaited, not how it queried. Unconverted routers stayed unmounted rather than half-working: mounting one early would not have thrown, it would have quietly returned wrong data.

Shippers as configuration. Everything specific to one shipper (how its documents are laid out, how it writes a route, how it marks a reissued invoice) lives in a connector profile, one file each, so adding the next client doesn’t touch the code every other one runs through.

Notes

Roughly 1,500 commits, 58 backend test files, deployed with Docker and Caddy. Company name, tax details and logo come from environment variables; with none set it prints a deliberately generic name, so a misconfigured deploy is obvious instead of showing another company’s brand. The same domain, reduced to what a single owner-operator needs, became Vector Driver.

The repository is private, and the screens show a client’s real operations, so they aren’t published here. Happy to walk through the architecture or demo it on request.