Agent skill

Android Data Layer and Room in KMP

by rcosteira79 in rcosteira79/android-skills

Sets out the repository pattern's error-propagation model for Android and Kotlin Multiplatform, plus the Room setup for commonMain.

MITAuto-check passedMobile

Install Android Data Layer and Room in KMP

skills CLI
$ npx skills add rcosteira79/android-skills --skill android-data-layer -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rcosteira79/android-skills android-data-layer --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rcosteira79/android-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/android-skills/skills/android-data-layer .claude/skills/android-data-layer && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
android-data-layer
GitHub stars
151
Token cost
~1.2k tokens
SKILL.md length
342 words
Files
1
Skills in repo
21
Repo updated
First seen
Licence
MIT

At a glance

Sets out the repository pattern's error-propagation model for Android and Kotlin Multiplatform, plus the Room setup for commonMain.

  • Works in 4 steps: Data sources throw platform/library… → Repository is the error boundary — catch… → Use cases (when present) are the Result… → …
  • Designing how repository errors reach the ViewModel in an Android app
  • SKILL.md covers Error propagation — the… and Room in KMP (commonMain)
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

The data layer's public API is a set of repository interfaces, and its internals never leak upward. The core of this skill is a layered error model: data sources throw platform exceptions such as IOException, HttpException or SQLiteException, the repository is the error boundary and remaps them to a sealed DataError hierarchy, and the ViewModel never sees raw platform types. Without a domain layer the repository returns Result directly; with one, the repository throws DataError and the use case turns it into a Result with a domain error model.

It also covers Room in commonMain, which has been KMP-stable since 2.7.0. The shared setup differs from Android-only Room in three places: @ConstructedBy on the database paired with an expect object, BundledSQLiteDriver from androidx.sqlite to pin one SQLite version across targets, and per-target KSP configuration. Room types default to an Entity suffix unless the project already has a convention. Related skills handle Retrofit wiring and overall app architecture.

When your agent uses it

  • Designing how repository errors reach the ViewModel in an Android app
  • Deciding where Result is created with or without a domain layer
  • Setting up Room in commonMain for Kotlin Multiplatform
  • Replacing leaked IOException or HttpException handling with a DataError type

Example prompts

  • “Refactor our ArticleRepository so network and database exceptions become a sealed DataError.”
  • “We added use cases. Where should Result be created and who catches DataError?”
  • “Set up Room in commonMain with BundledSQLiteDriver for Android and iOS.”

Requirements

  • An Android or Kotlin Multiplatform project

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. Data sources throw platform/library exceptions (IOException, HttpException, SQLiteException).
  2. Repository is the error boundary — catch those and remap to DataError; never let raw platform types leak. Without a domain layer (simple…
  3. Use cases (when present) are the Result boundary — the repository instead throws DataError, and the use case catches it and returns Result…
  4. ViewModels handle Result and map it to UI state (explicit loading / success / error).

What it can do on your machine

Read from SKILL.md and the folder at commit 0f9af5a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are kotlin).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Android Data Layer and Room in KMP loads about 1.2k tokens when it runs. Until then it costs about 78 tokens; SKILL.md has 342 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~78
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rcosteira79/android-skills at commit 0f9af5a, republished under its MIT licence (© rcosteira79). 342 words, ~1,187 tokens.

