# snowbillr/turn-based-game-engine architecture

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

- Interactive diagram: https://gitdiagram.com/snowbillr/turn-based-game-engine
- Repository: https://github.com/snowbillr/turn-based-game-engine

## Overview

##### Core Components Layer
- Engine (engine.ts) - Central coordinator
- Flow (flow.ts) - Game flow controller
- FlowBuilder (flow_builder.ts) - Game flow construction
- FlowNode (flow_node.ts) - Individual game states
- Player (player.ts) - Player management
- Data Structures (queue.ts, stack.ts) - Supporting components

##### Game Implementation Layer
- How specific games (like Tic-tac-toe) are implemented:
- Board (board.ts) and game-specific main.ts
- How it connects to the core engine

##### Component Relationships
- Flow Builder → Flow (creation relationship)
- Flow → Flow Node (composition)
- Engine → Flow (management)
- Engine → Player (coordination)
- Game Implementation → Engine (usage)

- [Game Implementation Layer]
- ↓
- [Core Engine Layer]
- ↓
- [Data Structures Layer]

##### Important Details
- Extensibility points where new games can be implemented
- Turn-based nature of the engine
- Flow control mechanisms
- How state management works between components

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#a8d1f0,stroke:#333
    classDef game fill:#90EE90,stroke:#333
    classDef data fill:#FFE5B4,stroke:#333
    classDef main fill:#FFB6C1,stroke:#333

    %% Core Engine Layer
    subgraph CoreEngine["Core Engine Components"]
        Engine["Engine<br/>(Central Coordinator)"]
        Flow["Flow<br/>(Game Flow Controller)"]
        FlowBuilder["FlowBuilder<br/>(Game Flow Construction)"]
        FlowNode["FlowNode<br/>(Game States)"]
        Player["Player<br/>(Player Management)"]
    end

    %% Data Structures Layer
    subgraph DataStructures["Data Structures"]
        Queue["Queue"]
        Stack["Stack"]
    end

    %% Game Implementation Layer
    subgraph GameImpl["Game Implementation"]
        Board["Board<br/>(Tic-tac-toe)"]
        GameMain["Game Main<br/>(Tic-tac-toe Entry)"]
    end

    %% Main Entry Point
    MainEntry["Main Entry Point"]

    %% Relationships
    FlowBuilder --> Flow
    Flow --> FlowNode
    Engine --> Flow
    Engine --> Player
    GameMain --> Engine
    Board --> Engine
    Player --> Queue
    Flow --> Stack
    MainEntry --> Engine
    MainEntry --> GameImpl

    %% Click Events
    click Engine "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/engine.ts"
    click Flow "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/flow.ts"
    click FlowBuilder "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/flow_builder.ts"
    click FlowNode "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/flow_node.ts"
    click Player "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/player.ts"
    click Queue "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/queue.ts"
    click Stack "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/lib/stack.ts"
    click Board "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/tic-tac-toe/board.ts"
    click GameMain "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/tic-tac-toe/main.ts"
    click MainEntry "https://github.com/snowbillr/turn-based-game-engine/blob/main/src/main.ts"

    %% Style Applications
    class Engine,Flow,FlowBuilder,FlowNode,Player core
    class Board,GameMain game
    class Queue,Stack data
    class MainEntry main

    %% Legend
    subgraph Legend
        CoreComp["Core Component"]:::core
        GameComp["Game Component"]:::game
        DataComp["Data Structure"]:::data
        MainComp["Entry Point"]:::main
    end
```
