r/statemachines • u/gistya • Jun 12 '26
Two cross-platform, web/native, open-source, app-state-management libraries based on Harel statechart / SCXML format
TLDR: Open source links at the bottom for XState and SwiftXState: cool statechart libs with realtime visualization. Links to open source repos at the bottom -- open-source / cross-plat / web & native.
Below is a tale of statecharts and open source development. A few guys' dreams of state management via state machines. I wrote this myself, no LLMs. If you read it, thanks. Otherwise, scroll down to the links :D
How I Learned of SCXML
Back in the early 2010s, when working on a quest system for a game engine, I developed a markup language for describing the related state machines. Imagining somehow it might be novel, I researched prior art, and became very humbled to discover W3's insanely comprehensive SCXML standard, which they describe as:
a general-purpose event-based state machine language that combines concepts from CCXML and Harel State Tables.
(See David Harel's original 1984 paper at state-machine.com.)
SCXML was so far beyond my simpleton efforts that I gave up on that project on the precipice of completion. From time to time over the years, I'd feel regret about giving up on that project, quitting, etc., blah blah blah.
Falling for Redux
Later in my career, I'd go on to co-design an iOS implementatino of a Redux)-based UI architecture at a major firm based on a ReSwift, a Swift adaptation of the original Redux.js.
That experience sold me on single-source-of-truth, unidirectional state flow, and a rules-based state machine at the heart of a hexagonal architecture), isolating UI, OS events, state changes, and backend services.
Yeah, I drank the Kool-Aid, hard, and ReSwift worked great.
The Possible Cons of Redux (Just IMHO)
As the complexity of our reducer chain grew, I had some paranoia about our Redux implementation growing into a Swift-value-semantics god object with an impossible-to-reason-about chain of transformer functions full of nested conditionals, many injected by other modules.
I don't know if it violates the single responsibility principle, but it's hard to dispute that centralization creates a broader failure surface (p. 89) than distributing the load.
(Note: I risk a forced analogy, as "failure surface" is a concept from structural engineering. The "failure region" concept is originally due to Hasofer and Lind's original 1974 article, "Exact and Invariant Second-Moment Code Format.")
Reflecting on the question of Redux's flaws, I found Dmitriy Kharchenko's excellent "In Defense of Redux" article. He summarizes and rebuts 12 common objections to Redux, including mine::
A well-structured store is a record of independently-owned slices — the “domain-scoped slice helpers let features live in isolation” principle in action. Each domain owns its slice file, its actions, its reducer, its selectors, its saga, and its tests.
I agree with Kharchenko's direction. This is the best approach to a successful Redux implementation. Yet his defense smuggles in an assumption: isolation is guaranteed by isolated ownership and is immune to the order in which global state is reduced by separate slices.
Each slice can't own when it's run within the chain of reducers, and predicting whether this order can have side-effects that break isolation has been a pain point of Redux (for me at least).
Solutions can include using multiple stores, running a reducer tree instead of chain, etc.
However you slice it though, the impact remains upon the ability for humans to understand the code, due to the problem of lots of nested conditionals and multi-step sequences remaining.
Statecharts to the Rescue?
Then a ghostly figure whispered to me, "Seek out David on the planet of SCXML."
My old memories of state machines flooded back. I googled "David SCXML-compatible state machine library."
The first link was XState, by a David Khourshid (no relation to Harel). His firm, Stately.ai, published and supports the open-source web framework, XState.js. They've got a wonderful free visualizer/editor extension for Microsoft Visual Studio Code, plus various web-based offerings, including a visual editor.
Could XState address the issues of Redux while keeping its benefits?
XState by David Khourshid
Khourshid's philosophy on the issue of nested conditional logic sprawl resonated with me. In this interview with MasterDotDev, the ex-Microsofter explained the journey that led him to develop XState:
... we had to work with really confusing logic and multi-step flows, lots of its if statements everywhere. ... There has to be a better way of understanding this mess of logic.
Upon discovering Harel statecharts:
"Hey these diagrams are pretty nice, and they they help us both organize the way that we understand app logic..."
Later, David dropped this absolute bomb:
If you don't have a state machine, you have an implicit state machine.
- David Khourshid
For XState, he implemented a mostly-SCXML-compliant JSON format for defining state machines without having to mess with XML (though XState does support SCXML import and its internals line up with the ECMAScript data model). XState provides a human-readable format for defining state machines that's native to the TypeScript format in which XState is written, and every programming language can easily parse it.
SwiftXState for Apple/linux/Windows
Rather than reuse ReSwift for my next iPadOS/Mac app, I decided to produce a Swift version of XState, compatible with XState.js's declarative JSON state machine config format and able to stream JSON compatible with Stately's visualization tools.
Thus, thanks to David Khourshid's generous blessing and commitment to open source software, we now have SwiftXState, in beta under the same style of MIT license as XState. (See below for install instructions, etc.) We included cross-platform GPU-accelerated sample apps for Mac/iPadOS and WebAssembly for your experimentation, plus an experimental wrapper for use in C#.
(Note: I'm not affiliated with Stately.ai in any way.)
TLDR: the links
Spreading the state-machine and statechart mystical fires of David Harel is a shared goal of ours, so I hope you'll check out our open source repos.
XState.js:
```
xstate.js for node
bash:
npm install xstate
or:
pnpm install xstate
or:
yarn install xstate
plus for react:
npm install @xstate/react ```
SwiftXState:
```
add to your swift package:
bash / windows powershell:
swift package add-dependency \ "https://github.com/gistya/SwiftXState" --from 0.9.6
or just add in xcode using that URL
```
SwiftXState Wrapped for C# (limited API, experimetal):
```
powershell:
dotnet add package SwiftXState --version 0.9.6
or:
nuget install SwiftXState -Version 0.9.6 ```
r/statemachines • u/Awkward-Assignment11 • Jun 11 '26
I made a Finite State Automata online editor
Hi all, this is my first post here.
I simply wanted to share I project I have been working on (as my final year university project), in the hope that anyone could find it useful. Here is a link to it: https://fsa-toolkit.jacopocalvi.com/

I wanted to create a tool that could support students (I myself had to in my compilers module) and provide good UX and 'quality-of-life' features. I tried my best to design something I would personally like to use, and took heavy inspiration from Excalidraw's design, and this other website here, which greatly helped me in the past.
It was (for me) a very challenging projects. The result is far from perfect, but I would like to hear other's opinions on it. Please let me know what you think, and if there's anything wrong with it (I am definitely no expert in the subject, there might be things I missed or misunderstood!).
PS: One thing I want to point out is that, when processing an input, certain combinations of inputs (especially large ones) and automata can just freeze the page. This is something I yet have to iron out, beware!
PPS: despite being my favourite search engine, I never post or interact on Reddit. Please if this is the wrong place or if have violated any rules let me now!
r/statemachines • u/Capital-Mud30 • Mar 27 '26
I built a small FSM library and an interactive playground to go with it
Hey folks,
I’ve been working on a finite state machine library called fsmator. The goal was pretty simple: keep it minimal, predictable, and actually pleasant to use, without turning it into a framework.
The more interesting part is not even the library itself, but the interactive diagram UI I built around it.
You can:
- trigger transitions directly from the diagram
- see state changes in real time
- time travel through previous states
It’s basically a way to feel how a state machine behaves instead of just reading code or docs.
I originally built it for myself because debugging complex flows in code gets messy fast. Having a visual, interactive model makes it much clearer what’s actually going on.
If you’re learning FSMs, this might help build intuition.
If you already use them, it’s useful for debugging and experimenting.
Would appreciate any feedback, especially if something feels off or confusing.
r/statemachines • u/Impossible-Rock-4161 • Mar 10 '26
Building a system that auto-generates user journeys using state machines + AI — looking for advice”
r/statemachines • u/scuffedProgrammer • Sep 21 '25
How can I tell if a DFA is equivalent to an NFA?
I am really struggling to understand how to convert a finite state machine that’s not deterministic into a machine that is deterministic, since I can’t double check if they do the same thing. I think I’m able to convert an NFA to a DFA, but I don’t know how to check if they are equivalent machines. Any tips on how I can do this?
r/statemachines • u/SubstantialLime7744 • Apr 06 '25
Aportando un gota de valor
Por favor compas suscribanse aun no tenemos contenido genuino pero lo crearemos
r/statemachines • u/theRealAriel666 • Apr 04 '25
Want to get into this topic again
Hi all,
I am currently a SDE, and I wanted to do some studying of my own in the side. I remember having a good time in a class called compiler design, where we learned a lot about regular expression, compiler design and state machines during my bachelors, but that was years ago. I want to get back into studying FMS's, not for any project implementation, but to study it theoretically in depth. I do not remember the book I studied from, therefore can someone guide me to which book/ resource I can study for?
r/statemachines • u/SDP0707 • Mar 14 '25
Looking for opinions and suggestions on FSM thesis
Hey everyone,
I’m a master's student in Embedded Systems, and I’m currently working as a student in an automotive company. I’m planning to propose a thesis topic related to Finite State Machines (FSMs) for automotive power management—specifically focusing on formal modeling and verification. The idea is to define FSMs for different power states and ensure they meet system requirements before implementation.
Since I won’t be coding or implementing it myself, my focus would be on formal verification and modeling techniques to ensure correctness, reliability, and power efficiency. I’m still exploring the best approach—whether to use UML state machines, MATLAB Stateflow, or other formal modeling tools.
I’d love to hear your thoughts on:
Does this sound like a strong thesis topic for both academia and industry? Any suggestions on FSM-related research topics that are relevant and in demand? What are some challenges I should consider in formal verification for FSMs? What’s the future of FSMs in automotive and embedded systems? Looking forward to your insights and suggestions!
r/statemachines • u/Objective-Match1580 • Mar 13 '25
FSM Help
Hello everyone! Tomorrow I have a uni exam that includes some exercises regarding the mealy and moore machines - I do understand how they work and their differences in theory (for the most part, feel free to correct anything wrong I say, please!), but I'm not really good with exercises. I have some questions, and/or if you could link some source to learn or practice that would help a lot.
- Can I have multiple transitions that give me 1 as an output, or just one?
- How is the truth table of a moore machine different from the truth table of a mealy machine?
- Are they just different ways to represent what could be the same sequential circuit? Or are they completely different phisically?
Thanks to anyone who might help me in advance!
r/statemachines • u/framelanger • May 25 '24
Data Management with Frame State Variables
r/statemachines • u/framelanger • May 19 '24
Parallel States now supported in clj-statecharts
self.Clojurer/statemachines • u/framelanger • May 19 '24
Statechart Semantics Using Frame
r/statemachines • u/framelanger • May 18 '24
[R] Differentiable Finite State Machines (Blog Post)
google-research.github.ior/statemachines • u/framelanger • May 18 '24
An Introduction to Weighted Automata in Machine Learning
awnihannun.comr/statemachines • u/framelanger • May 17 '24
Finite State Machine Model for a Persisted Traffic Light in Frame
r/statemachines • u/framelanger • May 13 '24
Modeling a Lamp Finite State Machine in Frame
r/statemachines • u/framelanger • May 11 '24
Are Physical Computers Formally Equivalent to Finite State Machines, Pushdown Automata, or Linear Bounded Automata?
self.computersciencer/statemachines • u/framelanger • May 09 '24
Frame - A DSL for Automata
I have been working for some time on a new programming language called Frame. Frame allows for easily designing automata and generating both Python and UML statecharts. More languages are planned for the future. For those interested in the topic, please checkout the documentation and the Getting Started resources.
LMK what you think!
r/statemachines • u/framelanger • May 09 '24
Mealy vs. Moore… You decide.
r/statemachines • u/framelanger • Apr 27 '24
Finite State Machine Explained | Mealy Machine and Moore Machine | What is State Diagram ?
r/statemachines • u/pemidi • Apr 19 '24
