# yanten/statemachine architecture

> Architecture diagram of the GitHub repository yanten/statemachine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yanten/statemachine
- Repository: https://github.com/yanten/statemachine

## Overview

A compact C library for running finite state machines. A caller defines states, transitions, events, and optional callbacks, initializes a machine, then submits events; the runtime searches the current state and its parents, selects a guarded transition, runs lifecycle/action callbacks, updates state, and reports the outcome. The source excerpt supports the core dispatch and query behavior; no external services or persistence are indicated.

Main entry points: [`src/stateMachine.c`](https://github.com/yanten/statemachine/blob/master/src/stateMachine.c) (Event runtime), [`src/stateMachine.h`](https://github.com/yanten/statemachine/blob/master/src/stateMachine.h) (FSM API)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("Library caller"))
node_model["FSM model<br/>[stateMachine.h]"]
node_api["FSM API<br/>[stateMachine.h]"]
node_runtime["Event runtime<br/>[stateMachine.c]"]
node_callbacks["User callbacks"]
node_outcome["State and result<br/>[stateMachine.h]"]

node_caller -->|"defines states"| node_model
node_caller -->|"initializes machine"| node_api
node_caller -->|"submits event"| node_api
node_model -->|"configures dispatch"| node_runtime
node_api -->|"dispatches event"| node_runtime
node_runtime -->|"checks guard"| node_callbacks
node_runtime -->|"runs actions"| node_callbacks
node_runtime -->|"runs entry/exit"| node_callbacks
node_runtime -->|"updates and reports"| node_outcome
node_caller -->|"queries state"| node_outcome

click node_model "https://github.com/yanten/statemachine/blob/master/src/stateMachine.h"
click node_api "https://github.com/yanten/statemachine/blob/master/src/stateMachine.h"
click node_runtime "https://github.com/yanten/statemachine/blob/master/src/stateMachine.c"
click node_outcome "https://github.com/yanten/statemachine/blob/master/src/stateMachine.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_caller,node_model toneIndigo
class node_api toneMint
class node_runtime,node_outcome toneTeal
class node_callbacks toneBlue
```

## Components

### Other components

- **Library caller**
- [FSM model](https://github.com/yanten/statemachine/blob/master/src/stateMachine.h): `src/stateMachine.h`
- [FSM API](https://github.com/yanten/statemachine/blob/master/src/stateMachine.h): `src/stateMachine.h`
- [Event runtime](https://github.com/yanten/statemachine/blob/master/src/stateMachine.c): `src/stateMachine.c`
- **User callbacks**
- [State and result](https://github.com/yanten/statemachine/blob/master/src/stateMachine.h): `src/stateMachine.h`

## Connections

- Library caller → FSM model: defines states
- Library caller → FSM API: initializes machine
- Library caller → FSM API: submits event
- FSM model → Event runtime: configures dispatch
- FSM API → Event runtime: dispatches event
- Event runtime → User callbacks: checks guard
- Event runtime → User callbacks: runs actions
- Event runtime → User callbacks: runs entry/exit
- Event runtime → State and result: updates and reports
- Library caller → State and result: queries state
