# lochheadr92-creator/living-world architecture

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

- Interactive diagram: https://gitdiagram.com/lochheadr92-creator/living-world
- Repository: https://github.com/lochheadr92-creator/living-world

## Overview

Living World is a browser-based isometric civilisation simulator: the user watches a deterministic settlement evolve rather than directly controlling each person. The main workflow creates a world, advances its fixed-timestep simulation, and presents the resulting state through rendering and inspection UI. Simulation stages include local knowledge, action selection and execution, resource accounting, production, and social life. The README documents these capabilities; unsampled implementation details are represented at subsystem level, and optional inhabitant control is kept separate.

Main entry points: [`src/app/game.ts`](https://github.com/lochheadr92-creator/living-world/blob/main/src/app/game.ts) (Game clock), [`src/sim/options_work.ts`](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/options_work.ts) (Work planning), [`src/sim/decision.ts`](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/decision.ts) (Action choice), [`src/sim/activities.ts`](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/activities.ts) (Activities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_game["Game clock<br/>[game.ts]"]
  node_save["Save and restore<br/>[save.ts]"]
end

subgraph group_simulation["World simulation"]
  node_worldgen["World setup<br/>[worldgen.ts]"]
  node_world["World state<br/>[world.ts]"]
  node_perception["Local perception<br/>[perception.ts]"]
  node_knowledge["Beliefs<br/>[knowledge.ts]"]
  node_decision["Action choice<br/>[decision.ts]"]
  node_activities["Activities<br/>[activities.ts]"]
  node_social["Social life<br/>[social.ts]"]
  node_people["People<br/>[people.ts]"]
end

subgraph group_economy["Settlement economy"]
  node_production["Work planning<br/>[options_work.ts]"]
  node_facilities["Workplaces<br/>[facilities.ts]"]
  node_buildings["Building lifecycle<br/>[buildings.ts]"]
  node_recipes["Recipes<br/>[recipes.ts]"]
  node_accounting["Resource ledger<br/>[economy.ts]"]
  node_tooling["Tools and carts<br/>[tools.ts]"]
end

subgraph group_presentation["Presentation"]
  node_renderer["Isometric renderer<br/>[renderer.ts]"]
  node_sprites["Sprites<br/>[sprites.ts]"]
  node_ui["Viewer interface<br/>[index.ts]"]
  node_inspector["Inspector<br/>[entity.ts]"]
end

subgraph group_agent["Optional agent"]
  node_agentrun["Agent runner<br/>[run.ts]"]
  node_observation["Agent observation<br/>[observe.ts]"]
end

node_viewer(("Viewer"))

node_viewer -->|"watches"| node_game
node_game -->|"creates world"| node_worldgen
node_game -->|"advances ticks"| node_world
node_world -.->|"updates awareness"| node_perception
node_perception -->|"records beliefs"| node_knowledge
node_knowledge -->|"informs choices"| node_decision
node_decision -->|"chooses action"| node_activities
node_activities -->|"changes state"| node_world
node_decision -->|"plans work"| node_production
node_production -->|"plans batches"| node_facilities
node_facilities -->|"uses recipes"| node_recipes
node_facilities -->|"moves resources"| node_accounting
node_buildings -->|"accounts materials"| node_accounting
node_production -->|"plans construction"| node_buildings
node_production -->|"uses equipment"| node_tooling
node_activities -.->|"supports interactions"| node_social
node_social -->|"updates relations"| node_people
node_game -->|"provides view state"| node_renderer
node_renderer -->|"draws sprites"| node_sprites
node_viewer -->|"inspects world"| node_ui
node_ui -->|"opens details"| node_inspector
node_game -->|"saves state"| node_save
node_agentrun -->|"reads person state"| node_observation
node_viewer -.->|"optionally drives"| node_agentrun
node_observation -->|"reads beliefs"| node_knowledge

click node_game "https://github.com/lochheadr92-creator/living-world/blob/main/src/app/game.ts"
click node_worldgen "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/worldgen.ts"
click node_world "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/world.ts"
click node_perception "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/perception.ts"
click node_knowledge "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/knowledge.ts"
click node_decision "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/decision.ts"
click node_activities "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/activities.ts"
click node_production "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/options_work.ts"
click node_facilities "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/facilities.ts"
click node_buildings "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/buildings.ts"
click node_recipes "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/recipes.ts"
click node_accounting "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/economy.ts"
click node_tooling "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/tools.ts"
click node_social "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/social.ts"
click node_people "https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/people.ts"
click node_renderer "https://github.com/lochheadr92-creator/living-world/blob/main/src/render/renderer.ts"
click node_sprites "https://github.com/lochheadr92-creator/living-world/blob/main/src/render/sprites.ts"
click node_ui "https://github.com/lochheadr92-creator/living-world/blob/main/src/ui/index.ts"
click node_inspector "https://github.com/lochheadr92-creator/living-world/blob/main/src/ui/entity.ts"
click node_save "https://github.com/lochheadr92-creator/living-world/blob/main/src/app/save.ts"
click node_agentrun "https://github.com/lochheadr92-creator/living-world/blob/main/src/agent/run.ts"
click node_observation "https://github.com/lochheadr92-creator/living-world/blob/main/src/agent/observe.ts"

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_game,node_save,node_viewer toneBlue
class node_worldgen,node_world,node_perception,node_knowledge,node_decision,node_activities,node_social,node_people toneAmber
class node_production,node_facilities,node_buildings,node_recipes,node_accounting,node_tooling toneMint
class node_renderer,node_sprites,node_ui,node_inspector toneRose
class node_agentrun,node_observation toneIndigo
```

## Components

### Application

- [Game clock](https://github.com/lochheadr92-creator/living-world/blob/main/src/app/game.ts): `src/app/game.ts`
- [Save and restore](https://github.com/lochheadr92-creator/living-world/blob/main/src/app/save.ts): `src/app/save.ts`

### World simulation

- [World setup](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/worldgen.ts): `src/sim/worldgen.ts`
- [World state](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/world.ts): `src/sim/world.ts`
- [Local perception](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/perception.ts): `src/sim/perception.ts`
- [Beliefs](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/knowledge.ts): `src/sim/knowledge.ts`
- [Action choice](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/decision.ts): `src/sim/decision.ts`
- [Activities](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/activities.ts): `src/sim/activities.ts`
- [Social life](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/social.ts): `src/sim/social.ts`
- [People](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/people.ts): `src/sim/people.ts`

### Settlement economy

- [Work planning](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/options_work.ts): `src/sim/options_work.ts`
- [Workplaces](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/facilities.ts): `src/sim/facilities.ts`
- [Building lifecycle](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/buildings.ts): `src/sim/buildings.ts`
- [Recipes](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/recipes.ts): `src/sim/recipes.ts`
- [Resource ledger](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/economy.ts): `src/sim/economy.ts`
- [Tools and carts](https://github.com/lochheadr92-creator/living-world/blob/main/src/sim/tools.ts): `src/sim/tools.ts`

### Presentation

- [Isometric renderer](https://github.com/lochheadr92-creator/living-world/blob/main/src/render/renderer.ts): `src/render/renderer.ts`
- [Sprites](https://github.com/lochheadr92-creator/living-world/blob/main/src/render/sprites.ts): `src/render/sprites.ts`
- [Viewer interface](https://github.com/lochheadr92-creator/living-world/blob/main/src/ui/index.ts): `src/ui/index.ts`
- [Inspector](https://github.com/lochheadr92-creator/living-world/blob/main/src/ui/entity.ts): `src/ui/entity.ts`

### Optional agent

- [Agent runner](https://github.com/lochheadr92-creator/living-world/blob/main/src/agent/run.ts): `src/agent/run.ts`
- [Agent observation](https://github.com/lochheadr92-creator/living-world/blob/main/src/agent/observe.ts): `src/agent/observe.ts`

### Other components

- **Viewer**

## Connections

- Viewer → Game clock: watches (evidence: `README.md`)
- Game clock → World setup: creates world (evidence: `src/app/game.ts`)
- Game clock → World state: advances ticks (evidence: `src/app/game.ts`)
- World state → Local perception: updates awareness
- Local perception → Beliefs: records beliefs (evidence: `src/sim/knowledge.ts`)
- Beliefs → Action choice: informs choices (evidence: `README.md`)
- Action choice → Activities: chooses action (evidence: `README.md`)
- Activities → World state: changes state (evidence: `README.md`)
- Action choice → Work planning: plans work (evidence: `src/sim/options_work.ts`)
- Work planning → Workplaces: plans batches
- Workplaces → Recipes: uses recipes (evidence: `src/sim/facilities.ts`)
- Workplaces → Resource ledger: moves resources (evidence: `src/sim/facilities.ts`)
- Building lifecycle → Resource ledger: accounts materials (evidence: `src/sim/buildings.ts`)
- Work planning → Building lifecycle: plans construction (evidence: `src/sim/options_work.ts`)
- Work planning → Tools and carts: uses equipment (evidence: `src/sim/production.ts`)
- Activities → Social life: supports interactions (evidence: `src/sim/social.ts`)
- Social life → People: updates relations (evidence: `src/sim/social.ts`)
- Game clock → Isometric renderer: provides view state (evidence: `src/app/game.ts`)
- Isometric renderer → Sprites: draws sprites
- Viewer → Viewer interface: inspects world (evidence: `README.md`)
- Viewer interface → Inspector: opens details (evidence: `src/ui/index.ts`)
- Game clock → Save and restore: saves state (evidence: `src/app/save.ts`)
- Agent runner → Agent observation: reads person state (evidence: `src/agent/run.ts`)
- Viewer → Agent runner: optionally drives (evidence: `README.md`)
- Agent observation → Beliefs: reads beliefs (evidence: `src/agent/observe.ts`)
