Skip to content

Examples Overview

machina ships with five runnable example apps covering real-world patterns — from async health checks to React integration. Each one is a self-contained app you can run locally, and on the deployed docs site they’re live at their own routes.

ExampleWhat it demonstratesKey machina features
Connectivity MonitorNetwork connectivity tracking with async health checkscreateFsm, async in _onEnter, AbortController cleanup in _onExit, custom events
Traffic IntersectionHierarchical traffic light controller with pedestrian signals_child delegation, compositeState(), input bubbling, defer(), child auto-reset
Dungeon CrittersMultiple critter instances sharing one FSM definitioncreateBehavioralFsm, per-client state via WeakMap, shared behavior definition
Shopping CartCheckout flow with deferred operationscreateFsm, defer(), defer({ until }), lifecycle hooks
With ReactReact integration for a todo appcreateFsm, useSyncExternalStore, framework integration

On the deployed docs site, each example is a working app at /demos/{name}/. The doc pages above explain the patterns; the “Run” link at the top of each page opens the live app in a new tab.

During local development, examples run on their own Vite dev server — the docs site doesn’t serve them. See below.

# Run any example's dev server
pnpm --filter @machina-examples/connectivity dev

# Or from the example directory
cd examples/connectivity && pnpm dev

Swap connectivity for any of the example names: traffic-intersection, dungeon-critters, shopping-cart, or with-react.