# lamm-mit/swarmworld architecture

> Architecture diagram of the GitHub repository lamm-mit/swarmworld, 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/lamm-mit/swarmworld
- Repository: https://github.com/lamm-mit/swarmworld

## Overview

SwarmWorld is a deterministic agent-society research simulator. Its principal workflow configures a world and agent policy, advances an authoritative simulation, records traces for replay, then analyzes study outcomes and presents live or recorded state in the Observatory. The graph also preserves documented capabilities for technology and artifact inheritance, scenario packages, LLM providers, and human play. Several analysis and presentation modules were not sampled; their capabilities and broad relationships are included only where the README documents them.

Main entry points: [`src/biofoundry/simulation.py`](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/simulation.py) (Authoritative simulator), [`src/biofoundry/config.py`](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/config.py) (Run configuration), [`web/src/App.tsx`](https://github.com/lamm-mit/swarmworld/blob/main/web/src/App.tsx) (Three.js Observatory), [`src/biofoundry/policies/llm.py`](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/policies/llm.py) (LLM policy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["World simulation"]
  node_config["Run configuration<br/>[config.py]"]
  node_scenario["Scenario packages<br/>[scenarios.py]"]
  node_sim["Authoritative simulator<br/>[simulation.py]"]
  node_world["World state<br/>[world.py]"]
  node_materials["Material systems<br/>[materials.py]"]
end

subgraph group_agents["Agents and technology"]
  node_policies["Agent policies<br/>[scripted.py]"]
  node_llm["LLM policy<br/>[llm.py]"]
  node_provider["Compatible model provider"]
  node_memory["Agent memory<br/>[memory.py]"]
  node_programs["Executable programs<br/>[programs.py]"]
  node_artifacts["Persistent artifacts<br/>[artifacts.py]"]
  node_knowledge["Causal knowledge<br/>[knowledge.py]"]
end

subgraph group_research["Research and replay"]
  node_events["Event traces<br/>[events.py]"]
  node_study["Study analysis<br/>[analysis.py]"]
  node_mobility["Mobility analysis"]
  node_trace["Trace diagnostics<br/>[trace_analysis.py]"]
  node_counterfactual["Counterfactual replay<br/>[counterfactuals.py]"]
  node_ecology["Ecological evaluation"]
end

subgraph group_clients["Live clients"]
  node_server["Live simulation server<br/>[server.py]"]
  node_observatory["Three.js Observatory<br/>[App.tsx]"]
  node_livehook["Live state connection<br/>[useBiofoundry.ts]"]
  node_renderer["World renderer<br/>[WorldScene.tsx]"]
  node_lineage["Lineage visualization<br/>[lineage.ts]"]
  node_gameclient["Human-in-swarm client<br/>[main.js]"]
  node_gamesession["Human game session<br/>[session.py]"]
end

node_researcher(("Researcher"))
node_human(("Human player"))
node_modelservice(("Model API<br/>external service"))

node_researcher -->|"configures"| node_config
node_config -->|"selects"| node_scenario
node_config -->|"configures"| node_sim
node_scenario -->|"supplies world"| node_sim
node_sim -->|"advances"| node_world
node_sim -->|"updates"| node_materials
node_sim -->|"records"| node_events
node_policies -->|"consults"| node_materials
node_llm -->|"retrieves"| node_memory
node_llm -->|"requests generation"| node_provider
node_provider -.->|"calls API"| node_modelservice
node_sim -->|"uses programs"| node_programs
node_sim -->|"updates artifacts"| node_artifacts
node_sim -->|"uses knowledge"| node_knowledge
node_researcher -->|"analyzes studies"| node_study
node_researcher -->|"analyzes movement"| node_mobility
node_researcher -->|"diagnoses trace"| node_trace
node_researcher -->|"runs interventions"| node_counterfactual
node_researcher -->|"evaluates artifacts"| node_ecology
node_sim -->|"served by"| node_server
node_server -->|"streams state"| node_observatory
node_observatory -->|"uses connection"| node_livehook
node_livehook -.->|"supplies state"| node_renderer
node_observatory -->|"builds lineage"| node_lineage
node_human -->|"joins and acts"| node_gameclient
node_gameclient -->|"sends actions"| node_gamesession
node_gamesession -->|"uses engine"| node_sim

click node_config "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/config.py"
click node_scenario "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/scenarios.py"
click node_sim "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/simulation.py"
click node_world "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/world.py"
click node_materials "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/materials.py"
click node_events "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/events.py"
click node_policies "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/policies/scripted.py"
click node_llm "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/policies/llm.py"
click node_provider "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/providers/openai_compatible.py"
click node_memory "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/memory.py"
click node_programs "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/programs.py"
click node_artifacts "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/artifacts.py"
click node_knowledge "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/knowledge.py"
click node_study "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/analysis.py"
click node_mobility "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/mobility_analysis.py"
click node_trace "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/trace_analysis.py"
click node_counterfactual "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/counterfactuals.py"
click node_ecology "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/technology_ecology.py"
click node_server "https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/server.py"
click node_observatory "https://github.com/lamm-mit/swarmworld/blob/main/web/src/App.tsx"
click node_livehook "https://github.com/lamm-mit/swarmworld/blob/main/web/src/hooks/useBiofoundry.ts"
click node_renderer "https://github.com/lamm-mit/swarmworld/blob/main/web/src/components/WorldScene.tsx"
click node_lineage "https://github.com/lamm-mit/swarmworld/blob/main/web/src/lib/lineage.ts"
click node_gameclient "https://github.com/lamm-mit/swarmworld/blob/main/game/client/js/main.js"
click node_gamesession "https://github.com/lamm-mit/swarmworld/blob/main/game/session.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_config,node_scenario,node_sim,node_world,node_materials toneBlue
class node_policies,node_llm,node_provider,node_memory,node_programs,node_artifacts,node_knowledge toneAmber
class node_events,node_study,node_mobility,node_trace,node_counterfactual,node_ecology,node_modelservice toneMint
class node_server,node_observatory,node_livehook,node_renderer,node_lineage,node_gameclient,node_gamesession toneRose
class node_researcher,node_human toneIndigo
```

## Components

### World simulation

- [Run configuration](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/config.py): `src/biofoundry/config.py`
- [Scenario packages](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/scenarios.py): `src/biofoundry/scenarios.py`
- [Authoritative simulator](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/simulation.py): `src/biofoundry/simulation.py`
- [World state](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/world.py): `src/biofoundry/world.py`
- [Material systems](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/materials.py): `src/biofoundry/materials.py`

### Agents and technology

- [Agent policies](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/policies/scripted.py): `src/biofoundry/policies/scripted.py`
- [LLM policy](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/policies/llm.py): `src/biofoundry/policies/llm.py`
- [Compatible model provider](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/providers/openai_compatible.py): `src/biofoundry/providers/openai_compatible.py`
- [Agent memory](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/memory.py): `src/biofoundry/memory.py`
- [Executable programs](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/programs.py): `src/biofoundry/programs.py`
- [Persistent artifacts](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/artifacts.py): `src/biofoundry/artifacts.py`
- [Causal knowledge](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/knowledge.py): `src/biofoundry/knowledge.py`

### Research and replay

- [Event traces](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/events.py): `src/biofoundry/events.py`
- [Study analysis](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/analysis.py): `src/biofoundry/analysis.py`
- [Mobility analysis](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/mobility_analysis.py): `src/biofoundry/mobility_analysis.py`
- [Trace diagnostics](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/trace_analysis.py): `src/biofoundry/trace_analysis.py`
- [Counterfactual replay](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/counterfactuals.py): `src/biofoundry/counterfactuals.py`
- [Ecological evaluation](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/technology_ecology.py): `src/biofoundry/technology_ecology.py`

### Live clients

- [Live simulation server](https://github.com/lamm-mit/swarmworld/blob/main/src/biofoundry/server.py): `src/biofoundry/server.py`
- [Three.js Observatory](https://github.com/lamm-mit/swarmworld/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [Live state connection](https://github.com/lamm-mit/swarmworld/blob/main/web/src/hooks/useBiofoundry.ts): `web/src/hooks/useBiofoundry.ts`
- [World renderer](https://github.com/lamm-mit/swarmworld/blob/main/web/src/components/WorldScene.tsx): `web/src/components/WorldScene.tsx`
- [Lineage visualization](https://github.com/lamm-mit/swarmworld/blob/main/web/src/lib/lineage.ts): `web/src/lib/lineage.ts`
- [Human-in-swarm client](https://github.com/lamm-mit/swarmworld/blob/main/game/client/js/main.js): `game/client/js/main.js`
- [Human game session](https://github.com/lamm-mit/swarmworld/blob/main/game/session.py): `game/session.py`

### Other components

- **Researcher**
- **Human player**
- **Model API**: external service

## Connections

- Researcher → Run configuration: configures (evidence: `README.md`)
- Run configuration → Scenario packages: selects (evidence: `src/biofoundry/simulation.py`)
- Run configuration → Authoritative simulator: configures (evidence: `src/biofoundry/server.py`)
- Scenario packages → Authoritative simulator: supplies world (evidence: `src/biofoundry/simulation.py`)
- Authoritative simulator → World state: advances (evidence: `src/biofoundry/simulation.py`)
- Authoritative simulator → Material systems: updates (evidence: `src/biofoundry/simulation.py`)
- Authoritative simulator → Event traces: records (evidence: `src/biofoundry/simulation.py`)
- Agent policies → Material systems: consults (evidence: `src/biofoundry/policies/scripted.py`)
- LLM policy → Agent memory: retrieves (evidence: `src/biofoundry/policies/llm.py`)
- LLM policy → Compatible model provider: requests generation (evidence: `src/biofoundry/policies/llm.py`)
- Compatible model provider → Model API: calls API
- Authoritative simulator → Executable programs: uses programs (evidence: `src/biofoundry/simulation.py`)
- Authoritative simulator → Persistent artifacts: updates artifacts (evidence: `src/biofoundry/simulation.py`)
- Authoritative simulator → Causal knowledge: uses knowledge (evidence: `src/biofoundry/simulation.py`)
- Researcher → Study analysis: analyzes studies (evidence: `README.md`)
- Researcher → Mobility analysis: analyzes movement (evidence: `README.md`)
- Researcher → Trace diagnostics: diagnoses trace (evidence: `README.md`)
- Researcher → Counterfactual replay: runs interventions (evidence: `README.md`)
- Researcher → Ecological evaluation: evaluates artifacts (evidence: `README.md`)
- Authoritative simulator → Live simulation server: served by (evidence: `src/biofoundry/server.py`)
- Live simulation server → Three.js Observatory: streams state (evidence: `README.md`)
- Three.js Observatory → Live state connection: uses connection (evidence: `web/src/App.tsx`)
- Live state connection → World renderer: supplies state
- Three.js Observatory → Lineage visualization: builds lineage (evidence: `web/src/App.tsx`)
- Human player → Human-in-swarm client: joins and acts (evidence: `README.md`)
- Human-in-swarm client → Human game session: sends actions (evidence: `game/client/js/main.js`)
- Human game session → Authoritative simulator: uses engine (evidence: `game/session.py`)
