state-machines-pattern
Installation
SKILL.md
State Machine Pattern
Models application logic as a set of explicit states with deterministic transitions between them. At any moment, the system is in exactly one state. Transitions happen in response to events and may be guarded by conditions.
State machines eliminate impossible states — the root cause of most state management bugs — by making invalid combinations structurally impossible rather than handled by if/else chains.
When to Use
- Async operations with loading/success/error states
- Multi-step user flows (onboarding, checkout, form wizard)
- Business workflows with defined rules (order lifecycle, document approval)
- Any logic where boolean flag combinations produce impossible states
Don't use for:
- Simple toggle state (open/closed, visible/hidden) —
useStateis sufficient - Pure data transformations with no state transitions
- Server-side CRUD with no meaningful workflow logic