# chezyname/survive architecture

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

- Interactive diagram: https://gitdiagram.com/chezyname/survive
- Repository: https://github.com/chezyname/survive

## Overview

1. **Overall shape**
   - This is a native Rust, single-player top-down survival game with a strong “game loop + state machine” architecture.
   - The code is organized into gameplay systems, menu/UI systems, and a reusable item/power-up system, with assets stored locally under `assets/`.

2. **Application entry and runtime**
   - `src/main.rs` is the entry point that wires the game together and starts the runtime.
   - The project is built and run with standard Cargo tooling; there are no external backend services or network dependencies in the repository.

3. **Core state management**
   - `src/gamestate.rs` appears to be the central boundary for switching between high-level modes such as main menu, gameplay, shop, and game over.
   - The menu-related files (`main_menu.rs`, `menu_base.rs`, `shop.rs`, `game_over.rs`) are likely separate state implementations that plug into the shared game-state flow.

4. **Gameplay loop**
   - The core survival loop is split across `player.rs`, `enemy.rs`, `projectile.rs`, `wave.rs`, and `wave_manager.rs`.
   - The likely data flow is: waves are generated/spawned by the wave manager, enemies are updated, the player attacks via projectiles, and combat outcomes feed back into player health, gold, and progression.

5. **Player model and stats**
   - `player.rs` and `player_stats.rs` separate runtime player behavior from stat bookkeeping.
   - This suggests a boundary between transient gameplay state (position, health, attacks) and upgradeable attributes (damage, crit, speed, etc.), which is important for diagramming how items modify the player.

6. **Item / card subsystem**
   - `src/items/` is a major subsystem: each file is a distinct upgrade/card type such as damage, crit, lifeline, shotgun, rapid fire, explosion, gold multipliers, and wave-related effects.
   - The README shows items implement a shared `Item` trait and are registered through an `ItemFactory`, so the item system is effectively a plugin-like registry of purchasable upgrades.

7. **Shop and progression flow**
   - `src/shop.rs` is the likely point where item choice, cost, and purchase conditions are evaluated.
   - Items can be unique, conditional, or repeatable, which means the shop depends on current player state to determine availability and shapes the progression loop between combat rounds.

8. **UI and presentation**
   - `src/player_ui.rs` handles in-game HUD elements such as health, resources, and possibly current build/status.
   - `src/config.rs` likely holds shared formatting and display helpers used by UI and descriptions, keeping presentation logic separate from gameplay rules.

9. **Audio subsystem**
   - `src/audio.rs` is the central interface for sound/music playback.
   - The `assets/audio/*.ogg` files show clearly separated effects and music for menu, gameplay, shop, hurt, explosion, selection, and game-over states, so audio is state-driven and event-driven rather than ambient.

10. **Assets and content packaging**
   - `assets/` contains runtime content rather than code, including audio and fonts.
   - That means the executable depends on local asset loading at runtime, and the visual/audio identity of the game is bundled with the binary rather than fetched externally.

11. **Supporting utilities**
   - `LineReader.py` is present as a standalone helper script, but it is not part of the Rust runtime architecture shown by the main source tree.
   - `CREDITS.md`, `LICENSE`, and `README.md` are documentation/support files rather than runtime systems.

12. **Architectural summary**
   - The main architectural boundary is between **state management** (menu/shop/gameplay/game-over), **combat simulation** (player/enemy/projectile/waves), and **progression** (items/shop/player stats), with **audio/UI** layered around those systems.
   - For a diagram, the most important flow is: startup → menu → gameplay loop → wave/combat updates → rewards/shop/item upgrades → eventual game over → return to menu.

