Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Promise Luxury Bus Company 🚌

A full bus ticketing platform for Kenya β€” search routes, pick seats, enter passenger details, pay with M-Pesa, and receive an e-ticket with QR code.

Live site: https://weruuweruy--84cb9d9e812211f191c21607ee4eb77e.web.val.run

Booking flow

Rendering mermaid diagram...

Structure

FilePurpose
main.tsHTTP server β€” API routes + serves the frontend
frontend/index.htmlSingle-page app shell (home, results, seat map, checkout, ticket, lookup)
frontend/style.cssNavy + gold luxury theme, mobile-first
frontend/app.jsClient logic β€” search, seat selection, hold timer, booking
cron/release-seats.tsReleases expired seat holds (every 15 min; holds also self-expire via held_until checks on every read)
seed_seats.tsUtility β€” generates seat rows for new trips

API

  • GET /api/locations β€” town list for autocomplete
  • GET /api/search?from=&to=&date= β€” trips with live seats-left counts
  • GET /api/trips/:id/seats β€” seat map with statuses
  • POST /api/hold β€” atomically hold seats for 8 minutes (concurrency-safe)
  • POST /api/book β€” validate hold β†’ create booking, payment, ticket
  • GET /api/booking/:ref β€” ticket lookup by booking or ticket ref

Database (Val Town SQLite)

routes, pickup_points, buses (with seat layout 2-2 / 2-1), trips, seats (per-trip, with held_until for concurrency), bookings, payments, tickets, promo_codes, users, company_settings.

Payments β€” important

Checkout currently records payments in demo mode (booking confirms instantly, no money moves). To take real M-Pesa payments, integrate Safaricom Daraja or an aggregator (Pesapal/Flutterwave) and store keys as environment variables β€” the /api/book handler has a marked section to swap in the STK push + webhook confirmation.

Next phases

  • Admin panel (routes, buses, trips, bookings, settings)
  • Conductor QR check-in view
  • Real M-Pesa STK push + payment webhook
  • SMS/WhatsApp ticket delivery