# usernob/sfml-tetris architecture

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

- Interactive diagram: https://gitdiagram.com/usernob/sfml-tetris
- Repository: https://github.com/usernob/sfml-tetris

## Overview

SFML-Tetris is a C++ desktop Tetris clone. The main workflow is window events into Game input, timed game-state updates, and drawing the board, score, and next-piece preview; piece generation, collision/line handling, and audio support that loop. The README identifies the clone and SFML, while the excerpts show these runtime responsibilities. Grid internals are only partially sampled, so the diagram omits uncertain calls and does not infer additional UI or gameplay systems.

Main entry points: [`src/game.cpp`](https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp) (Game controller), [`src/grid.cpp`](https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp) (Board movement and lines), [`src/pieces.cpp`](https://github.com/usernob/sfml-tetris/blob/master/src/pieces.cpp) (Piece shapes and rotation), [`src/main.cpp`](https://github.com/usernob/sfml-tetris/blob/master/src/main.cpp) (Application loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_app_loop["Application loop<br/>[main.cpp]"]
  node_game["Game controller<br/>[game.cpp]"]
  node_audio_assets["Audio and font assets"]
end

subgraph group_gameplay["Gameplay"]
  node_game_rules["Timed play and score<br/>[game.cpp]"]
  node_input_handling["Keyboard controls<br/>[game.cpp]"]
  node_board_rules["Board movement and lines<br/>[grid.cpp]"]
end

subgraph group_rendering["Board rendering"]
  node_board_cells["Board grid state<br/>[grid.cpp]"]
  node_board_draw["Grid drawing<br/>[grid.cpp]"]
  node_preview["Next-piece preview<br/>[grid.cpp]"]
end

subgraph group_support["Piece support"]
  node_pieces["Piece shapes and rotation<br/>[pieces.cpp]"]
  node_random_utils["Random selection<br/>[utils.cpp]"]
  node_constants["Game constants and types<br/>[constant.h]"]
  node_assets_store["Bundled media files"]
end

node_player(("Player"))
node_sfml_window["SFML window"]

node_player -->|"uses"| node_sfml_window
node_sfml_window -->|"delivers events"| node_app_loop
node_app_loop -->|"initializes and calls"| node_game
node_app_loop -->|"clears and displays"| node_sfml_window
node_game -->|"handles keys"| node_input_handling
node_game -->|"updates and draws"| node_game_rules
node_game -->|"loads media"| node_audio_assets
node_input_handling -->|"moves and rotates"| node_board_rules
node_game_rules -->|"checks rows and locks"| node_board_rules
node_game_rules -->|"selects next piece"| node_pieces
node_game_rules -->|"updates preview"| node_preview
node_game_rules -->|"plays effects"| node_audio_assets
node_board_rules -->|"changes cell state"| node_board_cells
node_board_draw -->|"draws vertices"| node_board_cells
node_preview -->|"updates cells"| node_board_cells
node_pieces -->|"chooses shape and color"| node_random_utils
node_board_rules -->|"rotates piece"| node_pieces
node_pieces -->|"uses piece types"| node_constants
node_board_rules -->|"uses board dimensions"| node_constants
node_game -->|"draws board"| node_board_draw
node_game -->|"draws preview"| node_preview
node_assets_store -.->|"provides files"| node_audio_assets

click node_app_loop "https://github.com/usernob/sfml-tetris/blob/master/src/main.cpp"
click node_game "https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp"
click node_audio_assets "https://github.com/usernob/sfml-tetris/tree/master/assets"
click node_game_rules "https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp"
click node_input_handling "https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp"
click node_pieces "https://github.com/usernob/sfml-tetris/blob/master/src/pieces.cpp"
click node_random_utils "https://github.com/usernob/sfml-tetris/blob/master/src/utils.cpp"
click node_board_rules "https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp"
click node_board_cells "https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp"
click node_board_draw "https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp"
click node_preview "https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp"
click node_constants "https://github.com/usernob/sfml-tetris/blob/master/src/constant.h"
click node_assets_store "https://github.com/usernob/sfml-tetris/tree/master/assets"

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_loop,node_game,node_audio_assets toneBlue
class node_game_rules,node_input_handling,node_board_rules toneAmber
class node_board_cells,node_board_draw,node_preview toneMint
class node_pieces,node_random_utils,node_constants,node_assets_store toneRose
class node_player,node_sfml_window toneIndigo
```

## Components

### Game runtime

- [Application loop](https://github.com/usernob/sfml-tetris/blob/master/src/main.cpp): `src/main.cpp`
- [Game controller](https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp): `src/game.cpp`
- [Audio and font assets](https://github.com/usernob/sfml-tetris/tree/master/assets): `assets`

### Gameplay

- [Timed play and score](https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp): `src/game.cpp`
- [Keyboard controls](https://github.com/usernob/sfml-tetris/blob/master/src/game.cpp): `src/game.cpp`
- [Board movement and lines](https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp): `src/grid.cpp`

### Board rendering

- [Board grid state](https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp): `src/grid.cpp`
- [Grid drawing](https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp): `src/grid.cpp`
- [Next-piece preview](https://github.com/usernob/sfml-tetris/blob/master/src/grid.cpp): `src/grid.cpp`

### Piece support

- [Piece shapes and rotation](https://github.com/usernob/sfml-tetris/blob/master/src/pieces.cpp): `src/pieces.cpp`
- [Random selection](https://github.com/usernob/sfml-tetris/blob/master/src/utils.cpp): `src/utils.cpp`
- [Game constants and types](https://github.com/usernob/sfml-tetris/blob/master/src/constant.h): `src/constant.h`
- [Bundled media files](https://github.com/usernob/sfml-tetris/tree/master/assets): `assets`

### Other components

- **Player**
- **SFML window**

## Connections

- Player → SFML window: uses
- SFML window → Application loop: delivers events (evidence: `src/main.cpp`)
- Application loop → Game controller: initializes and calls (evidence: `src/main.cpp`)
- Application loop → SFML window: clears and displays (evidence: `src/main.cpp`)
- Game controller → Keyboard controls: handles keys (evidence: `src/game.cpp`)
- Game controller → Timed play and score: updates and draws (evidence: `src/game.cpp`)
- Game controller → Audio and font assets: loads media (evidence: `src/game.cpp`)
- Keyboard controls → Board movement and lines: moves and rotates (evidence: `src/game.cpp`)
- Timed play and score → Board movement and lines: checks rows and locks (evidence: `src/game.cpp`)
- Timed play and score → Piece shapes and rotation: selects next piece (evidence: `src/game.cpp`)
- Timed play and score → Next-piece preview: updates preview (evidence: `src/game.cpp`)
- Timed play and score → Audio and font assets: plays effects (evidence: `src/game.cpp`)
- Board movement and lines → Board grid state: changes cell state (evidence: `src/grid.cpp`)
- Grid drawing → Board grid state: draws vertices (evidence: `src/grid.cpp`)
- Next-piece preview → Board grid state: updates cells (evidence: `src/grid.cpp`)
- Piece shapes and rotation → Random selection: chooses shape and color (evidence: `src/pieces.cpp`)
- Board movement and lines → Piece shapes and rotation: rotates piece (evidence: `src/grid.cpp`)
- Piece shapes and rotation → Game constants and types: uses piece types (evidence: `src/pieces.cpp`)
- Board movement and lines → Game constants and types: uses board dimensions (evidence: `src/grid.cpp`)
- Game controller → Grid drawing: draws board (evidence: `src/game.cpp`)
- Game controller → Next-piece preview: draws preview (evidence: `src/game.cpp`)
- Bundled media files → Audio and font assets: provides files
