# mharcerz/tetris architecture

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

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

## Overview

Tetris is an SFML desktop game. The principal workflow starts in `main`, which creates the window and game objects, then delegates to screen routines for start, username entry, gameplay, and game-over/replay. Gameplay state tracks the active and next pieces, board placement, scoring, and row clearing; visualization renders the game and input supplies controls. The README is only a title, so detailed capabilities and several internal calls are inferred from interfaces and the source index; unverified links are dashed.

Main entry points: [`src/gameLogic/GameState.cpp`](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/GameState.cpp) (Game state), [`src/main.cpp`](https://github.com/mharcerz/tetris/blob/main/src/main.cpp) (Game entry), [`src/gameLogic/Run.cpp`](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Run.cpp) (Screen flow), [`src/gameLogic/BlockOnBoard.cpp`](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockOnBoard.cpp) (Active piece movement)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application flow"]
  node_main["Game entry<br/>[main.cpp]"]
  node_screens["Screen flow<br/>[Run.cpp]"]
end

subgraph group_interface["SFML interface"]
  node_input["User input<br/>[UserInput.cpp]"]
  node_visual["Game rendering<br/>[Visualization.cpp]"]
end

subgraph group_game["Game rules"]
  node_state["Game state<br/>[GameState.cpp]"]
  node_board["Board scoring<br/>[GameBoard.cpp]"]
  node_blockboard["Active piece movement<br/>[BlockOnBoard.cpp]"]
  node_constants["Game dimensions<br/>[GameConstants.h]"]
  node_matrix["Board occupancy matrix<br/>[BoolMatrix.tpp]"]
end

subgraph group_pieces["Piece construction"]
  node_pattern["Piece patterns<br/>[BlockPattern.cpp]"]
  node_colored["Colored pieces<br/>[BlockWithColor.cpp]"]
  node_blockfactory["Pattern factory<br/>[BlockFactory.cpp]"]
  node_colorfactory["Color factory<br/>[ColorFactory.cpp]"]
  node_coloredfactory["Piece factory"]
end

node_player(("Player"))

node_main -->|"calls screens"| node_screens
node_main -->|"creates input"| node_input
node_main -->|"creates renderer"| node_visual
node_main -->|"creates state"| node_state
node_player -.->|"provides controls"| node_input
node_screens -.->|"uses controls"| node_input
node_screens -.->|"requests rendering"| node_visual
node_screens -.->|"advances game"| node_state
node_state -.->|"updates board"| node_board
node_state -.->|"moves pieces"| node_blockboard
node_state -.->|"creates pieces"| node_coloredfactory
node_visual -.->|"reads game state"| node_state
node_coloredfactory -.->|"requests pattern"| node_blockfactory
node_coloredfactory -.->|"requests color"| node_colorfactory
node_blockfactory -.->|"produces pattern"| node_pattern
node_colored -.->|"extends pattern"| node_pattern
node_blockboard -.->|"extends piece"| node_colored
node_board -.->|"tracks occupancy"| node_matrix
node_board -.->|"places piece"| node_blockboard
node_blockboard -.->|"uses dimensions"| node_constants

click node_main "https://github.com/mharcerz/tetris/blob/main/src/main.cpp"
click node_screens "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Run.cpp"
click node_input "https://github.com/mharcerz/tetris/blob/main/src/sfml/UserInput.cpp"
click node_visual "https://github.com/mharcerz/tetris/blob/main/src/sfml/Visualization.cpp"
click node_state "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/GameState.cpp"
click node_board "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/GameBoard.cpp"
click node_blockboard "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockOnBoard.cpp"
click node_constants "https://github.com/mharcerz/tetris/blob/main/src/GameConstants.h"
click node_matrix "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BoolMatrix.tpp"
click node_pattern "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockPattern.cpp"
click node_colored "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockWithColor.cpp"
click node_blockfactory "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/BlockFactory.cpp"
click node_colorfactory "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/ColorFactory.cpp"
click node_coloredfactory "https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/ColoredBlockFactory.cpp"

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_main,node_screens toneBlue
class node_input,node_visual toneAmber
class node_state,node_board,node_blockboard,node_constants,node_matrix toneMint
class node_pattern,node_colored,node_blockfactory,node_colorfactory,node_coloredfactory toneRose
class node_player toneIndigo
```

## Components

### Application flow

- [Game entry](https://github.com/mharcerz/tetris/blob/main/src/main.cpp): `src/main.cpp`
- [Screen flow](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Run.cpp): `src/gameLogic/Run.cpp`

### SFML interface

- [User input](https://github.com/mharcerz/tetris/blob/main/src/sfml/UserInput.cpp): `src/sfml/UserInput.cpp`
- [Game rendering](https://github.com/mharcerz/tetris/blob/main/src/sfml/Visualization.cpp): `src/sfml/Visualization.cpp`

### Game rules

- [Game state](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/GameState.cpp): `src/gameLogic/GameState.cpp`
- [Board scoring](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/GameBoard.cpp): `src/gameLogic/GameBoard.cpp`
- [Active piece movement](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockOnBoard.cpp): `src/gameLogic/BlockOnBoard.cpp`
- [Game dimensions](https://github.com/mharcerz/tetris/blob/main/src/GameConstants.h): `src/GameConstants.h`
- [Board occupancy matrix](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BoolMatrix.tpp): `src/gameLogic/BoolMatrix.tpp`

### Piece construction

- [Piece patterns](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockPattern.cpp): `src/gameLogic/BlockPattern.cpp`
- [Colored pieces](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/BlockWithColor.cpp): `src/gameLogic/BlockWithColor.cpp`
- [Pattern factory](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/BlockFactory.cpp): `src/gameLogic/Factory/BlockFactory.cpp`
- [Color factory](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/ColorFactory.cpp): `src/gameLogic/Factory/ColorFactory.cpp`
- [Piece factory](https://github.com/mharcerz/tetris/blob/main/src/gameLogic/Factory/ColoredBlockFactory.cpp): `src/gameLogic/Factory/ColoredBlockFactory.cpp`

### Other components

- **Player**

## Connections

- Game entry → Screen flow: calls screens (evidence: `src/main.cpp`)
- Game entry → User input: creates input (evidence: `src/main.cpp`)
- Game entry → Game rendering: creates renderer (evidence: `src/main.cpp`)
- Game entry → Game state: creates state (evidence: `src/main.cpp`)
- Player → User input: provides controls
- Screen flow → User input: uses controls
- Screen flow → Game rendering: requests rendering
- Screen flow → Game state: advances game
- Game state → Board scoring: updates board
- Game state → Active piece movement: moves pieces
- Game state → Piece factory: creates pieces
- Game rendering → Game state: reads game state
- Piece factory → Pattern factory: requests pattern
- Piece factory → Color factory: requests color
- Pattern factory → Piece patterns: produces pattern
- Colored pieces → Piece patterns: extends pattern
- Active piece movement → Colored pieces: extends piece
- Board scoring → Board occupancy matrix: tracks occupancy
- Board scoring → Active piece movement: places piece
- Active piece movement → Game dimensions: uses dimensions
