# ci4ic4/life architecture

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

- Interactive diagram: https://gitdiagram.com/ci4ic4/life
- Repository: https://github.com/ci4ic4/life

## Overview

#### Purpose and entry points
This repository implements a watchable spatial-ecology cellular simulation: pine martens suppress invasive grey squirrels, enabling native red squirrels to recover. The active Rust workspace separates application orchestration, simulation logic, GPU stepping, and rendering. Primary executable entry points are `crates/life-app/src/main.rs` and `crates/life-app/src/app.rs`. Legacy browser-facing prototypes remain at `life-ecology.html`, `life-ecology-core.js`, and related HTML/JS files.

#### Application orchestration
`life-app` is the composition layer that initializes and coordinates the simulation, graphics, and user-facing runtime loop. It should be the boundary where the core model, GPU backend, and renderer are selected and connected.
- `crates/life-app/src/main.rs`
- `crates/life-app/src/app.rs`
- `crates/life-app/Cargo.toml`

#### Core ecology and cellular-state model
`life-core` defines the domain model independent of graphics: grid state, topology, rules, stochastic probability handling, terrain, and simulation statistics. Its model is an ecology CA rather than conventional B/S Life: prey growth is contact-process-like and predation is conserved/WaTor-style, with marten/red/grey asymmetry central to the rules.
- `crates/life-core/src/grid.rs`
- `crates/life-core/src/rule.rs`
- `crates/life-core/src/evolve.rs`

#### Simulation evolution and experiments
Core evolution appears split between ordinary stepping, evolved/environmental behavior, detection, and trial execution. This is the natural CPU-side control-flow boundary: initialize a grid and rules, repeatedly evolve state, detect outcomes or stability, and aggregate statistics for presentation or search.
- `crates/life-core/src/evolve.rs`
- `crates/life-core/src/detect.rs`
- `crates/life-core/src/trial.rs`

#### Spatial environment and topology
Terrain and topology are explicit model inputs rather than renderer-only concerns. They likely control neighborhood/wrapping semantics and habitat effects, supporting the repository’s stated future habitat distinction (conifer favoring reds; broadleaf favoring greys).
- `crates/life-core/src/topology.rs`
- `crates/life-core/src/terrain.rs`
- `crates/life-core/src/prob.rs`

#### GPU simulation backend
`life-gpu` provides a GPU implementation or acceleration path for simulation stepping. Rust context/simulation modules manage GPU resources and dispatch; WGSL shaders encode standard, stochastic, and evolutionary step kernels. This is the key boundary between domain state and device-resident buffers/compute execution.
- `crates/life-gpu/src/context.rs`
- `crates/life-gpu/src/sim.rs`
- `crates/life-gpu/src/step_stoch.wgsl`

#### Rendering and interaction
`life-render` turns simulation state into a drawable mesh and GPU shaders, with camera and picking support for spatial inspection. It is deliberately separate from evolution, so visualization and interaction should consume state without owning ecological rules.
- `crates/life-render/src/lib.rs`
- `crates/life-render/src/mesh.rs`
- `crates/life-render/src/pick.rs`

#### Runtime, infrastructure, and migration context
The material runtime is Rust/Cargo, organized as a multi-crate workspace (`Cargo.toml`), with GPU shader programs in WGSL. CI is defined in `.github/workflows/ci.yml`. The root HTML/JS assets represent prior Life-suite and ecology implementations; Rust rewrite and ecology design documents indicate an active migration/specification trail rather than a separate service architecture.
- `Cargo.toml`
- `.github/workflows/ci.yml`
- `docs/superpowers/specs/2026-07-14-life-ecology-design.md`

