Most business apps I've built end up as a status column plus a pile of if statements: which status can follow which, who may change it, and what has to be true first. That logic ends up spread across handlers, and nobody can see the whole workflow in one place.
I've been building FastYoke, a workflow engine that makes that logic the core. A workflow is a JSON document of states and transitions. Each transition can carry a guard. Every transition that fires is appended to an event log that's never updated.
In this post we'll build a small dispatch board on it, from an empty folder, with nothing but Node 18+. No Docker, no account, no API key. Here's the whole thing in under 3 minutes:
1. Start the engine
mkdir dispatch && cd dispatch npx fastyoke init init writes a .fastyoke/ folder: a config.json, a seed.json, an auth.key generated on your machine, and an uploads/ folder.
2. Describe the workflow
The seed file holds everything the engine starts with: the entity kinds, their records, and the workflows. Replace .fastyoke/seed.json with this:
{ "tenant": { "id": "local", "name": "Dispatch" }, "users": [{ "email": "local@fastyoke.dev", "role": "admin" }], "entity_kinds": [ { "name": "delivery", "schema": { "fields": [ { "key": "ref", "type": "string" }, { "key": "customer", "type": "string" }, { "key": "driver", "type": "string" } ] } } ], "entity_records": { "delivery": [ { "id": "dl_1001", "data_payload": { "ref": "DL-1001", "customer": "Harbor Foods", "driver": "Ana" } }, { "id": "dl_1002", "data_payload": { "ref": "DL-1002", "customer": "Northside Hardware", "driver": "" } }, { "id": "dl_1003", "data_payload": { "ref": "DL-1003", "customer": "Bayview Clinic", "driver": "Sam" } } ] }, "fsm_schemas": [ { "id": "sch-delivery", "name": "delivery_flow", "entity_name": "delivery", "schema_json": { "initial_state": "pending", "transitions": [ { "event": "dispatch", "from": "pending", "to": "out_for_delivery", "guard": { "!!": [{ "var": "driver" }] } }, { "event": "deliver", "from": "out_for_delivery", "to": "delivered" } ] } } ], "jobs": [ { "id": "job_1001", "schema_id": "sch-delivery", "current_state": "pending", "context_record_id": "dl_1001" }, { "id": "job_1002", "schema_id": "sch-delivery", "current_state": "pending", "context_record_id": "dl_1002" }, { "id": "job_1003", "schema_id": "sch-delivery", "current_state": "pending", "context_record_id": "dl_1003" } ] } The interesting part is schema_json. A delivery goes pending → out_for_delivery → delivered, and the dispatch event has a guard written in JSONLogic: { "!!": [{ "var": "driver" }] } means "only if the delivery has a driver". The guard is data, not code, so there's no string eval anywhere.
Each delivery has a job: the workflow instance that tracks its state. DL-1002 has no driver, which matters in a minute.
3. Run it and poke it
npx fastyoke dev & That serves the API on 127.0.0.1:8787 over a SQLite file at .fastyoke/local.db. Each time it starts, dev writes a local admin token, valid for 24 hours, to .fastyoke/token. Here's a small helper to fire events:
export T=$(cat .fastyoke/token) fire() { curl -s localhost:8787/api/v1/tenant/jobs/$1/transition -H "authorization: Bearer $T" -H 'content-type: application/json' -d "{\"tenant_id\":\"local\",\"event_type\":\"$2\"}" -w ' → %{http_code}\n'; } Now try to dispatch the delivery with no driver:
$ fire job_1002 dispatch {"error":"guard rejected event 'dispatch'","code":"guard_failed"} → 422 The guard refused it, and nothing was written. Dispatch the one that has a driver:
$ fire job_1001 dispatch {"id":"job_1001",...,"current_state":"out_for_delivery",...} → 200 Fire the same event again:
$ fire job_1001 dispatch {"error":"no transition for event 'dispatch' from state 'out_for_delivery'","code":"no_transition"} → 400 There's no dispatch edge out of out_for_delivery, so the engine refuses it. You never wrote an if for any of this. The graph is the rule.
Every transition that fires is appended to the job's event log:
curl -s "localhost:8787/api/v1/tenant/jobs/job_1001/history?tenant_id=local" -H "authorization: Bearer $T" A refused guard writes nothing. A successful transition updates the state and appends the event-log row in one SQLite transaction, then broadcasts it on a WebSocket. That last part is what the front end uses.
4. A front end
Start with a stock Vite app and add the SDK:
npm create -y vite@latest web -- --template react-ts cd web npm i react@18 react-dom@18 @types/react@18 @types/react-dom@18 @fastyoke/sdk echo "VITE_FASTYOKE_TOKEN=$(cat ../.fastyoke/token)" > .env.local The SDK peer-depends on React 18 today, and a fresh Vite app is React 19, so we pin it.
The local engine sends no CORS headers, so let Vite proxy /api to it. Replace vite.config.ts:
import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; // The local sidecar sends no CORS headers, so proxy /api through Vite. export default defineConfig({ plugins: [react()], server: { proxy: { '/api': { target: 'http://127.0.0.1:8787', ws: true } } }, }); Then replace src/App.tsx. It's about 60 lines:
import { useState } from 'react'; import { FastYokeProvider, useEntities, useJobs, useTransitionJob } from '@fastyoke/sdk'; const token = import.meta.env.VITE_FASTYOKE_TOKEN as string; const fetcher: typeof fetch = (input, init = {}) => fetch(input, { ...init, headers: { ...init.headers, authorization: `Bearer ${token}` } }); export default function App() { return ( <FastYokeProvider baseUrl="" tenantId="local" token={token} fetcher={fetcher}> <h1>Deliveries</h1> <Board /> </FastYokeProvider> ); } // Next event per state, straight from the delivery_flow schema. const NEXT: Record<string, string> = { pending: 'dispatch', out_for_delivery: 'deliver' }; function Board() { const deliveries = useEntities('delivery'); const jobs = useJobs({ schemaId: 'sch-delivery' }, { realtime: true }); const { transitionJob } = useTransitionJob(); const [error, setError] = useState(''); const rows = (deliveries.data as any)?.rows ?? deliveries.data?.records ?? []; return ( <> <table> <thead><tr><th>Ref</th><th>Customer</th><th>Driver</th><th>State</th><th /></tr></thead> <tbody> {rows.map((d: any) => { const job = jobs.data?.find((j) => j.context_record_id === d.id); const next = job && NEXT[job.current_state]; return ( <tr key={d.id}> <td>{d.data_payload.ref}</td> <td>{d.data_payload.customer}</td> <td>{d.data_payload.driver || '—'}</td> <td><span className={`state ${job?.current_state}`}>{job?.current_state}</span></td> <td> {next && ( <button onClick={async () => { setError(''); try { await transitionJob({ id: job!.id, input: { eventType: next } }); } catch (e) { setError(`${d.data_payload.ref}: ${(e as Error).message}`); } jobs.refetch(); }}>{next}</button> )} </td> </tr> ); })} </tbody> </table> {error && <p className="error">{error}</p>} </> ); } Three hooks do the work:
-
useEntities('delivery')reads the delivery records. -
useJobs({ schemaId }, { realtime: true })reads each delivery's workflow state and refetches when the engine broadcasts a change. -
useTransitionJob()fires events. When the engine refuses one, the error carries the engine's own message, so the guard's refusal shows up in the UI with no extra code.
One wart: the local runtime returns entity lists as { rows, total } and the full engine as { records, total, page, page_size }, so the rows line reads both.
The video also uses a small src/index.css for the table and state pills. Any styling works; the class names are state, state.out_for_delivery, state.delivered and error.
5. Watch it move
npm run dev Open http://localhost:5173:
- Click dispatch on DL-1002. The guard refuses it, and the board shows
DL-1002: guard rejected event 'dispatch'. - Click deliver on DL-1001. It moves to
delivered. - Back in the terminal,
fire job_1003 dispatch. The browser updates over the WebSocket without a refresh.
What this runtime is, and isn't
What you just ran is the light runtime: one Node process over one SQLite file, so one node and one tenant. It has the workflow engine (guards, self-loops, an admin override), entities, public forms, the event log and realtime.
It's a deliberate subset. The full engine is a single Rust binary that adds PDF rendering, a sandboxed scripting tier, extensions and e-signatures. You run it yourself in Docker or use the hosted version. Both speak the same REST and WebSocket contract, so an app built on the shared core moves between them by changing a base URL.
On licensing: the npm packages (the runtime, the SDKs and the CLI) are MIT, and their source is on GitHub. The full engine is proprietary today. The plan is open core, under the Business Source License.
Where to go next
- The docs: fastyoke.io/docs
- The quick start: fastyoke.io/docs/developers/quickstart
- The CLI, for scaffolding a typed app from one entity and its workflow:
npm i -g @fastyoke/cli, thenfy app create --help
I'd like to hear whether "the state machine is the app" matches how you'd want to build this kind of software, and what would stop you from using it. Comments are open.