# jeremy-oz/godot-tetris architecture

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

- Interactive diagram: https://gitdiagram.com/jeremy-oz/godot-tetris
- Repository: https://github.com/jeremy-oz/godot-tetris

## Overview

#### Purpose and startup
This is a Godot 4.7 Tetris clone supporting solo play and multiplayer versus play. Godot launches `scenes/main.tscn` via `project.godot`; the main gameplay implementation is centered on `board.gd` and `scenes/board.tscn`.

#### Scene-level composition
The application is assembled as Godot scenes rather than a web/server stack:
- Main/menu routing: `scenes/main.tscn`
- Solo wrapper: `scenes/solo.tscn`, `solo.gd`
- Multiplayer lobby: `scenes/lobby.tscn`, `lobby.gd`
- Versus match wrapper: `scenes/versus.tscn`, `versus.gd`
- Reusable board: `scenes/board.tscn`, `board.gd`

These wrappers select game mode and compose one or more board instances.

#### Core board simulation
`board.gd` owns the Tetris state machine: falling tetromino movement, rotation/wall kicks, collision and locking, row clearing, scoring/levels, hold behavior, ghost/hard drop, and game-over conditions. Its visual and collision boundary is the board scene:
- `board.gd`
- `scenes/board.tscn`
- `assets/tetrominoes.png.import`

The Godot 4.7 board uses separate `TileMapLayer` nodes for landed/wall cells and active-piece rendering, sharing a tileset.

#### Solo flow
`solo.gd` hosts a board for local play and mediates solo-specific UI actions such as starting a new game. Input enters through Godot’s frame/input callbacks, is translated into board actions, then board state updates the TileMap layers and HUD.
- `solo.gd`
- `scenes/solo.tscn`
- `scenes/board.tscn`

#### Multiplayer lifecycle
The lobby is the network session boundary: it handles hosting/joining and the peer handshake before transitioning into versus gameplay. The versus scene then coordinates the local and remote boards, including synchronization/mirroring of player state.
- `lobby.gd`
- `scenes/lobby.tscn`
- `versus.gd`
- `scenes/versus.tscn`

#### Versus gameplay and outcomes
Versus mode operates two board views and propagates competitive events across the multiplayer boundary. Line clears can produce garbage for the opponent; player loss or winning status ends the match. Board mechanics remain local to `board.gd`, while match coordination belongs in `versus.gd`.
- `versus.gd`
- `board.gd`
- `scenes/versus.tscn`

#### Runtime, networking, and verification
The material runtime is the Godot 4.7 engine and GDScript; export targets are declared in `export_presets.cfg`. Multiplayer uses Godot’s built-in networking APIs rather than a separately represented backend service. Headless scripts provide automation entry points for board and network behavior:
- `project.godot`
- `test_headless.gd`
- `test_net_host.gd`
- `test_net_client.gd`

