# vozderjus/qualia architecture

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

- Interactive diagram: https://gitdiagram.com/vozderjus/qualia
- Repository: https://github.com/vozderjus/qualia

## Overview

1. **Project shape**
   - `Qualia` is a single-player 2D roguelike built in **Python** with **pygame-ce**.
   - The repo is organized around a classic game architecture: **entrypoint/game loop**, **state-based screens**, **entity system**, **procedural world generation**, and **supporting UI/audio assets**.

2. **Entry point and runtime loop**
   - `qualia/game.py` is the main executable entrypoint.
   - `qualia/game_settings.py`, `qualia/run_state.py`, and `qualia/constants.py` suggest a central runtime configuration/state layer used by the loop and the screens.
   - The game updates over **delta time** rather than fixed FPS logic, which affects movement, cooldowns, animations, and combat timing.

3. **Screen/state architecture**
   - `qualia/states/` contains the game’s major modes: title screen, world gameplay, pause menu, settings, shop, game over, victory, debug HUD, and player UI.
   - `qualia/states/state.py` is the base state abstraction; other states likely implement a common update/render/input interface.
   - This means the application is structured as a **state machine**: only one high-level state is active at a time, with transitions driven by input and game events.

4. **World gameplay boundary**
   - `qualia/states/game_world.py` appears to be the main in-game state that ties together level generation, combat, entities, and world interactions.
   - The `qualia/world/` package is the boundary for level construction and level-level systems, separating “what the floor is” from “what the entities do.”

5. **Procedural generation pipeline**
   - Two generation strategies are present:
     - `qualia/world/bsp_generator.py` for room-based dungeon floors.
     - `qualia/world/maze_generator.py` for the labyrinth floor.
   - `qualia/world/floor_builder.py`, `floor_definitions.py`, `level.py`, and `room_layout_cache.py` likely assemble generated layouts into playable floors and persist reusable room layouts.
   - The README’s validation step corresponds to `tests/test_bsp_generator.py`, `tests/test_maze_generator.py`, and `tests/test_level.py`, implying generation is treated as a core subsystem with correctness checks.

6. **World simulation systems**
   - `qualia/world/combat_system.py`, `encounter_manager.py`, `room_lock_system.py`, and `world_interaction_system.py` indicate the floor is not just geometry; it also has systems that:
     - spawn or manage room encounters,
     - lock/unlock progression,
     - resolve interactions with exits, doors, pickups, and shop flow,
     - coordinate combat triggers and room progression.
   - This is the main “gameplay orchestration” layer beneath the screen/state layer.

7. **Entity model**
   - `qualia/entities/` contains the moving/combat actors and interactive objects.
   - Player/combat entities include `player.py`, `bullet.py`, multiple enemy classes, `boss_enemy.py`, `heat_pickup.py`, `level_exit.py`, `shop_keeper.py`, `room_door.py`, and `floating_damage_text.py`.
   - Shared behavior modules like `movement_behaviors.py`, `attack_behaviors.py`, `boss_behaviors.py`, and `attack_command.py` suggest composition over inheritance for AI and attack patterns.

8. **Combat and AI flow**
   - The combat loop is centered on the player firing bullets and enemies executing behavior-driven attacks.
   - Enemy variants such as `blue_eye_enemy.py`, `orange_eye_enemy.py`, `heart_enemy.py`, `prism_enemy.py`, `teeth_enemy.py`, and `basic_enemy.py` imply multiple AI archetypes with distinct movement/attack logic.
   - The boss uses phase-based behavior changes through `boss_behaviors.py`, matching the README’s multi-phase boss description.
   - Projectiles and enemy attacks are likely resolved against world geometry and actors using collision checks inside the entity/world systems.

9. **Camera, rendering, and presentation**
   - `qualia/entities/camera.py` and `qualia/world/level_renderer.py` indicate a dedicated camera/rendering path for drawing the current floor relative to the player.
   - `qualia/entities/floating_damage_text.py` and `qualia/states/player_ui.py` suggest separate layers for combat feedback and HUD.
   - `qualia/ui_helpers.py` and `qualia/uis.py` are likely shared UI building blocks used by menus, the shop, and settings.

10. **Menus and meta-progression**
   - `qualia/states/title.py`, `pause_menu.py`, `settings_menu.py`, `shop_menu.py`, `game_over.py`, and `game_victory.py` define the non-gameplay screens.
   - `qualia/settings_content.py` and `qualia/shop_content.py` appear to hold data/configuration for settings options and purchasable upgrades.
   - The shop is a distinct gameplay boundary: it consumes the in-game currency `heat`/`жар` via `heat_pickup.py` and likely upgrades player capabilities between encounters.

