# ghsrg/alife architecture

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

- Interactive diagram: https://gitdiagram.com/ghsrg/alife
- Repository: https://github.com/ghsrg/alife

## Overview

ALife Simulation is a Rust artificial-life engine with a browser control center for configuring runs and inspecting their evolution. The principal workflow is scenario resolution, world bootstrap, repeated simulation ticks, snapshot/projection generation, and display in the viewer. The source index supports the engine, bootstrap, runner, observer, and server relationships shown here; the UI’s controller-to-client flow is excerpted. The README emphasizes documentation-first design, while the available tree and excerpts show runtime implementation. Several subsystems are represented at directory level where their implementation was not sampled.

Main entry points: [`src/core/tick.rs`](https://github.com/ghsrg/alife/blob/main/src/core/tick.rs) (Tick Executor), [`src/runner/engine.rs`](https://github.com/ghsrg/alife/blob/main/src/runner/engine.rs) (Run Engine), [`ui/control-center/src/app/runnerController.ts`](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/app/runnerController.ts) (Run Controller), [`src/core/snapshot.rs`](https://github.com/ghsrg/alife/blob/main/src/core/snapshot.rs) (Committed Snapshot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Scenario Setup"]
  node_scenario["Scenario Document<br/>[scenario_doc.rs]"]
  node_parser["Config Parser<br/>[config_parser.rs]"]
  node_bootstrap["World Bootstrap<br/>[mod.rs]"]
  node_runtime_config["Runtime Config<br/>[config.rs]"]
end

subgraph group_engine["Simulation Engine"]
  node_run_engine["Run Engine<br/>[engine.rs]"]
  node_tick["Tick Executor<br/>[tick.rs]"]
  node_world["World State<br/>[world.rs]"]
  node_cells[("Cell Store<br/>[cell_store.rs]")]
  node_genome["Genome Runtime<br/>[genome.rs]"]
  node_processes["Process Registry<br/>[process.rs]"]
  node_resources["Resource State<br/>[resources.rs]"]
end

subgraph group_observe["Observation"]
  node_snapshot["Committed Snapshot<br/>[snapshot.rs]"]
  node_projection["Observer Projections<br/>[projection.rs]"]
  node_storage["Analytics Export"]
end

subgraph group_interface["Viewer Interface"]
  node_viewer_api["Viewer API<br/>[run.rs]"]
  node_server_state["Server State<br/>[state.rs]"]
  node_controller["Run Controller"]
  node_api_client["Runner API Client<br/>[apiClient.ts]"]
  node_stream_client["Runner Stream Client<br/>[streamClient.ts]"]
  node_live_adapter["Live Projection Adapter<br/>[liveAdapter.ts]"]
  node_browser["Control Center<br/>[App.tsx]"]
end

node_operator(("Operator"))

node_operator -.->|"configures runs"| node_browser
node_scenario -->|"parses via"| node_parser
node_scenario -->|"produces config"| node_runtime_config
node_run_engine -->|"prepares world"| node_bootstrap
node_run_engine -->|"executes ticks"| node_tick
node_run_engine -->|"caches snapshots"| node_snapshot
node_tick -->|"updates cells"| node_cells
node_tick -->|"uses genome"| node_genome
node_tick -->|"dispatches processes"| node_processes
node_tick -->|"updates resources"| node_resources
node_tick -->|"updates world"| node_world
node_snapshot -->|"captures state"| node_cells
node_snapshot -->|"captures resources"| node_resources
node_projection -->|"projects snapshot"| node_snapshot
node_storage -.->|"exports analytics"| node_projection
node_viewer_api -->|"controls runs"| node_run_engine
node_viewer_api -->|"uses server state"| node_server_state
node_server_state -->|"manages engine"| node_run_engine
node_controller -->|"issues commands"| node_api_client
node_controller -->|"opens stream"| node_stream_client
node_controller -->|"adapts frames"| node_live_adapter
node_api_client -.->|"sends HTTP requests"| node_viewer_api
node_stream_client -.->|"receives run stream"| node_viewer_api
node_browser -.->|"drives controls"| node_controller
node_live_adapter -.->|"consumes projections"| node_projection

click node_scenario "https://github.com/ghsrg/alife/blob/main/src/runner/scenario_doc.rs"
click node_parser "https://github.com/ghsrg/alife/blob/main/src/runner/config_parser.rs"
click node_bootstrap "https://github.com/ghsrg/alife/blob/main/src/bootstrap/mod.rs"
click node_runtime_config "https://github.com/ghsrg/alife/blob/main/src/core/config.rs"
click node_run_engine "https://github.com/ghsrg/alife/blob/main/src/runner/engine.rs"
click node_tick "https://github.com/ghsrg/alife/blob/main/src/core/tick.rs"
click node_world "https://github.com/ghsrg/alife/blob/main/src/core/world.rs"
click node_cells "https://github.com/ghsrg/alife/blob/main/src/core/cell_store.rs"
click node_genome "https://github.com/ghsrg/alife/blob/main/src/core/genome.rs"
click node_processes "https://github.com/ghsrg/alife/blob/main/src/core/process.rs"
click node_resources "https://github.com/ghsrg/alife/blob/main/src/core/resources.rs"
click node_snapshot "https://github.com/ghsrg/alife/blob/main/src/core/snapshot.rs"
click node_projection "https://github.com/ghsrg/alife/blob/main/src/observer/projection.rs"
click node_storage "https://github.com/ghsrg/alife/blob/main/src/storage/analytics_export.rs"
click node_viewer_api "https://github.com/ghsrg/alife/blob/main/src/viewer_server/api/run.rs"
click node_server_state "https://github.com/ghsrg/alife/blob/main/src/viewer_server/state.rs"
click node_controller "https://github.com/ghsrg/alife/blob/main/ui/control-center/src/app/runnerController.ts"
click node_api_client "https://github.com/ghsrg/alife/blob/main/ui/control-center/src/runner/apiClient.ts"
click node_stream_client "https://github.com/ghsrg/alife/blob/main/ui/control-center/src/runner/streamClient.ts"
click node_live_adapter "https://github.com/ghsrg/alife/blob/main/ui/control-center/src/projection/liveAdapter.ts"
click node_browser "https://github.com/ghsrg/alife/blob/main/ui/control-center/src/App.tsx"

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_scenario,node_parser,node_bootstrap,node_runtime_config toneBlue
class node_run_engine,node_tick,node_world,node_cells,node_genome,node_processes,node_resources toneAmber
class node_snapshot,node_projection,node_storage toneMint
class node_viewer_api,node_server_state,node_controller,node_api_client,node_stream_client,node_live_adapter,node_browser toneRose
class node_operator toneIndigo
```

## Components

### Scenario Setup

- [Scenario Document](https://github.com/ghsrg/alife/blob/main/src/runner/scenario_doc.rs): `src/runner/scenario_doc.rs`
- [Config Parser](https://github.com/ghsrg/alife/blob/main/src/runner/config_parser.rs): `src/runner/config_parser.rs`
- [World Bootstrap](https://github.com/ghsrg/alife/blob/main/src/bootstrap/mod.rs): `src/bootstrap/mod.rs`
- [Runtime Config](https://github.com/ghsrg/alife/blob/main/src/core/config.rs): `src/core/config.rs`

### Simulation Engine

- [Run Engine](https://github.com/ghsrg/alife/blob/main/src/runner/engine.rs): `src/runner/engine.rs`
- [Tick Executor](https://github.com/ghsrg/alife/blob/main/src/core/tick.rs): `src/core/tick.rs`
- [World State](https://github.com/ghsrg/alife/blob/main/src/core/world.rs): `src/core/world.rs`
- [Cell Store](https://github.com/ghsrg/alife/blob/main/src/core/cell_store.rs): `src/core/cell_store.rs`
- [Genome Runtime](https://github.com/ghsrg/alife/blob/main/src/core/genome.rs): `src/core/genome.rs`
- [Process Registry](https://github.com/ghsrg/alife/blob/main/src/core/process.rs): `src/core/process.rs`
- [Resource State](https://github.com/ghsrg/alife/blob/main/src/core/resources.rs): `src/core/resources.rs`

### Observation

- [Committed Snapshot](https://github.com/ghsrg/alife/blob/main/src/core/snapshot.rs): `src/core/snapshot.rs`
- [Observer Projections](https://github.com/ghsrg/alife/blob/main/src/observer/projection.rs): `src/observer/projection.rs`
- [Analytics Export](https://github.com/ghsrg/alife/blob/main/src/storage/analytics_export.rs): `src/storage/analytics_export.rs`

### Viewer Interface

- [Viewer API](https://github.com/ghsrg/alife/blob/main/src/viewer_server/api/run.rs): `src/viewer_server/api/run.rs`
- [Server State](https://github.com/ghsrg/alife/blob/main/src/viewer_server/state.rs): `src/viewer_server/state.rs`
- [Run Controller](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/app/runnerController.ts): `ui/control-center/src/app/runnerController.ts`
- [Runner API Client](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/runner/apiClient.ts): `ui/control-center/src/runner/apiClient.ts`
- [Runner Stream Client](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/runner/streamClient.ts): `ui/control-center/src/runner/streamClient.ts`
- [Live Projection Adapter](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/projection/liveAdapter.ts): `ui/control-center/src/projection/liveAdapter.ts`
- [Control Center](https://github.com/ghsrg/alife/blob/main/ui/control-center/src/App.tsx): `ui/control-center/src/App.tsx`

### Other components

- **Operator**

## Connections

- Operator → Control Center: configures runs
- Scenario Document → Config Parser: parses via (evidence: `src/runner/scenario_doc.rs`)
- Scenario Document → Runtime Config: produces config (evidence: `src/runner/scenario_doc.rs`)
- Run Engine → World Bootstrap: prepares world (evidence: `src/runner/engine.rs`)
- Run Engine → Tick Executor: executes ticks (evidence: `src/runner/engine.rs`)
- Run Engine → Committed Snapshot: caches snapshots (evidence: `src/runner/engine.rs`)
- Tick Executor → Cell Store: updates cells (evidence: `src/core/tick.rs`)
- Tick Executor → Genome Runtime: uses genome (evidence: `src/core/tick.rs`)
- Tick Executor → Process Registry: dispatches processes (evidence: `src/core/tick.rs`)
- Tick Executor → Resource State: updates resources (evidence: `src/core/tick.rs`)
- Tick Executor → World State: updates world (evidence: `src/core/tick.rs`)
- Committed Snapshot → Cell Store: captures state (evidence: `src/core/snapshot.rs`)
- Committed Snapshot → Resource State: captures resources (evidence: `src/core/snapshot.rs`)
- Observer Projections → Committed Snapshot: projects snapshot (evidence: `src/observer/projection.rs`)
- Analytics Export → Observer Projections: exports analytics
- Viewer API → Run Engine: controls runs (evidence: `src/viewer_server/api/run.rs`)
- Viewer API → Server State: uses server state (evidence: `src/viewer_server/api/run.rs`)
- Server State → Run Engine: manages engine (evidence: `src/viewer_server/state.rs`)
- Run Controller → Runner API Client: issues commands (evidence: `ui/control-center/src/app/runnerController.ts`)
- Run Controller → Runner Stream Client: opens stream (evidence: `ui/control-center/src/app/runnerController.ts`)
- Run Controller → Live Projection Adapter: adapts frames (evidence: `ui/control-center/src/app/runnerController.ts`)
- Runner API Client → Viewer API: sends HTTP requests
- Runner Stream Client → Viewer API: receives run stream
- Control Center → Run Controller: drives controls
- Live Projection Adapter → Observer Projections: consumes projections
