# etturo/pacman architecture

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

- Interactive diagram: https://gitdiagram.com/etturo/pacman
- Repository: https://github.com/etturo/pacman

## Overview

Pacman is a Pygame desktop game. The main loop loads settings, routes input and game events through distinct screens, updates gameplay (including maze, entities, scoring and level transitions), then renders and presents each frame. Players can also start AI play; the game supports persistent highscores, configurable sound sets and CRT-style display effects. The README documents these capabilities, while sampled source and the source index support the main runtime links. Some subsystem wiring is documented rather than directly excerpted, so those links cite the README; unsampled details are not inferred.

Main entry points: [`src/core/game_state.py`](https://github.com/etturo/pacman/blob/main/src/core/game_state.py) (Game states), [`src/core/game.py`](https://github.com/etturo/pacman/blob/main/src/core/game.py) (Game loop), [`src/world/maze.py`](https://github.com/etturo/pacman/blob/main/src/world/maze.py) (Maze grid), [`src/ai/agent.py`](https://github.com/etturo/pacman/blob/main/src/ai/agent.py) (AI agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_launcher["Game loop<br/>[game.py]"]
  node_screens["Game states<br/>[game_state.py]"]
  node_scores[("Highscores<br/>[game_state.py]")]
end

subgraph group_play["Gameplay systems"]
  node_mazegen["Maze generation<br/>[maze_wrapper.py]"]
  node_maze["Maze grid<br/>[maze.py]"]
  node_cell["Maze cells<br/>[cell.py]"]
  node_pacman["Pac-Man<br/>[pacman.py]"]
  node_ghosts["Ghost behavior<br/>[ghost.py]"]
  node_ghostnav["Ghost movement<br/>[ghost_movement.py]"]
  node_collectibles["Pac-gums<br/>[pacgums.py]"]
end

subgraph group_presentation["Presentation"]
  node_maze_render["Maze renderer<br/>[maze_render.py]"]
  node_screen["Display effects<br/>[screen_manager.py]"]
  node_sprites["Sprite assets<br/>[sprite_library.py]"]
  node_sprite_sheet["Sprite sheets<br/>[sprite_sheet.py]"]
  node_ui["Game interface<br/>[element.py]"]
  node_sound["Sound sets<br/>[sound_library.py]"]
  node_sound_effect["Sound effects<br/>[sound_effects.py]"]
end

subgraph group_support["Configuration and AI"]
  node_settings["Settings parser<br/>[parser.py]"]
  node_models["Settings model<br/>[models.py]"]
  node_ai["AI agent<br/>[agent.py]"]
  node_ai_context["AI context<br/>[context.py]"]
  node_ai_features["AI features<br/>[features.py]"]
end

node_player(("Player"))

node_player -->|"starts"| node_launcher
node_launcher -->|"loads config"| node_settings
node_settings -->|"validates"| node_models
node_launcher -->|"routes events"| node_screens
node_screens -->|"builds levels"| node_mazegen
node_mazegen -->|"adapts output"| node_maze
node_maze -->|"stores grid"| node_cell
node_screens -->|"updates"| node_pacman
node_screens -->|"updates"| node_ghosts
node_screens -->|"updates"| node_collectibles
node_ghosts -->|"chooses movement"| node_ghostnav
node_ghostnav -->|"reads paths"| node_maze
node_screens -->|"saves results"| node_scores
node_screens -->|"requests actions"| node_ai
node_ai -->|"uses context"| node_ai_context
node_ai -->|"extracts features"| node_ai_features
node_ai_context -->|"reads maze"| node_maze
node_screens -->|"renders maze"| node_maze_render
node_screens -->|"draws interface"| node_ui
node_launcher -->|"presents frames"| node_screen
node_maze_render -->|"uses sprites"| node_sprites
node_sprites -->|"loads sheets"| node_sprite_sheet
node_launcher -->|"loads sounds"| node_sound
node_sound -->|"selects effects"| node_sound_effect
node_screens -->|"plays cues"| node_sound

click node_launcher "https://github.com/etturo/pacman/blob/main/src/core/game.py"
click node_screens "https://github.com/etturo/pacman/blob/main/src/core/game_state.py"
click node_settings "https://github.com/etturo/pacman/blob/main/src/utils/parser.py"
click node_models "https://github.com/etturo/pacman/blob/main/src/utils/models.py"
click node_mazegen "https://github.com/etturo/pacman/blob/main/src/world/maze_wrapper.py"
click node_maze "https://github.com/etturo/pacman/blob/main/src/world/maze.py"
click node_cell "https://github.com/etturo/pacman/blob/main/src/world/cell.py"
click node_pacman "https://github.com/etturo/pacman/blob/main/src/entities/pacman.py"
click node_ghosts "https://github.com/etturo/pacman/blob/main/src/entities/ghost.py"
click node_ghostnav "https://github.com/etturo/pacman/blob/main/src/entities/ghost_movement.py"
click node_collectibles "https://github.com/etturo/pacman/blob/main/src/entities/pacgums.py"
click node_scores "https://github.com/etturo/pacman/blob/main/src/core/game_state.py"
click node_ai "https://github.com/etturo/pacman/blob/main/src/ai/agent.py"
click node_ai_context "https://github.com/etturo/pacman/blob/main/src/ai/context.py"
click node_ai_features "https://github.com/etturo/pacman/blob/main/src/ai/features.py"
click node_maze_render "https://github.com/etturo/pacman/blob/main/src/graphics/maze_render.py"
click node_screen "https://github.com/etturo/pacman/blob/main/src/graphics/screen_manager.py"
click node_sprites "https://github.com/etturo/pacman/blob/main/src/graphics/graphical_utils/sprite_library.py"
click node_sprite_sheet "https://github.com/etturo/pacman/blob/main/src/graphics/graphical_utils/sprite_sheet.py"
click node_ui "https://github.com/etturo/pacman/blob/main/src/graphics/ui/element.py"
click node_sound "https://github.com/etturo/pacman/blob/main/src/sounds/sound_library.py"
click node_sound_effect "https://github.com/etturo/pacman/blob/main/src/sounds/sound_effects.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_launcher,node_screens,node_scores toneBlue
class node_mazegen,node_maze,node_cell,node_pacman,node_ghosts,node_ghostnav,node_collectibles toneAmber
class node_maze_render,node_screen,node_sprites,node_sprite_sheet,node_ui,node_sound,node_sound_effect toneMint
class node_settings,node_models,node_ai,node_ai_context,node_ai_features toneRose
class node_player toneIndigo
```

## Components

### Game runtime

- [Game loop](https://github.com/etturo/pacman/blob/main/src/core/game.py): `src/core/game.py`
- [Game states](https://github.com/etturo/pacman/blob/main/src/core/game_state.py): `src/core/game_state.py`
- [Highscores](https://github.com/etturo/pacman/blob/main/src/core/game_state.py): `src/core/game_state.py`

### Gameplay systems

- [Maze generation](https://github.com/etturo/pacman/blob/main/src/world/maze_wrapper.py): `src/world/maze_wrapper.py`
- [Maze grid](https://github.com/etturo/pacman/blob/main/src/world/maze.py): `src/world/maze.py`
- [Maze cells](https://github.com/etturo/pacman/blob/main/src/world/cell.py): `src/world/cell.py`
- [Pac-Man](https://github.com/etturo/pacman/blob/main/src/entities/pacman.py): `src/entities/pacman.py`
- [Ghost behavior](https://github.com/etturo/pacman/blob/main/src/entities/ghost.py): `src/entities/ghost.py`
- [Ghost movement](https://github.com/etturo/pacman/blob/main/src/entities/ghost_movement.py): `src/entities/ghost_movement.py`
- [Pac-gums](https://github.com/etturo/pacman/blob/main/src/entities/pacgums.py): `src/entities/pacgums.py`

### Presentation

- [Maze renderer](https://github.com/etturo/pacman/blob/main/src/graphics/maze_render.py): `src/graphics/maze_render.py`
- [Display effects](https://github.com/etturo/pacman/blob/main/src/graphics/screen_manager.py): `src/graphics/screen_manager.py`
- [Sprite assets](https://github.com/etturo/pacman/blob/main/src/graphics/graphical_utils/sprite_library.py): `src/graphics/graphical_utils/sprite_library.py`
- [Sprite sheets](https://github.com/etturo/pacman/blob/main/src/graphics/graphical_utils/sprite_sheet.py): `src/graphics/graphical_utils/sprite_sheet.py`
- [Game interface](https://github.com/etturo/pacman/blob/main/src/graphics/ui/element.py): `src/graphics/ui/element.py`
- [Sound sets](https://github.com/etturo/pacman/blob/main/src/sounds/sound_library.py): `src/sounds/sound_library.py`
- [Sound effects](https://github.com/etturo/pacman/blob/main/src/sounds/sound_effects.py): `src/sounds/sound_effects.py`

### Configuration and AI

- [Settings parser](https://github.com/etturo/pacman/blob/main/src/utils/parser.py): `src/utils/parser.py`
- [Settings model](https://github.com/etturo/pacman/blob/main/src/utils/models.py): `src/utils/models.py`
- [AI agent](https://github.com/etturo/pacman/blob/main/src/ai/agent.py): `src/ai/agent.py`
- [AI context](https://github.com/etturo/pacman/blob/main/src/ai/context.py): `src/ai/context.py`
- [AI features](https://github.com/etturo/pacman/blob/main/src/ai/features.py): `src/ai/features.py`

### Other components

- **Player**

## Connections

- Player → Game loop: starts
- Game loop → Settings parser: loads config (evidence: `src/core/game.py`)
- Settings parser → Settings model: validates (evidence: `src/utils/parser.py`)
- Game loop → Game states: routes events (evidence: `src/core/game.py`)
- Game states → Maze generation: builds levels (evidence: `src/core/game_state.py`)
- Maze generation → Maze grid: adapts output (evidence: `src/world/maze_wrapper.py`)
- Maze grid → Maze cells: stores grid (evidence: `src/world/maze.py`)
- Game states → Pac-Man: updates (evidence: `src/core/game_state.py`)
- Game states → Ghost behavior: updates (evidence: `src/core/game_state.py`)
- Game states → Pac-gums: updates (evidence: `src/core/game_state.py`)
- Ghost behavior → Ghost movement: chooses movement (evidence: `src/entities/ghost.py`)
- Ghost movement → Maze grid: reads paths (evidence: `src/entities/ghost_movement.py`)
- Game states → Highscores: saves results (evidence: `src/core/game_state.py`)
- Game states → AI agent: requests actions (evidence: `src/core/game_state.py`)
- AI agent → AI context: uses context (evidence: `src/ai/agent.py`)
- AI agent → AI features: extracts features (evidence: `src/ai/agent.py`)
- AI context → Maze grid: reads maze (evidence: `src/ai/context.py`)
- Game states → Maze renderer: renders maze (evidence: `src/core/game_state.py`)
- Game states → Game interface: draws interface (evidence: `src/core/game_state.py`)
- Game loop → Display effects: presents frames (evidence: `src/core/game.py`)
- Maze renderer → Sprite assets: uses sprites (evidence: `src/graphics/maze_render.py`)
- Sprite assets → Sprite sheets: loads sheets (evidence: `src/graphics/graphical_utils/sprite_library.py`)
- Game loop → Sound sets: loads sounds (evidence: `src/core/game.py`)
- Sound sets → Sound effects: selects effects (evidence: `src/sounds/sound_library.py`)
- Game states → Sound sets: plays cues (evidence: `src/core/game_state.py`)
