# aslahmohamadbahari/glitch-garden architecture

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

- Interactive diagram: https://gitdiagram.com/aslahmohamadbahari/glitch-garden
- Repository: https://github.com/aslahmohamadbahari/glitch-garden

## Overview

This repository is a Unity game project organized around a scene-driven 2D gameplay loop with a small set of reusable gameplay systems and asset libraries.

1. Core application boundary  
The project is a Unity app, not a service-based system. The main runtime is defined by Unity scenes, prefabs, scripts, and Resources-loaded content. Most behavior is split between scene objects and reusable prefabbed systems.

2. Primary gameplay model: attackers vs defenders  
The gameplay appears to be a lane/defense style loop with two opposing entity families:
- Attackers: Fox and Lizard
- Defenders: Cactus, Gnome, Gravestone, Trophy  
These are represented both as prefabs and as dedicated animation/controller assets, suggesting each entity has its own movement/attack state machine.

3. Scene structure and lifecycle flow  
The project includes multiple scenes for the full user flow:
- Splash Screen
- Start Screen
- Options Screen
- Blank Level
- Level 1
- Win Screen
- Lose Screen  
This indicates a menu-to-level-to-result flow, with the level scenes being separate from the UI/menus.

4. Level orchestration subsystem  
The main runtime coordination is likely handled by:
- LevelController
- LevelLoader
- GameTimer
- AttackerSpawner
- DefenderSpawner  
These form the control layer that starts levels, advances timers, spawns enemies/units, and transitions to win/lose states.

5. Combat and interaction boundaries  
Combat is built around a small set of reusable components:
- Health for survivability
- DamageCollider for hit detection
- Shooter for ranged offense
- Projectile for launched attacks  
This suggests defenders and attackers are composed from shared combat primitives rather than having entirely separate combat code paths.

6. Entity hierarchy and specialization  
There are base scripts for shared behavior and child scripts for specialization:
- Attacker and Defender are the abstract/base roles
- Fox, Lizard, and Gravestone are specialized behaviors
- Shooter likely powers ranged defenders such as Gnome or Cactus  
This separation implies a composition-plus-inheritance model where core role logic is centralized and per-character logic is thin.

7. UI and player interaction layer  
The UI is split into prefabs and scripts:
- Main Canvas, Level Complete Canvas, Level Lost Canvas
- Buttons prefab
- DefenderButton
- LivesDisplay
- StarDisplay
- OptionsController
- PlayerPrefsController  
This layer handles selection, display, and persistence of player-facing game state rather than gameplay simulation.

8. Progression, feedback, and end-state systems  
Several dedicated systems support game flow and feedback:
- LivesDisplay tracks failure conditions
- StarDisplay tracks completion/performance
- LevelLoader handles scene transitions
- Load Sound, Music Player, and result sounds provide audiovisual feedback  
These systems are mostly presentation and state-transition oriented, bridging gameplay events to UI and audio.

9. Asset organization by domain  
The Assets folder is strongly segmented:
- Animations grouped by Attackers, Defenders, and UI
- Prefabs grouped by Attackers, Defenders, Projectiles, and Core Game
- Resources grouped by Fonts, Images, Sounds, Sprites, and VFX  
This is a clean domain-based organization that matches the runtime boundaries of the game.

10. Runtime content loading and persistence  
The presence of a Resources folder implies some assets are loaded dynamically at runtime through Unity’s Resources system, especially audio, sprites, and VFX. PlayerPrefsController and BillingMode.json suggest local persistent configuration/state is also part of the runtime model.

11. Visual effects and audio as supporting subsystems  
VFX and audio are treated as first-class content, not incidental extras:
- Explosion VFX prefab and material
- Multiple background and event sound files
- Per-character animation controllers  
These assets support the game’s feedback loop and likely trigger from combat and level transitions.

12. External/tooling boundaries  
This is a standard Unity project with package-managed dependencies, editor/build settings, and project-wide physics/audio/input configuration. The important architecture boundary is between Unity-managed engine systems and the game’s own scripts/prefabs/scenes.

