0. the idea

Booking cargo/freight service the traditional way meant a phone call or an email back and forth just to get a quote. fleetmarket puts that whole flow — quote, book, track — online.

1. architecture

Stack:
  • React (TypeScript) frontend
  • REST API backend handling bookings, pricing, and status

The booking form shows a live price estimate as the customer fills it in, then confirms that price against the backend at submit time.

2. features

What it does:
  • Cargo service booking with a live quote preview
  • Booking status tracking for the customer
  • Admin / dispatcher view of incoming bookings

3. a challenge — one price, two places

The live quote preview in the form and the authoritative price calculated by the backend both need to agree — weight, distance, and service tier all feed into the number, and if the two implementations drift even slightly, customers see one price and get charged another.

Keep the pricing formula in one shared module both the client-side preview and the server-side confirmation import, instead of writing it twice. If it only exists once, it can't drift.

4. the code

export function calculateQuote({ weightKg, distanceKm, tier }) {
  const base = 15;
  const perKg = tier === "express" ? 2.5 : 1.5;
  const perKm = tier === "express" ? 0.35 : 0.2;

  return base + weightKg * perKg + distanceKm * perKm;
}

5. what i learned

Any time a number is shown to a user before it's confirmed, treat it as a preview of a calculation that lives in exactly one place — duplicating pricing logic client- and server-side is a bug waiting to happen the moment either one changes.