11. **Audio and art asset pipeline**
   - `audio/` contains background music per floor plus weapon, hit, pickup, and UI sounds.
   - `images/` contains `.aseprite` source art for enemies, the boss, and wall tiles.
   - `qualia/audio_manager.py` is the runtime bridge between the game and audio assets, while the asset folders are the content boundary for presentation and feedback.

12. **Testing and reliability**
   - Tests cover generation and core runtime pieces: `bsp_generator`, `maze_generator`, `level`, `encounter_manager`, `game_settings`, and `run_state`.
   - That distribution shows the repo prioritizes deterministic behavior in its procedural generation and core state/configuration logic.
   - For architecture diagrams, the most important distinction is between **deterministic world-building code** and **real-time simulation/UI code**.

13. **High-level data flow**
   - Input enters through pygame and is consumed by the active state.
   - The active state delegates to world systems and entities.
   - World systems update the level, combat, collisions, and interactions.
   - Entities produce visible effects and UI feedback.
   - State transitions happen on events such as death, victory, pause, shop entry, or floor completion.

14. **Key boundaries to show in a diagram**
   - **Entry/runtime**: `game.py` and run-state/config.
   - **State machine**: title/gameplay/shop/settings/pause/end states.
   - **World generation**: BSP/maze builders and validation.
   - **Simulation**: combat, encounters, doors, exits, interactions.
   - **Entities**: player, enemies, bullets, boss, pickups.
   - **Presentation**: rendering, UI, camera, debug HUD.
   - **Content/assets**: audio and art files feeding the runtime.

