Skip to content
Brian Jiménez Landa
Freight quoting and trip costing, pilot in production since Sep 2026

Freight quotes that show which trips lose money before the price goes out

A quoting and trip-costing web app for small freight carriers in Mexico. It finds the toll plazas on a route with PostGIS and costs the empty kilometers before and after each load. Pilot in production since September 2026.

Trips list with the direct margin of each trip

The problem

Small freight carriers in Mexico often quote a trip from memory, in a WhatsApp message. That price rarely includes the real tolls on the route or the empty kilometers to reach the load and drive back. A trip can look profitable and still lose money, and the owner has no simple way to see which trips do.

What I built

  • I built a quote screen where the owner enters two points as an address, a Google Maps, Waze or Apple Maps link, coordinates or a click on the map. It asks Google Routes for up to 3 paths and costs each one.
  • I match each path against 1,376 points from Mexico's national toll-plaza dataset in PostGIS, so the quote lists the plazas on the route in the order the truck crosses them.
  • Only 57 of the 574 plazas have an official rate. The rest get an estimate by kilometer and axle count, and the quote's assumptions say how many plazas on the route have an official rate and how many are estimated.
  • I cost the empty drive to the load and the empty return as their own lines. Two switches turn tolls and the empty return on or off, so the owner sees the margin move before sending a price.
  • The carrier's customer gets a one-page quote on the carrier's letterhead with a per-company quote number, and VAT is added, included or left out. Cost and margin never reach that page because the query behind it doesn't select them.
  • Before a second company went live, I found 5 endpoints in my own code that let one company reach another company's records by ID, and closed them. Cross-company attack tests got a 404 on all 5.

Screens

  • Today: units stopped by missing paperwork, creditable tolls and what is being lost in cash. Demo data.
  • Every trip with what was charged, what it cost and its direct margin.
  • Fleet: cost per kilometer, fuel efficiency and driver for each unit. Units below target are flagged.
  • Unit detail with its assignments and document file.
  • Cost per kilometer month by month, backed by the ledger entries.
  • Coverage of the national toll catalog: which plazas have an official rate and which are estimated.
  • Tax screen: the toll credit and each rule with its legal basis.
  • Dark mode.
  • The domain core test run: 149 tests passing.

How it works

The business rules live in a pure JavaScript core with no database, network or environment access. Quoting, per-km cost, fuel efficiency, tax regimes and location parsing are plain functions. I typed it with JSDoc under strict checking instead of TypeScript. Its 149 unit tests run on node:test without a database.

PostgreSQL with PostGIS holds the data. Every cost goes into one ledger. Cost per km and a trip's result are views over that ledger, not stored totals. Tax rates are rows with a validity period and their legal citation, so a rate change is data entry. Only the quoting side is in pilot use; trips and expenses run on seeded demo data.

A thin Fastify API resolves the company from the session on every request. The React 19 front end draws the alternative paths and their toll plazas on Google Maps, in light or dark theme. Route and geocoding answers are cached in Postgres so the same trip isn't paid for twice, and the PDF renders in the browser with libraries that load only when needed.

It runs on a Linux server behind nginx with TLS, with the API under pm2 and PostGIS in Docker. The API listens only on localhost. Each of the 8 updates since launch went out after a verified Postgres backup.

Results

15% → −59%
Margin on a demo quote once tolls and the empty return were costed
1,376
Toll-plaza points (574 plazas) checked against every route
149
Unit tests on the domain core, all passing
13 days
From the first commit to the first production deploy

Who else worked on it

I wrote all of the code. Toll-plaza locations and official rates come from public Mexican government data, routes and maps come from Google Maps Platform, and the color scales come from the open-source Radix Colors and Radix Themes (MIT).

Full stack

JavaScript (ESM, JSDoc with strict checking), Node.js, Fastify 5, PostgreSQL 16, PostGIS 3.4, React 19, Vite 6, Google Routes API, Google Maps JavaScript API, node:test, Docker, nginx, pm2, jsPDF, html-to-image