Overall, the architecture is a classic Unity scene-based game: scene flow and UI drive the high-level state, level controllers manage spawning and victory/failure, and individual attackers/defenders are built from shared combat components plus per-character animation and behavior assets.

Main entry points: [`Assets/Scripts/LevelController.cs`](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LevelController.cs) (Level Controller), [`Assets/Resources`](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources) (Resources), [`Assets/Scripts`](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Scripts) (Combat Core), [`Assets/Resources/Sounds`](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources/Sounds) (Audio)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime Flow"]
  node_scene_flow["Scene Flow<br/>unity scenes"]
  node_level_controller["Level Controller<br/>game flow<br/>[LevelController.cs]"]
  node_level_loader["Level Loader<br/>scene transition<br/>[LevelLoader.cs]"]
  node_game_timer(("Game Timer<br/>level timing<br/>[GameTimer.cs]"))
  node_attacker_spawner["Attacker Spawner<br/>enemy spawn<br/>[AttackerSpawner.cs]"]
  node_defender_spawner["Defender Spawner<br/>unit placement<br/>[DefenderSpawner.cs]"]
end

subgraph group_gameplay["Gameplay Systems"]
  node_attacker_role["Attacker<br/>base entity<br/>[Attacker.cs]"]
  node_defender_role["Defender<br/>base entity<br/>[Defender.cs]"]
  node_combat_core{{"Combat Core<br/>shared combat"}}
  node_fox_lizard["Fox & Lizard<br/>attacker specials<br/>[Fox.cs]"]
  node_cactus_gnome["Cactus & Gnome<br/>defender specials<br/>[Shooter.cs]"]
  node_gravestone_trophy["Gravestone & Trophy<br/>defender specials<br/>[Gravestone.cs]"]
end

subgraph group_ui["UI and Options"]
  node_core_ui["Core UI<br/>menus and HUD"]
  node_defender_button["Defender Button<br/>selection UI<br/>[DefenderButton.cs]"]
  node_lives_display["Lives Display<br/>HUD<br/>[LivesDisplay.cs]"]
  node_star_display["Star Display<br/>progress HUD<br/>[StarDisplay.cs]"]
  node_options_controller["Options<br/>settings UI"]
  node_prefs_controller["Prefs Controller<br/>persistence"]
end

subgraph group_content["Content Libraries"]
  node_attackers_content["Attackers<br/>prefabs and anims"]
  node_defenders_content["Defenders<br/>prefabs and anims"]
  node_projectiles_vfx["Projectiles & VFX<br/>impact content"]
  node_resources["Resources<br/>runtime assets"]
  node_audio(("Audio<br/>sound library"))
end

node_scene_flow -->|"enters gameplay"| node_level_loader
node_scene_flow -->|"hosts UI"| node_core_ui
node_level_loader -->|"starts level"| node_level_controller
node_level_controller -->|"drives"| node_game_timer
node_level_controller -->|"spawns enemies"| node_attacker_spawner
node_level_controller -->|"places defenders"| node_defender_spawner
node_level_controller -->|"updates failure"| node_lives_display
node_level_controller -->|"updates score"| node_star_display
node_core_ui -->|"opens settings"| node_options_controller
node_options_controller -->|"persists"| node_prefs_controller
node_defender_button -->|"selects unit"| node_defender_spawner
node_attacker_spawner -->|"instantiates"| node_attackers_content
node_defender_spawner -->|"instantiates"| node_defenders_content
node_attacker_role -->|"specializes"| node_fox_lizard
node_defender_role -->|"specializes"| node_cactus_gnome
node_defender_role -->|"specializes"| node_gravestone_trophy
node_combat_core -->|"used by"| node_attacker_role
node_combat_core -->|"used by"| node_defender_role
node_combat_core -->|"drives effects"| node_projectiles_vfx
node_resources -->|"contains"| node_audio
node_resources -->|"contains"| node_projectiles_vfx
node_resources -->|"contains sprites"| node_attackers_content
node_resources -->|"contains sprites"| node_defenders_content
node_audio -->|"plays load sound"| node_level_loader
node_audio -->|"plays feedback"| node_level_controller

