# igord69/snake_game architecture

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

- Interactive diagram: https://gitdiagram.com/igord69/snake_game
- Repository: https://github.com/igord69/snake_game

## Overview

Snake Game is a C++ game whose main workflow is started by `main.cpp`, then orchestrated by `Engine`: it initializes the board, snake, and apple; reads Raylib keyboard/window state, advances movement and collision/eating logic, and sends a character-grid image and score text to the Raylib renderer. Core gameplay and rendering calls are visible in the excerpts. Other indexed modules document map, position, direction, and input abstractions, but their runtime relationships are not inferred where callers were not shown.

Main entry points: [`Engine.cpp`](https://github.com/igord69/snake_game/blob/main/Engine.cpp) (Game engine), [`Player.cpp`](https://github.com/igord69/snake_game/blob/main/Player.cpp) (Player), [`Renderer.cpp`](https://github.com/igord69/snake_game/blob/main/Renderer.cpp) (Raylib renderer), [`Apple.cpp`](https://github.com/igord69/snake_game/blob/main/Apple.cpp) (Apple)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gameplay["Game orchestration"]
  node_engine["Game engine<br/>[Engine.cpp]"]
  node_main["Application entry<br/>[main.cpp]"]
end

subgraph group_domain["Game state"]
  node_player["Player<br/>[Player.cpp]"]
  node_apple["Apple<br/>[Apple.cpp]"]
  node_map["Map<br/>[Map.cpp]"]
  node_position["Position<br/>[Position.cpp]"]
  node_direction["Direction<br/>[Direction.cpp]"]
end

subgraph group_presentation["Rendering"]
  node_renderer["Raylib renderer<br/>[Renderer.cpp]"]
  node_renderer_api["Renderer contract"]
end

subgraph group_input["Input abstractions"]
  node_listener_api["Listener contract"]
  node_cmd_listener["Terminal listener<br/>[CmdListener.cpp]"]
end

node_player_actor(("Player"))
node_raylib["Raylib"]

node_main -->|"starts"| node_engine
node_engine -->|"initializes"| node_map
node_engine -->|"initializes"| node_player
node_engine -->|"initializes"| node_apple
node_engine -->|"moves and checks"| node_player
node_engine -->|"eats apple"| node_player
node_engine -->|"replaces"| node_apple
node_engine -->|"draws through"| node_renderer
node_engine -->|"reads window input"| node_renderer
node_engine -->|"sends game image"| node_renderer
node_renderer -->|"implements"| node_renderer_api
node_renderer -->|"renders with"| node_raylib
node_player -->|"stores coordinates"| node_position
node_player -->|"moves by"| node_direction
node_apple -->|"stores coordinates"| node_position
node_renderer_api -->|"uses coordinates"| node_position
node_player_actor -.->|"controls"| node_engine
node_cmd_listener -->|"implements"| node_listener_api

click node_player "https://github.com/igord69/snake_game/blob/main/Player.cpp"
click node_apple "https://github.com/igord69/snake_game/blob/main/Apple.cpp"
click node_map "https://github.com/igord69/snake_game/blob/main/Map.cpp"
click node_position "https://github.com/igord69/snake_game/blob/main/Position.cpp"
click node_direction "https://github.com/igord69/snake_game/blob/main/Direction.cpp"
click node_engine "https://github.com/igord69/snake_game/blob/main/Engine.cpp"
click node_main "https://github.com/igord69/snake_game/blob/main/main.cpp"
click node_renderer "https://github.com/igord69/snake_game/blob/main/Renderer.cpp"
click node_renderer_api "https://github.com/igord69/snake_game/blob/main/Abstract_Renderer.hpp"
click node_listener_api "https://github.com/igord69/snake_game/blob/main/AbstractListener.hpp"
click node_cmd_listener "https://github.com/igord69/snake_game/blob/main/CmdListener.cpp"

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_engine,node_main toneBlue
class node_player,node_apple,node_map,node_position,node_direction toneAmber
class node_renderer,node_renderer_api toneMint
class node_listener_api,node_cmd_listener toneRose
class node_player_actor,node_raylib toneIndigo
```

## Components

### Game orchestration

- [Game engine](https://github.com/igord69/snake_game/blob/main/Engine.cpp): `Engine.cpp`
- [Application entry](https://github.com/igord69/snake_game/blob/main/main.cpp): `main.cpp`

### Game state

- [Player](https://github.com/igord69/snake_game/blob/main/Player.cpp): `Player.cpp`
- [Apple](https://github.com/igord69/snake_game/blob/main/Apple.cpp): `Apple.cpp`
- [Map](https://github.com/igord69/snake_game/blob/main/Map.cpp): `Map.cpp`
- [Position](https://github.com/igord69/snake_game/blob/main/Position.cpp): `Position.cpp`
- [Direction](https://github.com/igord69/snake_game/blob/main/Direction.cpp): `Direction.cpp`

### Rendering

- [Raylib renderer](https://github.com/igord69/snake_game/blob/main/Renderer.cpp): `Renderer.cpp`
- [Renderer contract](https://github.com/igord69/snake_game/blob/main/Abstract_Renderer.hpp): `Abstract_Renderer.hpp`

### Input abstractions

- [Listener contract](https://github.com/igord69/snake_game/blob/main/AbstractListener.hpp): `AbstractListener.hpp`
- [Terminal listener](https://github.com/igord69/snake_game/blob/main/CmdListener.cpp): `CmdListener.cpp`

### Other components

- **Player**
- **Raylib**

## Connections

- Application entry → Game engine: starts (evidence: `main.cpp`)
- Game engine → Map: initializes (evidence: `Engine.cpp`)
- Game engine → Player: initializes (evidence: `Engine.cpp`)
- Game engine → Apple: initializes (evidence: `Engine.cpp`)
- Game engine → Player: moves and checks (evidence: `Engine.cpp`)
- Game engine → Player: eats apple (evidence: `Engine.cpp`)
- Game engine → Apple: replaces (evidence: `Engine.cpp`)
- Game engine → Raylib renderer: draws through (evidence: `Engine.cpp`)
- Game engine → Raylib renderer: reads window input (evidence: `Engine.cpp`)
- Game engine → Raylib renderer: sends game image (evidence: `Engine.cpp`)
- Raylib renderer → Renderer contract: implements
- Raylib renderer → Raylib: renders with
- Player → Position: stores coordinates (evidence: `Player.cpp`)
- Player → Direction: moves by
- Apple → Position: stores coordinates
- Renderer contract → Position: uses coordinates (evidence: `Abstract_Renderer.hpp`)
- Player → Game engine: controls (evidence: `README.md`)
- Terminal listener → Listener contract: implements
