How kongquan98/snakegame works
Project type and purpose
• This is an Android mobile application implementing the classic Snake game in Kotlin using Jetpack Compose.
• It follows MVVM with DI (Hilt), a local persistence layer (Room + DataStore), and a clean separation between presentation, view-model, and service layers.
File structure
• Top-level “app” module with Gradle/Kotlin DSL build scripts
• src/main/java/com/example/snakegame/
– presentation/
· ui/ (Compose screen components, NavigationController)
· viewmodel/ (HighScoreViewModel, SettingsViewModel)
· datamodel/ (enums and settings data classes)
– service/
· repo/ (HighScoreRepository, SettingsRepository)
· roomDB/ (Room entities, DAO, Database)
· datastore/ (SettingsDataStore)
· hilt/ (DatabaseModule for DI)
• res/ (drawables, fonts, raw audio, XML rules, values)
Key insights from README
• Five primary screens: Main Menu, Game Screen, Settings, High Score, Special Modes
• Uses MVVM + Jetpack Compose + Material3
• Persists settings in DataStore, high-scores in Room DB
• Hilt injects repositories and DB into ViewModels
a. Main components
1) Android Framework Layer
• Activities (MainMenuActivity, MyApplication)
• NavigationController
2) Presentation Layer (UI)
• Compose Screens (MainMenuScreen, SnakeGameScreen, HighScoreScreen, SettingsScreen, SpecialModeScreen, etc.)
3) ViewModel Layer
• HighScoreViewModel
• SettingsViewModel
4) Service Layer
• HighScoreRepository
• SettingsRepository
5) Persistence Layer
• Room Database (HighScoreDatabase with HighScoreDao)
• DataStore (SettingsDataStore)
6) Dependency Injection
• Hilt modules (DatabaseModule)
7) Resources
• drawables, raw audio, fonts, XML configurations
b. Relationships & data flow
• User taps UI (Compose screen) → UI calls methods on its ViewModel
• ViewModel → invokes Repository interfaces
• Repository → queries/persists via Room DAO or DataStore
• DataStore/Room → returns data → Repository → ViewModel → UI
• Hilt manages injection of Repositories, Database, DataStore into ViewModels
c. Architectural patterns & principles
• MVVM: clear separation between UI (Compose) and business logic (ViewModel)
• Clean layering: Presentation → Domain-like Repositories → Data sources
• DI with Hilt: decoupled component instantiation
• Single-Activity with Compose and NavigationController
d. Key technologies & frameworks
• Kotlin, Jetpack Compose, Material3
• Android ViewModel, LiveData/StateFlow
• Room (SQLite abstraction)
• DataStore (key-value settings)
• Hilt for DI
• Gradle Kotlin DSL