Skip to content

State Machines ​

The canonical state machines for the four core objects. Every API response, database enum and UI state derives from these.

text
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 → completed

Journey ​

Owned by the driver. Created by a driver, always has a driver and a vehicle, and exists whether or not anyone boards.

text
                    ┌──────────────┐
                    │    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:

StateMeaning
CANCELLEDDriver or system cancelled before departure
EXPIREDDeparture time passed without departure
FLAGGEDA compliance signal is attached and under review
SUSPENDEDHeld by an administrative action

Journey transitions ​

FromEventTo
—POST /journeysDRAFT
DRAFTpublish + compliance ALLOWPUBLISHED
PUBLISHEDmatching beginsMATCHING
PUBLISHED/MATCHINGseats exhaustedFULL
FULLa booking is cancelledMATCHING
MATCHING/FULLPOST /journeys/{id}/startIN_PROGRESS
IN_PROGRESSPOST /journeys/{id}/completeCOMPLETED
any non-terminalPOST /journeys/{id}/cancelCANCELLED

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.

text
  REQUESTED ──▶ MATCHING ──▶ MATCHED ──▶ ACCEPTED ──▶ BOOKED ──▶ COMPLETED
      │             │            │           │
      └─────────────┴────────────┴───────────┴──▶ REJECTED | CANCELLED | EXPIRED

  any state ──▶ FLAGGED
StateMeaning
REQUESTEDCreated, not yet evaluated
MATCHINGCandidates being evaluated
MATCHEDCandidates available to the passenger
ACCEPTEDA driver accepted a match
REJECTEDThe selected driver declined
BOOKEDA booking exists
CANCELLEDPassenger or system cancelled
EXPIREDexpires_at elapsed with no booking
COMPLETEDThe shared journey finished
FLAGGEDA 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.

text
  CANDIDATE ──▶ OFFERED ──▶ ACCEPTED
      │            │
      │            ├──▶ DECLINED
      │            └──▶ EXPIRED
      └──▶ BLOCKED
StateMeaning
CANDIDATEEvaluated, not yet surfaced
OFFEREDSurfaced with an expiry
ACCEPTEDDriver accepted; a booking may be created
DECLINEDDriver declined
EXPIREDOffer window elapsed
BLOCKEDCompliance 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.

text
  PENDING_CONFIRMATION ──▶ CONFIRMED ──▶ IN_PROGRESS ──▶ COMPLETED
          │                     │
          └─────────────────────┴──▶ CANCELLED
                                    │
  CONFIRMED ──▶ NO_SHOW
  any state ──▶ SUSPENDED
StateMeaning
PENDING_CONFIRMATIONCreated from a match; awaiting confirmation
CONFIRMEDBoth parties confirmed
IN_PROGRESSJourney under way
COMPLETEDJourney finished
CANCELLEDCancelled before or during the journey
NO_SHOWA party did not arrive
SUSPENDEDHeld 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 ​

text
Journey FULL ──────▶ all further matches BLOCKED
Booking CONFIRMED ─▶ journey IN_PROGRESS
Booking CANCELLED ─▶ capacity released, journey MATCHING
Journey CANCELLED ─▶ all bookings CANCELLED, passengers notified

A 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.

KHAWI — same route, go together.