fate-studio: Seeing and Driving Statecharts in the Browser
A viewer and simulator for fate statecharts. Open a descriptor snapshot from disk and it redraws as the file changes; drive a live machine over Server-Sent Events, even one running inside another service; jump from any state or transition to the Go line that defines it. One static binary, and the page makes no external request.
If fate is the engine, fate-studio is where you watch it run. Open a machine and its diagram appears; then step through it (send events, fire delayed transitions, resolve or reject invocations) and the active state updates live on screen.
When this post was first written, that was all it did, and a machine could only be seen if it was registered in Go code, inside a program that linked the studio. The September work removed that requirement. The October releases, up to v0.10.0 on 2026-10-13, went the other way: from the chart back to the code that wrote it.
Why it’s a separate repo
This is the question it gets most, and the answer is one sentence: the engine has no dependencies, and the studio needs a web server.
In one repo, go get github.com/arisros/fate would drag the whole studio into the program of someone who only wanted a state machine. Splitting them means people pay only for what they use. The studio’s go.mod has exactly one requirement, fate v0.14.0, vendored, so the Docker build downloads nothing. The studio follows the engine closely: v0.6.1 and v0.6.2 exist only to ship engine fixes, because a simulator running an old engine does not just lag a version, it steps machines through the wrong states. The running studio prints both versions in its top bar, and GET /api/version returns them.
Snapshots: a chart without a runtime
A machine can reach the studio as a file. fate/snapshot writes a machine’s descriptor as JSON, and the studio renders it with nothing running behind it:
go run ./cmd/fate-studio --snapshots ./.fate --watch
With --watch, the studio polls the directory every 500 ms and redraws a chart when its file changes, pushing a graph-changed event to the page over a server-wide SSE stream. It polls rather than using OS file notifications, because a notification library would be the studio’s first dependency. A half-written file fails to parse and the last good chart stays on screen, so saving from an editor never blanks the page.
With no flags at all, the binary loads ./.fate if that directory exists and falls back to the built-in demos if it does not.
Simulating a machine that lives somewhere else
A snapshot can be looked at but not driven, since there is no engine behind it. fate v0.5.0 added fate/httphandler, which exposes a machine as an HTTP simulator with the same wire format the studio already speaks. So the studio can proxy a snapshot’s simulator to wherever the real machine runs:
{
"snapshots": ["./.fate"],
"watch": true,
"proxyURLs": { "checkout": "http://localhost:8081/fsm/checkout" }
}
The same mapping can come from the environment: FATE_PROXY_CHECKOUT, with the machine name upper-cased and everything that is not a letter or digit turned into _. Cookies the remote sets are narrowed to the studio’s own path, and if the remote is down the simulator answers with a 502 that names the machine instead of hanging.
A virtual simulator for charts with no backend
For a snapshot with no proxy at all, every machine page has a “virtual sim” button. It steps through the chart in the browser using only the graph. It cannot run guards, because guards are Go functions, so when an event has several possible targets it stops and asks you which branch to take.
That is where the engine’s guard metadata earns its place. A guard described with action.Gates(action.Field("$.approvals").Gte(1)) shows up in the inspector as a readable condition, and the virtual simulator checks it against a mock context you type in, marking each gate open, closed or unknown. (Since fate v0.6.0 split the engine into packages, that is action.Gates rather than the old fate.Gates.) Per-state view models show up the same way, next to the JSON Schema they were derived from.
fate v0.13.0 added two flags the studio now draws: the unconditional transition that ends a list of guarded ones is labelled as the fallback branch, and a transition listed after an unconditional one, which can never fire, carries a warning on its row, its edge label and its tooltip.
From the chart to the code
This is the main thing v0.9.0 and v0.10.0 added. Every state, transition, guard and action in a live machine links back to the Go that defines it, using the source locations fate v0.14.0 reports. Hover a node or a transition row and two buttons appear: open the file in your editor at that line, or view it on GitHub or GitLab at the commit the binary was built from. The machine’s own file and line sit in the toolbar.
Editor links open VS Code by default and appear only when the source is on the host the studio runs on. --editor-url points them at another scheme:
fate-studio --editor-url "idea://open?file={path}&line={line}"
Neovim or Helix in a terminal has no URL scheme to follow, so v0.10.0 added --editor-cmd. The button then asks the studio to run a command on its own host, and only for a place the studio itself linked to:
fate-studio --editor-cmd "nvim --server /tmp/nvim.sock --remote {path}"
The links have limits the README states plainly. States and transitions are found by reading the machine’s source file, so a state built by a helper function may link to the nearest line that names it, or to nothing. A snapshot has no code behind it and shows no links unless it is proxied to a fate httphandler, which serves the locations at /sources.
Edit, rebuild, keep your place
Following a link into the code means editing the machine, rebuilding and restarting the program, and that used to drop the simulator back to the initial state. Since v0.9.0 the browser remembers the steps of the current session. When the stream comes back from a new server, it replays those steps against the rebuilt machine and says how many of them still applied, so a change that breaks step four tells you it stopped at step four.
It still embeds into your own program
The studio is an ordinary http.Handler, so it can be mounted inside a running application:
srv := studio.NewServer("my app")
srv.SetBasePath("/studio/")
srv.Register(studio.Entry{
Name: "checkout",
Summary: "the checkout flow",
Build: checkoutMachine().Describe,
BuildLive: func() studio.LiveInstance {
return studio.NewLiveActor(checkoutMachine(), dispatch, checkoutMachine().Describe)
},
})
http.Handle("/studio/", http.StripPrefix("/studio", srv.Handler()))
SetBasePath is required when mounting under a prefix. Before it existed, the README already showed mounting under http.StripPrefix, but the page asked for its bundle and its API at the site root, so a mounted studio rendered blank. The server rewrites the page’s <base> and asset paths to the prefix and scopes the session cookie to it, and a Playwright test renders every demo both at / and mounted under /studio/ to keep it that way.
The key type is still LiveInstance. fate is generic, Actor[Ctx, Evt], while the simulator has to drive any machine without knowing its concrete types. LiveInstance erases them, and the dispatch function you supply maps an event name from the UI onto one of your typed events. A machine registered with only Build shows its diagram without the live simulator.
Since v0.9.0 the registry, snapshot loading and simulation sessions live in a core package with no HTTP in it. The web server is one front end over it, Server.Core() hands the same studio to another one, and the existing API stays in place through aliases. The pull request names a TUI and CLI commands as what that split is for; neither is in the repo.
Canvas and transport
The diagram is drawn with React Flow (@xyflow/react), laid out by elkjs and routed with libavoid, shipped as a WebAssembly file inside the binary. Every container now uses ELK’s layered layout: with the default 20 px gap between layers, narrower than the 68 px the router needs between two anchored nodes, edges doubled back on themselves. State changes travel from server to browser over Server-Sent Events rather than WebSockets, because the data really does flow one way; user events go back as ordinary requests.
The inspector was rebuilt in v0.8.0 as a readout. Each event is a row that shows where it leads, the context is a code block that marks the lines the last step changed, and the timeline logs what each step did, with undo, import and export. A first visit gets a three-step guide, remembered in localStorage and replayed with ?.
One binary
The built UI (Vite output) is committed into assets/ and embedded in the Go binary, including the two fonts it uses, Rubik and IBM Plex Mono, as latin woff2 subsets. What gets deployed is a single file: no Node, no CDN, no external font request. The only outbound traffic the server ever makes is to a simulator you configured it to proxy.
go run ./cmd/fate-studio --demos # then open http://localhost:8090
The address comes from --addr or FATE_STUDIO_ADDR. The Docker image builds with CGO_ENABLED=0 onto a distroless, non-root base, and each release publishes it to the GitHub container registry. A hosted copy runs at fate-studio.arisjirat.com.
Demos as the test suite
There are nine demo machines, and each exists to cover a feature: traffic-light and pipeline for transitions and final states, media-player for parallel regions, editor for deep history, counter for live context, timeout for delayed transitions, fetch for invocations, order for parallel lanes with a view model per lane, and ticket for named and gated guards.
They are also the UI’s fixtures. make fixtures writes each demo out as a snapshot and as the graph the UI tests read, and go test fails while those files are stale, so a demo cannot drift from what the tests believe it looks like.