# zshebjtzs/tree-grow-game architecture

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

- Interactive diagram: https://gitdiagram.com/zshebjtzs/tree-grow-game
- Repository: https://github.com/zshebjtzs/tree-grow-game

## Overview

Growth Tree is a browser strategy game in which players expand tree-shaped forces across a generated region graph and resolve structural combat. The main runtime coordinates setup, turns, validated growth, combat, feedback and match results; players can also play against a worker-based AI, follow a tutorial, save games and inspect replays. The graph emphasizes these product stages and the rule, map, state and presentation layers. Connections are limited to README statements and shown source references; tutorial internals are not in the supplied tree.

Main entry points: [`js/main.js`](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/main.js) (Game coordinator), [`js/ai/AIController.js`](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/AIController.js) (AI decisions), [`js/replay/ReplaySaveValidator.js`](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/replay/ReplaySaveValidator.js) (Save validation), [`js/core/MapManager.js`](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/core/MapManager.js) (Map generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_main["Game coordinator<br/>[main.js]"]
  node_appstate["Match configuration<br/>[AppState.js]"]
end

subgraph group_domain["Map and rules"]
  node_map["Map generation<br/>[MapManager.js]"]
  node_rules["Growth validation<br/>[RuleEngine.js]"]
  node_state["Game state<br/>[GameState.js]"]
  node_growth["Growth action"]
  node_combat["Combat resolution<br/>[CombatResolver.js]"]
  node_tracker["Match statistics<br/>[MatchTracker.js]"]
  node_history["Action history<br/>[MatchHistory.js]"]
end

subgraph group_opponents["AI opponent"]
  node_worker["AI worker<br/>[AIWorker.js]"]
  node_ai["AI decisions<br/>[AIController.js]"]
  node_profiles["Difficulty profiles"]
  node_evaluation["Position evaluation"]
  node_search["Adversarial search<br/>[SearchEngine.js]"]
end

subgraph group_experience["Player experience"]
  node_tutorial["Interactive tutorial"]
  node_renderer["Canvas rendering<br/>[CanvasDrawer.js]"]
  node_presentation["Combat presentation"]
  node_audio["Sound effects<br/>[AudioController.js]"]
end

subgraph group_records["Saves and replays"]
  node_save["Save encoding<br/>[SaveCodec.js]"]
  node_validator["Save validation"]
  node_replay["Replay session<br/>[ReplaySession.js]"]
end

node_player(("Player"))

node_player -->|"plays through"| node_main
node_main -->|"configures match"| node_appstate
node_main -->|"generates map"| node_map
node_main -->|"coordinates state"| node_state
node_main -->|"checks growth"| node_rules
node_main -->|"executes growth"| node_growth
node_main -->|"resolves combat"| node_combat
node_main -->|"records match"| node_tracker
node_main -->|"records actions"| node_history
node_rules -->|"reads adjacency"| node_map
node_main -->|"requests AI move"| node_worker
node_worker -->|"runs decision"| node_ai
node_ai -->|"uses difficulty"| node_profiles
node_ai -->|"evaluates positions"| node_evaluation
node_ai -->|"searches moves"| node_search
node_ai -->|"simulates combat"| node_combat
node_main -->|"renders game"| node_renderer
node_main -->|"presents combat"| node_presentation
node_main -->|"plays effects"| node_audio
node_main -->|"offers tutorial"| node_tutorial
node_main -->|"encodes saves"| node_save
node_main -->|"validates imports"| node_validator
node_main -->|"opens replays"| node_replay
node_validator -->|"rebuilds map"| node_map
node_validator -->|"checks state"| node_state
node_replay -->|"reads history"| node_history

click node_main "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/main.js"
click node_appstate "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/app/AppState.js"
click node_map "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/core/MapManager.js"
click node_rules "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/RuleEngine.js"
click node_state "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/GameState.js"
click node_growth "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/GrowthActionService.js"
click node_combat "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/CombatResolver.js"
click node_tracker "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/MatchTracker.js"
click node_history "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/MatchHistory.js"
click node_worker "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/AIWorker.js"
click node_ai "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/AIController.js"
click node_profiles "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/DifficultyProfiles.js"
click node_evaluation "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/PositionEvaluator.js"
click node_search "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/SearchEngine.js"
click node_tutorial "https://github.com/zshebjtzs/tree-grow-game/tree/main/js/tutorial"
click node_renderer "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/renderer/CanvasDrawer.js"
click node_presentation "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/presentation/PresentationController.js"
click node_audio "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/presentation/AudioController.js"
click node_save "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/storage/SaveCodec.js"
click node_validator "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/replay/ReplaySaveValidator.js"
click node_replay "https://github.com/zshebjtzs/tree-grow-game/blob/main/js/replay/ReplaySession.js"

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_main,node_appstate toneBlue
class node_map,node_rules,node_state,node_growth,node_combat,node_tracker,node_history toneAmber
class node_worker,node_ai,node_profiles,node_evaluation,node_search toneMint
class node_tutorial,node_renderer,node_presentation,node_audio toneRose
class node_save,node_validator,node_replay,node_player toneIndigo
```

## Components

### Game runtime

- [Game coordinator](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/main.js): `js/main.js`
- [Match configuration](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/app/AppState.js): `js/app/AppState.js`

### Map and rules

- [Map generation](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/core/MapManager.js): `js/core/MapManager.js`
- [Growth validation](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/RuleEngine.js): `js/game/RuleEngine.js`
- [Game state](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/GameState.js): `js/game/GameState.js`
- [Growth action](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/GrowthActionService.js): `js/game/GrowthActionService.js`
- [Combat resolution](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/CombatResolver.js): `js/game/CombatResolver.js`
- [Match statistics](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/MatchTracker.js): `js/game/MatchTracker.js`
- [Action history](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/game/MatchHistory.js): `js/game/MatchHistory.js`

### AI opponent

- [AI worker](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/AIWorker.js): `js/ai/AIWorker.js`
- [AI decisions](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/AIController.js): `js/ai/AIController.js`
- [Difficulty profiles](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/DifficultyProfiles.js): `js/ai/DifficultyProfiles.js`
- [Position evaluation](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/PositionEvaluator.js): `js/ai/PositionEvaluator.js`
- [Adversarial search](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/ai/SearchEngine.js): `js/ai/SearchEngine.js`

### Player experience

- [Interactive tutorial](https://github.com/zshebjtzs/tree-grow-game/tree/main/js/tutorial): `js/tutorial`
- [Canvas rendering](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/renderer/CanvasDrawer.js): `js/renderer/CanvasDrawer.js`
- [Combat presentation](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/presentation/PresentationController.js): `js/presentation/PresentationController.js`
- [Sound effects](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/presentation/AudioController.js): `js/presentation/AudioController.js`

### Saves and replays

- [Save encoding](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/storage/SaveCodec.js): `js/storage/SaveCodec.js`
- [Save validation](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/replay/ReplaySaveValidator.js): `js/replay/ReplaySaveValidator.js`
- [Replay session](https://github.com/zshebjtzs/tree-grow-game/blob/main/js/replay/ReplaySession.js): `js/replay/ReplaySession.js`

### Other components

- **Player**

## Connections

- Player → Game coordinator: plays through (evidence: `README.md`)
- Game coordinator → Match configuration: configures match (evidence: `README.md`)
- Game coordinator → Map generation: generates map (evidence: `README.md`)
- Game coordinator → Game state: coordinates state (evidence: `README.md`)
- Game coordinator → Growth validation: checks growth (evidence: `js/main.js`)
- Game coordinator → Growth action: executes growth (evidence: `js/main.js`)
- Game coordinator → Combat resolution: resolves combat (evidence: `js/main.js`)
- Game coordinator → Match statistics: records match (evidence: `README.md`)
- Game coordinator → Action history: records actions (evidence: `README.md`)
- Growth validation → Map generation: reads adjacency (evidence: `js/game/RuleEngine.js`)
- Game coordinator → AI worker: requests AI move (evidence: `README.md`)
- AI worker → AI decisions: runs decision (evidence: `js/ai/AIWorker.js`)
- AI decisions → Difficulty profiles: uses difficulty (evidence: `js/ai/AIController.js`)
- AI decisions → Position evaluation: evaluates positions (evidence: `js/ai/AIController.js`)
- AI decisions → Adversarial search: searches moves (evidence: `js/ai/AIController.js`)
- AI decisions → Combat resolution: simulates combat (evidence: `js/ai/AIController.js`)
- Game coordinator → Canvas rendering: renders game (evidence: `README.md`)
- Game coordinator → Combat presentation: presents combat (evidence: `js/main.js`)
- Game coordinator → Sound effects: plays effects (evidence: `js/main.js`)
- Game coordinator → Interactive tutorial: offers tutorial (evidence: `README.md`)
- Game coordinator → Save encoding: encodes saves (evidence: `js/main.js`)
- Game coordinator → Save validation: validates imports (evidence: `README.md`)
- Game coordinator → Replay session: opens replays (evidence: `README.md`)
- Save validation → Map generation: rebuilds map (evidence: `js/replay/ReplaySaveValidator.js`)
- Save validation → Game state: checks state (evidence: `js/replay/ReplaySaveValidator.js`)
- Replay session → Action history: reads history (evidence: `js/replay/ReplaySession.js`)
