# sdgoij/goats architecture

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

- Interactive diagram: https://gitdiagram.com/sdgoij/goats
- Repository: https://github.com/sdgoij/goats

## Overview

Slag Goat is a JavaScript-driven 3D goat sandbox, with both an interactive client and multiplayer hosting/bridging components. The principal play loop is player input into the scene, which updates goats, herd, terrain, weather, and world presentation; the client also renders lighting, water, and audio. Multiplayer adds a headless host that simulates the shared scene and a session/protocol layer for peers. The README and excerpts support these major branches, but many game modules were not sampled, so internal game-to-game calls are not asserted.

Main entry points: [`crates/goats/src/game`](https://github.com/sdgoij/goats/tree/main/crates/goats/src/game) (Scene runtime), [`crates/godot/src/net.rs`](https://github.com/sdgoij/goats/blob/main/crates/godot/src/net.rs) (Godot networking), [`crates/server/src/main.rs`](https://github.com/sdgoij/goats/blob/main/crates/server/src/main.rs) (Dedicated server), [`crates/server/src/headless.rs`](https://github.com/sdgoij/goats/blob/main/crates/server/src/headless.rs) (Headless scene host)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game scene"]
  node_scene["Scene runtime"]
  node_goat["Goat state<br/>[goat.js]"]
  node_herd["Bot herd<br/>[bots.js]"]
  node_terrain["Terrain and world<br/>[world.js]"]
  node_weather["Weather and sky<br/>[weather.js]"]
  node_water["Water pools<br/>[water.js]"]
  node_lighting["Lighting and shadows<br/>[lighting.js]"]
  node_explosions["Explosions<br/>[explosions.js]"]
  node_audiojs["Scene audio<br/>[audio.js]"]
end

subgraph group_host["Runtime hosts"]
  node_client["Raylib client<br/>[lib.rs]"]
  node_audiohost["Audio host<br/>[audio.rs]"]
  node_headless["Headless scene host<br/>[headless.rs]"]
  node_server["Dedicated server<br/>[main.rs]"]
  node_godot["Godot bridge<br/>[lib.rs]"]
end

subgraph group_multiplayer["Multiplayer"]
  node_netbridge["Godot networking<br/>[net.rs]"]
  node_session["Session transport<br/>[lib.rs]"]
  node_swarm["Host discovery<br/>[swarm.rs]"]
  node_protocol["Protocol messages<br/>[lib.rs]"]
  node_wire["Datagram encoding<br/>[wire.rs]"]
end

subgraph group_extensions["Mods and voice"]
  node_modloader["Mod loading<br/>[lib.rs]"]
  node_voice["Voice codec<br/>[lib.rs]"]
  node_godotvoice["Godot voice bridge<br/>[voice.rs]"]
end

node_player(("Player"))

node_player -->|"controls"| node_scene
node_scene -->|"updates"| node_goat
node_scene -->|"simulates"| node_herd
node_scene -->|"uses"| node_terrain
node_scene -->|"drives"| node_weather
node_scene -->|"simulates"| node_water
node_scene -->|"renders with"| node_lighting
node_scene -->|"triggers"| node_explosions
node_scene -->|"plays"| node_audiojs
node_client -->|"evaluates"| node_scene
node_client -->|"uses"| node_audiohost
node_server -->|"starts"| node_headless
node_headless -->|"evaluates"| node_scene
node_headless -->|"loads mods"| node_modloader
node_server -->|"hosts session"| node_session
node_server -->|"starts discovery"| node_swarm
node_godot -->|"registers"| node_netbridge
node_netbridge -->|"uses transport"| node_session
node_netbridge -->|"uses frames"| node_protocol
node_session -->|"encodes messages"| node_protocol
node_protocol -->|"uses datagrams"| node_wire
node_netbridge -->|"joins topics"| node_swarm
node_godotvoice -->|"uses codec"| node_voice
node_netbridge -->|"owns voice state"| node_godotvoice

click node_scene "https://github.com/sdgoij/goats/tree/main/crates/goats/src/game"
click node_goat "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/goat.js"
click node_herd "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/bots.js"
click node_terrain "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/world.js"
click node_weather "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/weather.js"
click node_water "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/water.js"
click node_lighting "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/lighting.js"
click node_explosions "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/explosions.js"
click node_audiojs "https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/audio.js"
click node_client "https://github.com/sdgoij/goats/blob/main/crates/goats/src/lib.rs"
click node_audiohost "https://github.com/sdgoij/goats/blob/main/crates/goats/src/audio.rs"
click node_headless "https://github.com/sdgoij/goats/blob/main/crates/server/src/headless.rs"
click node_server "https://github.com/sdgoij/goats/blob/main/crates/server/src/main.rs"
click node_godot "https://github.com/sdgoij/goats/blob/main/crates/godot/src/lib.rs"
click node_netbridge "https://github.com/sdgoij/goats/blob/main/crates/godot/src/net.rs"
click node_session "https://github.com/sdgoij/goats/blob/main/crates/session/src/lib.rs"
click node_swarm "https://github.com/sdgoij/goats/blob/main/crates/session/src/swarm.rs"
click node_protocol "https://github.com/sdgoij/goats/blob/main/crates/proto/src/lib.rs"
click node_wire "https://github.com/sdgoij/goats/blob/main/crates/proto/src/wire.rs"
click node_modloader "https://github.com/sdgoij/goats/blob/main/crates/mods/src/lib.rs"
click node_voice "https://github.com/sdgoij/goats/blob/main/crates/voice/src/lib.rs"
click node_godotvoice "https://github.com/sdgoij/goats/blob/main/crates/godot/src/voice.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_scene,node_goat,node_herd,node_terrain,node_weather,node_water,node_lighting,node_explosions,node_audiojs toneBlue
class node_client,node_audiohost,node_headless,node_server,node_godot toneAmber
class node_netbridge,node_session,node_swarm,node_protocol,node_wire toneMint
class node_modloader,node_voice,node_godotvoice toneRose
class node_player toneIndigo
```

## Components

### Game scene

- [Scene runtime](https://github.com/sdgoij/goats/tree/main/crates/goats/src/game): `crates/goats/src/game`
- [Goat state](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/goat.js): `crates/goats/src/game/goat.js`
- [Bot herd](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/bots.js): `crates/goats/src/game/bots.js`
- [Terrain and world](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/world.js): `crates/goats/src/game/world.js`
- [Weather and sky](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/weather.js): `crates/goats/src/game/weather.js`
- [Water pools](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/water.js): `crates/goats/src/game/water.js`
- [Lighting and shadows](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/lighting.js): `crates/goats/src/game/lighting.js`
- [Explosions](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/explosions.js): `crates/goats/src/game/explosions.js`
- [Scene audio](https://github.com/sdgoij/goats/blob/main/crates/goats/src/game/audio.js): `crates/goats/src/game/audio.js`

### Runtime hosts

- [Raylib client](https://github.com/sdgoij/goats/blob/main/crates/goats/src/lib.rs): `crates/goats/src/lib.rs`
- [Audio host](https://github.com/sdgoij/goats/blob/main/crates/goats/src/audio.rs): `crates/goats/src/audio.rs`
- [Headless scene host](https://github.com/sdgoij/goats/blob/main/crates/server/src/headless.rs): `crates/server/src/headless.rs`
- [Dedicated server](https://github.com/sdgoij/goats/blob/main/crates/server/src/main.rs): `crates/server/src/main.rs`
- [Godot bridge](https://github.com/sdgoij/goats/blob/main/crates/godot/src/lib.rs): `crates/godot/src/lib.rs`

### Multiplayer

- [Godot networking](https://github.com/sdgoij/goats/blob/main/crates/godot/src/net.rs): `crates/godot/src/net.rs`
- [Session transport](https://github.com/sdgoij/goats/blob/main/crates/session/src/lib.rs): `crates/session/src/lib.rs`
- [Host discovery](https://github.com/sdgoij/goats/blob/main/crates/session/src/swarm.rs): `crates/session/src/swarm.rs`
- [Protocol messages](https://github.com/sdgoij/goats/blob/main/crates/proto/src/lib.rs): `crates/proto/src/lib.rs`
- [Datagram encoding](https://github.com/sdgoij/goats/blob/main/crates/proto/src/wire.rs): `crates/proto/src/wire.rs`

### Mods and voice

- [Mod loading](https://github.com/sdgoij/goats/blob/main/crates/mods/src/lib.rs): `crates/mods/src/lib.rs`
- [Voice codec](https://github.com/sdgoij/goats/blob/main/crates/voice/src/lib.rs): `crates/voice/src/lib.rs`
- [Godot voice bridge](https://github.com/sdgoij/goats/blob/main/crates/godot/src/voice.rs): `crates/godot/src/voice.rs`

### Other components

- **Player**

## Connections

- Player → Scene runtime: controls
- Scene runtime → Goat state: updates
- Scene runtime → Bot herd: simulates
- Scene runtime → Terrain and world: uses
- Scene runtime → Weather and sky: drives
- Scene runtime → Water pools: simulates
- Scene runtime → Lighting and shadows: renders with
- Scene runtime → Explosions: triggers
- Scene runtime → Scene audio: plays
- Raylib client → Scene runtime: evaluates
- Raylib client → Audio host: uses (evidence: `crates/goats/src/lib.rs`)
- Dedicated server → Headless scene host: starts (evidence: `crates/server/src/main.rs`)
- Headless scene host → Scene runtime: evaluates (evidence: `crates/server/src/headless.rs`)
- Headless scene host → Mod loading: loads mods (evidence: `crates/server/src/headless.rs`)
- Dedicated server → Session transport: hosts session (evidence: `crates/server/src/main.rs`)
- Dedicated server → Host discovery: starts discovery (evidence: `crates/server/src/main.rs`)
- Godot bridge → Godot networking: registers (evidence: `crates/godot/src/lib.rs`)
- Godot networking → Session transport: uses transport (evidence: `crates/godot/src/net.rs`)
- Godot networking → Protocol messages: uses frames (evidence: `crates/godot/src/net.rs`)
- Session transport → Protocol messages: encodes messages (evidence: `crates/session/src/lib.rs`)
- Protocol messages → Datagram encoding: uses datagrams (evidence: `crates/proto/src/lib.rs`)
- Godot networking → Host discovery: joins topics (evidence: `crates/godot/src/net.rs`)
- Godot voice bridge → Voice codec: uses codec (evidence: `crates/godot/src/voice.rs`)
- Godot networking → Godot voice bridge: owns voice state (evidence: `crates/godot/src/voice.rs`)
