liveBook · Manning

Finite-state machine

As explained in Crack Any Codebase with AI

A state machine is a computational model in which an entity occupies one of a defined set of states and changes state through specified transitions.

A finite-state machine models a record as occupying one value from a defined set and changing values through specified transitions. In a schema, an enum can make that lifecycle explicit: each transition represents a business rule that application code must enforce. section 7.1

Read a finite-state machine in a schema by asking:

  • Which states are explicitly allowed? A booking status may be ACCEPTED, PENDING, REJECTED, CANCELLED, or AWAITING_HOST. section 7.1
  • Which transitions matter to the business? Moving from PENDING to ACCEPTED is not merely a data update; it expresses a rule the application must enforce. section 7.1
  • What surrounding fields explain the lifecycle? A cancellation-reason field signals that cancellations are important enough to track. section 7.0

Booking workflow

A booking begins as PENDING, may become ACCEPTED, and can also be REJECTED or CANCELLED. The enum defines the permitted vocabulary; application behavior must define and protect the valid paths between those states. section 7.1

Listing 7.1 A minimal_booking_schema defining the tables and columns for a simple booking system in SQL.
CREATE TABLE booking (
  id              SERIAL PRIMARY KEY,
  event_type_id   INT NOT NULL REFERENCES event_type(id),
  start_time      TIMESTAMPTZ NOT NULL,
  attendee_email  TEXT NOT NULL,
  status          booking_status NOT NULL DEFAULT 'pending',
  metadata        JSONB
);
CREATE INDEX ON booking (start_time, event_type_id);
CREATE UNIQUE INDEX ON booking (attendee_email);

Inspect the status column in a minimal SQL booking schema to see a state-machine value embedded alongside required fields, relationships, and indexes. section 7.1

How Crack Any Codebase with AI covers it

How deep it goes
Defines explicit states and transition significance, but stops short of enumerating every valid transition or implementing enforcement logic.
Examples
Uses Cal.com booking statuses, pending-to-accepted movement, cancellation tracking, and a minimal SQL booking schema.
What it assumes
Assumes familiarity with schemas and columns while grounding the model in recognizable booking records and SQL types.
What you can do after
Evaluate booking workflows by identifying allowed states and locating the application rules that must enforce their transitions.
How it connects
Connects enums with schemas, business rules, application code, constraints, and booking workflows.

Also explained in

Compare how 13 books explain finite-state machine →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Crack Any Codebase with AI. The section links point to the parts of the book it draws on.