# sfostine/2048 architecture

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

- Interactive diagram: https://gitdiagram.com/sfostine/2048
- Repository: https://github.com/sfostine/2048

## Overview

This is a Java Swing 2048 game. The player starts from the home screen, chooses board dimensions, and plays by moving tiles with arrow keys; merges increase the score, and a blocked board triggers the game-over screen. The game supports boards up to 11 columns by 7 rows and uses distinct tile colors. The graph follows the sampled calls and README; unsampled implementation details are not inferred.

Main entry points: [`src/controller/GameController.java`](https://github.com/sfostine/2048/blob/master/src/controller/GameController.java) (Input and Turn Controller), [`src/game_2048/Board.java`](https://github.com/sfostine/2048/blob/master/src/game_2048/Board.java) (Board and Tile Rendering), [`src/gui_2048/Home.java`](https://github.com/sfostine/2048/blob/master/src/gui_2048/Home.java) (Home and Board Setup), [`src/game_2048/Game_2048.java`](https://github.com/sfostine/2048/blob/master/src/game_2048/Game_2048.java) (2048 Move and Merge Rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Startup and Setup"]
  node_main["Application Entry<br/>[Main.java]"]
  node_home["Home and Board Setup<br/>[Home.java]"]
  node_frame["Game Window<br/>[GameFrame.java]"]
end

subgraph group_control["Game Interaction"]
  node_controller["Input and Turn Controller"]
end

subgraph group_logic["Game State and Rules"]
  node_rules["2048 Move and Merge Rules<br/>[Game_2048.java]"]
  node_game["Game Dimensions and State<br/>[Game.java]"]
  node_board["Board and Tile Rendering<br/>[Board.java]"]
  node_cell["Tile Cell<br/>[Cell.java]"]
end

subgraph group_view["Game Display"]
  node_boardpanel["Board Panel<br/>[BoardPanel.java]"]
  node_scorepanel["Score Panel<br/>[ScorePanel.java]"]
  node_gameover["Game Over Screen<br/>[GameOverGUI.java]"]
end

node_player(("Player"))

node_player -->|"starts"| node_main
node_main -->|"opens"| node_home
node_player -->|"chooses dimensions"| node_home
node_home -->|"starts game"| node_frame
node_frame -->|"creates"| node_controller
node_controller -->|"creates and moves"| node_rules
node_player -->|"presses arrow keys"| node_controller
node_controller -->|"updates board"| node_board
node_controller -->|"redraws"| node_boardpanel
node_controller -->|"redraws"| node_scorepanel
node_controller -->|"opens on loss"| node_gameover
node_rules -->|"inherits state"| node_game
node_game -->|"gets board"| node_board
node_board -->|"creates tiles"| node_cell
node_boardpanel -->|"paints board"| node_board
node_scorepanel -->|"reads score"| node_rules
node_gameover -->|"reads dimensions"| node_game

click node_main "https://github.com/sfostine/2048/blob/master/src/main/Main.java"
click node_home "https://github.com/sfostine/2048/blob/master/src/gui_2048/Home.java"
click node_frame "https://github.com/sfostine/2048/blob/master/src/gui_2048/GameFrame.java"
click node_controller "https://github.com/sfostine/2048/blob/master/src/controller/GameController.java"
click node_rules "https://github.com/sfostine/2048/blob/master/src/game_2048/Game_2048.java"
click node_game "https://github.com/sfostine/2048/blob/master/src/game_2048/Game.java"
click node_board "https://github.com/sfostine/2048/blob/master/src/game_2048/Board.java"
click node_cell "https://github.com/sfostine/2048/blob/master/src/game_2048/Cell.java"
click node_boardpanel "https://github.com/sfostine/2048/blob/master/src/gui_2048/BoardPanel.java"
click node_scorepanel "https://github.com/sfostine/2048/blob/master/src/gui_2048/ScorePanel.java"
click node_gameover "https://github.com/sfostine/2048/blob/master/src/gui_2048/GameOverGUI.java"

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_home,node_frame toneBlue
class node_controller toneAmber
class node_rules,node_game,node_board,node_cell toneMint
class node_boardpanel,node_scorepanel,node_gameover toneRose
class node_player toneIndigo
```

## Components

### Startup and Setup

- [Application Entry](https://github.com/sfostine/2048/blob/master/src/main/Main.java): `src/main/Main.java`
- [Home and Board Setup](https://github.com/sfostine/2048/blob/master/src/gui_2048/Home.java): `src/gui_2048/Home.java`
- [Game Window](https://github.com/sfostine/2048/blob/master/src/gui_2048/GameFrame.java): `src/gui_2048/GameFrame.java`

### Game Interaction

- [Input and Turn Controller](https://github.com/sfostine/2048/blob/master/src/controller/GameController.java): `src/controller/GameController.java`

### Game State and Rules

- [2048 Move and Merge Rules](https://github.com/sfostine/2048/blob/master/src/game_2048/Game_2048.java): `src/game_2048/Game_2048.java`
- [Game Dimensions and State](https://github.com/sfostine/2048/blob/master/src/game_2048/Game.java): `src/game_2048/Game.java`
- [Board and Tile Rendering](https://github.com/sfostine/2048/blob/master/src/game_2048/Board.java): `src/game_2048/Board.java`
- [Tile Cell](https://github.com/sfostine/2048/blob/master/src/game_2048/Cell.java): `src/game_2048/Cell.java`

### Game Display

- [Board Panel](https://github.com/sfostine/2048/blob/master/src/gui_2048/BoardPanel.java): `src/gui_2048/BoardPanel.java`
- [Score Panel](https://github.com/sfostine/2048/blob/master/src/gui_2048/ScorePanel.java): `src/gui_2048/ScorePanel.java`
- [Game Over Screen](https://github.com/sfostine/2048/blob/master/src/gui_2048/GameOverGUI.java): `src/gui_2048/GameOverGUI.java`

### Other components

- **Player**

## Connections

- Player → Application Entry: starts (evidence: `src/main/Main.java`)
- Application Entry → Home and Board Setup: opens (evidence: `src/main/Main.java`)
- Player → Home and Board Setup: chooses dimensions (evidence: `src/gui_2048/Home.java`)
- Home and Board Setup → Game Window: starts game (evidence: `src/gui_2048/Home.java`)
- Game Window → Input and Turn Controller: creates (evidence: `src/gui_2048/GameFrame.java`)
- Input and Turn Controller → 2048 Move and Merge Rules: creates and moves (evidence: `src/controller/GameController.java`)
- Player → Input and Turn Controller: presses arrow keys (evidence: `src/controller/GameController.java`)
- Input and Turn Controller → Board and Tile Rendering: updates board (evidence: `src/controller/GameController.java`)
- Input and Turn Controller → Board Panel: redraws (evidence: `src/controller/GameController.java`)
- Input and Turn Controller → Score Panel: redraws (evidence: `src/controller/GameController.java`)
- Input and Turn Controller → Game Over Screen: opens on loss (evidence: `src/controller/GameController.java`)
- 2048 Move and Merge Rules → Game Dimensions and State: inherits state (evidence: `src/game_2048/Game_2048.java`)
- Game Dimensions and State → Board and Tile Rendering: gets board (evidence: `src/game_2048/Game.java`)
- Board and Tile Rendering → Tile Cell: creates tiles (evidence: `src/game_2048/Board.java`)
- Board Panel → Board and Tile Rendering: paints board (evidence: `src/gui_2048/BoardPanel.java`)
- Score Panel → 2048 Move and Merge Rules: reads score (evidence: `src/gui_2048/ScorePanel.java`)
- Game Over Screen → Game Dimensions and State: reads dimensions (evidence: `src/gui_2048/GameOverGUI.java`)
