# sushi3085/terminalgame architecture

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

- Interactive diagram: https://gitdiagram.com/sushi3085/terminalgame
- Repository: https://github.com/sushi3085/terminalgame

## Overview

TerminalGame combines a reusable C# terminal UI framework with a playable, four-chapter JRPG. The player enters through the demo, advances through location/story interactions and menus, and encounters turn-based battles; game rules and state are separate from presentation. The framework handles input, scene lifecycle, widgets, text layout, and terminal rendering. The README documents content loading, saving, and headless rendering; some of those implementation relationships are not visible in the sampled excerpts, so uncertain links are omitted.

Main entry points: [`src/TerminalGame.Rpg/State/GameSession.cs`](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/GameSession.cs) (Game Session), [`src/TerminalGame.Demo/LocationScene.cs`](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/LocationScene.cs) (Location Scene), [`src/TerminalGame.Demo/Program.cs`](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/Program.cs) (Demo Startup), [`src/TerminalGame.Demo/BattleScene.cs`](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/BattleScene.cs) (Battle Scene)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_demo["Playable JRPG"]
  node_program["Demo Startup<br/>[Program.cs]"]
  node_game["Game Setup<br/>[Game.cs]"]
  node_title["Title Scene<br/>[TitleScene.cs]"]
  node_location["Location Scene<br/>[LocationScene.cs]"]
  node_battle["Battle Scene<br/>[BattleScene.cs]"]
  node_shops["Shop Scene<br/>[ShopScene.cs]"]
  node_partyui["Party Menu<br/>[PartyMenuScene.cs]"]
end

subgraph group_rpg["Game Rules"]
  node_content[("Content Database<br/>[ContentDb.cs]")]
  node_session["Game Session<br/>[GameSession.cs]"]
  node_members["Party Members<br/>[PartyMember.cs]"]
  node_scripts["Event Scripts<br/>[ScriptRunner.cs]"]
  node_world["World Rules<br/>[WorldRules.cs]"]
  node_story["Story Rules<br/>[StoryRules.cs]"]
  node_engine["Battle Engine<br/>[BattleEngine.cs]"]
  node_auto["Auto Battle<br/>[AutoPolicy.cs]"]
  node_save["Save Data<br/>[SaveData.cs]"]
end

subgraph group_runtime["UI Runtime"]
  node_application["Application Loop<br/>[Application.cs]"]
  node_scene["Scene Lifecycle<br/>[Scene.cs]"]
  node_console["Console Backend<br/>[ConsoleBackend.cs]"]
end

subgraph group_presentation["UI Presentation"]
  node_widgets["Widgets<br/>[Widget.cs]"]
  node_dialogue["Dialogue Box<br/>[DialogueBox.cs]"]
  node_menus["Menu List<br/>[MenuList.cs]"]
  node_layout["Text Layout<br/>[TextLayout.cs]"]
  node_markup["Styled Markup<br/>[Markup.cs]"]
  node_canvas["Canvas<br/>[Canvas.cs]"]
  node_screen["Screen Buffer<br/>[ScreenBuffer.cs]"]
  node_renderer["Frame Renderer<br/>[FrameRenderer.cs]"]
end

node_player(("Player"))
node_terminal(("Terminal"))

node_player -->|"starts game"| node_program
node_program -->|"runs"| node_application
node_program -->|"starts at"| node_title
node_program -->|"uses"| node_game
node_game -->|"loads"| node_content
node_game -->|"creates"| node_session
node_title -.->|"begins adventure"| node_location
node_location -->|"runs events"| node_scripts
node_location -->|"opens battle"| node_battle
node_location -->|"opens shop"| node_shops
node_location -->|"opens menu"| node_partyui
node_partyui -->|"reads state"| node_session
node_shops -->|"updates state"| node_session
node_battle -->|"runs turns"| node_engine
node_battle -->|"requests policy"| node_auto
node_battle -->|"uses party"| node_session
node_engine -->|"uses party"| node_session
node_session -->|"resolves definitions"| node_content
node_session -->|"creates members"| node_members
node_members -->|"reads definitions"| node_content
node_location -.->|"applies world rules"| node_world
node_location -.->|"checks story"| node_story
node_session -.->|"serializes state"| node_save
node_application -->|"dispatches input"| node_scene
node_application -->|"reads input"| node_console
node_console -->|"writes ANSI"| node_terminal
node_scene -->|"manages focus"| node_widgets
node_scene -->|"draws on"| node_canvas
node_widgets -.->|"draws through"| node_canvas
node_dialogue -->|"parses text"| node_markup
node_dialogue -->|"paginates with"| node_layout
node_menus -->|"fits labels"| node_layout
node_canvas -->|"writes cells"| node_screen
node_application -->|"renders frame"| node_renderer
node_renderer -->|"compares buffers"| node_screen
node_renderer -.->|"outputs frame"| node_console

