Introduction

What is StateWalker FSM?

StateWalker FSM is a JavaScript library for building applications using finite state machines. Instead of scattering application logic across event handlers and conditional statements, you define your application as a collection of states and the transitions between them. When a user logs in, your application moves from a “LoggedOut” state to a “LoggingIn” state, then to “LoggedIn.” When a form validates, it transitions from “Validating” to either “ShowingErrors” or “ProcessingSubmission.” Every behavior in your application becomes an explicit state transition rather than an implicit side effect.

This approach makes complex applications manageable. You see the entire flow of your application in the state machine configuration. You test states independently. You add new features by extending the state graph rather than weaving new conditions into existing code. StateWalker FSM provides the infrastructure to define these state machines and execute them consistently across browsers and servers.

Key Features

Hierarchical State Machines: Real applications don’t fit into flat lists of states. A checkout process has states, but so does its payment validation subprocess. StateWalker supports nested states, letting you organize complex workflows into manageable hierarchies that mirror how you think about processes.

Layered Architecture: Separate your concerns through fragments. The core fragment defines your state machine structure. Handler fragments implement business logic. View fragments manage presentation. Trigger fragments generate events. Logger fragments provide observability. Each fragment contributes its functionality while sharing a common context, creating applications that are both modular and cohesive.

Universal JavaScript: Write your state machines once and run them everywhere. The same FSM definition works in Node.js, Bun, Deno, and browsers. Server-side execution lets you test business logic without DOM dependencies. Browser execution adds rich user interfaces. You choose which fragments to load based on your deployment environment.

Type-Safe Configuration: TypeScript support catches errors in your FSM definitions as you write them. Define your states and transitions with full autocomplete and validation. The library knows what states exist, what events they accept, and what transitions are possible. Your IDE becomes a guide to your application’s behavior.


Get Started

Ready to build your first state machine? Start with installation to add StateWalker to your project, then follow the Quick Start guide to create a working application in minutes.

Installation — Add StateWalker FSM to your project

Quick Start — Build your first state machine in minutes