Main entry points: [`src/player.rs`](https://github.com/chezyname/survive/blob/main/src/player.rs) (Player), [`src/audio.rs`](https://github.com/chezyname/survive/blob/main/src/audio.rs) (Audio), [`src/gamestate.rs`](https://github.com/chezyname/survive/blob/main/src/gamestate.rs) (Game State), [`src/shop.rs`](https://github.com/chezyname/survive/blob/main/src/shop.rs) (Shop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Main<br/>entrypoint<br/>[main.rs]"]
  node_gamestate{{"Game State<br/>state machine<br/>[gamestate.rs]"}}
  node_menu_base["Menu Base<br/>menu framework<br/>[menu_base.rs]"]
  node_main_menu["Main Menu<br/>menu state<br/>[main_menu.rs]"]
  node_shop["Shop<br/>progression state<br/>[shop.rs]"]
  node_game_over["Game Over<br/>end state<br/>[game_over.rs]"]
end

subgraph group_systems["Systems"]
  node_wave_manager["Wave Manager<br/>spawner<br/>[wave_manager.rs]"]
  node_wave["Wave<br/>encounter rules<br/>[wave.rs]"]
  node_player["Player<br/>actor<br/>[player.rs]"]
  node_player_stats["Player Stats<br/>stats model<br/>[player_stats.rs]"]
  node_enemy["Enemy<br/>actor<br/>[enemy.rs]"]
  node_projectile["Projectile<br/>combat entity<br/>[projectile.rs]"]
  node_player_ui["Player UI<br/>hud<br/>[player_ui.rs]"]
  node_audio["Audio<br/>sound system<br/>[audio.rs]"]
  node_config["Config<br/>display helpers<br/>[config.rs]"]
end

subgraph group_content["Content"]
  node_items_mod[("Items<br/>upgrade registry<br/>[mod.rs]")]
  node_item_types["Item Types<br/>upgrade modules"]
  node_assets["Assets<br/>runtime content"]
end

node_main -->|"boot"| node_gamestate
node_gamestate -->|"menu"| node_main_menu
node_gamestate -->|"shop"| node_shop
node_gamestate -->|"lose"| node_game_over
node_main_menu -->|"uses"| node_menu_base
node_gamestate -->|"play"| node_player
node_player -->|"stats"| node_player_stats
node_player -->|"fires"| node_projectile
node_player -->|"hits"| node_enemy
node_wave_manager -->|"spawns"| node_wave
node_wave -->|"contains"| node_enemy
node_enemy -->|"targets"| node_player
node_projectile -->|"damages"| node_enemy
node_shop -->|"purchases"| node_items_mod
node_items_mod -->|"loads"| node_item_types
node_shop -->|"upgrades"| node_player_stats
node_player_ui -->|"displays"| node_player
node_player_ui -->|"formats"| node_config
node_audio -->|"loads"| node_assets
node_main_menu -->|"music"| node_audio
node_shop -->|"sfx"| node_audio
node_game_over -->|"music"| node_audio
node_player -->|"sfx"| node_audio
node_wave_manager -->|"sfx"| node_audio

click node_main "https://github.com/chezyname/survive/blob/main/src/main.rs"
click node_gamestate "https://github.com/chezyname/survive/blob/main/src/gamestate.rs"
click node_menu_base "https://github.com/chezyname/survive/blob/main/src/menu_base.rs"
click node_main_menu "https://github.com/chezyname/survive/blob/main/src/main_menu.rs"
click node_shop "https://github.com/chezyname/survive/blob/main/src/shop.rs"
click node_game_over "https://github.com/chezyname/survive/blob/main/src/game_over.rs"
click node_wave_manager "https://github.com/chezyname/survive/blob/main/src/wave_manager.rs"
click node_wave "https://github.com/chezyname/survive/blob/main/src/wave.rs"
click node_player "https://github.com/chezyname/survive/blob/main/src/player.rs"
click node_player_stats "https://github.com/chezyname/survive/blob/main/src/player_stats.rs"
click node_enemy "https://github.com/chezyname/survive/blob/main/src/enemy.rs"
click node_projectile "https://github.com/chezyname/survive/blob/main/src/projectile.rs"
click node_player_ui "https://github.com/chezyname/survive/blob/main/src/player_ui.rs"
click node_audio "https://github.com/chezyname/survive/blob/main/src/audio.rs"
click node_config "https://github.com/chezyname/survive/blob/main/src/config.rs"
click node_items_mod "https://github.com/chezyname/survive/blob/main/src/items/mod.rs"
click node_assets "https://github.com/chezyname/survive/tree/main/assets"

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_main,node_gamestate,node_menu_base,node_main_menu,node_shop,node_game_over toneBlue
class node_wave_manager,node_wave,node_player,node_player_stats,node_enemy,node_projectile,node_player_ui,node_audio,node_config toneAmber
class node_items_mod,node_item_types,node_assets toneMint
```

## Components

### Runtime

Entry, state flow, and the main play loop.

- [Main](https://github.com/chezyname/survive/blob/main/src/main.rs): entrypoint · Starts the game and wires the runtime. · `src/main.rs`
- [Game State](https://github.com/chezyname/survive/blob/main/src/gamestate.rs): state machine · Central boundary for switching between menu, gameplay, shop, and game over. · `src/gamestate.rs`
- [Menu Base](https://github.com/chezyname/survive/blob/main/src/menu_base.rs): menu framework · Shared menu/state behavior used by menu screens. · `src/menu_base.rs`
- [Main Menu](https://github.com/chezyname/survive/blob/main/src/main_menu.rs): menu state · Front-door state before gameplay begins. · `src/main_menu.rs`
- [Shop](https://github.com/chezyname/survive/blob/main/src/shop.rs): progression state · Handles item selection, cost, and purchases. · `src/shop.rs`
- [Game Over](https://github.com/chezyname/survive/blob/main/src/game_over.rs): end state · Terminal state shown after defeat. · `src/game_over.rs`

### Systems

Gameplay, combat, progression, UI, and audio subsystems.

- [Wave Manager](https://github.com/chezyname/survive/blob/main/src/wave_manager.rs): spawner · Drives wave generation and pacing. · `src/wave_manager.rs`
- [Wave](https://github.com/chezyname/survive/blob/main/src/wave.rs): encounter rules · Defines wave composition and progression rules. · `src/wave.rs`
- [Player](https://github.com/chezyname/survive/blob/main/src/player.rs): actor · Runtime player behavior, movement, combat, and health. · `src/player.rs`
- [Player Stats](https://github.com/chezyname/survive/blob/main/src/player_stats.rs): stats model · Upgradeable player attributes and persistent combat modifiers. · `src/player_stats.rs`
- [Enemy](https://github.com/chezyname/survive/blob/main/src/enemy.rs): actor · Enemy behavior, targeting, and combat interactions. · `src/enemy.rs`
- [Projectile](https://github.com/chezyname/survive/blob/main/src/projectile.rs): combat entity · Fired attacks and hit resolution. · `src/projectile.rs`
- [Player UI](https://github.com/chezyname/survive/blob/main/src/player_ui.rs): hud · In-game HUD for health, resources, and status. · `src/player_ui.rs`
- [Audio](https://github.com/chezyname/survive/blob/main/src/audio.rs): sound system · Central playback interface for music and sound effects. · `src/audio.rs`
- [Config](https://github.com/chezyname/survive/blob/main/src/config.rs): display helpers · Shared formatting and presentation helpers. · `src/config.rs`

### Content

Bundled assets and item definitions.

- [Items](https://github.com/chezyname/survive/blob/main/src/items/mod.rs): upgrade registry · Shared item trait and factory/registration boundary. · `src/items/mod.rs`
- **Item Types**: upgrade modules · Representative set of purchasable cards and modifiers.
- [Assets](https://github.com/chezyname/survive/tree/main/assets): runtime content · Bundled audio and font resources loaded at runtime. · `assets`

## Connections

- Main → Game State: boot · Initializes the game and hands control to state management.
- Game State → Main Menu: menu · Routes into the main menu state.
- Game State → Shop: shop · Switches to the shop/progression state.
- Game State → Game Over: lose · Transitions to the game over state.
- Main Menu → Menu Base: uses · Builds on shared menu behavior.
- Game State → Player: play · Enters the gameplay loop.
- Player → Player Stats: stats · Reads and updates player attributes.
- Player → Projectile: fires · Creates attacks during combat.
- Player → Enemy: hits · Deals damage in combat.
- Wave Manager → Wave: spawns · Generates and schedules enemy waves.
- Wave → Enemy: contains · Defines enemy encounters within a wave.
- Enemy → Player: targets · Threatens the player during survival play.
- Projectile → Enemy: damages · Applies combat outcomes to enemies.
- Shop → Items: purchases · Uses the item registry to present upgrades.
- Items → Item Types: loads · Registers concrete upgrade implementations.
- Shop → Player Stats: upgrades · Changes player capabilities through purchases.
- Player UI → Player: displays · Renders player state in the HUD.
- Player UI → Config: formats · Uses shared presentation helpers.
- Audio → Assets: loads · Plays bundled audio content from disk.
- Main Menu → Audio: music · Triggers menu music and selection effects.
- Shop → Audio: sfx · Plays shop and selection sounds.
- Game Over → Audio: music · Triggers game-over audio.
- Player → Audio: sfx · Uses gameplay audio cues such as hurt and attacks.
- Wave Manager → Audio: sfx · Drives encounter sound cues.
