# emmanueldrivescode/number-guessing-game architecture

> Architecture diagram of the GitHub repository emmanueldrivescode/number-guessing-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emmanueldrivescode/number-guessing-game
- Repository: https://github.com/emmanueldrivescode/number-guessing-game

## Overview

#### Purpose and entry point
This is a Python command-line number-guessing game. A player selects a difficulty, guesses a random number from 1–100 within an attempt limit, receives hints, and can replay. Start the application with `main.py`.

Paths: `main.py`, `game.py`

#### Application orchestration
`main.py` is the CLI-facing coordinator: it should present the game loop, invoke a game round, and handle the play-again lifecycle. It forms the boundary between terminal input/output and domain logic.

Paths: `main.py`, `game.py`

#### Game-round engine
`game.py` owns core gameplay state and control flow: random target generation, difficulty-derived attempt budgets, guess evaluation, hint delivery, success/failure determination, and elapsed-time tracking. It should not need to know persistence details beyond calling score/stat interfaces.

Paths: `game.py`, `main.py`

#### Difficulty and hint behavior
Difficulty is a domain policy expressed through the round engine: Easy permits 10 attempts, Medium 5, and Hard 3. Guess feedback narrows the range (“greater”/“less”), while difficulty may govern hint behavior. Inputs must be validated before they affect round state.

Paths: `game.py`

#### High-score persistence
High scores are persisted locally as JSON. `highscores.py` is the persistence/service boundary for reading prior records, comparing a winning result—likely attempts and/or time—and writing improved scores. The application uses the repository working directory as its storage location.

Paths: `highscores.py`, `highscores.json`

#### Aggregate game statistics
`stats.py` maintains durable aggregate counters for games played, wins, losses, and derived win rate. Each completed round should report exactly one terminal result to this component; `stats.json` is the backing store.

Paths: `stats.py`, `stats.json`, `game.py`

#### Runtime and external boundaries
The system runs on Python 3 in a local terminal and relies on standard-library facilities: random-number generation, timing, and JSON serialization. There are no network services, database systems, web runtime, or third-party infrastructure indicated. Persistent JSON files are shared mutable state and require tolerant handling of missing, malformed, or empty files.

Paths: `main.py`, `highscores.json`, `stats.json`

Main entry points: [`game.py`](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py) (Round engine), [`highscores.py`](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/highscores.py) (High-score service), [`stats.py`](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/stats.py) (Statistics service), [`main.py`](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/main.py) (Application loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["CLI Application"]
  node_terminal(("Local terminal<br/>runtime boundary"))
  node_main["Application loop<br/>CLI coordinator<br/>[main.py]"]
end

subgraph group_domain["Game Domain"]
  node_game["Round engine<br/>game domain<br/>[game.py]"]
  node_difficulty{{"Difficulty policy<br/>domain policy<br/>[game.py]"}}
  node_feedback{{"Guess feedback<br/>domain behavior<br/>[game.py]"}}
  node_random_time(("Randomness and timing<br/>Python standard library"))
end

subgraph group_persistence["Local Persistence"]
  node_highscores["High-score service<br/>persistence service<br/>[highscores.py]"]
  node_stats["Statistics service<br/>persistence service<br/>[stats.py]"]
  node_highscores_json["High scores<br/>JSON file<br/>[highscores.json]"]
  node_stats_json["Game statistics<br/>JSON file<br/>[stats.json]"]
  node_json(("JSON serialization<br/>Python standard library"))
end

node_python(("Python 3 runtime"))

node_terminal -->|"input / output"| node_main
node_main -->|"starts round"| node_game
node_game -->|"applies attempt budget"| node_difficulty
node_game -->|"evaluates validated guesses"| node_feedback
node_game -->|"uses"| node_random_time
node_game -->|"reports winning result"| node_highscores
node_game -->|"reports terminal result"| node_stats
node_highscores -->|"reads / writes"| node_highscores_json
node_stats -->|"reads / writes"| node_stats_json
node_highscores -->|"serializes"| node_json
node_stats -->|"serializes"| node_json
node_python -->|"executes"| node_main
node_python -->|"executes"| node_game
node_python -->|"executes"| node_highscores
node_python -->|"executes"| node_stats

click node_main "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/main.py"
click node_game "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py"
click node_difficulty "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py"
click node_feedback "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py"
click node_highscores "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/highscores.py"
click node_stats "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/stats.py"
click node_highscores_json "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/highscores.json"
click node_stats_json "https://github.com/emmanueldrivescode/number-guessing-game/blob/main/stats.json"

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_terminal,node_main toneBlue
class node_game,node_difficulty,node_feedback,node_random_time toneAmber
class node_highscores,node_stats,node_highscores_json,node_stats_json,node_json toneMint
class node_python toneNeutral
```

## Components

### CLI Application

- **Local terminal**: runtime boundary · Player input and game output.
- [Application loop](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/main.py): CLI coordinator · Runs rounds and manages replay. · `main.py`

### Game Domain

- [Round engine](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py): game domain · Owns round state, validation, hints, and terminal outcomes. · `game.py`
- [Difficulty policy](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py): domain policy · Sets Easy, Medium, and Hard attempt budgets. · `game.py`
- [Guess feedback](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/game.py): domain behavior · Evaluates guesses and provides greater/less hints. · `game.py`
- **Randomness and timing**: Python standard library · Generates targets and measures elapsed time.

### Local Persistence

- [High-score service](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/highscores.py): persistence service · Reads, compares, and writes improved winning scores. · `highscores.py`
- [Statistics service](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/stats.py): persistence service · Records one win or loss for every completed round. · `stats.py`
- [High scores](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/highscores.json): JSON file · Local durable score records. · `highscores.json`
- [Game statistics](https://github.com/emmanueldrivescode/number-guessing-game/blob/main/stats.json): JSON file · Local aggregate counters and win rate data. · `stats.json`
- **JSON serialization**: Python standard library · Handles local JSON data with tolerant file loading.

### Other components

- **Python 3 runtime**: runtime

## Connections

- Local terminal → Application loop: input / output
- Application loop → Round engine: starts round
- Round engine → Difficulty policy: applies attempt budget
- Round engine → Guess feedback: evaluates validated guesses
- Round engine → Randomness and timing: uses
- Round engine → High-score service: reports winning result
- Round engine → Statistics service: reports terminal result
- High-score service → High scores: reads / writes
- Statistics service → Game statistics: reads / writes
- High-score service → JSON serialization: serializes
- Statistics service → JSON serialization: serializes
- Python 3 runtime → Application loop: executes
- Python 3 runtime → Round engine: executes
- Python 3 runtime → High-score service: executes
- Python 3 runtime → Statistics service: executes
