# tkem/fsmlite architecture

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

- Interactive diagram: https://gitdiagram.com/tkem/fsmlite
- Repository: https://github.com/tkem/fsmlite

## Overview

##### Project type and purpose
- fsmlite is a lightweight, header-only C++11 finite state machine (FSM) framework (a reusable library), not a standalone application.
- Its goal is to provide a compile-time transition table and runtime engine for defining state machines via C++ templates.

##### File structure
- Top‐level build and CI:
- .github/workflows/ci.yml, .travis.yml – continuous integration pipelines
- CMakeLists.txt, Makefile.am, autogen.sh, configure.ac, m4/… – GNU Autotools + optional CMake build support
- Source tree:
- src/fsm.h – the single public header defining the fsm template, transition table machinery, row/mem_fn_row helpers
- Tests:
- tests/*.cpp – unit tests showing usage patterns, covering core FSM behavior and template metaprogramming constructs
- Documentation:
- docs/ – Sphinx/ReST sources and Doxygen integration

##### README for additional insights
- Describes the core abstraction: class fsm<Derived> with a nested transition_table of rows
- Shows example “player” FSM with states, events, guards, and actions
- Points to unit tests as canonical usage examples

##### Be detailed and capture all architectural elements
- Interplay of template definitions in src/fsm.h with user-supplied Derived classes
- Flow: Autotools → configure → make → make test → make doc
- Don’t hesitate to break down “transition_table” into subcomponents (rows, table, guards, actions) for clarity

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & CI Layer
    subgraph "Build & CI"
        direction TB
        subgraph "Autotools" 
            direction TB
            AC["configure.ac"]:::build
            AG["autogen.sh"]:::build
            MA_A["Makefile.am"]:::build
            M4["m4/"]:::build
        end
        subgraph "CMake Wrapper"
            direction TB
            CMake["CMakeLists.txt"]:::build
        end
        subgraph "CI Pipelines"
            direction TB
            GH["GitHub Actions CI"]:::build
            TR["Travis CI"]:::build
        end
    end

    %% Core Library Layer
    subgraph "Core FSM Library"
        direction TB
        FSM["fsm<Derived> engine"]:::core
        TT["transition_table"]:::core
        ROW["row"]:::core
        MFR["mem_fn_row"]:::core
    end

    %% User Code & Tests Layer
    subgraph "User Code & Tests"
        direction TB
        TESTS["tests/"]:::user
        CTest["tests/CMakeLists.txt"]:::user
        MTest["tests/Makefile.am"]:::user
    end

    %% Documentation Layer
    subgraph "Documentation"
        direction TB
        Dox["docs/Doxyfile"]:::doc
        RST["docs/index.rst"]:::doc
        Conf["docs/conf.py"]:::doc
        MA_D["docs/Makefile.am"]:::doc
        Req["docs/requirements.txt"]:::doc
        GI["docs/.gitignore"]:::doc
    end

    %% Build Flow
    GH -->|"triggers build"| AC
    TR -->|"triggers build"| CMake
    AC -->|"configures"| FSM
    CMake -->|"generates build files for"| FSM
    MA_A -->|"used by Autotools"| AC
    AG -->|"bootstraps Autotools"| AC
    M4 -->|"macros for"| AC

    %% Runtime Flow
    TESTS -->|"include fsm.h"| FSM
    FSM -->|"uses transition_table"| TT
    TT -->|"composed of"| ROW
    TT -->|"composed of"| MFR
    TESTS -->|"defines Derived FSMs"| FSM

    %% CI Test & Doc Steps
    GH -->|"runs tests"| TESTS
    TR -->|"runs tests"| TESTS
    GH -->|"builds docs"| Dox
    TR -->|"builds docs"| Dox

    %% Click Events
    click AC "https://github.com/tkem/fsmlite/blob/master/configure.ac"
    click AG "https://github.com/tkem/fsmlite/blob/master/autogen.sh"
    click MA_A "https://github.com/tkem/fsmlite/blob/master/Makefile.am"
    click M4 "https://github.com/tkem/fsmlite/tree/master/m4/"
    click CMake "https://github.com/tkem/fsmlite/blob/master/CMakeLists.txt"
    click GH "https://github.com/tkem/fsmlite/blob/master/.github/workflows/ci.yml"
    click TR "https://github.com/tkem/fsmlite/blob/master/.travis.yml"
    click FSM "https://github.com/tkem/fsmlite/blob/master/src/fsm.h"
    click MA_A "https://github.com/tkem/fsmlite/blob/master/src/Makefile.am"
    click TESTS "https://github.com/tkem/fsmlite/tree/master/tests/"
    click CTest "https://github.com/tkem/fsmlite/blob/master/tests/CMakeLists.txt"
    click MTest "https://github.com/tkem/fsmlite/blob/master/tests/Makefile.am"
    click Dox "https://github.com/tkem/fsmlite/tree/master/docs/Doxyfile"
    click RST "https://github.com/tkem/fsmlite/blob/master/docs/index.rst"
    click Conf "https://github.com/tkem/fsmlite/blob/master/docs/conf.py"
    click MA_D "https://github.com/tkem/fsmlite/blob/master/docs/Makefile.am"
    click Req "https://github.com/tkem/fsmlite/blob/master/docs/requirements.txt"
    click GI "https://github.com/tkem/fsmlite/blob/master/docs/.gitignore"

    %% Styles
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef core fill:#add8e6,stroke:#333,stroke-width:1px
    classDef user fill:#98fb98,stroke:#333,stroke-width:1px
    classDef doc fill:#fffacd,stroke:#333,stroke-width:1px
```
