How xxfast/nytimes-kmp works
Project Type and Purpose
• This is a Kotlin Multiplatform (KMP) application showcasing the New York Times on multiple targets (Android, WearOS, iOS, Desktop, Web‐JS, Web‐WASM).
• Its purpose is to share as much UI and business logic as possible via Compose Multiplatform, Ktor networking, Kotlinx Serialization, Decompose for navigation, Molecule for state, and KStore for persistence.
File Structure Analysis
• Top‐level “app” folder contains subprojects per platform:
• app/android, app/wear, app/desktop, app/ios, app/web
• Each has its own Gradle config and entry point (MainActivity.kt, Application.kt, etc.).
• Shared code under app/src:
• commonMain: shared domain, API client (NyTimesWebService), models, navigation ViewModel, UI components, DI, resources, utils
• platform‐specific sources (androidMain, desktopMain, iosMain, jsMain, wasmJsMain) override or adapt storage, WindowInsets, navigation bindings, AppDelegate, etc.
• Build orchestration: Gradle Kotlin DSL, settings.gradle.kts, libs.versions.toml, GitHub workflows.
README Insights
• Key libraries: Compose Multiplatform (UI), Ktor (HTTP), Kotlinx Serialization, Datetime, KStore (local storage), Decompose+Router (navigation), Molecule (state), compose-imageloader.
• Execution: each platform has a run configuration.
a. Main Components
• Shared Core Module
• UI layer (Compose Multiplatform)
• Navigation & State (Decompose + Molecule + ViewModels)
• Domain & Data layer
– Models (ApiModels, StorageModels)
– Repository/Storage (KStore)
– API client (Ktor HttpClient, NyTimesWebService)
• Platform Adapters
• androidMain, iosMain, desktopMain, jsMain, wasmJsMain: provide platform bindings (WindowInsets, AppDelegate, Application launcher, Storage implementation)
• Platform‐specific Applications
• Android app
• WearOS app
• iOS app
• Desktop app
• Web‐JS & Web‐WASM app
• External Service
• New York Times REST API
b. Relationships & Data Flow
1. UI (Compose) sends user interactions → ViewModel
2. ViewModel invokes domain/data layer → Repository
3. Repository
‐ checks local store (KStore)
‐ if stale or missing, uses Ktor client to fetch from NYT API
‐ stores fresh data in KStore
4. Repository returns models → ViewModel → UI updates
5. Navigation handled via Decompose Router between screens
c. Architectural Patterns
• MVVM / MVI hybrid with ViewModels driving state via Molecule
• Clean separation: UI / Presentation / Domain / Data
• Dependency Injection via a simple DI object (AppStorage) in commonMain
d. Key Technologies
• Kotlin Multiplatform & Gradle
• Compose Multiplatform
• Ktor + Kotlinx Serialization
• KStore for persistence
• Decompose + Router for navigation
• Molecule for reactive state
• Compose-imageloader for images