click node_scene_flow "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Scenes"
click node_level_controller "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LevelController.cs"
click node_level_loader "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LevelLoader.cs"
click node_game_timer "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/GameTimer.cs"
click node_attacker_spawner "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/AttackerSpawner.cs"
click node_defender_spawner "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/DefenderSpawner.cs"
click node_core_ui "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Core Game"
click node_defender_button "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/DefenderButton.cs"
click node_lives_display "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LivesDisplay.cs"
click node_star_display "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/StarDisplay.cs"
click node_options_controller "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/OptionsController.cs"
click node_prefs_controller "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/PlayerPrefsController.cs"
click node_attacker_role "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Attacker.cs"
click node_defender_role "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Defender.cs"
click node_combat_core "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Scripts"
click node_fox_lizard "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Fox.cs"
click node_cactus_gnome "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Shooter.cs"
click node_gravestone_trophy "https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Gravestone.cs"
click node_attackers_content "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Attackers"
click node_defenders_content "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Defenders"
click node_projectiles_vfx "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Projectiles"
click node_resources "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources"
click node_audio "https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources/Sounds"

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_flow,node_level_controller,node_level_loader,node_game_timer,node_attacker_spawner,node_defender_spawner toneBlue
class node_attacker_role,node_defender_role,node_combat_core,node_fox_lizard,node_cactus_gnome,node_gravestone_trophy toneAmber
class node_core_ui,node_defender_button,node_lives_display,node_star_display,node_options_controller,node_prefs_controller toneMint
class node_attackers_content,node_defenders_content,node_projectiles_vfx,node_resources,node_audio toneRose
```

## Components

### Runtime Flow

Scenes and coordination systems that drive the game loop.

- [Scene Flow](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Scenes): unity scenes · Splash, menu, level, and result scenes that define the player journey. · `Assets/Scenes`
- [Level Controller](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LevelController.cs): game flow · Coordinates level state, victory and defeat progression. · `Assets/Scripts/LevelController.cs`
- [Level Loader](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LevelLoader.cs): scene transition · Handles switching between scenes and loading levels. · `Assets/Scripts/LevelLoader.cs`
- [Game Timer](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/GameTimer.cs): level timing · Drives timed progression within a level. · `Assets/Scripts/GameTimer.cs`
- [Attacker Spawner](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/AttackerSpawner.cs): enemy spawn · Creates attackers into lanes during gameplay. · `Assets/Scripts/AttackerSpawner.cs`
- [Defender Spawner](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/DefenderSpawner.cs): unit placement · Instantiates defender units for the player. · `Assets/Scripts/DefenderSpawner.cs`

### Gameplay Systems

Entity roles and combat primitives.

- [Attacker](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Attacker.cs): base entity · Shared behavior for enemy-side units. · `Assets/Scripts/Attacker.cs`
- [Defender](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Defender.cs): base entity · Shared behavior for player-side units. · `Assets/Scripts/Defender.cs`
- [Combat Core](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Scripts): shared combat · Health, damage collider, shooter, and projectile interaction. · `Assets/Scripts`
- [Fox & Lizard](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Fox.cs): attacker specials · Specialized attacker behaviors built on the attacker base role. · `Assets/Scripts/Fox.cs`
- [Cactus & Gnome](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Shooter.cs): defender specials · Ranged defenders and their specialized combat behavior. · `Assets/Scripts/Shooter.cs`
- [Gravestone & Trophy](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/Gravestone.cs): defender specials · Defender variants with distinct idle or utility behavior. · `Assets/Scripts/Gravestone.cs`

### UI and Options

Menus, HUD, and player-facing state.

- [Core UI](https://github.com/aslahmohamadbahari/glitch-garden/tree/HEAD/Assets/Prefabs/Core%20Game): menus and HUD · Main canvas, buttons, level-complete, and level-lost canvases. · `Assets/Prefabs/Core Game`
- [Defender Button](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/DefenderButton.cs): selection UI · Selects which defender to place. · `Assets/Scripts/DefenderButton.cs`
- [Lives Display](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/LivesDisplay.cs): HUD · Shows remaining lives and failure state. · `Assets/Scripts/LivesDisplay.cs`
- [Star Display](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/StarDisplay.cs): progress HUD · Shows level completion and performance stars. · `Assets/Scripts/StarDisplay.cs`
- [Options](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/OptionsController.cs): settings UI · Controls options screen interactions and settings. · `Assets/Scripts/OptionsController.cs`
- [Prefs Controller](https://github.com/aslahmohamadbahari/glitch-garden/blob/main/Assets/Scripts/PlayerPrefsController.cs): persistence · Reads and writes player preferences and local config. · `Assets/Scripts/PlayerPrefsController.cs`

### Content Libraries

Prefabs, animations, audio, and VFX grouped by domain.

- [Attackers](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Attackers): prefabs and anims · Fox and lizard prefabs plus their animation controllers. · `Assets/Prefabs/Attackers`
- [Defenders](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Defenders): prefabs and anims · Cactus, gnome, gravestone, and trophy prefabs plus animations. · `Assets/Prefabs/Defenders`
- [Projectiles & VFX](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Prefabs/Projectiles): impact content · Axe and zucchini projectiles, explosion VFX, and related materials. · `Assets/Prefabs/Projectiles`
- [Resources](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources): runtime assets · Loaded-at-runtime sounds, sprites, fonts, and billing config. · `Assets/Resources`
- [Audio](https://github.com/aslahmohamadbahari/glitch-garden/tree/main/Assets/Resources/Sounds): sound library · Music, load sounds, and result/event effects. · `Assets/Resources/Sounds`

## Connections

- Scene Flow → Level Loader: enters gameplay · Scenes lead into level loading and transitions.
- Scene Flow → Core UI: hosts UI · Menu and result scenes present the main UI prefabs.
- Level Loader → Level Controller: starts level · Loaded levels are coordinated by the level controller.
- Level Controller → Game Timer: drives · The controller uses time to advance the level state.
- Level Controller → Attacker Spawner: spawns enemies · Level state triggers attacker waves.
- Level Controller → Defender Spawner: places defenders · Level state enables defender placement.
- Level Controller → Lives Display: updates failure · Lives and defeat state feed the HUD.
- Level Controller → Star Display: updates score · Completion and performance feed the star display.
- Core UI → Options: opens settings · Options UI is managed from the menu layer.
- Options → Prefs Controller: persists · Settings are saved through player preferences.
- Defender Button → Defender Spawner: selects unit · UI button chooses which defender to spawn.
- Attacker Spawner → Attackers: instantiates · Spawner creates attacker prefabs into the level.
- Defender Spawner → Defenders: instantiates · Spawner creates defender prefabs onto lanes.
- Attacker → Fox & Lizard: specializes · Fox and lizard behavior extends the attacker role.
- Defender → Cactus & Gnome: specializes · Cactus and gnome behavior extend the defender role.
- Defender → Gravestone & Trophy: specializes · Gravestone and trophy behavior extend the defender role.
- Combat Core → Attacker: used by · Attackers depend on shared combat primitives.
- Combat Core → Defender: used by · Defenders depend on shared combat primitives.
- Combat Core → Projectiles & VFX: drives effects · Damage and projectile interactions trigger impacts and VFX.
- Resources → Audio: contains · Runtime resources include audio assets.
- Resources → Projectiles & VFX: contains · Runtime resources include VFX assets.
- Resources → Attackers: contains sprites · Attacker art assets are organized in Resources.
- Resources → Defenders: contains sprites · Defender art assets are organized in Resources.
- Audio → Level Loader: plays load sound · Scene transitions are backed by load and menu audio.
- Audio → Level Controller: plays feedback · Win and loss progression is supported by audio cues.
