← ClaudeAtlas

android-data-layerlisted

Data layer patterns for Android/KMP - data sources, repositories, DTOs, mappers, Room entities, Ktor HttpClient, safe call helpers, token storage, and offline-first. Use this skill whenever writing or reviewing a data source or repository, creating DTOs or Room entities, writing mappers, setting up the Ktor HttpClient, handling network errors, or implementing token refresh. Trigger on phrases like "create a repository", "create a data source", "add a DAO", "Ktor client", "write a mapper", "DTO", "Room entity", "network call", "token storage", or "offline-first".
lenorebreakneck630/claude-zero-to-hero-android-KMP · ★ 1 · Data & Documents · score 64
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android / KMP Data Layer ## Error Handling This skill uses `Result<T, E>`, `DataError`, and the extension helpers defined in the **android-error-handling** skill. Refer to that skill for the full `Result` wrapper, `DataError` sealed interface, and `map`/`onSuccess`/`onFailure`/`asEmptyResult` extensions. --- ## Data Source vs Repository - **Data source** — accesses a single data source (local DB, remote API, file system). Most classes in the data layer are data sources. - **Repository** — combines multiple data sources (e.g., a remote API + a local DB for offline-first). Only use the term "repository" when the class genuinely coordinates multiple sources. ```kotlin // Single source → data source interface NoteLocalDataSource { suspend fun getNotes(): Result<List<Note>, DataError.Local> suspend fun insertNote(note: Note): EmptyResult<DataError.Local> } interface NoteRemoteDataSource { suspend fun fetchNotes(): Result<List<Note>, DataError.Network> } // Multiple sources → repository interface NoteRepository { suspend fun getNotes(): Result<List<Note>, DataError> suspend fun sync(): EmptyResult<DataError> } ``` ## Domain Layer Contracts - Pure Kotlin — no Android/framework imports. - Contains: domain models, data source/repository **interfaces**, error types. - **Every data source or repository used by a ViewModel must have an interface in `domain`** — enforces that `presentation` never depends on `data`, and enables testing. --- ## DTOs and