Stately

Understand how your app behaves

Stately turns app behavior into diagrams you can explore and share. Map flows from your code, simulate what can happen, and review what changed in a pull request.

Statechart of an example checkout flowExample checkout statechart, simulated on a loop: an order is added, checked out, submitted, declined, cancelled, and then paid. States: idle (initial), cart, address, payment, declined, confirmed (final), refund (unreachable). Transitions: idle on ADD_ITEM to cart; cart on CHECKOUT to address; cart on EMPTY to idle; address on SUBMIT to payment; payment on PAID to confirmed; payment on FAIL to declined; declined on RETRY to payment; declined on CANCEL to cart.ADD_ITEMEMPTYCHECKOUTSUBMITPAIDFAILRETRYCANCELidlecartaddresspaymentdeclinedconfirmedrefund
7 states · 8 transitions · 1 unreachable · example: checkout · state: idle

See how it works

In this checkout example, a pull request adds a payment retry and removes the only path to a refund.

Compare behavior before and after

Before
From declined, the REFUND event led to refund.
After
From declined, the new RETRY event leads back to payment. The refund state has no incoming transition.
After the change
Checkout statechart after the pull requestThe checkout statechart after the pull request. States: idle (initial), cart, address, payment, declined, confirmed (final), refund (unreachable: no transition leads to it). Transitions: idle on ADD_ITEM to cart; cart on CHECKOUT to address; cart on EMPTY to idle; address on SUBMIT to payment; payment on PAID to confirmed; payment on FAIL to declined; declined on RETRY to payment (added in the pull request); declined on CANCEL to cart. Removed in the pull request: declined on REFUND to refund.ADD_ITEMEMPTYCHECKOUTSUBMITPAIDFAILRETRYCANCELREFUNDidlecartaddresspaymentdeclinedconfirmedrefund

The dashed REFUND arrow marks the removed transition. The refund state is unreachable.

Try the simulator

Start simulation in the editor and send ADD_ITEM, CHECKOUT, SUBMIT, and FAIL one at a time. Then try RETRY or CANCEL.

Map a flow from your code

Import a machine in a supported format to see its possible paths. For flows spread across application code, ask your agent to draft a model and link its transitions to the relevant source.

Use the Stately CLI to find XState machines in your repo, render them as SVG, or export them to formats such as Mermaid and SCXML.

$ npx statelyai scan
stately mcpstable

terminal

$ claude mcp add --transport http stately https://mcp.stately.ai/mcp

In Claude Code, run /mcp and complete Stately sign-in.

Add the skills with npx skills add statelyai/skills.

MCP URL
https://mcp.stately.ai/mcp
Docs
MCP server · llms.txt

Validate and convert

stable

Find missing targets, unreachable states, and invalid config, then translate between XState, SCXML, Mermaid, and D2.

  • validate_machine
  • convert_machine

Diff and patch

stable

List the states and transitions that changed between two machines, and apply structured edits.

  • diff_machines
  • apply_machine_patches

Simulate and visualize

stable

Explore paths, step a machine through events, and render statecharts or sequence diagrams.

  • generate_graph_paths
  • simulate_machine
  • visualize_machinebeta
  • visualize_sequence

Extract and review

beta

Extract machines from source and compare a model with implementation evidence.

  • extract_machines_from_code
  • review_machine_implementation

How an agent's change gets reviewed.

Map behavior, review a proposed change, and compare the implementation with the model.

review

Mapped

A model inferred from the code, with citations to the source.

statechart + source hash

Proposed

A proposed edit to the graph, made in the editor or over MCP.

proposed change

Approved

A reviewer examines the proposed change and approves it.

review + approval

Implemented

The approved edit, written into the source.

commit

Compared

The agent compares the implementation with the approved model and reports differences.

review findings

CI gate

The diff command can fail a build when machine semantics change.

$ statelyai diff <base> <head> --fail-on-changes
no changeschanges

Review the evidence

Review the source citations behind the model. Run application tests to confirm how the code behaves. MCP docs

Runs over MCP, with the CLI for scan, push, pull, and diff. The editor is optional, and so is XState in your code.

Understand the whole system.

system

Storefront

Next.js

Checkout

Node service

Orders

Postgres

Payments

Node service

Email

Queue

Architecture view. Components: Storefront (Next.js), Checkout (Node service), Orders (Postgres), Payments (Node service), Email (queue). Relationships: Storefront sends ORDER to Checkout; Checkout writes Orders; Checkout sends CHARGE to Payments; Payments sends RECEIPT to Email.

Architecture

Map how services, actors, and machines connect. Import Structurizr JSON, D2, or Mermaid, including Mermaid C4 diagrams.

The editor

The editor inspecting a running checkout actor. The payment state is active with a double outline; the CHECKOUT transition it just took is highlighted. The inspection panel shows state payment, context orderId order-42, items 3, total 4200, the CHECKOUT event, and the actions reserveInventory and startPayment.

Inspection

Attach to a running app and watch states, events, and actors as they happen. Sequence diagrams show who sent what to whom.

Inspector

Payment statechart in the editorPayment statechart. States: payment (initial), declined, confirmed (final). Transitions: payment on PAID to confirmed; payment on FAIL to declined; declined on RETRY to payment.PAIDFAILRETRYpaymentconfirmeddeclined
// xstate-version: 6
states: {
  declined: {
    on: {
      RETRY: { target: 'payment' }
    },
  },
}

