# remieven/ysgo architecture

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

- Interactive diagram: https://gitdiagram.com/remieven/ysgo
- Repository: https://github.com/remieven/ysgo

## Overview

##### Main Components

a) Core Components:
- Dialogue Runner (runner.go)
- Parser System (internal/parser)
- Evaluator (evaluator.go)
- Variable Storage System (variable/)
- Command System (command_storer.go)
- Function System (function_storer.go)

b) Supporting Components:
- Markup System (markup/)
- Expression Tree (internal/tree)
- Container Utilities (internal/container)

##### Component Relationships

**[Input: Yarn Script] → [Parser System]**
- ↓
**[Variable Storage] ← [Dialogue Runner] → [Command System]**
- ↑               ↓    ↑             ↑
- → [Evaluator] ←──────────┘
- ↑
- [Function System]

**[Markup System] ←──→ [Dialogue Runner]**

##### Detailed Component Descriptions

a) Parser System (Blue):
- Shows the flow from YarnSpinner syntax to parsed AST
- Lexer and parser components
- To the expression tree builder

b) Dialogue Runner (Green):
- Central component coordinating all operations
- Shows connections to all major subsystems
- Handles dialogue flow control

c) Storage Systems (Yellow):
- Variable Storage for maintaining state
- Command Storage for registered commands
- Function Storage for available functions

d) Evaluator (Orange):
- Shows expression evaluation flow
- Connects to variable and function systems

##### Implementation Details

- "pull" mode architecture
- Runtime parsing approach (vs compilation)
- Test plan integration points
- Extension points for custom commands and functions

##### Notes Section

A notes section mentioning:
- Runtime vs compile-time behavior
- Missing YarnSpinner features (localization, type checking)
- Integration capabilities with game engines
- Test coverage and validation points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        YS[Yarn Script]
    end

    subgraph "Parser Layer"
        PS[Parser System]:::parser
        LEX[Lexer]:::parser
        ET[Expression Tree]:::parser
    end

    subgraph "Core Layer"
        DR[Dialogue Runner]:::core
        EV[Evaluator]:::core
    end

    subgraph "Storage Layer"
        VS[Variable Storage]:::storage
        CS[Command System]:::storage
        FS[Function System]:::storage
    end

    subgraph "Utility Layer"
        MS[Markup System]:::utility
        CU[Container Utils]:::utility
    end

    %% Relationships
    YS --> PS
    PS --> LEX
    LEX --> ET
    ET --> DR
    DR <--> VS
    DR --> EV
    DR <--> CS
    DR <--> MS
    EV <--> VS
    EV <--> FS
    EV <--> CS
    DR -.-> CU

    %% Click Events
    click PS "https://github.com/RemiEven/ysgo/tree/main/internal/parser/"
    click LEX "https://github.com/RemiEven/ysgo/blob/main/internal/parser/yarnspinner_lexer.go"
    click ET "https://github.com/RemiEven/ysgo/tree/main/internal/tree/"
    click DR "https://github.com/RemiEven/ysgo/blob/main/runner.go"
    click EV "https://github.com/RemiEven/ysgo/blob/main/evaluator.go"
    click VS "https://github.com/RemiEven/ysgo/tree/main/variable/"
    click CS "https://github.com/RemiEven/ysgo/blob/main/command_storer.go"
    click FS "https://github.com/RemiEven/ysgo/blob/main/function_storer.go"
    click MS "https://github.com/RemiEven/ysgo/tree/main/markup/"
    click CU "https://github.com/RemiEven/ysgo/tree/main/internal/container/"

    %% Styling
    classDef parser fill:#2374ab,stroke:#000,stroke-width:2px,color:#fff
    classDef core fill:#47a025,stroke:#000,stroke-width:2px,color:#fff
    classDef storage fill:#f7b32b,stroke:#000,stroke-width:2px,color:#000
    classDef utility fill:#6c757d,stroke:#000,stroke-width:2px,color:#fff

    %% Legend
    subgraph Legend
        P[Parser Components]:::parser
        C[Core Components]:::core
        S[Storage Components]:::storage
        U[Utility Components]:::utility
        L1["--> Direct Flow"]
        L2["--> Optional Flow"]
    end
```