Main entry points: [`qualia/states/game_world.py`](https://github.com/vozderjus/qualia/blob/main/qualia/states/game_world.py) (World state), [`qualia/world/floor_builder.py`](https://github.com/vozderjus/qualia/blob/main/qualia/world/floor_builder.py) (Floor build), [`qualia/game.py`](https://github.com/vozderjus/qualia/blob/main/qualia/game.py) (Game), [`qualia/world/level_renderer.py`](https://github.com/vozderjus/qualia/blob/main/qualia/world/level_renderer.py) (Renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_game["Game<br/>entrypoint<br/>[game.py]"]
  node_run_state["Run state<br/>runtime state<br/>[run_state.py]"]
  node_game_settings["Settings<br/>config<br/>[game_settings.py]"]
end

subgraph group_states["States"]
  node_state_base["State base<br/>state interface<br/>[state.py]"]
  node_title_state["Title<br/>menu state<br/>[title.py]"]
  node_game_world["World state<br/>play state<br/>[game_world.py]"]
  node_pause_menu["Pause<br/>menu state<br/>[pause_menu.py]"]
  node_shop_menu["Shop<br/>menu state<br/>[shop_menu.py]"]
  node_end_states["End screens<br/>result state"]
end

subgraph group_world["World"]
  node_bsp_generator["BSP gen<br/>floor generator<br/>[bsp_generator.py]"]
  node_maze_generator["Maze gen<br/>floor generator<br/>[maze_generator.py]"]
  node_floor_builder["Floor build<br/>assembly<br/>[floor_builder.py]"]
  node_level[("Level<br/>world model<br/>[level.py]")]
  node_encounter_manager["Encounters<br/>orchestration"]
  node_combat_system["Combat<br/>[combat_system.py]"]
  node_room_lock_system["Room locks"]
  node_world_interaction_system["Interactions"]
end

subgraph group_entities["Entities"]
  node_player(("Player<br/>actor<br/>[player.py]"))
  node_bullet["Bullet<br/>projectile<br/>[bullet.py]"]
  node_enemies["Enemies<br/>npc set"]
  node_boss_enemy{{"Boss<br/>[boss_enemy.py]"}}
  node_pickup_exit["Pickups & exits<br/>interactables"]
  node_enemy_behaviors["Behaviors<br/>ai/combat logic"]
  node_boss_behaviors["Boss phases<br/>boss logic<br/>[boss_behaviors.py]"]
end

subgraph group_presentation["Presentation"]
  node_level_renderer["Renderer<br/>render pipeline<br/>[level_renderer.py]"]
  node_camera["Camera<br/>view transform<br/>[camera.py]"]
  node_player_ui["HUD<br/>ui overlay<br/>[player_ui.py]"]
  node_debug_hud["Debug HUD<br/>overlay<br/>[debug_hud.py]"]
  node_audio_manager["Audio<br/>sound bridge<br/>[audio_manager.py]"]
  node_ui_helpers["UI helpers<br/>ui toolkit<br/>[ui_helpers.py]"]
  node_uis["Widgets<br/>ui components<br/>[uis.py]"]
end

subgraph group_content["Content"]
  node_audio_assets["Audio assets<br/>asset bundle"]
  node_image_assets["Art assets<br/>asset bundle"]
end

node_game -->|"uses"| node_run_state
node_game -->|"loads"| node_game_settings
node_game -->|"starts"| node_title_state
node_state_base -->|"base for"| node_title_state
node_state_base -->|"base for"| node_game_world
node_game_world -->|"owns"| node_level
node_game_world -->|"drives"| node_encounter_manager
node_game_world -->|"drives"| node_combat_system
node_game_world -->|"drives"| node_room_lock_system
node_game_world -->|"drives"| node_world_interaction_system
node_floor_builder -->|"builds via"| node_bsp_generator
node_floor_builder -->|"builds via"| node_maze_generator
node_floor_builder -->|"produces"| node_level
node_game_world -->|"requests"| node_floor_builder
node_level_renderer -->|"uses"| node_camera
node_game_world -->|"renders with"| node_level_renderer
node_game_world -->|"overlays"| node_player_ui
node_game_world -->|"overlays"| node_debug_hud
node_player -->|"fires"| node_bullet
node_enemy_behaviors -->|"drives"| node_enemies
node_boss_behaviors -->|"drives"| node_boss_enemy
node_pickup_exit -->|"triggered by"| node_world_interaction_system
node_player -->|"clashes with"| node_enemy_behaviors
node_game_world -->|"spawns"| node_player
node_game_world -->|"spawns"| node_enemies
node_game_world -->|"spawns"| node_boss_enemy
node_game_world -->|"spawns"| node_pickup_exit
node_ui_helpers -->|"builds"| node_uis
node_title_state -->|"plays"| node_audio_manager
node_game_world -->|"plays"| node_audio_manager
node_audio_manager -->|"loads"| node_audio_assets
node_level_renderer -->|"draws from"| node_image_assets

click node_game "https://github.com/vozderjus/qualia/blob/main/qualia/game.py"
click node_run_state "https://github.com/vozderjus/qualia/blob/main/qualia/run_state.py"
click node_game_settings "https://github.com/vozderjus/qualia/blob/main/qualia/game_settings.py"
click node_state_base "https://github.com/vozderjus/qualia/blob/main/qualia/states/state.py"
click node_title_state "https://github.com/vozderjus/qualia/blob/main/qualia/states/title.py"
click node_game_world "https://github.com/vozderjus/qualia/blob/main/qualia/states/game_world.py"
click node_pause_menu "https://github.com/vozderjus/qualia/blob/main/qualia/states/pause_menu.py"
click node_shop_menu "https://github.com/vozderjus/qualia/blob/main/qualia/states/shop_menu.py"
click node_bsp_generator "https://github.com/vozderjus/qualia/blob/main/qualia/world/bsp_generator.py"
click node_maze_generator "https://github.com/vozderjus/qualia/blob/main/qualia/world/maze_generator.py"
click node_floor_builder "https://github.com/vozderjus/qualia/blob/main/qualia/world/floor_builder.py"
click node_level "https://github.com/vozderjus/qualia/blob/main/qualia/world/level.py"
click node_encounter_manager "https://github.com/vozderjus/qualia/blob/main/qualia/world/encounter_manager.py"
click node_combat_system "https://github.com/vozderjus/qualia/blob/main/qualia/world/combat_system.py"
click node_room_lock_system "https://github.com/vozderjus/qualia/blob/main/qualia/world/room_lock_system.py"
click node_world_interaction_system "https://github.com/vozderjus/qualia/blob/main/qualia/world/world_interaction_system.py"
click node_level_renderer "https://github.com/vozderjus/qualia/blob/main/qualia/world/level_renderer.py"
click node_camera "https://github.com/vozderjus/qualia/blob/main/qualia/entities/camera.py"
click node_player_ui "https://github.com/vozderjus/qualia/blob/main/qualia/states/player_ui.py"
click node_debug_hud "https://github.com/vozderjus/qualia/blob/main/qualia/states/debug_hud.py"
click node_audio_manager "https://github.com/vozderjus/qualia/blob/main/qualia/audio_manager.py"
click node_player "https://github.com/vozderjus/qualia/blob/main/qualia/entities/player.py"
click node_bullet "https://github.com/vozderjus/qualia/blob/main/qualia/entities/bullet.py"
click node_boss_enemy "https://github.com/vozderjus/qualia/blob/main/qualia/entities/boss_enemy.py"
click node_enemy_behaviors "https://github.com/vozderjus/qualia/blob/main/qualia/entities/attack_behaviors.py"
click node_boss_behaviors "https://github.com/vozderjus/qualia/blob/main/qualia/entities/boss_behaviors.py"
click node_ui_helpers "https://github.com/vozderjus/qualia/blob/main/qualia/ui_helpers.py"
click node_uis "https://github.com/vozderjus/qualia/blob/main/qualia/uis.py"
click node_audio_assets "https://github.com/vozderjus/qualia/tree/main/audio"
click node_image_assets "https://github.com/vozderjus/qualia/tree/main/images"

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_game,node_run_state,node_game_settings toneBlue
class node_state_base,node_title_state,node_game_world,node_pause_menu,node_shop_menu,node_end_states toneAmber
class node_bsp_generator,node_maze_generator,node_floor_builder,node_level,node_encounter_manager,node_combat_system,node_room_lock_system,node_world_interaction_system toneMint
class node_player,node_bullet,node_enemies,node_boss_enemy,node_pickup_exit,node_enemy_behaviors,node_boss_behaviors toneRose
class node_level_renderer,node_camera,node_player_ui,node_debug_hud,node_audio_manager,node_ui_helpers,node_uis toneIndigo
class node_audio_assets,node_image_assets toneTeal
```

## Components

### Runtime

Entry point and shared game configuration

- [Game](https://github.com/vozderjus/qualia/blob/main/qualia/game.py): entrypoint · Main executable and loop · `qualia/game.py`
- [Run state](https://github.com/vozderjus/qualia/blob/main/qualia/run_state.py): runtime state · Shared runtime mode/config · `qualia/run_state.py`
- [Settings](https://github.com/vozderjus/qualia/blob/main/qualia/game_settings.py): config · Game configuration and options · `qualia/game_settings.py`

### States

State machine screens and overlays

- [State base](https://github.com/vozderjus/qualia/blob/main/qualia/states/state.py): state interface · Common screen/state contract · `qualia/states/state.py`
- [Title](https://github.com/vozderjus/qualia/blob/main/qualia/states/title.py): menu state · Main menu and start flow · `qualia/states/title.py`
- [World state](https://github.com/vozderjus/qualia/blob/main/qualia/states/game_world.py): play state · Primary in-game simulation state · `qualia/states/game_world.py`
- [Pause](https://github.com/vozderjus/qualia/blob/main/qualia/states/pause_menu.py): menu state · Pause overlay and resume flow · `qualia/states/pause_menu.py`
- [Shop](https://github.com/vozderjus/qualia/blob/main/qualia/states/shop_menu.py): menu state · Between-floor upgrade screen · `qualia/states/shop_menu.py`
- **End screens**: result state · Game over and victory flows

### World

Floor generation and simulation systems

- [BSP gen](https://github.com/vozderjus/qualia/blob/main/qualia/world/bsp_generator.py): floor generator · Room-based dungeon generation · `qualia/world/bsp_generator.py`
- [Maze gen](https://github.com/vozderjus/qualia/blob/main/qualia/world/maze_generator.py): floor generator · Labyrinth floor generation · `qualia/world/maze_generator.py`
- [Floor build](https://github.com/vozderjus/qualia/blob/main/qualia/world/floor_builder.py): assembly · Assembles generated floors · `qualia/world/floor_builder.py`
- [Level](https://github.com/vozderjus/qualia/blob/main/qualia/world/level.py): world model · Floor data and gameplay geometry · `qualia/world/level.py`
- [Encounters](https://github.com/vozderjus/qualia/blob/main/qualia/world/encounter_manager.py): orchestration · Room encounter spawning and flow · `qualia/world/encounter_manager.py`
- [Combat](https://github.com/vozderjus/qualia/blob/main/qualia/world/combat_system.py): system · Combat resolution and timing · `qualia/world/combat_system.py`
- [Room locks](https://github.com/vozderjus/qualia/blob/main/qualia/world/room_lock_system.py): system · Locks and unlocks room progression · `qualia/world/room_lock_system.py`
- [Interactions](https://github.com/vozderjus/qualia/blob/main/qualia/world/world_interaction_system.py): system · Doors, exits, pickups, and flow · `qualia/world/world_interaction_system.py`

### Entities

Actors, projectiles, and interactables

- [Player](https://github.com/vozderjus/qualia/blob/main/qualia/entities/player.py): actor · Controllable combat character · `qualia/entities/player.py`
- [Bullet](https://github.com/vozderjus/qualia/blob/main/qualia/entities/bullet.py): projectile · Player projectile entity · `qualia/entities/bullet.py`
- **Enemies**: npc set · Enemy archetypes and variants
- [Boss](https://github.com/vozderjus/qualia/blob/main/qualia/entities/boss_enemy.py): boss actor · Multi-phase boss enemy · `qualia/entities/boss_enemy.py`
- **Pickups & exits**: interactables · Heat, exits, doors, shopkeeper
- [Behaviors](https://github.com/vozderjus/qualia/blob/main/qualia/entities/attack_behaviors.py): ai/combat logic · Movement and attack behavior composition · `qualia/entities/attack_behaviors.py`
- [Boss phases](https://github.com/vozderjus/qualia/blob/main/qualia/entities/boss_behaviors.py): boss logic · Phase-driven boss behavior changes · `qualia/entities/boss_behaviors.py`

### Presentation

Camera, rendering, and UI

- [Renderer](https://github.com/vozderjus/qualia/blob/main/qualia/world/level_renderer.py): render pipeline · Draws the current floor · `qualia/world/level_renderer.py`
- [Camera](https://github.com/vozderjus/qualia/blob/main/qualia/entities/camera.py): view transform · World-to-screen framing · `qualia/entities/camera.py`
- [HUD](https://github.com/vozderjus/qualia/blob/main/qualia/states/player_ui.py): ui overlay · Player combat and status UI · `qualia/states/player_ui.py`
- [Debug HUD](https://github.com/vozderjus/qualia/blob/main/qualia/states/debug_hud.py): overlay · Debug diagnostics overlay · `qualia/states/debug_hud.py`
- [Audio](https://github.com/vozderjus/qualia/blob/main/qualia/audio_manager.py): sound bridge · Runtime sound and music control · `qualia/audio_manager.py`
- [UI helpers](https://github.com/vozderjus/qualia/blob/main/qualia/ui_helpers.py): ui toolkit · Shared UI building blocks · `qualia/ui_helpers.py`
- [Widgets](https://github.com/vozderjus/qualia/blob/main/qualia/uis.py): ui components · Reusable UI primitives · `qualia/uis.py`

### Content

Audio and art assets

- [Audio assets](https://github.com/vozderjus/qualia/tree/main/audio): asset bundle · Music and sound effects · `audio`
- [Art assets](https://github.com/vozderjus/qualia/tree/main/images): asset bundle · Sprite and tile source art · `images`

## Connections

- Game → Run state: uses · Initializes and advances runtime state
- Game → Settings: loads · Reads configuration for startup and play
- Game → Title: starts · Enters the title/menu flow
- State base → Title: base for · Common interface for screens
- State base → World state: base for · Common interface for screens
- World state → Level: owns · Hosts the active floor model
- World state → Encounters: drives · Coordinates room progression
- World state → Combat: drives · Updates combat timing and resolution
- World state → Room locks: drives · Controls room access and unlocking
- World state → Interactions: drives · Handles exits, doors, and pickups
- Floor build → BSP gen: builds via · Creates room-based floors
- Floor build → Maze gen: builds via · Creates maze floors
- Floor build → Level: produces · Outputs playable level data
- World state → Floor build: requests · Constructs the next floor
- Renderer → Camera: uses · Frames world drawing
- World state → Renderer: renders with · Draws the active floor
- World state → HUD: overlays · Shows health, heat, and combat status
- World state → Debug HUD: overlays · Optionally shows debug information
- Player → Bullet: fires · Creates projectiles during combat
- Behaviors → Enemies: drives · Shared movement and attack patterns
- Boss phases → Boss: drives · Phase-based boss logic
- Pickups & exits → Interactions: triggered by · Interactive world objects feed progression
- Player → Behaviors: clashes with · Enemies respond to player presence
- World state → Player: spawns · Places the controllable actor in the floor
- World state → Enemies: spawns · Populates encounters with enemies
- World state → Boss: spawns · Creates boss encounters on boss floors
- World state → Pickups & exits: spawns · Adds exits, doors, heat, and shop flow
- UI helpers → Widgets: builds · Shared UI construction pieces
- Title → Audio: plays · Menu music and feedback
- World state → Audio: plays · Combat and floor audio cues
- Audio → Audio assets: loads · Uses sound and music files
- Renderer → Art assets: draws from · Uses sprite and tile art