Main entry points: [`board.gd`](https://github.com/jeremy-oz/godot-tetris/blob/main/board.gd) (Board Simulation), [`scenes/board.tscn`](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/board.tscn) (Board Scene), [`versus.gd`](https://github.com/jeremy-oz/godot-tetris/blob/main/versus.gd) (Versus Controller), [`scenes/main.tscn`](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/main.tscn) (Main Menu Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Godot Runtime"]
  node_project["Project Startup<br/>Godot project<br/>[project.godot]"]
  node_engine{{"Godot 4.7 Engine<br/>runtime"}}
  node_headless_checks["Headless Checks<br/>GDScript automation<br/>[test_headless.gd]"]
  node_export_presets["Export Presets<br/>Godot config<br/>[export_presets.cfg]"]
end

subgraph group_scenes["Scene Composition"]
  node_main_scene["Main Menu Router<br/>Godot scene<br/>[main.tscn]"]
  node_solo_scene["Solo Scene<br/>Godot scene<br/>[solo.tscn]"]
  node_versus_scene["Versus Scene<br/>Godot scene<br/>[versus.tscn]"]
end

subgraph group_gameplay["Gameplay"]
  node_solo_controller["Solo Controller<br/>GDScript<br/>[solo.gd]"]
  node_board_scene["Board Scene<br/>Godot scene<br/>[board.tscn]"]
  node_board_simulation["Board Simulation<br/>GDScript<br/>[board.gd]"]
  node_tileset["Tetromino Tileset<br/>imported asset"]
end

subgraph group_multiplayer["Multiplayer"]
  node_lobby_scene["Lobby Scene<br/>Godot scene<br/>[lobby.tscn]"]
  node_lobby_controller["Lobby Controller<br/>GDScript<br/>[lobby.gd]"]
  node_versus_controller["Versus Controller<br/>GDScript<br/>[versus.gd]"]
  node_godot_networking{{"Godot Networking APIs<br/>engine API"}}
end

node_project -->|"runs on"| node_engine
node_project -->|"launches"| node_main_scene
node_main_scene -->|"routes to solo"| node_solo_scene
node_main_scene -->|"routes to multiplayer"| node_lobby_scene
node_lobby_scene -->|"enters after handshake"| node_versus_scene
node_solo_scene -->|"attaches"| node_solo_controller
node_solo_scene -->|"hosts one board"| node_board_scene
node_solo_controller -->|"sends board actions"| node_board_simulation
node_board_scene -->|"binds script"| node_board_simulation
node_board_scene -->|"renders with"| node_tileset
node_versus_scene -->|"attaches"| node_versus_controller
node_versus_scene -->|"composes two board views"| node_board_scene
node_versus_controller -->|"coordinates board state"| node_board_simulation
node_lobby_scene -->|"attaches"| node_lobby_controller
node_lobby_controller -->|"host/join handshake"| node_godot_networking
node_versus_controller -->|"syncs players and events"| node_godot_networking
node_board_simulation -->|"clears and loss outcomes"| node_versus_controller
node_headless_checks -.->|"exercises mechanics"| node_board_simulation
node_export_presets -.->|"declares export targets"| node_engine

click node_project "https://github.com/jeremy-oz/godot-tetris/blob/main/project.godot"
click node_main_scene "https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/main.tscn"
click node_solo_scene "https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/solo.tscn"
click node_versus_scene "https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/versus.tscn"
click node_lobby_scene "https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/lobby.tscn"
click node_solo_controller "https://github.com/jeremy-oz/godot-tetris/blob/main/solo.gd"
click node_board_scene "https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/board.tscn"
click node_board_simulation "https://github.com/jeremy-oz/godot-tetris/blob/main/board.gd"
click node_tileset "https://github.com/jeremy-oz/godot-tetris/blob/main/assets/tetrominoes.png.import"
click node_lobby_controller "https://github.com/jeremy-oz/godot-tetris/blob/main/lobby.gd"
click node_versus_controller "https://github.com/jeremy-oz/godot-tetris/blob/main/versus.gd"
click node_headless_checks "https://github.com/jeremy-oz/godot-tetris/blob/main/test_headless.gd"
click node_export_presets "https://github.com/jeremy-oz/godot-tetris/blob/main/export_presets.cfg"

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_project,node_engine,node_headless_checks,node_export_presets toneBlue
class node_main_scene,node_solo_scene,node_versus_scene toneAmber
class node_solo_controller,node_board_scene,node_board_simulation,node_tileset toneMint
class node_lobby_scene,node_lobby_controller,node_versus_controller,node_godot_networking toneRose
```

## Components

### Godot Runtime

- [Project Startup](https://github.com/jeremy-oz/godot-tetris/blob/main/project.godot): Godot project · Launches the main scene. · `project.godot`
- **Godot 4.7 Engine**: runtime
- [Headless Checks](https://github.com/jeremy-oz/godot-tetris/blob/main/test_headless.gd): GDScript automation · Board and host/client automation entry points. · `test_headless.gd`
- [Export Presets](https://github.com/jeremy-oz/godot-tetris/blob/main/export_presets.cfg): Godot config · `export_presets.cfg`

### Scene Composition

- [Main Menu Router](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/main.tscn): Godot scene · `scenes/main.tscn`
- [Solo Scene](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/solo.tscn): Godot scene · `scenes/solo.tscn`
- [Versus Scene](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/versus.tscn): Godot scene · `scenes/versus.tscn`

### Gameplay

- [Solo Controller](https://github.com/jeremy-oz/godot-tetris/blob/main/solo.gd): GDScript · Maps local input and new-game UI to a board. · `solo.gd`
- [Board Scene](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/board.tscn): Godot scene · Defines TileMapLayer rendering for active and landed cells. · `scenes/board.tscn`
- [Board Simulation](https://github.com/jeremy-oz/godot-tetris/blob/main/board.gd): GDScript · Owns local Tetris mechanics and game state. · `board.gd`
- [Tetromino Tileset](https://github.com/jeremy-oz/godot-tetris/blob/main/assets/tetrominoes.png.import): imported asset · `assets/tetrominoes.png.import`

### Multiplayer

- [Lobby Scene](https://github.com/jeremy-oz/godot-tetris/blob/main/scenes/lobby.tscn): Godot scene · `scenes/lobby.tscn`
- [Lobby Controller](https://github.com/jeremy-oz/godot-tetris/blob/main/lobby.gd): GDScript · Hosts or joins peers and completes the session handshake. · `lobby.gd`
- [Versus Controller](https://github.com/jeremy-oz/godot-tetris/blob/main/versus.gd): GDScript · Coordinates local and remote boards, garbage, and match outcomes. · `versus.gd`
- **Godot Networking APIs**: engine API · Built-in peer transport and RPC boundary.

## Connections

- Project Startup → Godot 4.7 Engine: runs on
- Project Startup → Main Menu Router: launches
- Main Menu Router → Solo Scene: routes to solo
- Main Menu Router → Lobby Scene: routes to multiplayer
- Lobby Scene → Versus Scene: enters after handshake
- Solo Scene → Solo Controller: attaches
- Solo Scene → Board Scene: hosts one board
- Solo Controller → Board Simulation: sends board actions
- Board Scene → Board Simulation: binds script
- Board Scene → Tetromino Tileset: renders with
- Versus Scene → Versus Controller: attaches
- Versus Scene → Board Scene: composes two board views
- Versus Controller → Board Simulation: coordinates board state
- Lobby Scene → Lobby Controller: attaches
- Lobby Controller → Godot Networking APIs: host/join handshake
- Versus Controller → Godot Networking APIs: syncs players and events
- Board Simulation → Versus Controller: clears and loss outcomes
- Headless Checks → Board Simulation: exercises mechanics
- Export Presets → Godot 4.7 Engine: declares export targets
