Skip to content

A statechart engine for Go

Every path is drawn before the first event.

fate computes state and never performs side effects. Hierarchical states, parallel regions and history, with no dependencies beyond the standard library.

$go get github.com/arisros/fate
activefinalinitialcompound
machine order
  • taken
  • can take now
  • drawn, not taken
pendingPAYCANCELpaidSHIPshippedDELIVEREDdeliveredcancelled
Active stateorder.paid
Events sentPAY
Click an event in the lime state to send it.

Three hands on one thread.

In the myth, three Fates spin, measure and cut the thread of a life. A statechart does the same to a process, and fate is the part that does it the same way every time.

  1. 01 / Clotho spins

    Declare

    Write down every state and transition up front. CreateMachine validates the config and returns an immutable machine. Nothing about it changes at runtime.

  2. 02 / Lachesis measures

    Send

    Send dispatches an event and the engine computes the next configuration. No I/O, no clock, no randomness. Delays and invocations surface as data for an adapter to carry out.

  3. 03 / Atropos cuts

    Finish

    A final state ends the run. At any point before it, Persist writes the actor to JSON and it restores byte for byte, so the thread can be picked up anywhere.

Same events, same fate.

The same machine driven by the same sequence of operations always reaches the same active configuration and produces the same persisted bytes.

Run one
PAYSHIPorder.shipped
=
Run two, restored from a snapshot
PAYSHIPorder.shipped
How persistence and determinism work
  • Statecharts, not flat FSMs

    Compound and parallel states, deep and shallow history, guards, actions, and final states.

  • No dependencies

    The engine imports only the standard library. The Temporal integration is a separate module.

  • Deterministic and persistable

    An Actor serialises to JSON and restores byte for byte, which makes replay exact.

  • Effects are data

    Delays and invocations surface as pending effects. An adapter performs them.

  • Runs inside Temporal

    No side effects in the engine, so a machine survives workflow replay unchanged.

  • Render and diff

    Render any machine to ASCII, Mermaid, or graph JSON, and diff two snapshots.

Released under the MIT License · v0.14.1 · pkg.go.dev