click node_program "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/Program.cs"
click node_game "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/Game.cs"
click node_title "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/TitleScene.cs"
click node_location "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/LocationScene.cs"
click node_battle "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/BattleScene.cs"
click node_shops "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/ShopScene.cs"
click node_partyui "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/PartyMenuScene.cs"
click node_content "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Data/ContentDb.cs"
click node_session "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/GameSession.cs"
click node_members "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/PartyMember.cs"
click node_scripts "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Script/ScriptRunner.cs"
click node_world "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/World/WorldRules.cs"
click node_story "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/World/StoryRules.cs"
click node_engine "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Battle/BattleEngine.cs"
click node_auto "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Battle/AutoPolicy.cs"
click node_save "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/SaveData.cs"
click node_application "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Runtime/Application.cs"
click node_scene "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Runtime/Scene.cs"
click node_console "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Backends/ConsoleBackend.cs"
click node_widgets "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/Widget.cs"
click node_dialogue "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/DialogueBox.cs"
click node_menus "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/MenuList.cs"
click node_layout "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Text/TextLayout.cs"
click node_markup "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Text/Markup.cs"
click node_canvas "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/Canvas.cs"
click node_screen "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/ScreenBuffer.cs"
click node_renderer "https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/FrameRenderer.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_game,node_title,node_location,node_battle,node_shops,node_partyui toneBlue
class node_content,node_session,node_members,node_scripts,node_world,node_story,node_engine,node_auto,node_save toneAmber
class node_application,node_scene,node_console toneMint
class node_widgets,node_dialogue,node_menus,node_layout,node_markup,node_canvas,node_screen,node_renderer toneRose
class node_player,node_terminal toneIndigo
```

## Components

### Playable JRPG

- [Demo Startup](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/Program.cs): `src/TerminalGame.Demo/Program.cs`
- [Game Setup](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/Game.cs): `src/TerminalGame.Demo/Game.cs`
- [Title Scene](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/TitleScene.cs): `src/TerminalGame.Demo/TitleScene.cs`
- [Location Scene](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/LocationScene.cs): `src/TerminalGame.Demo/LocationScene.cs`
- [Battle Scene](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/BattleScene.cs): `src/TerminalGame.Demo/BattleScene.cs`
- [Shop Scene](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/ShopScene.cs): `src/TerminalGame.Demo/ShopScene.cs`
- [Party Menu](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Demo/PartyMenuScene.cs): `src/TerminalGame.Demo/PartyMenuScene.cs`

### Game Rules

- [Content Database](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Data/ContentDb.cs): `src/TerminalGame.Rpg/Data/ContentDb.cs`
- [Game Session](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/GameSession.cs): `src/TerminalGame.Rpg/State/GameSession.cs`
- [Party Members](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/PartyMember.cs): `src/TerminalGame.Rpg/State/PartyMember.cs`
- [Event Scripts](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Script/ScriptRunner.cs): `src/TerminalGame.Rpg/Script/ScriptRunner.cs`
- [World Rules](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/World/WorldRules.cs): `src/TerminalGame.Rpg/World/WorldRules.cs`
- [Story Rules](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/World/StoryRules.cs): `src/TerminalGame.Rpg/World/StoryRules.cs`
- [Battle Engine](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Battle/BattleEngine.cs): `src/TerminalGame.Rpg/Battle/BattleEngine.cs`
- [Auto Battle](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/Battle/AutoPolicy.cs): `src/TerminalGame.Rpg/Battle/AutoPolicy.cs`
- [Save Data](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Rpg/State/SaveData.cs): `src/TerminalGame.Rpg/State/SaveData.cs`

### UI Runtime

- [Application Loop](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Runtime/Application.cs): `src/TerminalGame.Tui/Runtime/Application.cs`
- [Scene Lifecycle](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Runtime/Scene.cs): `src/TerminalGame.Tui/Runtime/Scene.cs`
- [Console Backend](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Backends/ConsoleBackend.cs): `src/TerminalGame.Tui/Backends/ConsoleBackend.cs`

### UI Presentation

- [Widgets](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/Widget.cs): `src/TerminalGame.Tui/Widgets/Widget.cs`
- [Dialogue Box](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/DialogueBox.cs): `src/TerminalGame.Tui/Widgets/DialogueBox.cs`
- [Menu List](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Widgets/MenuList.cs): `src/TerminalGame.Tui/Widgets/MenuList.cs`
- [Text Layout](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Text/TextLayout.cs): `src/TerminalGame.Tui/Text/TextLayout.cs`
- [Styled Markup](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Text/Markup.cs): `src/TerminalGame.Tui/Text/Markup.cs`
- [Canvas](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/Canvas.cs): `src/TerminalGame.Tui/Rendering/Canvas.cs`
- [Screen Buffer](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/ScreenBuffer.cs): `src/TerminalGame.Tui/Rendering/ScreenBuffer.cs`
- [Frame Renderer](https://github.com/sushi3085/terminalgame/blob/main/src/TerminalGame.Tui/Rendering/FrameRenderer.cs): `src/TerminalGame.Tui/Rendering/FrameRenderer.cs`

### Other components

- **Player**
- **Terminal**

## Connections

- Player → Demo Startup: starts game (evidence: `README.md`)
- Demo Startup → Application Loop: runs (evidence: `src/TerminalGame.Demo/Program.cs`)
- Demo Startup → Title Scene: starts at (evidence: `src/TerminalGame.Demo/Program.cs`)
- Demo Startup → Game Setup: uses (evidence: `src/TerminalGame.Demo/Program.cs`)
- Game Setup → Content Database: loads (evidence: `src/TerminalGame.Demo/Game.cs`)
- Game Setup → Game Session: creates (evidence: `src/TerminalGame.Demo/Game.cs`)
- Title Scene → Location Scene: begins adventure
- Location Scene → Event Scripts: runs events (evidence: `src/TerminalGame.Demo/LocationScene.cs`)
- Location Scene → Battle Scene: opens battle (evidence: `src/TerminalGame.Demo/LocationScene.cs`)
- Location Scene → Shop Scene: opens shop (evidence: `src/TerminalGame.Demo/LocationScene.cs`)
- Location Scene → Party Menu: opens menu (evidence: `src/TerminalGame.Demo/LocationScene.cs`)
- Party Menu → Game Session: reads state (evidence: `src/TerminalGame.Demo/PartyMenuScene.cs`)
- Shop Scene → Game Session: updates state (evidence: `src/TerminalGame.Demo/ShopScene.cs`)
- Battle Scene → Battle Engine: runs turns (evidence: `src/TerminalGame.Demo/BattleScene.cs`)
- Battle Scene → Auto Battle: requests policy (evidence: `src/TerminalGame.Demo/BattleScene.cs`)
- Battle Scene → Game Session: uses party (evidence: `src/TerminalGame.Demo/BattleScene.cs`)
- Battle Engine → Game Session: uses party (evidence: `src/TerminalGame.Rpg/Battle/BattleEngine.cs`)
- Game Session → Content Database: resolves definitions (evidence: `src/TerminalGame.Rpg/State/GameSession.cs`)
- Game Session → Party Members: creates members (evidence: `src/TerminalGame.Rpg/State/GameSession.cs`)
- Party Members → Content Database: reads definitions (evidence: `src/TerminalGame.Rpg/State/PartyMember.cs`)
- Location Scene → World Rules: applies world rules
- Location Scene → Story Rules: checks story
- Game Session → Save Data: serializes state (evidence: `src/TerminalGame.Rpg/State/SaveData.cs`)
- Application Loop → Scene Lifecycle: dispatches input (evidence: `src/TerminalGame.Tui/Runtime/Application.cs`)
- Application Loop → Console Backend: reads input (evidence: `src/TerminalGame.Tui/Runtime/Application.cs`)
- Console Backend → Terminal: writes ANSI (evidence: `src/TerminalGame.Tui/Backends/ConsoleBackend.cs`)
- Scene Lifecycle → Widgets: manages focus (evidence: `src/TerminalGame.Tui/Runtime/Scene.cs`)
- Scene Lifecycle → Canvas: draws on (evidence: `src/TerminalGame.Tui/Runtime/Scene.cs`)
- Widgets → Canvas: draws through
- Dialogue Box → Styled Markup: parses text (evidence: `src/TerminalGame.Tui/Widgets/DialogueBox.cs`)
- Dialogue Box → Text Layout: paginates with (evidence: `src/TerminalGame.Tui/Widgets/DialogueBox.cs`)
- Menu List → Text Layout: fits labels (evidence: `src/TerminalGame.Tui/Widgets/MenuList.cs`)
- Canvas → Screen Buffer: writes cells (evidence: `src/TerminalGame.Tui/Rendering/Canvas.cs`)
- Application Loop → Frame Renderer: renders frame (evidence: `src/TerminalGame.Tui/Runtime/Application.cs`)
- Frame Renderer → Screen Buffer: compares buffers (evidence: `src/TerminalGame.Tui/Rendering/FrameRenderer.cs`)
- Frame Renderer → Console Backend: outputs frame
