Start a project

Tool 139 of 194 · Architecture

State Machine Designer

Write your states and events in a few lines, click through them in the simulator, and get a list of the states that can't be reached or can't be left.

State Machine Designer at a glanceIllustration: 1, States in text; 2, processed in your browser; 3, Statechart.State Machine Designer1States in text3Statechart2In yourbrowser
1 States in text 2 processed on your device 3 Statechart

State Machine Designer

Your state machine

name: starts a state (indent for child states; add final, parallel or history). EVENT -> target [guard] / action. initial name. entry: action. after 5s -> target.

LevelWhereProblem

Chart and simulator

Active:

    Code

    XState v5
    Mermaid stateDiagram-v2
    TypeScript types

    States by depth

    01

    What it does

    Turns a short text description of states and events into a statechart you can click through, checks it for logic bugs and exports XState, Mermaid and TypeScript.

    • Nested, parallel, final and history states
    • Guards, actions, entry and exit actions, and delayed (after) transitions
    • Simulator with exit and entry order, guards you can switch off and history
    • Checks: unreachable states, dead ends, missing initial states, unknown targets, clashing transitions and case-only event clashes

    02

    Private by design

    Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

    03

    What you get

    A statechart, a simulator, problems found, and XState, Mermaid and TypeScript code, with a Copy and a Download button on every result.

    • State machines
    • XState
    • Mermaid
    • TypeScript

    Why it matters

    Interface and workflow code tends to grow into a tangle of flags: isLoading, hasError, isSubmitting, all true at once in some combination nobody planned. Writing down the states first, and which events move between them, makes those impossible combinations impossible. The catch is that statechart tools are often heavy, online-only, or tied to one library.

    This designer uses a few lines of plain text: a state per line, indented for child states, and EVENT -> target [guard] / action under each. It draws the chart as nested boxes, lets you send events and watch exit and entry actions run in the order the SCXML standard uses (including parallel regions and history), and checks the machine for the usual logic bugs: states nothing leads to, states nothing leads out of, compound states without an initial child, transitions to states that don't exist, and two handlers for the same event. When it's right, copy XState v5 code, a Mermaid diagram for your docs and TypeScript types. Paste an existing XState config to review it: it's read as data, never run.

    How it works

    1. InputStates and events in a few lines
    2. In your browserChecked, drawn and simulated
    3. OutputXState v5, Mermaid and TypeScript

    Where it fits in a designer's workflow

    1. Plan
    2. Design
    3. Build
    4. Test
    5. Launch
    Designing interface or workflow logic before writing it.

    By the numbers

    Outgoing transitions per state in the sample checkout machinecart: 2 transitions; details: 2 transitions; payment: 2 transitions; payment.card: 1 transition; payment.paypal: 1 transition; processing: 3 transitions; failed: 2 transitions; done: 0 transitions; giftWrap: 1 transitioncart2 transitionsdetails2 transitionspayment2 transitionspayment.card1 transitionpayment.paypal1 transitionprocessing3 transitionsfailed2 transitionsdone0 transitionsgiftWrap1 transition
    Counted by this tool from its sample: 9 states and 14 transitions. The checks flag giftWrap twice: nothing leads to it, and nothing but its own loop leads out. Children of payment also leave through payment's PAY and BACK, which is why a compound state's transitions count for every state inside it. Source: W3C: SCXML (state chart XML); Stately: XState v5 docs.
    Show the numbers as a table
    StateOwn transitions
    cart2
    details2
    payment2
    payment.card1
    payment.paypal1
    processing3
    failed2
    done0
    giftWrap1

    How to use it

    1. Write the states and transitions, or paste an XState createMachine config.
    2. Fix anything in the problems table.
    3. Click events in the simulator; type a guard name to make it false.
    4. Copy the XState, Mermaid or TypeScript output.

    FAQ

    What syntax does it use?

    One state per line ending in a colon, indented under its parent. Under a state: EVENT -> target, optionally [guard] and / action. initial name sets the starting child, entry: and exit: list actions, and after 5s -> target is a delayed transition. Add final, parallel or history after the colon.

    Is the XState output ready to use?

    It's XState v5 setup() code with typed events and placeholder guards and actions for you to fill in. Targets use sibling names where possible and #id paths otherwise, so it runs as it is.

    Can it read my existing XState machine?

    Yes, as a literal: states, initial, on, after, always, entry, exit, guards and actions. It's parsed as data (JSON5-style), so functions and imports are shown by name and nothing is executed.

    What counts as a dead end?

    A state that isn't final and has no transition out of it, including transitions inherited from its parent states. A state that only loops back to itself counts too.

    How does the simulator pick transitions?

    Like XState and SCXML: starting from each active state, the innermost state with a matching event whose guard passes wins. States are exited innermost first and entered outermost first, with their actions logged in that order.

    Work with me

    Want a site that gets these right?

    I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

    All developer tools · Back to leej.uk