# gianpgunawan/minesweeper architecture

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

- Interactive diagram: https://gitdiagram.com/gianpgunawan/minesweeper
- Repository: https://github.com/gianpgunawan/minesweeper

## Overview

This is a small terminal Minesweeper game implemented in one C file. The player moves a cursor, reveals cells, and flags suspected mines; the game generates a minefield, calculates adjacent counts, reveals connected empty areas, and renders the board and outcome. The main loop coordinates these actions. All components point to main.c; the excerpts show the key calls, but omitted lines limit detail about some internal behavior.

Main entry points: [`main.c`](https://github.com/gianpgunawan/minesweeper/blob/main/main.c) (Game loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Game control"]
  node_loop["Game loop<br/>[main.c]"]
end

subgraph group_board["Board logic"]
  node_board_setup["Board setup<br/>[main.c]"]
  node_random_coord["Random coordinate<br/>[main.c]"]
  node_mine_placement["Mine placement<br/>[main.c]"]
  node_number_placement["Number placement<br/>[main.c]"]
  node_adjacent_count["Adjacent mine count<br/>[main.c]"]
  node_reveal["Area reveal<br/>[main.c]"]
end

subgraph group_terminal["Terminal interface"]
  node_input["Key input<br/>[main.c]"]
  node_render["Board renderer<br/>[main.c]"]
end

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

node_player -->|"plays"| node_loop
node_loop -->|"initializes"| node_board_setup
node_board_setup -->|"places mines"| node_mine_placement
node_board_setup -->|"places numbers"| node_number_placement
node_mine_placement -->|"chooses locations"| node_random_coord
node_number_placement -->|"counts mines"| node_adjacent_count
node_loop -->|"reads keys"| node_input
node_loop -->|"reveals area"| node_reveal
node_loop -->|"renders board"| node_render
node_render -->|"prints board"| node_terminal_output

click node_loop "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_board_setup "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_random_coord "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_mine_placement "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_number_placement "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_adjacent_count "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_reveal "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_input "https://github.com/gianpgunawan/minesweeper/blob/main/main.c"
click node_render "https://github.com/gianpgunawan/minesweeper/blob/main/main.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 toneBlue
class node_board_setup,node_random_coord,node_mine_placement,node_number_placement,node_adjacent_count,node_reveal toneAmber
class node_input,node_render toneMint
class node_player,node_terminal_output toneIndigo
```

## Components

### Game control

- [Game loop](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`

### Board logic

- [Board setup](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Random coordinate](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Mine placement](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Number placement](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Adjacent mine count](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Area reveal](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`

### Terminal interface

- [Key input](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`
- [Board renderer](https://github.com/gianpgunawan/minesweeper/blob/main/main.c): `main.c`

### Other components

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

## Connections

- Player → Game loop: plays (evidence: `main.c`)
- Game loop → Board setup: initializes (evidence: `main.c`)
- Board setup → Mine placement: places mines (evidence: `main.c`)
- Board setup → Number placement: places numbers (evidence: `main.c`)
- Mine placement → Random coordinate: chooses locations (evidence: `main.c`)
- Number placement → Adjacent mine count: counts mines (evidence: `main.c`)
- Game loop → Key input: reads keys (evidence: `main.c`)
- Game loop → Area reveal: reveals area (evidence: `main.c`)
- Game loop → Board renderer: renders board (evidence: `main.c`)
- Board renderer → Terminal: prints board (evidence: `main.c`)
