# chincai-org/green-tech-2 architecture

> Architecture diagram of the GitHub repository chincai-org/green-tech-2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chincai-org/green-tech-2
- Repository: https://github.com/chincai-org/green-tech-2

## Overview

Green Tech 2 is an authoritative multiplayer PvPvE territory-building game. Players connect through the browser client, send gameplay inputs to the server, and receive snapshots from its deterministic 30 TPS simulation; account, store, and Almanac features provide persistent side workflows. The graph preserves the documented living-world, combat, progression, and client capabilities. Source excerpts are partial, so some subsystem links rely on README statements or SOURCE INDEX references rather than inspected call sites.

Main entry points: [`crates/sim/src/step.rs`](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/step.rs) (Tick and snapshots), [`client/js/main.js`](https://github.com/chincai-org/green-tech-2/blob/main/client/js/main.js) (Canvas game client), [`crates/server/src/lib.rs`](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/lib.rs) (HTTP and WebSocket server), [`crates/sim/src/grid.rs`](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/grid.rs) (Spatial grid and pathfinding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser game client"]
  node_client["Canvas game client<br/>[main.js]"]
  node_client_render["Rendering and audio<br/>[renderer.js]"]
  node_client_hud["HUD and Almanac<br/>[hud.js]"]
  node_client_almanac["Almanac view<br/>[almanac.js]"]
  node_client_modals["Store and account UI<br/>[modals.js]"]
  node_client_map["Minimap<br/>[minimap.js]"]
end

subgraph group_backend["Server and persistence"]
  node_server["HTTP and WebSocket server<br/>[lib.rs]"]
  node_session["Authentication and sessions<br/>[auth.rs]"]
  node_store["Store and checkout<br/>[shop.rs]"]
  node_persistence[("SQLite persistence<br/>[db.rs]")]
  node_almanac_service["Almanac persistence<br/>[almanac.rs]"]
  node_server_state["Match state<br/>[state.rs]"]
end

subgraph group_simulation["Deterministic simulation"]
  node_tick["Tick and snapshots<br/>[step.rs]"]
  node_world["World model<br/>[entities.rs]"]
  node_spatial["Spatial grid and pathfinding<br/>[grid.rs]"]
  node_combat["Combat and economy<br/>[combat.rs]"]
  node_living["Relics and combos<br/>[relics.rs]"]
  node_quests["Shrines and NPCs<br/>[quest_shrines.rs]"]
  node_director["World and wave directors<br/>[director.rs]"]
  node_climate["Climate and strains<br/>[climate.rs]"]
  node_ai["Bots and Lumberjacks<br/>[ai_bots.rs]"]
  node_rng["Deterministic randomness<br/>[rng.rs]"]
end

subgraph group_shared["Shared game protocol"]
  node_protocol["Wire protocol and DTOs<br/>[lib.rs]"]
end

node_player(("Player"))

node_player -->|"plays through"| node_client
node_client -->|"sends gameplay"| node_server
node_server -->|"broadcasts snapshots"| node_client
node_client -->|"renders world"| node_client_render
node_client -->|"shows HUD"| node_client_hud
node_client_hud -->|"shows Almanac"| node_client_almanac
node_client -->|"opens menus"| node_client_modals
node_client -->|"shows minimap"| node_client_map
node_client -->|"exchanges messages"| node_protocol
node_server -->|"uses wire DTOs"| node_protocol
node_server -->|"manages matches"| node_server_state
node_server -->|"handles sign-in"| node_session
node_server -->|"routes checkout"| node_store
node_server -->|"serves Almanac"| node_almanac_service
node_session -->|"reads and writes"| node_persistence
node_store -.->|"records purchases"| node_persistence
node_almanac_service -->|"reads and writes"| node_persistence
node_server_state -.->|"advances simulation"| node_tick
node_tick -->|"updates entities"| node_world
node_tick -.->|"queries positions"| node_spatial
node_tick -.->|"runs combat"| node_combat
node_tick -.->|"updates living world"| node_living
node_tick -.->|"runs shrine logic"| node_quests
node_tick -.->|"runs directors"| node_director
node_tick -->|"integrates climate"| node_climate
node_tick -->|"runs AI"| node_ai
node_combat -->|"uses relic and chain state"| node_living
node_quests -->|"reads entities"| node_world
node_quests -->|"queries tiles"| node_spatial
node_director -->|"reads entities"| node_world
node_director -->|"uses occupancy"| node_spatial
node_spatial -.->|"indexes positions"| node_world
node_tick -.->|"draws deterministic values"| node_rng
node_ai -->|"uses seeded draws"| node_rng
node_client -.->|"plays spatial audio"| node_client_render

click node_client "https://github.com/chincai-org/green-tech-2/blob/main/client/js/main.js"
click node_client_render "https://github.com/chincai-org/green-tech-2/blob/main/client/js/renderer.js"
click node_client_hud "https://github.com/chincai-org/green-tech-2/blob/main/client/js/hud.js"
click node_client_almanac "https://github.com/chincai-org/green-tech-2/blob/main/client/js/almanac.js"
click node_client_modals "https://github.com/chincai-org/green-tech-2/blob/main/client/js/modals.js"
click node_client_map "https://github.com/chincai-org/green-tech-2/blob/main/client/js/minimap.js"
click node_protocol "https://github.com/chincai-org/green-tech-2/blob/main/crates/protocol/src/lib.rs"
click node_server "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/lib.rs"
click node_session "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/auth.rs"
click node_store "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/shop.rs"
click node_persistence "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/db.rs"
click node_almanac_service "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/almanac.rs"
click node_server_state "https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/state.rs"
click node_tick "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/step.rs"
click node_world "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/entities.rs"
click node_spatial "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/grid.rs"
click node_combat "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/combat.rs"
click node_living "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/relics.rs"
click node_quests "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/quest_shrines.rs"
click node_director "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/director.rs"
click node_climate "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/climate.rs"
click node_ai "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/ai_bots.rs"
click node_rng "https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/rng.rs"

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_client,node_client_render,node_client_hud,node_client_almanac,node_client_modals,node_client_map toneBlue
class node_server,node_session,node_store,node_persistence,node_almanac_service,node_server_state toneAmber
class node_tick,node_world,node_spatial,node_combat,node_living,node_quests,node_director,node_climate,node_ai,node_rng toneMint
class node_protocol toneRose
class node_player toneIndigo
```

## Components

### Browser game client

- [Canvas game client](https://github.com/chincai-org/green-tech-2/blob/main/client/js/main.js): `client/js/main.js`
- [Rendering and audio](https://github.com/chincai-org/green-tech-2/blob/main/client/js/renderer.js): `client/js/renderer.js`
- [HUD and Almanac](https://github.com/chincai-org/green-tech-2/blob/main/client/js/hud.js): `client/js/hud.js`
- [Almanac view](https://github.com/chincai-org/green-tech-2/blob/main/client/js/almanac.js): `client/js/almanac.js`
- [Store and account UI](https://github.com/chincai-org/green-tech-2/blob/main/client/js/modals.js): `client/js/modals.js`
- [Minimap](https://github.com/chincai-org/green-tech-2/blob/main/client/js/minimap.js): `client/js/minimap.js`

### Server and persistence

- [HTTP and WebSocket server](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/lib.rs): `crates/server/src/lib.rs`
- [Authentication and sessions](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/auth.rs): `crates/server/src/auth.rs`
- [Store and checkout](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/shop.rs): `crates/server/src/shop.rs`
- [SQLite persistence](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/db.rs): `crates/server/src/db.rs`
- [Almanac persistence](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/almanac.rs): `crates/server/src/almanac.rs`
- [Match state](https://github.com/chincai-org/green-tech-2/blob/main/crates/server/src/state.rs): `crates/server/src/state.rs`

### Deterministic simulation

- [Tick and snapshots](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/step.rs): `crates/sim/src/step.rs`
- [World model](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/entities.rs): `crates/sim/src/entities.rs`
- [Spatial grid and pathfinding](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/grid.rs): `crates/sim/src/grid.rs`
- [Combat and economy](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/combat.rs): `crates/sim/src/combat.rs`
- [Relics and combos](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/relics.rs): `crates/sim/src/relics.rs`
- [Shrines and NPCs](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/quest_shrines.rs): `crates/sim/src/quest_shrines.rs`
- [World and wave directors](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/director.rs): `crates/sim/src/director.rs`
- [Climate and strains](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/climate.rs): `crates/sim/src/climate.rs`
- [Bots and Lumberjacks](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/ai_bots.rs): `crates/sim/src/ai_bots.rs`
- [Deterministic randomness](https://github.com/chincai-org/green-tech-2/blob/main/crates/sim/src/rng.rs): `crates/sim/src/rng.rs`

### Shared game protocol

- [Wire protocol and DTOs](https://github.com/chincai-org/green-tech-2/blob/main/crates/protocol/src/lib.rs): `crates/protocol/src/lib.rs`

### Other components

- **Player**

## Connections

- Player → Canvas game client: plays through
- Canvas game client → HTTP and WebSocket server: sends gameplay
- HTTP and WebSocket server → Canvas game client: broadcasts snapshots
- Canvas game client → Rendering and audio: renders world
- Canvas game client → HUD and Almanac: shows HUD
- HUD and Almanac → Almanac view: shows Almanac
- Canvas game client → Store and account UI: opens menus
- Canvas game client → Minimap: shows minimap
- Canvas game client → Wire protocol and DTOs: exchanges messages
- HTTP and WebSocket server → Wire protocol and DTOs: uses wire DTOs
- HTTP and WebSocket server → Match state: manages matches (evidence: `crates/server/src/lib.rs`)
- HTTP and WebSocket server → Authentication and sessions: handles sign-in (evidence: `crates/server/src/lib.rs`)
- HTTP and WebSocket server → Store and checkout: routes checkout (evidence: `crates/server/src/lib.rs`)
- HTTP and WebSocket server → Almanac persistence: serves Almanac (evidence: `crates/server/src/lib.rs`)
- Authentication and sessions → SQLite persistence: reads and writes (evidence: `crates/server/src/auth.rs`)
- Store and checkout → SQLite persistence: records purchases
- Almanac persistence → SQLite persistence: reads and writes (evidence: `crates/server/src/almanac.rs`)
- Match state → Tick and snapshots: advances simulation
- Tick and snapshots → World model: updates entities (evidence: `crates/sim/src/step.rs`)
- Tick and snapshots → Spatial grid and pathfinding: queries positions (evidence: `crates/sim/src/step.rs`)
- Tick and snapshots → Combat and economy: runs combat (evidence: `crates/sim/src/step.rs`)
- Tick and snapshots → Relics and combos: updates living world
- Tick and snapshots → Shrines and NPCs: runs shrine logic
- Tick and snapshots → World and wave directors: runs directors
- Tick and snapshots → Climate and strains: integrates climate
- Tick and snapshots → Bots and Lumberjacks: runs AI (evidence: `crates/sim/src/step.rs`)
- Combat and economy → Relics and combos: uses relic and chain state (evidence: `crates/sim/src/combat.rs`)
- Shrines and NPCs → World model: reads entities (evidence: `crates/sim/src/quest_shrines.rs`)
- Shrines and NPCs → Spatial grid and pathfinding: queries tiles (evidence: `crates/sim/src/quest_shrines.rs`)
- World and wave directors → World model: reads entities (evidence: `crates/sim/src/director.rs`)
- World and wave directors → Spatial grid and pathfinding: uses occupancy (evidence: `crates/sim/src/director.rs`)
- Spatial grid and pathfinding → World model: indexes positions (evidence: `crates/sim/src/entities.rs`)
- Tick and snapshots → Deterministic randomness: draws deterministic values
- Bots and Lumberjacks → Deterministic randomness: uses seeded draws (evidence: `crates/sim/src/ai_bots.rs`)
- Canvas game client → Rendering and audio: plays spatial audio
