# elegantgx/snakecli architecture

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

- Interactive diagram: https://gitdiagram.com/elegantgx/snakecli
- Repository: https://github.com/elegantgx/snakecli
- Video tour (about a minute): https://gitdiagram.com/elegantgx/snakecli/video

## Overview

Snake CLI is a terminal Snake game. Its main workflow is command-line handling, watchdog-managed game startup, terminal validation and ncurses setup, then menu selection and gameplay through pause, finish, and return/exit states. The graph also preserves the documented size-check mode, About screen, apple generation, and logical-to-physical rendering. Some gameplay implementation is excerpted only partially, so unshown internal calls are omitted; README statements support the watchdog and documented feature links.

Main entry points: [`game.c`](https://github.com/elegantgx/snakecli/blob/main/game.c) (Game runtime), [`menu.c`](https://github.com/elegantgx/snakecli/blob/main/menu.c) (Main menu), [`main.c`](https://github.com/elegantgx/snakecli/blob/main/main.c) (CLI entry), [`play.c`](https://github.com/elegantgx/snakecli/blob/main/play.c) (Play state machine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime lifecycle"]
  node_main["CLI entry<br/>[main.c]"]
  node_watchdog["Watchdog loop<br/>[main.c]"]
  node_game["Game runtime<br/>[game.c]"]
  node_env["Environment gate<br/>[game.c]"]
end

subgraph group_interface["Terminal interface"]
  node_menu["Main menu<br/>[menu.c]"]
  node_about["About screen<br/>[menu.c]"]
end

subgraph group_gameplay["Snake gameplay"]
  node_play["Play state machine<br/>[play.c]"]
  node_movement["Movement and collision<br/>[play.c]"]
  node_apple["Apple generation<br/>[play.c]"]
  node_render["Cell rendering<br/>[play.c]"]
end

subgraph group_shared["Shared utilities"]
  node_command["Command modes<br/>[utils.c]"]
  node_options["Option selection<br/>[utils.c]"]
  node_centering["Centered text<br/>[utils.c]"]
end

node_player(("Player"))
node_terminal["Terminal"]

node_player -->|"starts"| node_main
node_main -->|"checks arguments"| node_command
node_main -->|"enters loop"| node_watchdog
node_watchdog -->|"runs child"| node_game
node_watchdog -->|"restarts on resize"| node_game
node_game -->|"checks terminal"| node_env
node_game -->|"dispatches MENU"| node_menu
node_game -->|"dispatches PLAY"| node_play
node_menu -->|"shows About"| node_about
node_menu -->|"uses selection"| node_options
node_menu -->|"prints centered text"| node_centering
node_play -->|"runs playing state"| node_movement
node_play -->|"creates state menus"| node_options
node_movement -->|"generates apple"| node_apple
node_movement -->|"renders cells"| node_render
node_command -->|"checks dimensions"| node_terminal
node_env -->|"validates size and color"| node_terminal
node_render -->|"draws color blocks"| node_terminal

click node_main "https://github.com/elegantgx/snakecli/blob/main/main.c"
click node_command "https://github.com/elegantgx/snakecli/blob/main/utils.c"
click node_watchdog "https://github.com/elegantgx/snakecli/blob/main/main.c"
click node_game "https://github.com/elegantgx/snakecli/blob/main/game.c"
click node_env "https://github.com/elegantgx/snakecli/blob/main/game.c"
click node_menu "https://github.com/elegantgx/snakecli/blob/main/menu.c"
click node_about "https://github.com/elegantgx/snakecli/blob/main/menu.c"
click node_play "https://github.com/elegantgx/snakecli/blob/main/play.c"
click node_movement "https://github.com/elegantgx/snakecli/blob/main/play.c"
click node_apple "https://github.com/elegantgx/snakecli/blob/main/play.c"
click node_render "https://github.com/elegantgx/snakecli/blob/main/play.c"
click node_options "https://github.com/elegantgx/snakecli/blob/main/utils.c"
click node_centering "https://github.com/elegantgx/snakecli/blob/main/utils.c"

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_watchdog,node_game,node_env toneBlue
class node_menu,node_about toneAmber
class node_play,node_movement,node_apple,node_render toneMint
class node_command,node_options,node_centering toneRose
class node_player,node_terminal toneIndigo
```

## Components

### Runtime lifecycle

- [CLI entry](https://github.com/elegantgx/snakecli/blob/main/main.c): `main.c`
- [Watchdog loop](https://github.com/elegantgx/snakecli/blob/main/main.c): `main.c`
- [Game runtime](https://github.com/elegantgx/snakecli/blob/main/game.c): `game.c`
- [Environment gate](https://github.com/elegantgx/snakecli/blob/main/game.c): `game.c`

### Terminal interface

- [Main menu](https://github.com/elegantgx/snakecli/blob/main/menu.c): `menu.c`
- [About screen](https://github.com/elegantgx/snakecli/blob/main/menu.c): `menu.c`

### Snake gameplay

- [Play state machine](https://github.com/elegantgx/snakecli/blob/main/play.c): `play.c`
- [Movement and collision](https://github.com/elegantgx/snakecli/blob/main/play.c): `play.c`
- [Apple generation](https://github.com/elegantgx/snakecli/blob/main/play.c): `play.c`
- [Cell rendering](https://github.com/elegantgx/snakecli/blob/main/play.c): `play.c`

### Shared utilities

- [Command modes](https://github.com/elegantgx/snakecli/blob/main/utils.c): `utils.c`
- [Option selection](https://github.com/elegantgx/snakecli/blob/main/utils.c): `utils.c`
- [Centered text](https://github.com/elegantgx/snakecli/blob/main/utils.c): `utils.c`

### Other components

- **Player**
- **Terminal**

## Connections

- Player → CLI entry: starts (evidence: `README.md`)
- CLI entry → Command modes: checks arguments (evidence: `main.c`)
- CLI entry → Watchdog loop: enters loop (evidence: `main.c`)
- Watchdog loop → Game runtime: runs child (evidence: `main.c`)
- Watchdog loop → Game runtime: restarts on resize (evidence: `README.md`)
- Game runtime → Environment gate: checks terminal (evidence: `game.c`)
- Game runtime → Main menu: dispatches MENU (evidence: `game.c`)
- Game runtime → Play state machine: dispatches PLAY (evidence: `game.c`)
- Main menu → About screen: shows About (evidence: `menu.c`)
- Main menu → Option selection: uses selection (evidence: `menu.c`)
- Main menu → Centered text: prints centered text (evidence: `menu.c`)
- Play state machine → Movement and collision: runs playing state (evidence: `play.c`)
- Play state machine → Option selection: creates state menus (evidence: `play.c`)
- Movement and collision → Apple generation: generates apple (evidence: `README.md`)
- Movement and collision → Cell rendering: renders cells (evidence: `README.md`)
- Command modes → Terminal: checks dimensions (evidence: `utils.c`)
- Environment gate → Terminal: validates size and color (evidence: `game.c`)
- Cell rendering → Terminal: draws color blocks (evidence: `README.md`)
