# gghez/game-2048 architecture

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

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

## Overview

2exp11 is an Android 2048-style puzzle: the player swipes a 4×4 board, the game engine slides and merges tiles, then the app spawns a tile and updates score, timer, and saved progress. The Compose screen is driven by a ViewModel, which also handles undo, settings, feedback, and optional leaderboard submissions. DataStore backs settings and game/score persistence; Google Play Games is an optional leaderboard integration. The workflow is grounded in the README and sampled sources; unsampled subsystem links are limited to documented capabilities and paths present in the tree.

Main entry points: [`app/src/main/java/com/gghez/game2048/ui/game/GameViewModel.kt`](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameViewModel.kt) (Game ViewModel), [`app/src/main/java/com/gghez/game2048/ui/game/GameScreen.kt`](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameScreen.kt) (Game screen), [`app/src/main/java/com/gghez/game2048/Game2048App.kt`](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/Game2048App.kt) (App container), [`app/src/main/java/com/gghez/game2048/MainActivity.kt`](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/MainActivity.kt) (Main activity)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Android app"]
  node_activity["Main activity<br/>[MainActivity.kt]"]
  node_container["App container<br/>[Game2048App.kt]"]
end

subgraph group_ui["Game interface"]
  node_screen["Game screen<br/>[GameScreen.kt]"]
  node_viewmodel["Game ViewModel<br/>[GameViewModel.kt]"]
  node_grid["Animated grid<br/>[GameGrid.kt]"]
  node_tile["Tile display<br/>[TileView.kt]"]
  node_scorecard["Score display<br/>[ScoreCard.kt]"]
  node_newgame["New-game dialog<br/>[NewGameDialog.kt]"]
  node_settingsui["Settings sheet"]
end

subgraph group_game["Game domain"]
  node_engine["Game engine<br/>[GameEngine.kt]"]
  node_board["Board and tiles<br/>[Board.kt]"]
  node_state["Game state<br/>[GameState.kt]"]
  node_spawner["Random spawner"]
end

subgraph group_data["Persistence and scores"]
  node_settingsrepo["Settings repository"]
  node_scorerepo["Score and save repository<br/>[ScoreRepository.kt]"]
end

subgraph group_integrations["Device integrations"]
  node_leaderboard["Leaderboard provider"]
  node_feedback["Game feedback<br/>[GameFeedback.kt]"]
  node_synth["Tone synthesizer<br/>[Synth.kt]"]
end

node_player(("Player"))
node_datastore[("Preferences DataStore")]
node_playgames["Play Games"]
node_androiddevice["Android audio and haptics"]

node_player -->|"opens and plays"| node_activity
node_activity -->|"hosts"| node_screen
node_activity -->|"opens"| node_settingsui
node_activity -->|"attaches activity"| node_leaderboard
node_container -->|"provides dependencies"| node_viewmodel
node_screen -->|"dispatches actions"| node_viewmodel
node_viewmodel -->|"publishes UI state"| node_screen
node_screen -->|"renders board"| node_grid
node_grid -->|"renders tiles"| node_tile
node_screen -->|"shows scores"| node_scorecard
node_screen -->|"shows confirmation"| node_newgame
node_settingsui -->|"dispatches changes"| node_viewmodel
node_viewmodel -->|"applies moves and starts games"| node_engine
node_engine -->|"reads and updates"| node_board
node_engine -->|"updates"| node_state
node_engine -->|"chooses new tiles"| node_spawner
node_container -->|"constructs"| node_settingsrepo
node_container -->|"constructs"| node_scorerepo
node_container -->|"constructs"| node_leaderboard
node_container -->|"constructs"| node_feedback
node_viewmodel -->|"reads and updates settings"| node_settingsrepo
node_viewmodel -->|"reads and saves progress"| node_scorerepo
node_settingsrepo -->|"reads and writes"| node_datastore
node_scorerepo -->|"reads and writes"| node_datastore
node_viewmodel -.->|"submits scores"| node_leaderboard
node_leaderboard -.->|"signs in and submits"| node_playgames
node_viewmodel -->|"signals moves and merges"| node_feedback
node_feedback -->|"renders tones"| node_synth
node_feedback -->|"plays sound and vibrates"| node_androiddevice

