Examples
Learn StateWalker FSM through practical examples. Each example builds on concepts from the previous one, progressively demonstrating more sophisticated patterns and techniques.
These examples show complete, working applications using the StateWalker orchestrator. You’ll see how to structure FSM definitions, implement handlers, manage context, and integrate with external services. All code follows the best practices and conventions outlined in the documentation.
Light Bulb
The fundamentals of state machines
A simple on/off light bulb that toggles between two states. This example introduces the core concepts: state definitions, transitions, events, handlers, and views. Perfect for understanding how StateWalker FSM works before moving to more complex scenarios.
What you’ll learn:
- Defining states and transitions
- Implementing handlers for business logic
- Creating views for presentation
- Using triggers to generate events
- Understanding the orchestrator architecture
Complexity: Beginner
Traffic Light
Automatic transitions and cyclic state machines
A traffic light that cycles through red, green, and yellow states automatically. This example demonstrates time-based transitions, cyclic workflows, and exit conditions for continuous processes.
What you’ll learn:
- Timer-based automatic transitions
- Cyclic state machines that loop indefinitely
- State-specific durations and timing logic
- Exit conditions for continuous processes
- Global transitions from any state
Complexity: Intermediate
User Authentication
Error handling and validation flows
A complete authentication system managing login, session refresh, and logout flows. This example shows how to handle validation, error states, recovery paths, and automatic session management.
What you’ll learn:
- Decision branches for validation outcomes
- Error states and recovery paths
- Retry logic with attempt tracking
- Automatic session refresh
- Security patterns in state machines
- Integrating with external authentication APIs
Complexity: Intermediate
Order Processing
Complex business workflows
A full e-commerce order processing system handling validation, payment, fulfillment, shipping, and various error scenarios. This is the most sophisticated example, demonstrating enterprise-grade complexity with nested states and comprehensive error handling.
What you’ll learn:
- Complex multi-stage workflows
- Multiple terminal states (completed, cancelled, rejected)
- Rollback and refund flows
- External service integration (payment, inventory, shipping)
- Manual intervention states
- Comprehensive error handling strategies
- Production-ready patterns
Complexity: Advanced
Learning Path
Start here: Begin with the Light Bulb to understand FSM fundamentals.
Next steps: Move to Traffic Light to learn automatic transitions and cycles.
Add complexity: Study User Authentication for error handling and validation patterns.
Enterprise patterns: Tackle Order Processing to see how everything scales to real business applications.
Each example includes:
- Complete FSM configuration with all states and transitions
- Full handler implementations with business logic
- View code for browser interfaces
- Running instructions for both browser and server
- Explanation of key concepts and patterns
- Links to related documentation
Additional Resources
Ready to build your own state machines? These resources will help:
- Quick Start Guide - Build your first FSM in minutes
- FSM Concepts - Understanding state machine fundamentals
- Handler Patterns - Advanced handler techniques
Have questions or want to share your own examples? Visit the community forum or check the GitHub repository.