State Machines
The canonical state machines for the four core objects. Every API response, database enum and UI state derives from these.
JOURNEY driver creates → publishes → matches → fills → runs → completes
RIDE REQUEST passenger asks → matching → matched → accepted → booked → done
MATCH candidate → offered → accepted | declined | expired | blocked
BOOKING created → confirmed → in progress → completedJourney
Owned by the driver. Created by a driver, always has a driver and a vehicle, and exists whether or not anyone boards.
┌──────────────┐
│ DRAFT │ created, not visible to passengers
└──────┬───────┘
│ driver publishes
┌──────▼───────┐
┌───────────│ PUBLISHED │───────────┐
│ └──────┬───────┘ │
│ │ matching begins │ seats exhausted
│ ┌──────▼───────┐ ┌─────▼─────┐
│ │ MATCHING │ │ FULL │
│ └──────┬───────┘ └─────┬─────┘
│ │ │
│ ┌──────▼───────┐ │
└──────────▶│ IN_PROGRESS │◀────────┘
└──────┬───────┘
│
┌──────▼───────┐
│ COMPLETED │
└──────────────┘Terminal and control states, reachable from any non-terminal state:
| State | Meaning |
|---|---|
CANCELLED | Driver or system cancelled before departure |
EXPIRED | Departure time passed without departure |
FLAGGED | A compliance signal is attached and under review |
SUSPENDED | Held by an administrative action |
Journey transitions
| From | Event | To |
|---|---|---|
| — | POST /journeys | DRAFT |
DRAFT | publish + compliance ALLOW | PUBLISHED |
PUBLISHED | matching begins | MATCHING |
PUBLISHED/MATCHING | seats exhausted | FULL |
FULL | a booking is cancelled | MATCHING |
MATCHING/FULL | POST /journeys/{id}/start | IN_PROGRESS |
IN_PROGRESS | POST /journeys/{id}/complete | COMPLETED |
| any non-terminal | POST /journeys/{id}/cancel | CANCELLED |
A journey failing compliance stays in DRAFT. It is never published, and the driver receives the reason at creation time rather than discovering a silent failure later.
Ride Request
Owned by the passenger. Expresses want. Never creates supply.
REQUESTED ──▶ MATCHING ──▶ MATCHED ──▶ ACCEPTED ──▶ BOOKED ──▶ COMPLETED
│ │ │ │
└─────────────┴────────────┴───────────┴──▶ REJECTED | CANCELLED | EXPIRED
any state ──▶ FLAGGED| State | Meaning |
|---|---|
REQUESTED | Created, not yet evaluated |
MATCHING | Candidates being evaluated |
MATCHED | Candidates available to the passenger |
ACCEPTED | A driver accepted a match |
REJECTED | The selected driver declined |
BOOKED | A booking exists |
CANCELLED | Passenger or system cancelled |
EXPIRED | expires_at elapsed with no booking |
COMPLETED | The shared journey finished |
FLAGGED | A compliance signal is attached |
A request in REJECTED may return to MATCHING when other candidates remain. The passenger is re-offered rather than left with a dead end.
Match
Produced by the matching engine, not by either party. One match is one candidate journey evaluated against one request.
CANDIDATE ──▶ OFFERED ──▶ ACCEPTED
│ │
│ ├──▶ DECLINED
│ └──▶ EXPIRED
└──▶ BLOCKED| State | Meaning |
|---|---|
CANDIDATE | Evaluated, not yet surfaced |
OFFERED | Surfaced with an expiry |
ACCEPTED | Driver accepted; a booking may be created |
DECLINED | Driver declined |
EXPIRED | Offer window elapsed |
BLOCKED | Compliance blocked the match |
EXPIRED is mandatory, not advisory. Without it a passenger could accept an offer hours later against a journey whose seats are long gone.
Booking
The confirmed shared journey. The outcome of an accepted match.
PENDING_CONFIRMATION ──▶ CONFIRMED ──▶ IN_PROGRESS ──▶ COMPLETED
│ │
└─────────────────────┴──▶ CANCELLED
│
CONFIRMED ──▶ NO_SHOW
any state ──▶ SUSPENDED| State | Meaning |
|---|---|
PENDING_CONFIRMATION | Created from a match; awaiting confirmation |
CONFIRMED | Both parties confirmed |
IN_PROGRESS | Journey under way |
COMPLETED | Journey finished |
CANCELLED | Cancelled before or during the journey |
NO_SHOW | A party did not arrive |
SUSPENDED | Held by an administrative action |
Cancelling a booking releases seat capacity and returns the journey to MATCHING if it is still in the future.
Cross-object consistency
Journey FULL ──────▶ all further matches BLOCKED
Booking CONFIRMED ─▶ journey IN_PROGRESS
Booking CANCELLED ─▶ capacity released, journey MATCHING
Journey CANCELLED ─▶ all bookings CANCELLED, passengers notifiedA journey cancellation is the disruptive case: every booking on it must be resolved in the same operation, and every affected passenger notified. Half- cancelling leaves passengers holding a booking for a journey that will not run.
What is NOT a state machine
Ratings, incidents and compliance events are records, not lifecycles with a place in this chain. An incident can be raised at any point in a booking's life and does not change the booking's state.
