# 36vanquyet/snake_game architecture

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

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

## Overview

This is a console-menu and SDL Snake game. The main workflow is menu selection, game setup and play, then player-name entry and score saving; players can also browse scores and game guidance from the menu. The game includes difficulty levels, boundary walls, and hard-mode moving/random obstacles, while rendering and keyboard input are handled separately. The graph follows the sampled entry points and documented features; some internal runtime calls are not shown in the excerpts, so uncertain links are omitted.

Main entry points: [`src/game.cpp`](https://github.com/36vanquyet/snake_game/blob/master/src/game.cpp) (Game Orchestrator), [`src/main.cpp`](https://github.com/36vanquyet/snake_game/blob/master/src/main.cpp) (Application Entry), [`src/menu_choices.cpp`](https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp) (Menu Selection), [`src/controller.cpp`](https://github.com/36vanquyet/snake_game/blob/master/src/controller.cpp) (Keyboard Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and Menu"]
  node_main["Application Entry<br/>[main.cpp]"]
  node_menu["Menu Selection<br/>[menu_choices.cpp]"]
  node_score_views["Score Browsing<br/>[menu_choices.cpp]"]
  node_guide["Game Guide<br/>[menu_choices.cpp]"]
  node_terminal["Terminal Utilities<br/>[system_common.cpp]"]
end

subgraph group_play["Game Runtime"]
  node_game["Game Orchestrator<br/>[game.cpp]"]
  node_snake["Snake Simulation<br/>[snake.cpp]"]
  node_obstacles["Level Obstacles<br/>[game.cpp]"]
end

subgraph group_display["Input and Display"]
  node_controller["Keyboard Controller<br/>[controller.cpp]"]
  node_renderer["SDL Renderer<br/>[renderer.cpp]"]
end

subgraph group_records["Score Records"]
  node_database[("JSON Score Store<br/>[manager_db.cpp]")]
  node_level_names["Level Name Parser<br/>[parser_string.cpp]"]
end

node_player(("Player"))

node_player -->|"starts"| node_main
node_main -->|"runs menu"| node_menu
node_menu -->|"reads scores"| node_database
node_player -->|"chooses options"| node_menu
node_menu -->|"opens scores"| node_score_views
node_menu -->|"opens guide"| node_guide
node_menu -->|"uses utilities"| node_terminal
node_main -->|"starts play"| node_game
node_main -->|"creates"| node_controller
node_main -->|"creates"| node_renderer
node_player -->|"steers snake"| node_controller
node_game -->|"manages"| node_obstacles
node_game -->|"saves score"| node_database
node_game -->|"uses parser"| node_level_names
node_player -->|"provides name"| node_main
node_main -->|"persists result"| node_database
node_game -.->|"updates state"| node_snake
node_game -.->|"renders frame"| node_renderer
node_game -.->|"handles input"| node_controller

click node_main "https://github.com/36vanquyet/snake_game/blob/master/src/main.cpp"
click node_menu "https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp"
click node_score_views "https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp"
click node_guide "https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp"
click node_game "https://github.com/36vanquyet/snake_game/blob/master/src/game.cpp"
click node_snake "https://github.com/36vanquyet/snake_game/blob/master/src/snake.cpp"
click node_obstacles "https://github.com/36vanquyet/snake_game/blob/master/src/game.cpp"
click node_controller "https://github.com/36vanquyet/snake_game/blob/master/src/controller.cpp"
click node_renderer "https://github.com/36vanquyet/snake_game/blob/master/src/renderer.cpp"
click node_database "https://github.com/36vanquyet/snake_game/blob/master/src/manager_db.cpp"
click node_level_names "https://github.com/36vanquyet/snake_game/blob/master/src/parser_string.cpp"
click node_terminal "https://github.com/36vanquyet/snake_game/blob/master/src/system_common.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_main,node_menu,node_score_views,node_guide,node_terminal toneBlue
class node_game,node_snake,node_obstacles toneAmber
class node_controller,node_renderer toneMint
class node_database,node_level_names toneRose
class node_player toneIndigo
```

## Components

### Entry and Menu

- [Application Entry](https://github.com/36vanquyet/snake_game/blob/master/src/main.cpp): `src/main.cpp`
- [Menu Selection](https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp): `src/menu_choices.cpp`
- [Score Browsing](https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp): `src/menu_choices.cpp`
- [Game Guide](https://github.com/36vanquyet/snake_game/blob/master/src/menu_choices.cpp): `src/menu_choices.cpp`
- [Terminal Utilities](https://github.com/36vanquyet/snake_game/blob/master/src/system_common.cpp): `src/system_common.cpp`

### Game Runtime

- [Game Orchestrator](https://github.com/36vanquyet/snake_game/blob/master/src/game.cpp): `src/game.cpp`
- [Snake Simulation](https://github.com/36vanquyet/snake_game/blob/master/src/snake.cpp): `src/snake.cpp`
- [Level Obstacles](https://github.com/36vanquyet/snake_game/blob/master/src/game.cpp): `src/game.cpp`

### Input and Display

- [Keyboard Controller](https://github.com/36vanquyet/snake_game/blob/master/src/controller.cpp): `src/controller.cpp`
- [SDL Renderer](https://github.com/36vanquyet/snake_game/blob/master/src/renderer.cpp): `src/renderer.cpp`

### Score Records

- [JSON Score Store](https://github.com/36vanquyet/snake_game/blob/master/src/manager_db.cpp): `src/manager_db.cpp`
- [Level Name Parser](https://github.com/36vanquyet/snake_game/blob/master/src/parser_string.cpp): `src/parser_string.cpp`

### Other components

- **Player**

## Connections

- Player → Application Entry: starts (evidence: `src/main.cpp`)
- Application Entry → Menu Selection: runs menu (evidence: `src/main.cpp`)
- Menu Selection → JSON Score Store: reads scores
- Player → Menu Selection: chooses options (evidence: `README.md`)
- Menu Selection → Score Browsing: opens scores (evidence: `README.md`)
- Menu Selection → Game Guide: opens guide (evidence: `README.md`)
- Menu Selection → Terminal Utilities: uses utilities (evidence: `src/menu_choices.cpp`)
- Application Entry → Game Orchestrator: starts play (evidence: `src/main.cpp`)
- Application Entry → Keyboard Controller: creates (evidence: `src/main.cpp`)
- Application Entry → SDL Renderer: creates (evidence: `src/main.cpp`)
- Player → Keyboard Controller: steers snake (evidence: `src/controller.cpp`)
- Game Orchestrator → Level Obstacles: manages (evidence: `README.md`)
- Game Orchestrator → JSON Score Store: saves score (evidence: `src/game.cpp`)
- Game Orchestrator → Level Name Parser: uses parser (evidence: `src/game.cpp`)
- Player → Application Entry: provides name (evidence: `src/main.cpp`)
- Application Entry → JSON Score Store: persists result (evidence: `src/main.cpp`)
- Game Orchestrator → Snake Simulation: updates state
- Game Orchestrator → SDL Renderer: renders frame
- Game Orchestrator → Keyboard Controller: handles input
