# desmitry/game architecture

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

- Interactive diagram: https://gitdiagram.com/desmitry/game
- Repository: https://github.com/desmitry/game

## Overview

1. **Project shape**
   - This is a Python game project, likely a 2D stealth/survival game called **Eclipsed Evolution**.
   - The repository is organized around a typical game architecture: game loop entrypoint, state management, entity models, AI systems, rendering, audio, and level/map loading.

2. **Entry point and top-level control**
   - `main.py` is the application entrypoint.
   - The `controllers/game_controller.py` module appears to own the high-level runtime orchestration: starting the game, switching states, and coordinating updates between subsystems.

3. **Game state management**
   - `src/states/` contains the state machine layer.
   - `main_menu_state.py` and `game_state.py` indicate at least two major runtime modes: menu and active gameplay.
   - This boundary separates UI/menu logic from in-game simulation, which is important for the architecture diagram.

4. **World and level loading**
   - `src/systems/level.py` and `src/systems/map_loader.py` handle construction of the playable world from map data.
   - `src/maps/test_level.txt` is the current example level asset, suggesting levels are data-driven from text map files.
   - `src/models/wall.py`, `trapdoor.py`, `pickup.py`, and related classes are the concrete world objects instantiated from these level definitions.

5. **Entity/model layer**
   - `src/models/` contains the game’s core entities and interactables: `player`, `enemy`, `flashlight`, `flare`, `health`, `pickup`, `trapdoor`, and `wall`.
   - These are likely lightweight game objects used by the simulation and renderer rather than isolated business objects.
   - The model layer is the shared contract consumed by AI, physics/visibility, rendering, and game state logic.

6. **AI subsystem**
   - `src/ai/` is a substantial AI layer with multiple strategies:
     - `astar.py` and `pathfinding_grid.py` handle navigation/path search.
     - `bt_node.py`, `bt_composites.py`, `bt_actions.py`, and `bt_chase.py` implement behavior trees.
   - This suggests enemies are driven by a combination of pathfinding and behavior-tree decision making rather than a single monolithic AI loop.

7. **Enemy decision and movement flow**
   - `src/models/enemy.py` is the entity that likely binds together sensing, behavior selection, and movement execution.
   - AI decisions likely depend on visibility and navigation systems, then translate into world movement across the level grid.
   - `src/systems/vision_cone.py` and `raycast.py` suggest enemy perception is line-of-sight based.

8. **Perception, lighting, and visibility**
   - `src/rendering/lightmap.py`, `src/systems/vision_cone.py`, and `src/systems/raycast.py` point to a visibility-centric game loop.
   - `models/flashlight.py` and `models/flare.py` imply the player can influence visibility, which likely affects both gameplay and rendering.
   - This is a major architectural boundary: world state influences visibility, and visibility influences both rendering and AI detection.

9. **Rendering pipeline**
   - `src/rendering/renderer.py` is the main draw pipeline.
   - `lightmap.py` likely supplements rendering with darkness/shadow or illumination effects, which is consistent with the game’s title and stealth mechanics.
   - `src/systems/text_renderer.py` supports HUD or menu text output, probably used by both game state and main menu state.

10. **Core simulation helpers**
   - `src/systems/uniform_grid.py` suggests spatial partitioning for efficient collision, querying, or neighbor lookup.
   - `src/systems/object_pool.py` indicates reuse of transient objects, likely for performance-sensitive items like projectiles, flares, or temporary effects.
   - `src/systems/genome.py` and `genetic_algorithm.py` indicate an evolutionary simulation component, possibly for tuning enemy behavior or procedural traits.

11. **Audio**
   - `src/audio/sound_manager.py` is the centralized audio boundary.
   - It likely mediates all sound playback so gameplay code does not talk directly to the underlying audio backend.

12. **Testing and validation**
   - `tests/test_astar.py`, `tests/test_uniform_grid.py`, and `tests/test_genetic_algorithm.py` show the repo has unit coverage for the most algorithmic subsystems.
   - That means the architecture includes both game-specific runtime code and isolated algorithmic components that can be validated independently.

13. **Likely dependency direction**
   - Higher-level flow is: entrypoint/controller → state machine → level load → entities/models + systems → rendering/audio.
   - AI and visibility systems read from the same model/level data, while rendering consumes the resulting world state each frame.
   - Tests target the standalone algorithms beneath the gameplay layer, especially pathfinding, spatial indexing, and evolutionary logic.

