How kongquan98/mobiletypist works
Purpose and module layout
Keyboard Typist is an offline Kotlin Multiplatform typing-practice app for Android and iOS. The primary product module is composeApp; shared appears to be a separate minimal KMP template module, not part of the app’s core feature architecture. Gradle project setup is rooted at settings.gradle.kts and build.gradle.kts.
Platform entry points
Android launches the shared Compose UI from composeApp/src/androidMain/kotlin/org/example/project/MainActivity.kt. iOS exposes the Compose controller through composeApp/src/iosMain/kotlin/org/example/project/MainViewController.kt, while the native Xcode host starts in iosApp/iosApp/iOSApp.swift. Shared application composition begins at composeApp/src/commonMain/kotlin/org/example/project/App.kt.
Shared UI shell and navigation
App.kt applies the app theme and establishes the screen-level UI. A custom, screen-based navigation stack is defined by:
• composeApp/src/commonMain/kotlin/org/example/project/navigation/NavigationManager.kt
• composeApp/src/commonMain/kotlin/org/example/project/navigation/Navigation.kt
• composeApp/src/commonMain/kotlin/org/example/project/navigation/model/Screen.kt
composeApp/src/commonMain/kotlin/org/example/project/ui/MainScaffold.kt provides the common scaffold/bottom-level layout. Platform-specific back handling is an expect/actual boundary in navigation/BackHandler.kt, with Android and iOS implementations.
Typing-test execution flow
The principal interactive flow is the typing screen and its state holder:
• composeApp/src/commonMain/kotlin/org/example/project/screens/TypingScreen.kt
• composeApp/src/commonMain/kotlin/org/example/project/viewModel/TypingViewModel.kt
• composeApp/src/commonMain/kotlin/org/example/project/ui/TypingComponents.kt
The view model manages typing-session state for timed, word-count, and quote modes: input comparison, character/word progress, accuracy, WPM, completion, and result presentation. ResultBottomSheet.kt forms the result boundary back into persisted statistics. Source text comes from repositories, especially WordsRepository.kt and QuotesRepository.kt; English word data is bundled at composeApp/src/commonMain/composeResources/files/typing_words_en.json.
Local persistence and domain data
All user data is designed to remain on device. Shared models cover profiles, settings, results, achievements, and daily activity:
• composeApp/src/commonMain/kotlin/org/example/project/data/model/TypingTestResult.kt
• composeApp/src/commonMain/kotlin/org/example/project/data/model/AppSettings.kt
• composeApp/src/commonMain/kotlin/org/example/project/data/model/DailyActivityDurations.kt
StorageManager.kt is the shared persistence façade, backed by the platform abstraction in PlatformStorage.kt. Actual implementations use Android-specific storage and iOS UserDefaults:
• composeApp/src/androidMain/kotlin/org/example/project/data/storage/PlatformStorage.android.kt
• composeApp/src/iosMain/kotlin/org/example/project/data/storage/PlatformStorage.ios.kt
Home, statistics, and profile surfaces
HomeViewModel.kt aggregates persisted results/settings into the home experience. Screens for home, statistics, achievements, profile/account, avatar, and settings consume that state and repositories. Activity visualization is separated into ActivityHeatmapRepository.kt and ui/ActivityHeatmap.kt, creating a clear flow from saved test history to calendar-style display.
Platform effects and runtime boundaries
The shared Compose runtime targets Android API 24+ and iOS. Expect/actual implementations isolate platform services: storage, date formatting, audio, haptic feedback, device/platform metadata, and back navigation. Relevant boundaries include utils/AudioPlayer.kt, utils/TypingHapticFeedback.kt, and their Android/iOS counterparts. Android sound assets live under composeApp/src/androidMain/res/raw. The declared stack includes Compose Multiplatform, Material 3, MultiplatformSettings, Kotlinx Serialization, and Ktor; README describes Ktor as reserved for future features rather than a current service integration.
Main entry points: TypingViewModel.kt Typing session state · StorageManager.kt Storage manager · App.kt App composition · NavigationManager.kt Navigation stack
Components 20
Platform hosts
- Android activity
composeApp/src/androidMain/kotlin/org/example/project/MainActivity.kt - iOS SwiftUI host
iosApp/iosApp/iOSApp.swift - Compose view controller
composeApp/src/iosMain/kotlin/org/example/project/MainViewController.kt - Back handler · Android and iOS implementations isolate back behavior.
composeApp/src/commonMain/kotlin/org/example/project/navigation/BackHandler.kt - Platform storage · Uses Android storage or iOS UserDefaults.
composeApp/src/commonMain/kotlin/org/example/project/data/storage/PlatformStorage.kt - Audio and haptics · Platform feedback for typing interactions.
composeApp/src/commonMain/kotlin/org/example/project/utils/AudioPlayer.kt
Shared UI and navigation
- App composition
composeApp/src/commonMain/kotlin/org/example/project/App.kt - Navigation stack · Manages screen transitions and screen model.
composeApp/src/commonMain/kotlin/org/example/project/navigation/NavigationManager.kt - Main scaffold
composeApp/src/commonMain/kotlin/org/example/project/ui/MainScaffold.kt - Home state · Aggregates saved results and settings for home surfaces.
composeApp/src/commonMain/kotlin/org/example/project/viewModel/HomeViewModel.kt - Activity heatmap
composeApp/src/commonMain/kotlin/org/example/project/ui/ActivityHeatmap.kt
Typing workflow
- Typing screen
composeApp/src/commonMain/kotlin/org/example/project/screens/TypingScreen.kt - Typing session state · Calculates progress, accuracy, WPM, completion, and results.
composeApp/src/commonMain/kotlin/org/example/project/viewModel/TypingViewModel.kt - Typing components
composeApp/src/commonMain/kotlin/org/example/project/ui/TypingComponents.kt - Result bottom sheet · Commits completed sessions to statistics.
composeApp/src/commonMain/kotlin/org/example/project/ui/ResultBottomSheet.kt
Offline data and services
- Words and quotes · Supplies prompts for typing modes.
composeApp/src/commonMain/kotlin/org/example/project/data/repo/WordsRepository.kt - English word corpus
composeApp/src/commonMain/composeResources/files/typing_words_en.json - Storage manager · Shared access to on-device user data.
composeApp/src/commonMain/kotlin/org/example/project/data/storage/StorageManager.kt - Activity history · Derives calendar activity from saved test history.
composeApp/src/commonMain/kotlin/org/example/project/data/repo/ActivityHeatmapRepository.kt
Other components
- Gradle project
settings.gradle.kts
Connections 21
- Gradle project → Android activity: builds
- Gradle project → iOS SwiftUI host: builds
- Android activity → App composition: launches
- iOS SwiftUI host → Compose view controller: starts
- Compose view controller → App composition: hosts
- App composition → Navigation stack: establishes
- App composition → Main scaffold: renders
- Navigation stack → Typing screen: routes to
- Navigation stack → Back handler: handles back
- Typing screen → Typing session state: observes and sends input
- Typing screen → Typing components: composes
- Typing session state → Words and quotes: loads prompts
- Words and quotes → English word corpus: reads
- Typing session state → Audio and haptics: triggers feedback
- Typing session state → Result bottom sheet: presents completion
- Result bottom sheet → Storage manager: saves result
- Storage manager → Platform storage: persists through
- Storage manager → Home state: provides results and settings
- Storage manager → Activity history: provides history
- Home state → Activity heatmap: supplies activity state
- Activity history → Activity heatmap: derives activity data