# griffins2005/town-simulator architecture

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

- Interactive diagram: https://gitdiagram.com/griffins2005/town-simulator
- Repository: https://github.com/griffins2005/town-simulator

## Overview

Eidolon Society Lab is a browser-driven town simulation. The main workflow seats residents at the table, starts the town, then advances agent decisions into validated actions and visible town changes. Distinct stages include roster and strategy setup, perception and reasoning, action validation, economic and institutional consequences, and observation/analytics. The graph also shows memory and recording as internal layers, plus the optional Groq strategy path and the separate council match. Some links rely on README statements or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`lab/live_server.py`](https://github.com/griffins2005/town-simulator/blob/main/lab/live_server.py) (Live server), [`town/engine.py`](https://github.com/griffins2005/town-simulator/blob/main/town/engine.py) (Tick engine), [`roster/lineup.py`](https://github.com/griffins2005/town-simulator/blob/main/roster/lineup.py) (Seated lineup), [`town/actions.py`](https://github.com/griffins2005/town-simulator/blob/main/town/actions.py) (Action validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_lab["Lab interface"]
  node_browser["Browser client<br/>[live_shared.js]"]
  node_live_server["Live server<br/>[live_server.py]"]
end

subgraph group_roster["Roster and strategy"]
  node_lineup["Seated lineup<br/>[lineup.py]"]
  node_catalog["Agent catalog<br/>[catalog.py]"]
  node_strategy_code["Strategy language<br/>[code.py]"]
  node_resident_life["Resident behavior<br/>[play.py]"]
  node_translator["Description translator<br/>[translate.py]"]
end

subgraph group_simulation["Simulation runtime"]
  node_factory["Town factory<br/>[town_factory.py]"]
  node_world["World state<br/>[world.py]"]
  node_agent["Agent state<br/>[agent.py]"]
  node_engine["Tick engine<br/>[engine.py]"]
  node_deciders["Decision making<br/>[decision.py]"]
  node_actions["Action validation<br/>[actions.py]"]
  node_memory["Agent memory<br/>[memory.py]"]
end

subgraph group_institutions["Town systems"]
  node_economy["Economy<br/>[economy.py]"]
  node_governance["Governance<br/>[governance.py]"]
  node_faith["Faith institutions<br/>[faith.py]"]
  node_inventions["Inventions<br/>[inventions.py]"]
  node_chaos["Crises and shocks<br/>[chaos.py]"]
end

subgraph group_insight["Records and analytics"]
  node_recorder["Tick recorder<br/>[recorder.py]"]
  node_analytics["Town analytics<br/>[analytics.py]"]
  node_checkpoint["Save and restore<br/>[checkpoint.py]"]
end

subgraph group_extensions["Optional modes"]
  node_llm_decider["LLM decider<br/>[llm_decider.py]"]
  node_council_match["Flood match<br/>[match.py]"]
end

node_player(("Player"))
node_groq{{"Groq service"}}

node_player -->|"seats residents"| node_browser
node_browser -->|"sends controls"| node_live_server
node_live_server -->|"starts town"| node_lineup
node_lineup -->|"loads agents"| node_catalog
node_lineup -->|"uses rules"| node_strategy_code
node_lineup -->|"runs town life"| node_resident_life
node_lineup -->|"builds residents"| node_factory
node_resident_life -->|"advances town"| node_engine
node_live_server -->|"translates descriptions"| node_translator
node_translator -.->|"requests strategy"| node_groq
node_translator -->|"uses model name"| node_llm_decider
node_factory -->|"creates world"| node_world
node_factory -->|"creates agents"| node_agent
node_engine -->|"requests intents"| node_deciders
node_engine -->|"executes intents"| node_actions
node_engine -->|"records outcomes"| node_memory
node_actions -->|"applies trade and work"| node_economy
node_actions -->|"applies votes and laws"| node_governance
node_actions -->|"applies worship"| node_faith
node_actions -->|"validates inventions"| node_inventions
node_engine -->|"runs crisis hooks"| node_chaos
node_engine -->|"records frames"| node_recorder
node_live_server -->|"serves event stream"| node_recorder
node_live_server -->|"serves charts"| node_analytics
node_live_server -->|"handles save controls"| node_checkpoint
node_llm_decider -.->|"requests completions"| node_groq
node_player -->|"runs separate match"| node_council_match

click node_browser "https://github.com/griffins2005/town-simulator/blob/main/lab/live_shared.js"
click node_live_server "https://github.com/griffins2005/town-simulator/blob/main/lab/live_server.py"
click node_lineup "https://github.com/griffins2005/town-simulator/blob/main/roster/lineup.py"
click node_catalog "https://github.com/griffins2005/town-simulator/blob/main/roster/catalog.py"
click node_strategy_code "https://github.com/griffins2005/town-simulator/blob/main/roster/code.py"
click node_resident_life "https://github.com/griffins2005/town-simulator/blob/main/roster/play.py"
click node_translator "https://github.com/griffins2005/town-simulator/blob/main/roster/translate.py"
click node_factory "https://github.com/griffins2005/town-simulator/blob/main/town/town_factory.py"
click node_world "https://github.com/griffins2005/town-simulator/blob/main/town/world.py"
click node_agent "https://github.com/griffins2005/town-simulator/blob/main/town/agent.py"
click node_engine "https://github.com/griffins2005/town-simulator/blob/main/town/engine.py"
click node_deciders "https://github.com/griffins2005/town-simulator/blob/main/town/decision.py"
click node_actions "https://github.com/griffins2005/town-simulator/blob/main/town/actions.py"
click node_memory "https://github.com/griffins2005/town-simulator/blob/main/town/memory.py"
click node_economy "https://github.com/griffins2005/town-simulator/blob/main/town/economy.py"
click node_governance "https://github.com/griffins2005/town-simulator/blob/main/town/governance.py"
click node_faith "https://github.com/griffins2005/town-simulator/blob/main/town/faith.py"
click node_inventions "https://github.com/griffins2005/town-simulator/blob/main/town/inventions.py"
click node_chaos "https://github.com/griffins2005/town-simulator/blob/main/town/chaos.py"
click node_recorder "https://github.com/griffins2005/town-simulator/blob/main/town/recorder.py"
click node_analytics "https://github.com/griffins2005/town-simulator/blob/main/town/analytics.py"
click node_checkpoint "https://github.com/griffins2005/town-simulator/blob/main/town/checkpoint.py"
click node_llm_decider "https://github.com/griffins2005/town-simulator/blob/main/llm/llm_decider.py"
click node_council_match "https://github.com/griffins2005/town-simulator/blob/main/council/match.py"

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_browser,node_live_server toneBlue
class node_lineup,node_catalog,node_strategy_code,node_resident_life,node_translator toneAmber
class node_factory,node_world,node_agent,node_engine,node_deciders,node_actions,node_memory toneMint
class node_economy,node_governance,node_faith,node_inventions,node_chaos toneRose
class node_recorder,node_analytics,node_checkpoint,node_player,node_groq toneIndigo
class node_llm_decider,node_council_match toneTeal
```

## Components

### Lab interface

- [Browser client](https://github.com/griffins2005/town-simulator/blob/main/lab/live_shared.js): `lab/live_shared.js`
- [Live server](https://github.com/griffins2005/town-simulator/blob/main/lab/live_server.py): `lab/live_server.py`

### Roster and strategy

- [Seated lineup](https://github.com/griffins2005/town-simulator/blob/main/roster/lineup.py): `roster/lineup.py`
- [Agent catalog](https://github.com/griffins2005/town-simulator/blob/main/roster/catalog.py): `roster/catalog.py`
- [Strategy language](https://github.com/griffins2005/town-simulator/blob/main/roster/code.py): `roster/code.py`
- [Resident behavior](https://github.com/griffins2005/town-simulator/blob/main/roster/play.py): `roster/play.py`
- [Description translator](https://github.com/griffins2005/town-simulator/blob/main/roster/translate.py): `roster/translate.py`

### Simulation runtime

- [Town factory](https://github.com/griffins2005/town-simulator/blob/main/town/town_factory.py): `town/town_factory.py`
- [World state](https://github.com/griffins2005/town-simulator/blob/main/town/world.py): `town/world.py`
- [Agent state](https://github.com/griffins2005/town-simulator/blob/main/town/agent.py): `town/agent.py`
- [Tick engine](https://github.com/griffins2005/town-simulator/blob/main/town/engine.py): `town/engine.py`
- [Decision making](https://github.com/griffins2005/town-simulator/blob/main/town/decision.py): `town/decision.py`
- [Action validation](https://github.com/griffins2005/town-simulator/blob/main/town/actions.py): `town/actions.py`
- [Agent memory](https://github.com/griffins2005/town-simulator/blob/main/town/memory.py): `town/memory.py`

### Town systems

- [Economy](https://github.com/griffins2005/town-simulator/blob/main/town/economy.py): `town/economy.py`
- [Governance](https://github.com/griffins2005/town-simulator/blob/main/town/governance.py): `town/governance.py`
- [Faith institutions](https://github.com/griffins2005/town-simulator/blob/main/town/faith.py): `town/faith.py`
- [Inventions](https://github.com/griffins2005/town-simulator/blob/main/town/inventions.py): `town/inventions.py`
- [Crises and shocks](https://github.com/griffins2005/town-simulator/blob/main/town/chaos.py): `town/chaos.py`

### Records and analytics

- [Tick recorder](https://github.com/griffins2005/town-simulator/blob/main/town/recorder.py): `town/recorder.py`
- [Town analytics](https://github.com/griffins2005/town-simulator/blob/main/town/analytics.py): `town/analytics.py`
- [Save and restore](https://github.com/griffins2005/town-simulator/blob/main/town/checkpoint.py): `town/checkpoint.py`

### Optional modes

- [LLM decider](https://github.com/griffins2005/town-simulator/blob/main/llm/llm_decider.py): `llm/llm_decider.py`
- [Flood match](https://github.com/griffins2005/town-simulator/blob/main/council/match.py): `council/match.py`

### Other components

- **Player**
- **Groq service**

## Connections

- Player → Browser client: seats residents
- Browser client → Live server: sends controls
- Live server → Seated lineup: starts town (evidence: `lab/live_server.py`)
- Seated lineup → Agent catalog: loads agents (evidence: `roster/lineup.py`)
- Seated lineup → Strategy language: uses rules (evidence: `roster/lineup.py`)
- Seated lineup → Resident behavior: runs town life (evidence: `roster/lineup.py`)
- Seated lineup → Town factory: builds residents (evidence: `roster/lineup.py`)
- Resident behavior → Tick engine: advances town (evidence: `roster/play.py`)
- Live server → Description translator: translates descriptions (evidence: `lab/live_server.py`)
- Description translator → Groq service: requests strategy
- Description translator → LLM decider: uses model name (evidence: `roster/translate.py`)
- Town factory → World state: creates world (evidence: `town/town_factory.py`)
- Town factory → Agent state: creates agents (evidence: `town/town_factory.py`)
- Tick engine → Decision making: requests intents (evidence: `town/engine.py`)
- Tick engine → Action validation: executes intents (evidence: `town/engine.py`)
- Tick engine → Agent memory: records outcomes (evidence: `town/engine.py`)
- Action validation → Economy: applies trade and work (evidence: `town/actions.py`)
- Action validation → Governance: applies votes and laws (evidence: `town/actions.py`)
- Action validation → Faith institutions: applies worship (evidence: `town/actions.py`)
- Action validation → Inventions: validates inventions (evidence: `town/actions.py`)
- Tick engine → Crises and shocks: runs crisis hooks (evidence: `town/chaos.py`)
- Tick engine → Tick recorder: records frames (evidence: `town/recorder.py`)
- Live server → Tick recorder: serves event stream (evidence: `lab/live_server.py`)
- Live server → Town analytics: serves charts
- Live server → Save and restore: handles save controls (evidence: `lab/live_server.py`)
- LLM decider → Groq service: requests completions
- Player → Flood match: runs separate match
