# pythops/snakers architecture

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

- Interactive diagram: https://gitdiagram.com/pythops/snakers
- Repository: https://github.com/pythops/snakers

## Overview

Snakers is a terminal Snake game. The main loop initializes game state and the terminal UI, draws the current state, then processes timed ticks and keyboard input until the player quits; ticks advance the snake and collisions or wall contact end the game. The renderer displays the snake, prey, score, and game-over prompt, while the key handler supports direction changes and restarting. The README documents arrow keys and vi-style movement. The graph follows the sampled runtime source; no separate persistence or service layer is present.

Main entry points: [`src/main.rs`](https://github.com/pythops/snakers/blob/master/src/main.rs) (Game loop), [`src/app.rs`](https://github.com/pythops/snakers/blob/master/src/app.rs) (Game state and rules), [`src/event.rs`](https://github.com/pythops/snakers/blob/master/src/event.rs) (Event polling), [`src/tui.rs`](https://github.com/pythops/snakers/blob/master/src/tui.rs) (Terminal UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Game state"]
  node_app["Game state and rules<br/>[app.rs]"]
end

subgraph group_interaction["Terminal interaction"]
  node_main["Game loop<br/>[main.rs]"]
  node_handler["Key handler<br/>[handler.rs]"]
  node_events["Event polling<br/>[event.rs]"]
end

subgraph group_display["Game display"]
  node_tui["Terminal UI<br/>[tui.rs]"]
  node_ui["Game renderer<br/>[ui.rs]"]
end

node_player(("Player"))
node_terminal["Terminal"]
node_random["Random generator"]

node_main -->|"creates state"| node_app
node_main -->|"starts polling"| node_events
node_main -->|"initializes and draws"| node_tui
node_main -->|"receives events"| node_events
node_events -->|"sends events"| node_main
node_player -->|"presses keys"| node_terminal
node_events -->|"polls input"| node_terminal
node_main -->|"ticks game"| node_app
node_main -->|"dispatches keys"| node_handler
node_handler -->|"updates controls"| node_app
node_tui -->|"renders state"| node_ui
node_ui -->|"reads and sets bounds"| node_app
node_app -->|"generates prey"| node_random
node_tui -->|"configures display"| node_terminal
node_ui -->|"draws game"| node_terminal

click node_main "https://github.com/pythops/snakers/blob/master/src/main.rs"
click node_app "https://github.com/pythops/snakers/blob/master/src/app.rs"
click node_handler "https://github.com/pythops/snakers/blob/master/src/handler.rs"
click node_events "https://github.com/pythops/snakers/blob/master/src/event.rs"
click node_tui "https://github.com/pythops/snakers/blob/master/src/tui.rs"
click node_ui "https://github.com/pythops/snakers/blob/master/src/ui.rs"

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_app toneBlue
class node_main,node_handler,node_events toneAmber
class node_tui,node_ui toneMint
class node_player,node_terminal,node_random toneIndigo
```

## Components

### Game state

- [Game state and rules](https://github.com/pythops/snakers/blob/master/src/app.rs): `src/app.rs`

### Terminal interaction

- [Game loop](https://github.com/pythops/snakers/blob/master/src/main.rs): `src/main.rs`
- [Key handler](https://github.com/pythops/snakers/blob/master/src/handler.rs): `src/handler.rs`
- [Event polling](https://github.com/pythops/snakers/blob/master/src/event.rs): `src/event.rs`

### Game display

- [Terminal UI](https://github.com/pythops/snakers/blob/master/src/tui.rs): `src/tui.rs`
- [Game renderer](https://github.com/pythops/snakers/blob/master/src/ui.rs): `src/ui.rs`

### Other components

- **Player**
- **Terminal**
- **Random generator**

## Connections

- Game loop → Game state and rules: creates state
- Game loop → Event polling: starts polling
- Game loop → Terminal UI: initializes and draws
- Game loop → Event polling: receives events
- Event polling → Game loop: sends events
- Player → Terminal: presses keys
- Event polling → Terminal: polls input
- Game loop → Game state and rules: ticks game
- Game loop → Key handler: dispatches keys
- Key handler → Game state and rules: updates controls
- Terminal UI → Game renderer: renders state
- Game renderer → Game state and rules: reads and sets bounds
- Game state and rules → Random generator: generates prey
- Terminal UI → Terminal: configures display
- Game renderer → Terminal: draws game
