# victoro94/minesweeper architecture

> Architecture diagram of the GitHub repository victoro94/minesweeper, 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/victoro94/minesweeper
- Repository: https://github.com/victoro94/minesweeper

## Overview

Minesweeper is a terminal game implemented with ncurses. The player supplies optional grid, mine, seed, and safe-first-click settings, then moves through the grid, reveals cells, or flags them; the game reports a win or loss and displays the final board. The graph separates the terminal loop, game rules, and board storage/rendering. Source excerpts show the main calls and game logic; relationships beyond those excerpts are omitted.

Main entry points: [`src/main.c`](https://github.com/victoro94/minesweeper/blob/main/src/main.c) (Game Loop), [`src/board.h`](https://github.com/victoro94/minesweeper/blob/main/src/board.h) (Cell State), [`src/game.c`](https://github.com/victoro94/minesweeper/blob/main/src/game.c) (Input Handling), [`src/board.c`](https://github.com/victoro94/minesweeper/blob/main/src/board.c) (Board Allocation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Terminal Runtime"]
  node_loop["Game Loop<br/>[main.c]"]
  node_wincheck["Win Check<br/>[main.c]"]
end

subgraph group_rules["Game Rules"]
  node_options["Option Parsing<br/>[game.c]"]
  node_input["Input Handling<br/>[game.c]"]
  node_minegen["Mine Generation<br/>[game.c]"]
  node_reveal["Cell Reveal<br/>[game.c]"]
end

subgraph group_board["Board"]
  node_cells["Cell State<br/>[board.h]"]
  node_allocation["Board Allocation<br/>[board.c]"]
  node_render["Board Rendering<br/>[board.c]"]
end

node_player(("Player"))

node_player -.->|"starts game"| node_loop
node_loop -->|"parses arguments"| node_options
node_loop -->|"creates board"| node_allocation
node_loop -->|"processes keys"| node_input
node_input -->|"places mines"| node_minegen
node_input -->|"reveals cell"| node_reveal
node_input -->|"updates state"| node_cells
node_minegen -->|"sets mine data"| node_cells
node_reveal -->|"reads and updates"| node_cells
node_loop -->|"checks outcome"| node_wincheck
node_wincheck -->|"reveals mines"| node_cells
node_loop -->|"prints board"| node_render
node_wincheck -->|"prints result"| node_render
node_allocation -->|"allocates cells"| node_cells
node_render -->|"reads cells"| node_cells
node_loop -->|"frees board"| node_allocation

click node_loop "https://github.com/victoro94/minesweeper/blob/main/src/main.c"
click node_options "https://github.com/victoro94/minesweeper/blob/main/src/game.c"
click node_input "https://github.com/victoro94/minesweeper/blob/main/src/game.c"
click node_minegen "https://github.com/victoro94/minesweeper/blob/main/src/game.c"
click node_reveal "https://github.com/victoro94/minesweeper/blob/main/src/game.c"
click node_wincheck "https://github.com/victoro94/minesweeper/blob/main/src/main.c"
click node_cells "https://github.com/victoro94/minesweeper/blob/main/src/board.h"
click node_allocation "https://github.com/victoro94/minesweeper/blob/main/src/board.c"
click node_render "https://github.com/victoro94/minesweeper/blob/main/src/board.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_loop,node_wincheck toneBlue
class node_options,node_input,node_minegen,node_reveal toneAmber
class node_cells,node_allocation,node_render toneMint
class node_player toneIndigo
```

## Components

### Terminal Runtime

- [Game Loop](https://github.com/victoro94/minesweeper/blob/main/src/main.c): `src/main.c`
- [Win Check](https://github.com/victoro94/minesweeper/blob/main/src/main.c): `src/main.c`

### Game Rules

- [Option Parsing](https://github.com/victoro94/minesweeper/blob/main/src/game.c): `src/game.c`
- [Input Handling](https://github.com/victoro94/minesweeper/blob/main/src/game.c): `src/game.c`
- [Mine Generation](https://github.com/victoro94/minesweeper/blob/main/src/game.c): `src/game.c`
- [Cell Reveal](https://github.com/victoro94/minesweeper/blob/main/src/game.c): `src/game.c`

### Board

- [Cell State](https://github.com/victoro94/minesweeper/blob/main/src/board.h): `src/board.h`
- [Board Allocation](https://github.com/victoro94/minesweeper/blob/main/src/board.c): `src/board.c`
- [Board Rendering](https://github.com/victoro94/minesweeper/blob/main/src/board.c): `src/board.c`

### Other components

- **Player**

## Connections

- Player → Game Loop: starts game (evidence: `README.md`)
- Game Loop → Option Parsing: parses arguments (evidence: `src/main.c`)
- Game Loop → Board Allocation: creates board (evidence: `src/main.c`)
- Game Loop → Input Handling: processes keys (evidence: `src/main.c`)
- Input Handling → Mine Generation: places mines (evidence: `src/game.c`)
- Input Handling → Cell Reveal: reveals cell (evidence: `src/game.c`)
- Input Handling → Cell State: updates state (evidence: `src/game.c`)
- Mine Generation → Cell State: sets mine data (evidence: `src/game.c`)
- Cell Reveal → Cell State: reads and updates (evidence: `src/game.c`)
- Game Loop → Win Check: checks outcome (evidence: `src/main.c`)
- Win Check → Cell State: reveals mines (evidence: `src/main.c`)
- Game Loop → Board Rendering: prints board (evidence: `src/main.c`)
- Win Check → Board Rendering: prints result (evidence: `src/main.c`)
- Board Allocation → Cell State: allocates cells (evidence: `src/board.c`)
- Board Rendering → Cell State: reads cells (evidence: `src/board.c`)
- Game Loop → Board Allocation: frees board (evidence: `src/main.c`)
