statelyai/xstate
State machines, statecharts, and actors for complex logic
TypeScript state machines, statecharts, and actor model library with framework integrations
Events flow through state machines to produce new states, or through stores to update context. Framework integrations subscribe to these updates and trigger UI re-renders.
Under the hood, the system uses 3 feedback loops, 3 data pools, 2 control points to manage its runtime behavior.
Structural Verdict
A 10-component data pipeline with 6 connections. 423 files analyzed. Loosely coupled — components are relatively independent.
How Data Flows Through the System
Events flow through state machines to produce new states, or through stores to update context. Framework integrations subscribe to these updates and trigger UI re-renders.
- Event dispatch — Components send events to actors or stores via send() or store.send()
- State transition — Core engine processes events through state machine logic or store reducers
- State update — New state is computed and stored, observers are notified
- UI reaction — Framework hooks receive updates and trigger component re-renders
- Devtools inspection — Development tools receive state changes for debugging visualization
System Behavior
How the system actually operates at runtime — where data accumulates, what loops, what waits, and what controls what.
Data Pools
Global registry of active actors for development tools
Current context and computed state in store instances
Connected debugging clients for state inspection
Feedback Loops
- State Machine Transitions (recursive, balancing) — Trigger: Event sent to actor. Action: Compute next state based on current state and event. Exit: Reaches final state or stopped.
- Store Updates (convergence, balancing) — Trigger: Store event sent. Action: Apply reducer to current context. Exit: Context stabilizes.
- UI Re-render Loop (polling, reinforcing) — Trigger: State change detected. Action: Framework hook updates component. Exit: State stops changing.
Delays & Async Processing
- WebSocket Message Delivery (async-processing, ~network latency) — Debugging events arrive with delay
- Framework Hook Updates (eventual-consistency, ~render cycle) — UI updates lag behind state changes slightly
Control Points
- Development Mode Check (env-var) — Controls: Whether devtools registration is active. Default: process.env.NODE_ENV
- Comparison Functions (runtime-toggle) — Controls: When components re-render based on state changes. Default: defaultCompare function
Package Structure
This monorepo contains 14 packages:
Core state machine and actor system engine, framework-agnostic with TypeScript definitions
React hooks and utilities for XState integration
Vue composition API integration for XState
SolidJS reactive primitives for XState
Svelte store integration for XState
Simplified reactive state management without state machines
React hooks for XState store
Angular signals integration for XState store
Preact hooks for XState store with custom useSyncExternalStore
SolidJS signals for XState store
Svelte integration for XState store
Vue composition API for XState store
Immer integration for immutable XState context updates
Browser and WebSocket-based debugging tools for XState
Technology Stack
Primary language with comprehensive type definitions
Testing framework
Package build system for monorepo
Package manager with workspace support
Code linting
Version management and release automation
Immutable state updates
Real-time debugging communication
Key Components
- createActor (function) — Creates and manages actor instances from state machine or logic definitions
packages/core/src/createActor.ts - fromTransition (function) — Creates actor logic from a simple transition function
packages/core/src/actors/transition.ts - useActor (hook) — React hook that subscribes to actor state changes and returns current state and send function
packages/xstate-react/src/useActor.ts - createStore (function) — Creates a reactive store for state management without state machines
packages/xstate-store/src/store.ts - immerAssign (function) — Immutable state updates using Immer's draft pattern for XState context
packages/xstate-immer/src/index.ts - registerService (function) — Registers actors with browser devtools for inspection and debugging
packages/core/src/dev/index.ts - inspect (function) — Server-side inspection setup for WebSocket-based debugging of state machines
packages/xstate-inspect/src/server.ts - useSelector (hook) — React hook for selecting specific values from actor state with optional comparison
packages/xstate-react/src/useSelector.ts - createAtom (function) — Creates reactive atomic values that can be subscribed to
packages/xstate-store/src/atom.ts - createActorContext (function) — Creates React context providers for sharing XState actors across component trees
packages/xstate-react/src/createActorContext.ts
Configuration
pnpm-workspace.yaml (yaml)
packages(array, unknown) — default: packages/*,scripts/*
Explore the interactive analysis
See the full architecture map, data flow, and code patterns visualization.
Analyze on CodeSeaRelated Data Pipeline Repositories
Frequently Asked Questions
What is xstate used for?
TypeScript state machines, statecharts, and actor model library with framework integrations statelyai/xstate is a 10-component data pipeline written in TypeScript. Loosely coupled — components are relatively independent. The codebase contains 423 files.
How is xstate architected?
xstate is organized into 4 architecture layers: Core State Machine Engine, Framework Integrations, Store Abstraction, Development Tools. Loosely coupled — components are relatively independent. This layered structure keeps concerns separated and modules independent.
How does data flow through xstate?
Data moves through 5 stages: Event dispatch → State transition → State update → UI reaction → Devtools inspection. Events flow through state machines to produce new states, or through stores to update context. Framework integrations subscribe to these updates and trigger UI re-renders. This pipeline design reflects a complex multi-stage processing system.
What technologies does xstate use?
The core stack includes TypeScript (Primary language with comprehensive type definitions), Vitest (Testing framework), Preconstruct (Package build system for monorepo), pnpm (Package manager with workspace support), ESLint (Code linting), Changesets (Version management and release automation), and 2 more. A focused set of dependencies that keeps the build manageable.
What system dynamics does xstate have?
xstate exhibits 3 data pools (Actor Registry, Store State), 3 feedback loops, 2 control points, 2 delays. The feedback loops handle recursive and convergence. These runtime behaviors shape how the system responds to load, failures, and configuration changes.
What design patterns does xstate use?
5 design patterns detected: Actor Model, Framework Adapter Pattern, Store Pattern, Development Integration, Immutable Updates.
Analyzed on April 1, 2026 by CodeSea. Written by Karolina Sarna.