Main entry points: [`src/states/game_state.py`](https://github.com/desmitry/game/blob/master/src/states/game_state.py) (Game State), [`src/systems/level.py`](https://github.com/desmitry/game/blob/master/src/systems/level.py) (Level), [`src/controllers/game_controller.py`](https://github.com/desmitry/game/blob/master/src/controllers/game_controller.py) (Game Ctrl), [`src/models/enemy.py`](https://github.com/desmitry/game/blob/master/src/models/enemy.py) (Enemy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main["Main<br/>entrypoint<br/>[main.py]"]
  node_game_controller["Game Ctrl<br/>orchestrator<br/>[game_controller.py]"]
  node_main_menu_state["Menu State<br/>ui state<br/>[main_menu_state.py]"]
  node_game_state["Game State<br/>play state<br/>[game_state.py]"]
end

subgraph group_world["World Model"]
  node_level["Level<br/>world builder<br/>[level.py]"]
  node_map_loader["Map Loader<br/>data loader<br/>[map_loader.py]"]
  node_test_level["Test Map<br/>level asset<br/>[test_level.txt]"]
  node_player(("Player<br/>entity<br/>[player.py]"))
  node_enemy(("Enemy<br/>entity<br/>[enemy.py]"))
  node_world_objects{{"World Obj<br/>interactables<br/>[wall.py]"}}
end

subgraph group_ai["AI"]
  node_astar["A*<br/>pathfinding<br/>[astar.py]"]
  node_bt["Behavior Tree<br/>decision system<br/>[bt_node.py]"]
  node_path_grid[("Path Grid<br/>nav grid")]
end

subgraph group_rendering["Rendering"]
  node_renderer["Renderer<br/>draw pipeline<br/>[renderer.py]"]
  node_lightmap[("Lightmap<br/>visibility render<br/>[lightmap.py]")]
end

subgraph group_systems["Systems"]
  node_vision{{"Vision<br/>perception<br/>[vision_cone.py]"}}
  node_raycast["Raycast<br/>visibility<br/>[raycast.py]"]
  node_text_renderer["Text Draw<br/>hud text<br/>[text_renderer.py]"]
  node_genetic_algorithm["Genetic Alg<br/>evolution system"]
  node_genome["Genome<br/>fitness model<br/>[genome.py]"]
end

subgraph group_platform["Platform"]
  node_sound_manager["Sound<br/>audio service<br/>[sound_manager.py]"]
end

node_main -->|"launches"| node_game_controller
node_game_controller -->|"shows"| node_main_menu_state
node_game_controller -->|"runs"| node_game_state
node_game_state -->|"loads"| node_level
node_level -->|"parses"| node_map_loader
node_map_loader -->|"reads"| node_test_level
node_level -->|"spawns"| node_player
node_level -->|"spawns"| node_enemy
node_level -->|"instantiates"| node_world_objects
node_enemy -->|"decides"| node_bt
node_enemy -->|"navigates"| node_astar
node_astar -->|"queries"| node_path_grid
node_enemy -->|"senses"| node_vision
node_vision -->|"uses"| node_raycast
node_game_state -->|"draws"| node_renderer
node_renderer -->|"applies"| node_lightmap
node_game_state -->|"hud"| node_text_renderer
node_game_controller -->|"plays"| node_sound_manager
node_game_state -.->|"tunes"| node_genetic_algorithm
node_genetic_algorithm -->|"models"| node_genome

click node_main "https://github.com/desmitry/game/blob/master/main.py"
click node_game_controller "https://github.com/desmitry/game/blob/master/src/controllers/game_controller.py"
click node_main_menu_state "https://github.com/desmitry/game/blob/master/src/states/main_menu_state.py"
click node_game_state "https://github.com/desmitry/game/blob/master/src/states/game_state.py"
click node_level "https://github.com/desmitry/game/blob/master/src/systems/level.py"
click node_map_loader "https://github.com/desmitry/game/blob/master/src/systems/map_loader.py"
click node_test_level "https://github.com/desmitry/game/blob/master/src/maps/test_level.txt"
click node_player "https://github.com/desmitry/game/blob/master/src/models/player.py"
click node_enemy "https://github.com/desmitry/game/blob/master/src/models/enemy.py"
click node_world_objects "https://github.com/desmitry/game/blob/master/src/models/wall.py"
click node_astar "https://github.com/desmitry/game/blob/master/src/ai/astar.py"
click node_bt "https://github.com/desmitry/game/blob/master/src/ai/bt_node.py"
click node_path_grid "https://github.com/desmitry/game/blob/master/src/ai/pathfinding_grid.py"
click node_vision "https://github.com/desmitry/game/blob/master/src/systems/vision_cone.py"
click node_raycast "https://github.com/desmitry/game/blob/master/src/systems/raycast.py"
click node_renderer "https://github.com/desmitry/game/blob/master/src/rendering/renderer.py"
click node_lightmap "https://github.com/desmitry/game/blob/master/src/rendering/lightmap.py"
click node_text_renderer "https://github.com/desmitry/game/blob/master/src/systems/text_renderer.py"
click node_sound_manager "https://github.com/desmitry/game/blob/master/src/audio/sound_manager.py"
click node_genetic_algorithm "https://github.com/desmitry/game/blob/master/src/systems/genetic_algorithm.py"
click node_genome "https://github.com/desmitry/game/blob/master/src/systems/genome.py"

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_game_controller,node_main_menu_state,node_game_state toneBlue
class node_level,node_map_loader,node_test_level,node_player,node_enemy,node_world_objects toneAmber
class node_astar,node_bt,node_path_grid toneMint
class node_renderer,node_lightmap toneRose
class node_vision,node_raycast,node_text_renderer,node_genetic_algorithm,node_genome toneIndigo
class node_sound_manager toneTeal
```

## Components

### Runtime

Application entry, control, and game states

- [Main](https://github.com/desmitry/game/blob/master/main.py): entrypoint · Starts the application and launches the controller · `main.py`
- [Game Ctrl](https://github.com/desmitry/game/blob/master/src/controllers/game_controller.py): orchestrator · Owns runtime flow and state switching · `src/controllers/game_controller.py`
- [Menu State](https://github.com/desmitry/game/blob/master/src/states/main_menu_state.py): ui state · Main menu runtime mode · `src/states/main_menu_state.py`
- [Game State](https://github.com/desmitry/game/blob/master/src/states/game_state.py): play state · Active gameplay and simulation mode · `src/states/game_state.py`

### World Model

Levels, entities, and map assets

- [Level](https://github.com/desmitry/game/blob/master/src/systems/level.py): world builder · Builds playable world from map data · `src/systems/level.py`
- [Map Loader](https://github.com/desmitry/game/blob/master/src/systems/map_loader.py): data loader · Reads text map definitions · `src/systems/map_loader.py`
- [Test Map](https://github.com/desmitry/game/blob/master/src/maps/test_level.txt): level asset · Example text-based level · `src/maps/test_level.txt`
- [Player](https://github.com/desmitry/game/blob/master/src/models/player.py): entity · Controllable character model · `src/models/player.py`
- [Enemy](https://github.com/desmitry/game/blob/master/src/models/enemy.py): entity · Hostile model with AI hooks · `src/models/enemy.py`
- [World Obj](https://github.com/desmitry/game/blob/master/src/models/wall.py): interactables · Walls, pickups, traps, health, flashlight, flare · `src/models/wall.py`

### AI

Navigation and behavior logic

- [A*](https://github.com/desmitry/game/blob/master/src/ai/astar.py): pathfinding · Grid path search for navigation · `src/ai/astar.py`
- [Behavior Tree](https://github.com/desmitry/game/blob/master/src/ai/bt_node.py): decision system · Composable enemy behavior logic · `src/ai/bt_node.py`
- [Path Grid](https://github.com/desmitry/game/blob/master/src/ai/pathfinding_grid.py): nav grid · Navigation grid used by pathfinding · `src/ai/pathfinding_grid.py`

### Rendering

Draw pipeline and visibility effects

- [Renderer](https://github.com/desmitry/game/blob/master/src/rendering/renderer.py): draw pipeline · Main frame rendering pipeline · `src/rendering/renderer.py`
- [Lightmap](https://github.com/desmitry/game/blob/master/src/rendering/lightmap.py): visibility render · Lighting and darkness overlay · `src/rendering/lightmap.py`

### Systems

Reusable simulation helpers

- [Vision](https://github.com/desmitry/game/blob/master/src/systems/vision_cone.py): perception · Line-of-sight and cone checks · `src/systems/vision_cone.py`
- [Raycast](https://github.com/desmitry/game/blob/master/src/systems/raycast.py): visibility · Ray-based obstruction and sight queries · `src/systems/raycast.py`
- [Text Draw](https://github.com/desmitry/game/blob/master/src/systems/text_renderer.py): hud text · Renders menu and HUD text · `src/systems/text_renderer.py`
- [Genetic Alg](https://github.com/desmitry/game/blob/master/src/systems/genetic_algorithm.py): evolution system · Evolutionary simulation and tuning logic · `src/systems/genetic_algorithm.py`
- [Genome](https://github.com/desmitry/game/blob/master/src/systems/genome.py): fitness model · Data model for evolutionary traits · `src/systems/genome.py`

### Platform

Cross-cutting services

- [Sound](https://github.com/desmitry/game/blob/master/src/audio/sound_manager.py): audio service · Centralized audio playback boundary · `src/audio/sound_manager.py`

## Connections

- Main → Game Ctrl: launches · Application startup hands off to the controller
- Game Ctrl → Menu State: shows · Controller can activate the menu state
- Game Ctrl → Game State: runs · Controller can activate the gameplay state
- Game State → Level: loads · Gameplay initializes world content through level construction
- Level → Map Loader: parses · Level construction depends on map parsing
- Map Loader → Test Map: reads · Loader consumes text map assets
- Level → Player: spawns · Player entity is part of the world
- Level → Enemy: spawns · Enemy entities are part of the world
- Level → World Obj: instantiates · Walls, pickups, traps, and gear are created from level data
- Enemy → Behavior Tree: decides · Enemy behavior is driven by behavior trees
- Enemy → A*: navigates · Enemy movement can use path search
- A* → Path Grid: queries · A* operates on a navigation grid
- Enemy → Vision: senses · Enemy perception uses visibility checks
- Vision → Raycast: uses · Vision is implemented with ray-based obstruction queries
- Game State → Renderer: draws · Gameplay frame updates are rendered each tick
- Renderer → Lightmap: applies · Lighting affects final frame output
- Game State → Text Draw: hud · Gameplay and menu text use the text renderer
- Game Ctrl → Sound: plays · Audio is coordinated as a shared runtime service
- Game State → Genetic Alg: tunes · Evolutionary logic supports gameplay simulation or balancing
- Genetic Alg → Genome: models · Evolution operates on genome data
