# hedaas-code/linyi architecture

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

- Interactive diagram: https://gitdiagram.com/hedaas-code/linyi
- Repository: https://github.com/hedaas-code/linyi

## Overview

LinYi is a tick-driven, multi-agent shelter and society simulator with a web console and REST API. The main workflow is to start or restore a world, advance ticks, let residents respond to survival pressures and make decisions, then inspect telemetry, history, and saved state. The graph preserves documented social, economic, town, and civilization capabilities, as well as optional LLM support. Runtime-to-domain links are based on the loop excerpt or README; unsampled implementation details are not inferred as confirmed calls.

Main entry points: [`src/runtime/orchestrator/loop.js`](https://github.com/hedaas-code/linyi/blob/main/src/runtime/orchestrator/loop.js) (Tick loop), [`bin/server.js`](https://github.com/hedaas-code/linyi/blob/main/bin/server.js) (HTTP server), [`src/api/index.js`](https://github.com/hedaas-code/linyi/blob/main/src/api/index.js) (API routes), [`src/api/observer.js`](https://github.com/hedaas-code/linyi/blob/main/src/api/observer.js) (Query and save API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Simulation runtime"]
  node_loop["Tick loop<br/>[loop.js]"]
  node_clock["Simulation clock<br/>[clock.js]"]
  node_worldstate["World state<br/>[world-state.js]"]
  node_persistence["Snapshot persistence<br/>[persistence.js]"]
end

subgraph group_residents["Residents and AI"]
  node_agent["Resident behavior<br/>[index.js]"]
  node_ai["LLM gateway<br/>[gateway.js]"]
  node_providers["LLM providers<br/>[provider.a6api.js]"]
end

subgraph group_world["World systems"]
  node_survival["Survival pressures<br/>[index.js]"]
  node_social["Social systems<br/>[index.js]"]
  node_economy["Economy<br/>[index.js]"]
  node_civilization["Civilization<br/>[index.js]"]
  node_town["Town and facilities<br/>[index.js]"]
  node_genesis["World and resident generation<br/>[index.js]"]
end

subgraph group_insight["Observation and storage"]
  node_observer["History and experiments<br/>[index.js]"]
  node_recorder["Event and action logs<br/>[index.js]"]
  node_graphstore[("Graph store<br/>[graph.js]")]
  node_hotlog["Bounded log retention<br/>[hot-log.js]"]
end

subgraph group_interface["API and control"]
  node_server["HTTP server<br/>[server.js]"]
  node_api["API routes<br/>[index.js]"]
  node_control["Simulation control<br/>[control.js]"]
  node_apiobserver["Query and save API<br/>[observer.js]"]
end

node_operator(("Operator"))

node_operator -->|"starts service"| node_server
node_server -->|"starts routes"| node_api
node_api -->|"routes controls"| node_control
node_api -->|"routes queries"| node_apiobserver
node_control -->|"controls ticks"| node_loop
node_loop -->|"advances time"| node_clock
node_loop -->|"updates world"| node_worldstate
node_loop -->|"runs decisions"| node_agent
node_loop -->|"reads pressures"| node_survival
node_loop -->|"generates thoughts"| node_ai
node_loop -.->|"runs social systems"| node_social
node_loop -.->|"runs economy"| node_economy
node_loop -.->|"runs civilization"| node_civilization
node_loop -.->|"uses town systems"| node_town
node_loop -.->|"creates residents"| node_genesis
node_server -->|"configures provider"| node_ai
node_ai -->|"uses adapters"| node_providers
node_apiobserver -->|"queries history"| node_observer
node_apiobserver -->|"saves snapshots"| node_persistence
node_observer -->|"exposes logs"| node_recorder
node_recorder -->|"uses retention"| node_hotlog
node_hotlog -->|"trims log nodes"| node_graphstore

click node_server "https://github.com/hedaas-code/linyi/blob/main/bin/server.js"
click node_api "https://github.com/hedaas-code/linyi/blob/main/src/api/index.js"
click node_control "https://github.com/hedaas-code/linyi/blob/main/src/api/control.js"
click node_apiobserver "https://github.com/hedaas-code/linyi/blob/main/src/api/observer.js"
click node_loop "https://github.com/hedaas-code/linyi/blob/main/src/runtime/orchestrator/loop.js"
click node_clock "https://github.com/hedaas-code/linyi/blob/main/src/runtime/clock.js"
click node_worldstate "https://github.com/hedaas-code/linyi/blob/main/src/runtime/world-state.js"
click node_persistence "https://github.com/hedaas-code/linyi/blob/main/src/runtime/persistence.js"
click node_agent "https://github.com/hedaas-code/linyi/blob/main/src/agent/index.js"
click node_survival "https://github.com/hedaas-code/linyi/blob/main/src/survival/index.js"
click node_ai "https://github.com/hedaas-code/linyi/blob/main/src/ai/llm/gateway.js"
click node_providers "https://github.com/hedaas-code/linyi/blob/main/src/ai/llm/provider.a6api.js"
click node_social "https://github.com/hedaas-code/linyi/blob/main/src/social/index.js"
click node_economy "https://github.com/hedaas-code/linyi/blob/main/src/economy/index.js"
click node_civilization "https://github.com/hedaas-code/linyi/blob/main/src/civilization/index.js"
click node_town "https://github.com/hedaas-code/linyi/blob/main/src/town/index.js"
click node_genesis "https://github.com/hedaas-code/linyi/blob/main/src/genesis/index.js"
click node_observer "https://github.com/hedaas-code/linyi/blob/main/src/observer/index.js"
click node_recorder "https://github.com/hedaas-code/linyi/blob/main/src/observer/recorder/index.js"
click node_graphstore "https://github.com/hedaas-code/linyi/blob/main/src/infra/store/graph.js"
click node_hotlog "https://github.com/hedaas-code/linyi/blob/main/src/infra/store/hot-log.js"

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_loop,node_clock,node_worldstate,node_persistence toneBlue
class node_agent,node_ai,node_providers toneAmber
class node_survival,node_social,node_economy,node_civilization,node_town,node_genesis toneMint
class node_observer,node_recorder,node_graphstore,node_hotlog toneRose
class node_server,node_api,node_control,node_apiobserver,node_operator toneIndigo
```

## Components

### Simulation runtime

- [Tick loop](https://github.com/hedaas-code/linyi/blob/main/src/runtime/orchestrator/loop.js): `src/runtime/orchestrator/loop.js`
- [Simulation clock](https://github.com/hedaas-code/linyi/blob/main/src/runtime/clock.js): `src/runtime/clock.js`
- [World state](https://github.com/hedaas-code/linyi/blob/main/src/runtime/world-state.js): `src/runtime/world-state.js`
- [Snapshot persistence](https://github.com/hedaas-code/linyi/blob/main/src/runtime/persistence.js): `src/runtime/persistence.js`

### Residents and AI

- [Resident behavior](https://github.com/hedaas-code/linyi/blob/main/src/agent/index.js): `src/agent/index.js`
- [LLM gateway](https://github.com/hedaas-code/linyi/blob/main/src/ai/llm/gateway.js): `src/ai/llm/gateway.js`
- [LLM providers](https://github.com/hedaas-code/linyi/blob/main/src/ai/llm/provider.a6api.js): `src/ai/llm/provider.a6api.js`

### World systems

- [Survival pressures](https://github.com/hedaas-code/linyi/blob/main/src/survival/index.js): `src/survival/index.js`
- [Social systems](https://github.com/hedaas-code/linyi/blob/main/src/social/index.js): `src/social/index.js`
- [Economy](https://github.com/hedaas-code/linyi/blob/main/src/economy/index.js): `src/economy/index.js`
- [Civilization](https://github.com/hedaas-code/linyi/blob/main/src/civilization/index.js): `src/civilization/index.js`
- [Town and facilities](https://github.com/hedaas-code/linyi/blob/main/src/town/index.js): `src/town/index.js`
- [World and resident generation](https://github.com/hedaas-code/linyi/blob/main/src/genesis/index.js): `src/genesis/index.js`

### Observation and storage

- [History and experiments](https://github.com/hedaas-code/linyi/blob/main/src/observer/index.js): `src/observer/index.js`
- [Event and action logs](https://github.com/hedaas-code/linyi/blob/main/src/observer/recorder/index.js): `src/observer/recorder/index.js`
- [Graph store](https://github.com/hedaas-code/linyi/blob/main/src/infra/store/graph.js): `src/infra/store/graph.js`
- [Bounded log retention](https://github.com/hedaas-code/linyi/blob/main/src/infra/store/hot-log.js): `src/infra/store/hot-log.js`

### API and control

- [HTTP server](https://github.com/hedaas-code/linyi/blob/main/bin/server.js): `bin/server.js`
- [API routes](https://github.com/hedaas-code/linyi/blob/main/src/api/index.js): `src/api/index.js`
- [Simulation control](https://github.com/hedaas-code/linyi/blob/main/src/api/control.js): `src/api/control.js`
- [Query and save API](https://github.com/hedaas-code/linyi/blob/main/src/api/observer.js): `src/api/observer.js`

### Other components

- **Operator**

## Connections

- Operator → HTTP server: starts service
- HTTP server → API routes: starts routes (evidence: `bin/server.js`)
- API routes → Simulation control: routes controls (evidence: `src/api/index.js`)
- API routes → Query and save API: routes queries (evidence: `src/api/index.js`)
- Simulation control → Tick loop: controls ticks (evidence: `src/api/control.js`)
- Tick loop → Simulation clock: advances time (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → World state: updates world (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → Resident behavior: runs decisions (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → Survival pressures: reads pressures (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → LLM gateway: generates thoughts (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → Social systems: runs social systems (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → Economy: runs economy
- Tick loop → Civilization: runs civilization (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → Town and facilities: uses town systems (evidence: `src/runtime/orchestrator/loop.js`)
- Tick loop → World and resident generation: creates residents (evidence: `src/runtime/orchestrator/loop.js`)
- HTTP server → LLM gateway: configures provider (evidence: `bin/server.js`)
- LLM gateway → LLM providers: uses adapters (evidence: `src/ai/llm/gateway.js`)
- Query and save API → History and experiments: queries history (evidence: `src/api/observer.js`)
- Query and save API → Snapshot persistence: saves snapshots (evidence: `src/api/observer.js`)
- History and experiments → Event and action logs: exposes logs (evidence: `src/observer/index.js`)
- Event and action logs → Bounded log retention: uses retention (evidence: `src/observer/recorder/index.js`)
- Bounded log retention → Graph store: trims log nodes (evidence: `src/infra/store/hot-log.js`)
