# solvedsphinx126/life-simulation architecture

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

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

## Overview

This repository implements a browser-based ecosystem simulation: users load an XML scenario, the browser creates and configures a Rust/Wasm map, and the simulation advances while the browser renders it. Users can adjust simulation speed and export reports; completed runs are ranked in a leaderboard. The Rust implementation is concentrated in one large source file, so several domain components share that path. The excerpts show the browser-to-Wasm calls and selected simulation behavior, but not every internal interaction.

Main entry points: [`src/lib.rs`](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs) (Map and tick), [`www/index.js`](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js) (Report export)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Browser interface"]
  node_xml["XML scenario loader<br/>[index.js]"]
  node_controls["Speed controls<br/>[index.js]"]
  node_renderer["Canvas renderer<br/>[index.js]"]
  node_export["Report export<br/>[index.js]"]
  node_leaderboard["Run leaderboard<br/>[index.js]"]
end

subgraph group_sim["Simulation engine"]
  node_map["Map and tick<br/>[lib.rs]"]
  node_movement["Movement and vision<br/>[lib.rs]"]
  node_scoring["Simulation score<br/>[lib.rs]"]
end

subgraph group_domains["Ecosystem domains"]
  node_terrain["Rocks and obstacles<br/>[lib.rs]"]
  node_plants["Plant growth<br/>[lib.rs]"]
  node_grazers["Grazer behavior<br/>[lib.rs]"]
  node_predators["Predator behavior<br/>[lib.rs]"]
  node_reproduction["Genes and mating<br/>[lib.rs]"]
end

node_user(("Scenario user"))

node_user -->|"loads scenario"| node_xml
node_user -->|"sets speed"| node_controls
node_xml -->|"configures map"| node_map
node_controls -->|"sets delay"| node_renderer
node_renderer -->|"ticks and reads"| node_map
node_map -.->|"uses movement"| node_movement
node_map -.->|"stores entities"| node_terrain
node_map -.->|"ticks ecology"| node_plants
node_map -.->|"ticks ecology"| node_grazers
node_map -->|"ticks ecology"| node_predators
node_predators -->|"mates and births"| node_reproduction
node_export -->|"gets report data"| node_map
node_export -->|"records score"| node_leaderboard
node_export -->|"gets score"| node_scoring

click node_xml "https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js"
click node_controls "https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js"
click node_renderer "https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js"
click node_export "https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js"
click node_leaderboard "https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js"
click node_map "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_movement "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_terrain "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_plants "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_grazers "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_predators "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_reproduction "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"
click node_scoring "https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs"

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_xml,node_controls,node_renderer,node_export,node_leaderboard,node_user toneBlue
class node_map,node_movement,node_scoring toneAmber
class node_terrain,node_plants,node_grazers,node_predators,node_reproduction toneMint
```

## Components

### Browser interface

- [XML scenario loader](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js): `www/index.js`
- [Speed controls](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js): `www/index.js`
- [Canvas renderer](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js): `www/index.js`
- [Report export](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js): `www/index.js`
- [Run leaderboard](https://github.com/solvedsphinx126/life-simulation/blob/master/www/index.js): `www/index.js`

### Simulation engine

- [Map and tick](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Movement and vision](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Simulation score](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`

### Ecosystem domains

- [Rocks and obstacles](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Plant growth](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Grazer behavior](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Predator behavior](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`
- [Genes and mating](https://github.com/solvedsphinx126/life-simulation/blob/master/src/lib.rs): `src/lib.rs`

### Other components

- **Scenario user**

## Connections

- Scenario user → XML scenario loader: loads scenario (evidence: `www/index.js`)
- Scenario user → Speed controls: sets speed (evidence: `www/index.js`)
- XML scenario loader → Map and tick: configures map (evidence: `www/index.js`)
- Speed controls → Canvas renderer: sets delay (evidence: `www/index.js`)
- Canvas renderer → Map and tick: ticks and reads (evidence: `www/index.js`)
- Map and tick → Movement and vision: uses movement (evidence: `src/lib.rs`)
- Map and tick → Rocks and obstacles: stores entities (evidence: `src/lib.rs`)
- Map and tick → Plant growth: ticks ecology (evidence: `src/lib.rs`)
- Map and tick → Grazer behavior: ticks ecology (evidence: `src/lib.rs`)
- Map and tick → Predator behavior: ticks ecology (evidence: `src/lib.rs`)
- Predator behavior → Genes and mating: mates and births (evidence: `src/lib.rs`)
- Report export → Map and tick: gets report data (evidence: `www/index.js`)
- Report export → Run leaderboard: records score (evidence: `www/index.js`)
- Report export → Simulation score: gets score (evidence: `www/index.js`)
