# am-kantox/finitomata architecture

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

- Interactive diagram: https://gitdiagram.com/am-kantox/finitomata
- Repository: https://github.com/am-kantox/finitomata

## Overview

##### Main Components

a) Core FSM Engine:
- State Management
- Transition Handler
- Callback System

b) Supporting Systems:
- Supervision Tree
- Distribution System
- Persistence Layer
- Caching System
- Testing Framework
- Telemetry Integration

**┌─────────────────────────────────────────────────────────────┐**
- Client Applications                      │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Finitomata Interface                      │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
- FSM API   │  │ Pool API    │  │ Distribution API    │  │
- ┘  └─────────────┘  └─────────────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Core Components                          │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
- Parser    │  │    Flow     │  │  State Management   │  │
- ┘  └─────────────┘  └─────────────────────┘  │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
- Transitions │  │  Callbacks  │  │     Throttler       │  │
- ┘  └─────────────┘  └─────────────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────────┐**
- Support Systems                           │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
- Supervision │  │ Persistence │  │      Cache          │  │
- ┘  └─────────────┘  └─────────────────────┘  │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
- Telemetry  │  │   Testing   │  │    Distribution     │  │
- ┘  └─────────────┘  └─────────────────────┘  │
- ┘

##### Important Elements to Highlight

a) FSM Core:
- Callback system (on_transition, on_failure, on_enter, on_exit, on_terminate, on_timer)
- State validation and transition management

b) Distribution Features:
- Cluster communication paths
- Pool management
- Role of Infinitomata for distributed operations

c) Integration Points:
- Ecto integration capabilities
- Telemetry hooks
- Testing framework integration

##### Implementation Details

- Nested components to show hierarchy
- Clear labeling of components and interactions

This architecture reflects Finitomata's nature as a sophisticated FSM framework with distributed capabilities, persistence options, and strong integration features, while maintaining Elixir's supervision and fault-tolerance principles.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Applications"]
        App1[Application 1]
        App2[Application 2]
    end

    subgraph Interface["Finitomata Interface"]
        FSM_API[FSM API]
        Pool_API[Pool API]
        Dist_API["Distribution API"]
    end

    subgraph Core["Core Components"]
        subgraph Parser["Parser Component"]
            PlantUML[PlantUML Parser]
            Mermaid[Mermaid Parser]
        end

        subgraph StateMan["State Management"]
            State[State Handler]
            Trans[Transition Handler]
            Flow[Flow Manager]
        end

        subgraph Throttle["Throttling"]
            Consumer[Consumer]
            Producer[Producer]
        end
    end

    subgraph Support["Support Systems"]
        subgraph Supervision["Supervision System"]
            Manager[Manager]
            Supervisor[Supervisor]
        end

        subgraph Distribution["Distribution System"]
            ClusterInfo[Cluster Info]
            GroupMon[Group Monitor]
            DistSuper[Supervisor]
        end

        subgraph Persistence["Persistence Layer"]
            Protocol[Protocol]
            Persistable[Persistable]
        end

        Cache[Cache System]
        Testing[Testing Framework]
        Telemetry[Telemetry]
        Pool[Pool Management]
    end

    Client --> Interface
    Interface --> Core
    Core --> Support

    %% Component mappings
    click PlantUML "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/parser/plant_uml.ex"
    click Mermaid "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/parser/mermaid.ex"
    click Parser "https://github.com/am-kantox/finitomata/tree/main/lib/finitomata/parser/"
    click State "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/defstate.ex"
    click Trans "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/transition.ex"
    click Flow "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/flow.ex"
    click Manager "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/supervision/manager.ex"
    click Supervisor "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/supervision/supervisor.ex"
    click Supervision "https://github.com/am-kantox/finitomata/tree/main/lib/finitomata/supervision/"
    click ClusterInfo "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/distributed/cluster_info.ex"
    click GroupMon "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/distributed/group_monitor.ex"
    click DistSuper "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/distributed/supervisor.ex"
    click Distribution "https://github.com/am-kantox/finitomata/tree/main/lib/finitomata/distributed/"
    click Protocol "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/persistency/protocol.ex"
    click Persistable "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/persistency/persistable.ex"
    click Persistence "https://github.com/am-kantox/finitomata/tree/main/lib/finitomata/persistency/"
    click Cache "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/cache.ex"
    click Testing "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/test/ex_unit.ex"
    click Telemetry "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/telemetria.ex"
    click Consumer "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/throttler/consumer.ex"
    click Producer "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/throttler/producer.ex"
    click Throttle "https://github.com/am-kantox/finitomata/tree/main/lib/finitomata/throttler/"
    click Pool "https://github.com/am-kantox/finitomata/blob/main/lib/finitomata/pool/actor.ex"

    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef interface fill:#fd8,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef support fill:#9f9,stroke:#333,stroke-width:2px

    class App1,App2 client
    class FSM_API,Pool_API,Dist_API interface
    class PlantUML,Mermaid,State,Trans,Flow,Consumer,Producer core
    class Manager,Supervisor,ClusterInfo,GroupMon,DistSuper,Protocol,Persistable,Cache,Testing,Telemetry,Pool support
```