Main entry points: [`crates/life-core/src/evolve.rs`](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/evolve.rs) (CPU evolution), [`Cargo.toml`](https://github.com/ci4ic4/life/blob/master/Cargo.toml) (Cargo workspace), [`crates/life-app/src/app.rs`](https://github.com/ci4ic4/life/blob/master/crates/life-app/src/app.rs) (Runtime orchestration), [`crates/life-gpu/src/sim.rs`](https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/sim.rs) (GPU simulation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_app_main["Executable entry<br/>Rust binary<br/>[main.rs]"]
  node_app_runtime["Runtime orchestration<br/>application loop<br/>[app.rs]"]
end

subgraph group_core["Ecology Core"]
  node_core_grid["Grid state<br/>cellular state<br/>[grid.rs]"]
  node_ecology_rules["Ecology rules<br/>domain rules<br/>[rule.rs]"]
  node_cpu_evolution["CPU evolution<br/>simulation stepping<br/>[evolve.rs]"]
  node_outcome_trials["Detection &amp; trials<br/>experiment control<br/>[trial.rs]"]
  node_spatial_inputs["Terrain, topology &amp; probability<br/>model inputs<br/>[terrain.rs]"]
end

subgraph group_gpu["GPU Simulation"]
  node_gpu_context["GPU context<br/>device resources<br/>[context.rs]"]
  node_gpu_sim["GPU simulation<br/>compute dispatcher<br/>[sim.rs]"]
  node_stochastic_shader["Stochastic step shader<br/>WGSL compute kernel<br/>[step_stoch.wgsl]"]
end

subgraph group_render["Rendering"]
  node_renderer["Renderer<br/>graphics facade<br/>[lib.rs]"]
  node_mesh_builder["State mesh<br/>geometry builder<br/>[mesh.rs]"]
  node_spatial_picking["Spatial picking<br/>interaction<br/>[pick.rs]"]
end

subgraph group_migration["Runtime &amp; Migration"]
  node_workspace["Cargo workspace<br/>Rust workspace<br/>[Cargo.toml]"]
  node_ci["CI pipeline<br/>GitHub Actions<br/>[ci.yml]"]
  node_legacy_prototype["Legacy browser prototype<br/>HTML/JavaScript<br/>[life-ecology.html]"]
  node_ecology_design["Ecology design spec<br/>design document"]
end

node_workspace -->|"builds"| node_app_main
node_workspace -->|"builds"| node_cpu_evolution
node_workspace -->|"builds"| node_gpu_sim
node_workspace -->|"builds"| node_renderer
node_ci -->|"validates"| node_workspace
node_app_main -->|"starts"| node_app_runtime
node_app_runtime -->|"runs CPU path"| node_cpu_evolution
node_app_runtime -->|"runs GPU path"| node_gpu_sim
node_app_runtime -->|"drives"| node_renderer
node_cpu_evolution -->|"updates"| node_core_grid
node_cpu_evolution -->|"applies"| node_ecology_rules
node_cpu_evolution -->|"uses"| node_spatial_inputs
node_outcome_trials -->|"repeats"| node_cpu_evolution
node_gpu_sim -->|"uses"| node_gpu_context
node_gpu_sim -->|"dispatches"| node_stochastic_shader
node_gpu_sim -.->|"uploads/downloads state"| node_core_grid
node_renderer -->|"builds"| node_mesh_builder
node_renderer -->|"supports"| node_spatial_picking
node_renderer -.->|"visualizes"| node_core_grid
node_ecology_design -.->|"specifies"| node_ecology_rules
node_legacy_prototype -.->|"superseded by"| node_app_runtime

click node_workspace "https://github.com/ci4ic4/life/blob/master/Cargo.toml"
click node_ci "https://github.com/ci4ic4/life/blob/master/.github/workflows/ci.yml"
click node_app_main "https://github.com/ci4ic4/life/blob/master/crates/life-app/src/main.rs"
click node_app_runtime "https://github.com/ci4ic4/life/blob/master/crates/life-app/src/app.rs"
click node_core_grid "https://github.com/ci4ic4/life/blob/master/crates/life-core/src/grid.rs"
click node_ecology_rules "https://github.com/ci4ic4/life/blob/master/crates/life-core/src/rule.rs"
click node_cpu_evolution "https://github.com/ci4ic4/life/blob/master/crates/life-core/src/evolve.rs"
click node_outcome_trials "https://github.com/ci4ic4/life/blob/master/crates/life-core/src/trial.rs"
click node_spatial_inputs "https://github.com/ci4ic4/life/blob/master/crates/life-core/src/terrain.rs"
click node_gpu_context "https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/context.rs"
click node_gpu_sim "https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/sim.rs"
click node_stochastic_shader "https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/step_stoch.wgsl"
click node_renderer "https://github.com/ci4ic4/life/blob/master/crates/life-render/src/lib.rs"
click node_mesh_builder "https://github.com/ci4ic4/life/blob/master/crates/life-render/src/mesh.rs"
click node_spatial_picking "https://github.com/ci4ic4/life/blob/master/crates/life-render/src/pick.rs"
click node_legacy_prototype "https://github.com/ci4ic4/life/blob/master/life-ecology.html"
click node_ecology_design "https://github.com/ci4ic4/life/blob/master/docs/superpowers/specs/2026-07-14-life-ecology-design.md"

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_app_main,node_app_runtime toneBlue
class node_core_grid,node_ecology_rules,node_cpu_evolution,node_outcome_trials,node_spatial_inputs toneAmber
class node_gpu_context,node_gpu_sim,node_stochastic_shader toneMint
class node_renderer,node_mesh_builder,node_spatial_picking toneRose
class node_workspace,node_ci,node_legacy_prototype,node_ecology_design toneIndigo
```

## Components

### Application

- [Executable entry](https://github.com/ci4ic4/life/blob/master/crates/life-app/src/main.rs): Rust binary · `crates/life-app/src/main.rs`
- [Runtime orchestration](https://github.com/ci4ic4/life/blob/master/crates/life-app/src/app.rs): application loop · Selects and connects core stepping, GPU execution, and rendering. · `crates/life-app/src/app.rs`

### Ecology Core

- [Grid state](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/grid.rs): cellular state · `crates/life-core/src/grid.rs`
- [Ecology rules](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/rule.rs): domain rules · Encodes asymmetric marten, red squirrel, and grey squirrel dynamics. · `crates/life-core/src/rule.rs`
- [CPU evolution](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/evolve.rs): simulation stepping · `crates/life-core/src/evolve.rs`
- [Detection & trials](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/trial.rs): experiment control · Detects outcomes and aggregates repeated simulation runs. · `crates/life-core/src/trial.rs`
- [Terrain, topology & probability](https://github.com/ci4ic4/life/blob/master/crates/life-core/src/terrain.rs): model inputs · Supplies habitat, neighborhood semantics, and stochastic behavior. · `crates/life-core/src/terrain.rs`

### GPU Simulation

- [GPU context](https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/context.rs): device resources · `crates/life-gpu/src/context.rs`
- [GPU simulation](https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/sim.rs): compute dispatcher · Manages device-resident state and compute stepping. · `crates/life-gpu/src/sim.rs`
- [Stochastic step shader](https://github.com/ci4ic4/life/blob/master/crates/life-gpu/src/step_stoch.wgsl): WGSL compute kernel · `crates/life-gpu/src/step_stoch.wgsl`

### Rendering

- [Renderer](https://github.com/ci4ic4/life/blob/master/crates/life-render/src/lib.rs): graphics facade · Visualizes simulation state without owning ecological rules. · `crates/life-render/src/lib.rs`
- [State mesh](https://github.com/ci4ic4/life/blob/master/crates/life-render/src/mesh.rs): geometry builder · `crates/life-render/src/mesh.rs`
- [Spatial picking](https://github.com/ci4ic4/life/blob/master/crates/life-render/src/pick.rs): interaction · `crates/life-render/src/pick.rs`

### Runtime & Migration

- [Cargo workspace](https://github.com/ci4ic4/life/blob/master/Cargo.toml): Rust workspace · Builds and composes the active multi-crate runtime. · `Cargo.toml`
- [CI pipeline](https://github.com/ci4ic4/life/blob/master/.github/workflows/ci.yml): GitHub Actions · `.github/workflows/ci.yml`
- [Legacy browser prototype](https://github.com/ci4ic4/life/blob/master/life-ecology.html): HTML/JavaScript · Prior browser-facing ecology implementation retained during the Rust migration. · `life-ecology.html`
- [Ecology design spec](https://github.com/ci4ic4/life/blob/master/docs/superpowers/specs/2026-07-14-life-ecology-design.md): design document · Records the active ecology model and migration direction. · `docs/superpowers/specs/2026-07-14-life-ecology-design.md`

## Connections

- Cargo workspace → Executable entry: builds
- Cargo workspace → CPU evolution: builds
- Cargo workspace → GPU simulation: builds
- Cargo workspace → Renderer: builds
- CI pipeline → Cargo workspace: validates
- Executable entry → Runtime orchestration: starts
- Runtime orchestration → CPU evolution: runs CPU path
- Runtime orchestration → GPU simulation: runs GPU path
- Runtime orchestration → Renderer: drives
- CPU evolution → Grid state: updates
- CPU evolution → Ecology rules: applies
- CPU evolution → Terrain, topology & probability: uses
- Detection & trials → CPU evolution: repeats
- GPU simulation → GPU context: uses
- GPU simulation → Stochastic step shader: dispatches
- GPU simulation → Grid state: uploads/downloads state
- Renderer → State mesh: builds
- Renderer → Spatial picking: supports
- Renderer → Grid state: visualizes
- Ecology design spec → Ecology rules: specifies
- Legacy browser prototype → Runtime orchestration: superseded by
