Cookbook & Example Gallery
Real-world, battle-tested recipe patterns showing how to construct, test, and operate statecharts with xstate-statemachine-rs.
Every recipe includes:
- The architectural statechart topology (JSON / diagrams).
- Full, copy-pasteable Rust implementation.
- Unit and integration tests demonstrating lifecycle behavior.
- Failure handling and production best practices.
Recipes Index
-
Traffic Light Controller
Core Engine & Basics. Simple sequential state machine with entry/exit actions, typed enum events, and transition assertions. -
Hierarchical Order Fulfillment
Compound States & Context. Multi-step e-commerce workflow with nested payment states, inventory reservation, and root-level cancellation handling. -
Resilient Circuit Breaker & Exponential Backoff
Resilience Patterns. Protecting fragile downstream HTTP services usingxstate-patternswith failure counters, half-open probe testing, and decorrelated jitter. -
Distributed E-Commerce Saga
Distributed Transactions. Orchestrating multi-service payments, warehouse reservations, and shipments with automated compensating rollback actions. -
Durable Persistence & Deadlines
Crash Recovery & Storage. Storing statecharts in PostgreSQL and SQLite with optimistic concurrency control, idempotency tracking, and surviving server restarts. -
Event-Driven Architecture & Transactional Outbox
CloudEvents & Brokers. Dispatching and consuming events over NATS and RabbitMQ with transactional outbox relay guarantees and dead-letter queues. -
Axum HTTP Microservice & Live Inspector
Web API & Observability. Exposing statechart actors over REST and Server-Sent Events (SSE), with real-time visual inspection in Stately Studio. -
LLM Agent Tool Loop with Guardrail Budgets
AI Agents & Safety. Constrained autonomous agent loop with strict per-state tool allow-lists, token budget guards, and human-in-the-loop approvals. -
WebSocket Reconnection & Heartbeat
Network Resilience. Client connection manager with exponential backoff, decorrelated jitter, and ping/pong health monitoring. -
Stripe Webhook Payment Gateway
E-Commerce & Payments. Idempotent Stripe webhook receiver with signature validation, invoice payment handling, and duplicate deduplication. -
Form Wizard & Multi-Step Onboarding
UI & User Flows. Multi-step signup form with back/next navigation, step invariant validation, and context persistence. -
Feature Flag Progressive Rollout
DevOps & Release Engineering. Canary release progression with automated health monitoring and instant automated traffic rollback.