Edit in either direction

Open a supported source file in VS Code, edit its machine visually, and save supported changes back to the file.

VS Code extension

Embed the editor or inspector in your app with the Stately SDK.

Connect behavior across your stack.

Stately imports supported machine, store, workflow, and diagram formats into one graph model. Explore paths through the graph and export it to supported formats. Source write-back depends on the format.

Supported sources, tools, and outputs:

  • Libraries: XState, XState Store, Redux, Zustand
  • Workflow and agent runtimes: LangGraph, Inngest, Restate
  • Diagram and model formats: Mermaid, SCXML, D2
  • Tools and outputs: Graph paths, Inspector, TypeScript

With Inngest, Restate, and LangGraph, Stately reads the workflows you already run and models the behavior around them. It sits above those runtimes and does not replace them.

Built on XState.

XState is an MIT-licensed library for running state machines in the browser or in Node.js.

weekly npm downloads
7.9M+
GitHub stars
30K+
repositories depend on it
338K+
years in production
10
installstable
$ npm install xstate

For multi-step flows, async orchestration, retries and timeouts, and any behavior that must be reviewed.

ReactVueSvelteSolid
inspector

Inspect a running XState app.

Attach the inspector to a running app and watch states, events, and actors as they happen.

Open the inspector docs

xstate 5 · xstate/graph · @xstate/store · xstate 6 beta

XState naturally separates the logic and makes it simple to mock out API calls, so it's easier to test the code and organize it!
Presley PizzoCoder

XState is used by engineers at

We use XState to implement business workflows as statecharts. The visualizer helps us collaborate more closely with customers, the ability to externalize workflows as JSON configuration makes complex workflow changes surprisingly simple to roll out, and test case generation makes it easier than ever to move forward with confidence. XState makes it all possible!
James TharpeT-Mobile

Start free.

Community is the editor, simulation, and code export. Pro adds private projects, codebase sync, and version history. Team shares all of it with up to 10 people. Enterprise runs where you need it to.

PlanFeaturesPrice
Community
  • Public projects and machines
  • Editor, simulation, and code export
  • 200 AI credits a month
$0
Pro
  • Unlimited private and unlisted projects
  • Project sync through GitHub or the Stately CLI
  • Locked machines
  • Version history and live simulation
  • 1,000 AI credits a month
$39 / mo$33 / mo billed yearly
Team
  • Everything in Pro for up to 10 people
  • Shared team projects
  • 4,000 shared AI credits a month
  • Admins, editors, and unlimited viewers
$199 / mo$167 / mo billed yearly
Enterprise
  • Cloud or self-hosted, custom server locations
  • SSO and audit logs
  • Custom export formats and effect collections
  • Embed Stately in your own apps
  • Dedicated priority support
Book a demo (opens in a new tab)

Enterprise-ready.

Self-host it, sign in through your identity provider, and keep the model inside your boundary.

  • Run the editor on your own network. Local editing and simulation need no database.
  • Sign in through your identity provider: an SSO proxy or your OAuth issuer.
  • Disable AI features with AI_ENABLED=false.
  • Run machine conversion, comparison, and patching over HTTP or MCP on your host.
  • Commercial license, with MIT-licensed SDK and CLI.
self-hosted
AI_ENABLED=false
# Configure comments separately

What runs on your host

  • Visual editing and simulation
  • Source editing for supported formats
  • SCXML export
What is a state machine?

A state machine models behavior as states and transitions between them. Events can trigger transitions, changing the current state. Statecharts extend state machines with nested states and parallel regions for concurrent behavior.

Does Stately replace my workflow runtime?

No. Temporal, Inngest, Restate, and LangGraph keep running your workflows. Stately models and analyzes the behavior they run.

Do I need XState?

No. Stately maps existing code from many libraries and formats, and can capture behavior from a running app. Use XState when you want to execute the model directly.

Does my code leave my network?

The hosted service processes submitted code under the Stately privacy policy. For a self-hosted deployment, configure AI, comments, and network access to match your data policy.

What does my agent actually do with Stately?

It can map code into a statechart with cited evidence, propose graph changes, and compare a model with implementation evidence. People can review the resulting changes.

Where are the machine-readable docs?

Start with /llms.txt and /llms-full.txt. Docs pages are available as markdown by adding .mdx to the URL. The MCP server is at https://mcp.stately.ai/mcp, and npx skills add statelyai/skills installs the agent skills.

machine-readable
  • /llms.txtSite summary for agents
  • /llms-full.txtFull docs as plain text
  • https://mcp.stately.ai/mcpHosted MCP server
  • claude mcp add --transport http stately https://mcp.stately.ai/mcpAdd the MCP server to Claude Code
  • codex mcp add stately --url https://mcp.stately.ai/mcpAdd the MCP server to Codex
  • {"mcpServers":{"stately":{"url":"https://mcp.stately.ai/mcp"}}}Cursor: .cursor/mcp.json
  • code --add-mcp '{"name":"stately","type":"http","url":"https://mcp.stately.ai/mcp"}'Add the MCP server to VS Code
  • npx statelyai scanFind the machines in a repo
  • npx skills add statelyai/skillsAgent skills
  • /docs/packages/mcp.mdxMCP docs as markdown
  • https://github.com/statelyai (opens in a new tab)Source

Map your first repo.

$ npx statelyai scan