# adam-zethraeus/statetree architecture

> Architecture diagram of the GitHub repository adam-zethraeus/statetree, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adam-zethraeus/statetree
- Repository: https://github.com/adam-zethraeus/statetree

## Overview

##### Main Components Identification

The system should be divided into these core components:

a) Core State Management Layer
- StateTree Foundation
- State System
- Runtime Engine
- Behavior System

b) UI Integration Layers
- SwiftUI Integration
- Imperative UI Integration

c) Supporting Systems
- Intent System
- Playback System
- Testing Infrastructure

**┌─────────────────────────────────────────────┐**
- Client Applications            │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- UI Integration Layer             │
- ┌─────────────┐        ┌──────────────┐  │
- SwiftUI   │        │ ImperativeUI │  │
- ┘        └──────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Core State Layer               │
- ┌──────────┐ ┌─────────┐ ┌────────────┐   │
- StateTree │ │Behavior │ │  Intents   │   │
- Foundation│ │ System  │ │   System   │   │
- ┘ └─────────┘ └────────────┘   │
- ┘
- ↓
**┌─────────────────────────────────────────────┐**
- Supporting Systems               │
- ┌─────────┐ ┌──────────┐ ┌──────────────┐  │
- Playback │ │ Testing  │ │Tree Actor    │  │
- System   │ │Framework │ │              │  │
- ┘ └──────────┘ └──────────────┘  │
- ┘

##### Component Relationships

- Data flow between layers
- Dependencies between components
- State update propagation paths
- Event handling routes

##### Key Elements to Highlight

a) State Management:
- Tree structure representation
- State update mechanism
- Dependency injection system
- Field and node management

b) Behavior System:
- Async/Sync behaviors
- Stream handling
- Behavior tracking

c) Integration Points:
- SwiftUI bindings
- Imperative UI bridges
- Testing interfaces
- Playback capabilities

##### Implementation Details

- The tree-based state structure
- The actor-based concurrency model
- The projection system for state access
- The routing mechanism
- The intent handling system

This architectural representation should help developers understand how StateTree manages application state and integrates with different UI frameworks while maintaining a clear separation of concerns.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Applications"]
        App[Client App]
    end

    subgraph UI["UI Integration Layer"]
        SwiftUI["SwiftUI Integration"]:::ui
        ImpUI["Imperative UI"]:::ui
    end

    subgraph Core["Core State Layer"]
        Foundation["StateTree Foundation"]:::core
        State["State System"]:::core
        Runtime["Runtime Engine"]:::core
        Behavior["Behavior System"]:::core
        Projection["State Projection"]:::core
        Dependency["Dependency System"]:::core
        Routing["Routing System"]:::core
    end

    subgraph Support["Supporting Systems"]
        Intent["Intent System"]:::support
        Playback["Playback System"]:::support
        Testing["Testing Infrastructure"]:::support
        TreeActor["Tree Actor System"]:::support
    end

    subgraph Tests["Testing Components"]
        BehaviorTest["Behavior Tests"]:::test
        StateTest["State Tree Tests"]:::test
        UITest["UI Integration Tests"]:::test
    end

    %% Relationships
    App --> SwiftUI & ImpUI
    SwiftUI & ImpUI --> Foundation
    Foundation --> State
    State --> Runtime
    Runtime --> Behavior
    Runtime --> Projection
    Runtime --> Dependency
    Runtime --> Routing
    State --> Intent
    State --> TreeActor
    Testing --> Playback
    Testing --> BehaviorTest & StateTest & UITest

    %% Click Events
    click Foundation "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/Foundation"
    click State "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/System"
    click Runtime "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/System/Runtime"
    click Behavior "https://github.com/adam-zethraeus/statetree/tree/main/Sources/Behavior"
    click SwiftUI "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTreeSwiftUI"
    click ImpUI "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTreeImperativeUI"
    click Intent "https://github.com/adam-zethraeus/statetree/tree/main/Sources/Intents"
    click Playback "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTreePlayback"
    click Testing "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTreeTesting"
    click TreeActor "https://github.com/adam-zethraeus/statetree/tree/main/Sources/TreeActor"
    click Projection "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/System/Projection"
    click Dependency "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/System/Dependency"
    click Routing "https://github.com/adam-zethraeus/statetree/tree/main/Sources/StateTree/System/Rules/Routing"
    click BehaviorTest "https://github.com/adam-zethraeus/statetree/tree/main/Tests/BehaviorTests"
    click StateTest "https://github.com/adam-zethraeus/statetree/tree/main/Tests/StateTreeTests"
    click UITest "https://github.com/adam-zethraeus/statetree/tree/main/Tests/StateTreeSwiftUITests"

    %% Styles
    classDef core fill:#a8d1f0,stroke:#2980b9
    classDef ui fill:#a8f0c6,stroke:#27ae60
    classDef support fill:#f0d6a8,stroke:#f39c12
    classDef test fill:#f0a8a8,stroke:#c0392b
    
    %% Legend
    subgraph Legend
        CoreLegend["Core Components"]:::core
        UILegend["UI Components"]:::ui
        SupportLegend["Support Systems"]:::support
        TestLegend["Test Components"]:::test
    end
```
