Data Layer Overview
Repository Pattern
Repository Characteristics
Single Source of Truth
Repositories expose a single Flow that combines local and remote data
Offline First
Data is cached locally and displayed immediately while refreshing from network
Reactive
All data exposed as Kotlin Flows for reactive updates
Scoped
Repositories are
@ApplicationScope singletonsExample Repository Implementation
Room Database
Kafka uses Room for local data persistence with a well-structured database schema.Database Configuration
Entity Definitions
DAO Implementations
DAOs extendEntityDao for common CRUD operations.
Remote Data Sources
Ktor Client for Archive.org API
Firestore for Remote Config
DataStore for Preferences
Kafka uses DataStore for type-safe preference storage.Data Mapping
Mappers transform data between layers (network → database → domain).Data Flow Example
Complete data flow from UI to database:Best Practices
Single Source of Truth
Always read from database, never directly from network
Offline First
Cache data locally and display immediately
Flow-Based
Use Flow for reactive data streams
Coroutine Context
Use
withContext(dispatchers.io) for database operationsMappers
Transform data at repository layer
Error Handling
Handle errors in repositories, expose via Flow