Download SKILL.mdSave it as .claude/skills/android-data-layer/SKILL.md (or your agent's skills folder).
name
android-data-layer
description
Use when implementing the data layer in Android or KMP — the Repository pattern's layered error-propagation model (repository as the error boundary, sealed DataError, Result placement with and without a domain layer) and Room in commonMain (@ConstructedBy, BundledSQLiteDriver, per-target KSP).

Android Data Layer

The data layer coordinates data from multiple sources; its public API is repository interfaces, and its internals (DAOs, API services, DTOs) never leak upward. This skill is the canonical home for the error-propagation model, plus the KMP-Room setup. Related: android-skills:android-retrofit (Retrofit service/OkHttp/Hilt wiring), android-skills:android-dev (overall app architecture).

Error propagation — the layered model

The goal: data-layer errors (IOException / HttpException / SQLiteException) must never reach the ViewModel. Map them to a domain error type at the repository boundary. If the project already has an error convention, match it; otherwise a sealed DataError hierarchy is a reasonable default:

kotlin
sealed class DataError(message: String, cause: Throwable? = null) : Exception(message, cause) {
    class Network(cause: Throwable) : DataError("Network error", cause)
    class Server(val code: Int, message: String?) : DataError("Server error $code: $message")
    class Local(cause: Throwable) : DataError("Local storage error", cause)
}

// repository = error boundary: catch platform exceptions, return Result<T> (no domain layer) or throw DataError (with one)
suspend fun refreshNews(): Result<Unit> = withContext(io) {
    try { newsDao.insertAll(newsApi.fetchLatest().map(NewsDto::toEntity)); Result.success(Unit) }
    catch (e: IOException) { Result.failure(DataError.Network(e)) }
    catch (e: HttpException) { Result.failure(DataError.Server(e.code(), e.message())) }
}

The boundary moves outward by one layer when a domain layer exists:

  1. Data sources throw platform/library exceptions (IOException, HttpException, SQLiteException).
  2. Repository is the error boundary — catch those and remap to DataError; never let raw platform types leak. Without a domain layer (simple MVVM): the repository returns Result<T> directly and the ViewModel handles it without knowing about platform exceptions.
  3. Use cases (when present) are the Result boundary — the repository instead throws DataError, and the use case catches it and returns Result<T> with a domain-specific error model. Use cases never catch platform exception types.
  4. ViewModels handle Result<T> and map it to UI state (explicit loading / success / error).

(Default to the Entity suffix — ArticleEntity — for Room types; match an existing convention such as a Cached prefix if the project already uses one.)

Room in KMP (commonMain)

Room has been KMP-stable since 2.7.0. The shared setup differs from the Android-only setup in three places:

  1. @ConstructedBy(...) on the @Database, paired with an expect object Room generates per-platform actuals for.
  2. BundledSQLiteDriver (from androidx.sqlite:sqlite-bundled) — pins the same SQLite version across Android/iOS/JVM/web (Android's system SQLite drifts between API levels and devices).
  3. setQueryCoroutineContext(Dispatchers.IO) — Android Room defaults this; KMP doesn't.
kotlin
// commonMain
@Database(entities = [ArticleEntity::class], version = 1, exportSchema = true)
@ConstructedBy(AppDatabaseConstructor::class)
abstract class AppDatabase : RoomDatabase() { abstract fun articleDao(): ArticleDao }

@Suppress("KotlinNoActualForExpect")
expect object AppDatabaseConstructor : RoomDatabaseConstructor<AppDatabase>

fun getRoomDatabase(builder: RoomDatabase.Builder<AppDatabase>): AppDatabase =
    builder.setDriver(BundledSQLiteDriver()).setQueryCoroutineContext(Dispatchers.IO).build()

Each platform provides its own builder — Android Room.databaseBuilder(context, AppDatabase::class.java, "app.db"); iOS/JVM Room.databaseBuilder<AppDatabase>(databasePath = …). KSP must be wired per target (ksp(libs.androidx.room.compiler) is Android-only):

kotlin
dependencies {
    add("kspAndroid", libs.androidx.room.compiler)
    add("kspIosArm64", libs.androidx.room.compiler)
    add("kspIosSimulatorArm64", libs.androidx.room.compiler)
    // … one per target
}
room { schemaDirectory("$projectDir/schemas") }   // export the schema for migration-history tracking

For pure-Android projects, skip @ConstructedBy and call Room.databaseBuilder(context, AppDatabase::class.java, "app.db") directly — Room behaves identically; the KMP setup is opt-in when the data layer must live in commonMain.

© rcosteira79, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in plugins/android-skills/skills/android-data-layer of rcosteira79/android-skills.

Open the folder on GitHubat commit 0f9af5a

Compare with similar skills

Android Data Layer and Room in KMP next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Android Data Layer and Room in KMP compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Android Data Layer and Room in KMP this skillrcosteira79/android-skills151—~1.2kAutomated safety check: PassMIT
Android Clean Architectureaffaan-m/ECC275k2 repos~1.8kAutomated safety check: PassMIT
Android Clean Architectureaffaan-m/ECC275k4 repos~2.2kAutomated safety check: PassMIT
Quality Test Pilotnekomangaorg/Neko2.8k—~1.1kAutomated safety check: PassApache-2.0
Architecture Overclocknekomangaorg/Neko2.8k—~1.4kAutomated safety check: PassApache-2.0
Architecture Renovatornekomangaorg/Neko2.8k—~1.2kAutomated safety check: PassApache-2.0

Similar skills

  • 适用于Android和Kotlin多平台项目的Clean Architecture模式——模块结构、依赖规则、用例、仓库以及数据层模式。

    275k GitHub starsUsed in 2 repos~1.8k tokens
    MobileAuto-check passed
  • Applies Clean Architecture to Android and Kotlin Multiplatform projects: module layout, dependency rules, UseCases, Repositories and data layer patterns.

    275k GitHub starsUsed in 4 repos~2.2k tokens
    DevelopmentAuto-check passed
  • Quality Test Pilot

    nekomangaorg/Neko

    Writes high-quality unit tests for Kotlin Android codebases to increase meaningful test coverage.

    2.8k GitHub stars~1.1k tokensUpdated today
    Testing & QAAuto-check passed
  • Architecture Overclock

    nekomangaorg/Neko

    Resolves deep, structural performance bottlenecks in the Kotlin Android codebase.

    2.8k GitHub stars~1.4k tokensUpdated today
    MobileAuto-check passed
  • Architecture Renovator

    nekomangaorg/Neko

    Resolves deep architectural debt in the Kotlin Android codebase through macro-level refactoring.

    2.8k GitHub stars~1.2k tokensUpdated today
    MobileAuto-check passed
  • Composewebview Documentation

    parkwoocheol/compose-webview

    Manages MkDocs documentation site and API references for ComposeWebView.

    103 GitHub stars~1.5k tokensUpdated 1 mo ago
    MobileAuto-check passed

More from rcosteira79/android-skills

All 21 skills in this repo
  • Guides writing correct, performant Compose and Compose Multiplatform UI across Android, desktop, iOS and web, from state and animation to design-to-code and crash fixes.

    151 GitHub stars~2.6k tokensUpdated 19 days ago
    Auto-check passed
  • Kotlin Multiplatform Boundaries

    rcosteira79/android-skills

    Helps choose how common Kotlin Multiplatform code reaches platform APIs: expect/actual, a common interface with platform bindings, or separate platform screens.

    151 GitHub stars~1.5k tokensUpdated 19 days ago
    Auto-check passed
  • Android Debugging

    rcosteira79/android-skills

    Android and KMP debugging techniques for crashes, ANRs, memory leaks, R8 traces, Gradle failures and Compose recomposition, built on finding the root cause first.

    151 GitHub stars~2.6k tokensUpdated 19 days ago
    Auto-check passed
  • Android and KMP Baseline

    rcosteira79/android-skills

    Sets house defaults for Android and Kotlin Multiplatform work and routes to the right specialized skill for Compose, networking, testing or build tooling.

    151 GitHub stars~3k tokensUpdated 19 days ago
    Auto-check passed
  • Android Gradle Build Logic

    rcosteira79/android-skills

    Sets up Android Gradle convention plugins in a build-logic composite build, including the version catalog wiring and shared configuration that are easy to get wrong.

    151 GitHub stars~959 tokensUpdated 19 days ago
    Auto-check passed
  • Android Retrofit

    rcosteira79/android-skills

    A skill your agent uses when setting up or working with Retrofit in Android — service interface definitions, coroutines integration, OkHttp configuration, Hilt module setup, and error handling in…

    151 GitHub stars~942 tokensUpdated 19 days ago
    Auto-check passed

Questions about Android Data Layer and Room in KMP

What does Android Data Layer and Room in KMP do?

Sets out the repository pattern's error-propagation model for Android and Kotlin Multiplatform, plus the Room setup for commonMain. The data layer's public API is a set of repository interfaces, and its internals never leak upward. The core of this skill is a layered error model: data sources throw platform exceptions such as IOException, HttpException or SQLiteException, the repository is the error boundary and remaps them to a sealed DataError hierarchy, and the ViewModel never sees raw platform types.

When should I use Android Data Layer and Room in KMP?

Android Data Layer and Room in KMP fits situations like: designing how repository errors reach the ViewModel in an Android app; deciding where Result is created with or without a domain layer; setting up Room in commonMain for Kotlin Multiplatform; replacing leaked IOException or HttpException handling with a DataError type.

How do I install Android Data Layer and Room in KMP in Claude Code?

Run `npx skills add rcosteira79/android-skills --skill android-data-layer -a claude-code`. Or copy the skill folder (plugins/android-skills/skills/android-data-layer in rcosteira79/android-skills) into .claude/skills/android-data-layer in your project. Claude Code loads it when a task matches its description.

How do I install Android Data Layer and Room in KMP in Codex?

Run `npx skills add rcosteira79/android-skills --skill android-data-layer -a codex`. Or copy the skill folder (plugins/android-skills/skills/android-data-layer in rcosteira79/android-skills) into .agents/skills/android-data-layer in your project. Codex loads it when a task matches its description.

Can I use Android Data Layer and Room in KMP in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rcosteira79/android-skills --skill android-data-layer -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/android-data-layer, .gemini/skills/android-data-layer, .github/skills/android-data-layer and .opencode/skills/android-data-layer in your project.

What does Android Data Layer and Room in KMP need to run?

SKILL.md names no scripts, command-line tools or credentials: Android Data Layer and Room in KMP is instructions for the agent only. Our summary lists: An Android or Kotlin Multiplatform project.

Does Android Data Layer and Room in KMP access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Android Data Layer and Room in KMP safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Android Data Layer and Room in KMP use?

Android Data Layer and Room in KMP is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Android Data Layer and Room in KMP use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Android Data Layer and Room in KMP?

Skills that share tags, products or a category with Android Data Layer and Room in KMP: Android Clean Architecture (affaan-m/ECC, 275k stars), Android Clean Architecture (affaan-m/ECC, 275k stars), Quality Test Pilot (nekomangaorg/Neko, 2.8k stars) and Architecture Overclock (nekomangaorg/Neko, 2.8k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Android Data Layer and Room in KMP?

rcosteira79 (a GitHub user) maintains it in rcosteira79/android-skills, which has 151 GitHub stars. The repository holds 21 skills in this directory. The repository was last updated on September 19, 2026.

Source: rcosteira79/android-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.