click node_activity "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/MainActivity.kt"
click node_container "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/Game2048App.kt"
click node_screen "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameScreen.kt"
click node_viewmodel "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameViewModel.kt"
click node_grid "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/GameGrid.kt"
click node_tile "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/TileView.kt"
click node_scorecard "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/ScoreCard.kt"
click node_newgame "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/NewGameDialog.kt"
click node_settingsui "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/settings/SettingsBottomSheet.kt"
click node_engine "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/GameEngine.kt"
click node_board "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/Board.kt"
click node_state "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/GameState.kt"
click node_spawner "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/RandomTileSpawner.kt"
click node_settingsrepo "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/settings/SettingsRepository.kt"
click node_scorerepo "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/score/ScoreRepository.kt"
click node_leaderboard "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/leaderboard/LeaderboardProvider.kt"
click node_feedback "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/feedback/GameFeedback.kt"
click node_synth "https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/feedback/Synth.kt"

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_activity,node_container toneBlue
class node_screen,node_viewmodel,node_grid,node_tile,node_scorecard,node_newgame,node_settingsui,node_datastore toneAmber
class node_engine,node_board,node_state,node_spawner toneMint
class node_settingsrepo,node_scorerepo toneRose
class node_leaderboard,node_feedback,node_synth,node_player,node_playgames,node_androiddevice toneIndigo
```

## Components

### Android app

- [Main activity](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/MainActivity.kt): `app/src/main/java/com/gghez/game2048/MainActivity.kt`
- [App container](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/Game2048App.kt): `app/src/main/java/com/gghez/game2048/Game2048App.kt`

### Game interface

- [Game screen](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameScreen.kt): `app/src/main/java/com/gghez/game2048/ui/game/GameScreen.kt`
- [Game ViewModel](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/game/GameViewModel.kt): `app/src/main/java/com/gghez/game2048/ui/game/GameViewModel.kt`
- [Animated grid](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/GameGrid.kt): `app/src/main/java/com/gghez/game2048/ui/components/GameGrid.kt`
- [Tile display](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/TileView.kt): `app/src/main/java/com/gghez/game2048/ui/components/TileView.kt`
- [Score display](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/ScoreCard.kt): `app/src/main/java/com/gghez/game2048/ui/components/ScoreCard.kt`
- [New-game dialog](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/components/NewGameDialog.kt): `app/src/main/java/com/gghez/game2048/ui/components/NewGameDialog.kt`
- [Settings sheet](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/ui/settings/SettingsBottomSheet.kt): `app/src/main/java/com/gghez/game2048/ui/settings/SettingsBottomSheet.kt`

### Game domain

- [Game engine](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/GameEngine.kt): `app/src/main/java/com/gghez/game2048/domain/GameEngine.kt`
- [Board and tiles](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/Board.kt): `app/src/main/java/com/gghez/game2048/domain/Board.kt`
- [Game state](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/GameState.kt): `app/src/main/java/com/gghez/game2048/domain/GameState.kt`
- [Random spawner](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/domain/RandomTileSpawner.kt): `app/src/main/java/com/gghez/game2048/domain/RandomTileSpawner.kt`

### Persistence and scores

- [Settings repository](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/settings/SettingsRepository.kt): `app/src/main/java/com/gghez/game2048/data/settings/SettingsRepository.kt`
- [Score and save repository](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/score/ScoreRepository.kt): `app/src/main/java/com/gghez/game2048/data/score/ScoreRepository.kt`

### Device integrations

- [Leaderboard provider](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/data/leaderboard/LeaderboardProvider.kt): `app/src/main/java/com/gghez/game2048/data/leaderboard/LeaderboardProvider.kt`
- [Game feedback](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/feedback/GameFeedback.kt): `app/src/main/java/com/gghez/game2048/feedback/GameFeedback.kt`
- [Tone synthesizer](https://github.com/gghez/game-2048/blob/main/app/src/main/java/com/gghez/game2048/feedback/Synth.kt): `app/src/main/java/com/gghez/game2048/feedback/Synth.kt`

### Other components

- **Player**
- **Preferences DataStore**
- **Play Games**
- **Android audio and haptics**

## Connections

- Player → Main activity: opens and plays
- Main activity → Game screen: hosts
- Main activity → Settings sheet: opens
- Main activity → Leaderboard provider: attaches activity
- App container → Game ViewModel: provides dependencies
- Game screen → Game ViewModel: dispatches actions
- Game ViewModel → Game screen: publishes UI state
- Game screen → Animated grid: renders board
- Animated grid → Tile display: renders tiles
- Game screen → Score display: shows scores
- Game screen → New-game dialog: shows confirmation
- Settings sheet → Game ViewModel: dispatches changes
- Game ViewModel → Game engine: applies moves and starts games
- Game engine → Board and tiles: reads and updates
- Game engine → Game state: updates
- Game engine → Random spawner: chooses new tiles
- App container → Settings repository: constructs
- App container → Score and save repository: constructs
- App container → Leaderboard provider: constructs
- App container → Game feedback: constructs
- Game ViewModel → Settings repository: reads and updates settings
- Game ViewModel → Score and save repository: reads and saves progress
- Settings repository → Preferences DataStore: reads and writes
- Score and save repository → Preferences DataStore: reads and writes
- Game ViewModel → Leaderboard provider: submits scores
- Leaderboard provider → Play Games: signs in and submits
- Game ViewModel → Game feedback: signals moves and merges
- Game feedback → Tone synthesizer: renders tones
- Game feedback → Android audio and haptics: plays sound and vibrates
