# oosubhisara/rusty-snake architecture

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

- Interactive diagram: https://gitdiagram.com/oosubhisara/rusty-snake
- Repository: https://github.com/oosubhisara/rusty-snake

## Overview

rusty-snake is a Macroquad Snake game with single- and two-player modes. The runtime entry point creates and loads GameState, then repeatedly updates and draws it. GameState owns the gameplay flow: it handles input and level transitions, updates snakes and apples, and renders the playfield and status labels. Assets are loaded from the packaged data file through DataPakLoader. The excerpts show these principal calls; unsampled runtime details are represented only where the README or source index supports them.

Main entry points: [`src/gamestate.rs`](https://github.com/oosubhisara/rusty-snake/blob/main/src/gamestate.rs) (Game state), [`src/gamescene.rs`](https://github.com/oosubhisara/rusty-snake/blob/main/src/gamescene.rs) (Game scene), [`src/snake.rs`](https://github.com/oosubhisara/rusty-snake/blob/main/src/snake.rs) (Snake), [`src/apple.rs`](https://github.com/oosubhisara/rusty-snake/blob/main/src/apple.rs) (Apple)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_entry["Game loop<br/>[main.rs]"]
  node_state["Game state<br/>[gamestate.rs]"]
  node_timing["Shared timing<br/>[common.rs]"]
end

subgraph group_gameplay["Gameplay"]
  node_snake["Snake<br/>[snake.rs]"]
  node_apple["Apple<br/>[apple.rs]"]
end

subgraph group_presentation["Scene and UI"]
  node_scene["Game scene<br/>[gamescene.rs]"]
  node_labels["HUD labels<br/>[label.rs]"]
end

subgraph group_resources["Assets"]
  node_assets["Asset manager<br/>[assets.rs]"]
  node_pak["DataPak reader<br/>[datapakloader.rs]"]
  node_pakfile["Packaged assets<br/>[data.pak]"]
end

node_player(("Player"))
node_macroquad["Macroquad"]

node_player -->|"chooses mode"| node_state
node_entry -->|"runs loop"| node_state
node_state -->|"updates and draws"| node_snake
node_state -->|"spawns and updates"| node_apple
node_state -->|"updates and draws"| node_scene
node_state -->|"draws HUD"| node_labels
node_state -->|"loads and uses"| node_assets
node_state -->|"uses timers"| node_timing
node_snake -->|"checks collection"| node_apple
node_snake -->|"draws on"| node_scene
node_apple -->|"avoids positions"| node_snake
node_apple -->|"draws on"| node_scene
node_scene -->|"animates with"| node_timing
node_assets -->|"loads bundled data"| node_pak
node_pak -->|"reads"| node_pakfile
node_entry -->|"uses runtime"| node_macroquad
node_scene -->|"renders primitives"| node_macroquad
node_labels -->|"draws text"| node_macroquad
node_assets -->|"loads audio and graphics"| node_macroquad

click node_entry "https://github.com/oosubhisara/rusty-snake/blob/main/src/main.rs"
click node_state "https://github.com/oosubhisara/rusty-snake/blob/main/src/gamestate.rs"
click node_snake "https://github.com/oosubhisara/rusty-snake/blob/main/src/snake.rs"
click node_apple "https://github.com/oosubhisara/rusty-snake/blob/main/src/apple.rs"
click node_scene "https://github.com/oosubhisara/rusty-snake/blob/main/src/gamescene.rs"
click node_labels "https://github.com/oosubhisara/rusty-snake/blob/main/src/label.rs"
click node_timing "https://github.com/oosubhisara/rusty-snake/blob/main/src/common.rs"
click node_assets "https://github.com/oosubhisara/rusty-snake/blob/main/src/assets.rs"
click node_pak "https://github.com/oosubhisara/rusty-snake/blob/main/src/datapakloader.rs"
click node_pakfile "https://github.com/oosubhisara/rusty-snake/blob/main/data.pak"

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_entry,node_state,node_timing toneBlue
class node_snake,node_apple toneAmber
class node_scene,node_labels toneMint
class node_assets,node_pak,node_pakfile toneRose
class node_player,node_macroquad toneIndigo
```

## Components

### Game runtime

- [Game loop](https://github.com/oosubhisara/rusty-snake/blob/main/src/main.rs): `src/main.rs`
- [Game state](https://github.com/oosubhisara/rusty-snake/blob/main/src/gamestate.rs): `src/gamestate.rs`
- [Shared timing](https://github.com/oosubhisara/rusty-snake/blob/main/src/common.rs): `src/common.rs`

### Gameplay

- [Snake](https://github.com/oosubhisara/rusty-snake/blob/main/src/snake.rs): `src/snake.rs`
- [Apple](https://github.com/oosubhisara/rusty-snake/blob/main/src/apple.rs): `src/apple.rs`

### Scene and UI

- [Game scene](https://github.com/oosubhisara/rusty-snake/blob/main/src/gamescene.rs): `src/gamescene.rs`
- [HUD labels](https://github.com/oosubhisara/rusty-snake/blob/main/src/label.rs): `src/label.rs`

### Assets

- [Asset manager](https://github.com/oosubhisara/rusty-snake/blob/main/src/assets.rs): `src/assets.rs`
- [DataPak reader](https://github.com/oosubhisara/rusty-snake/blob/main/src/datapakloader.rs): `src/datapakloader.rs`
- [Packaged assets](https://github.com/oosubhisara/rusty-snake/blob/main/data.pak): `data.pak`

### Other components

- **Player**
- **Macroquad**

## Connections

- Player → Game state: chooses mode (evidence: `README.md`)
- Game loop → Game state: runs loop (evidence: `src/main.rs`)
- Game state → Snake: updates and draws (evidence: `src/gamestate.rs`)
- Game state → Apple: spawns and updates (evidence: `src/gamestate.rs`)
- Game state → Game scene: updates and draws (evidence: `src/gamestate.rs`)
- Game state → HUD labels: draws HUD (evidence: `src/gamestate.rs`)
- Game state → Asset manager: loads and uses (evidence: `src/gamestate.rs`)
- Game state → Shared timing: uses timers (evidence: `src/gamestate.rs`)
- Snake → Apple: checks collection (evidence: `src/snake.rs`)
- Snake → Game scene: draws on (evidence: `src/snake.rs`)
- Apple → Snake: avoids positions (evidence: `src/apple.rs`)
- Apple → Game scene: draws on (evidence: `src/apple.rs`)
- Game scene → Shared timing: animates with (evidence: `src/gamescene.rs`)
- Asset manager → DataPak reader: loads bundled data (evidence: `src/assets.rs`)
- DataPak reader → Packaged assets: reads (evidence: `src/datapakloader.rs`)
- Game loop → Macroquad: uses runtime (evidence: `src/main.rs`)
- Game scene → Macroquad: renders primitives (evidence: `src/gamescene.rs`)
- HUD labels → Macroquad: draws text (evidence: `src/label.rs`)
- Asset manager → Macroquad: loads audio and graphics (evidence: `src/assets.rs`)
