mcpbeat

Android Data Layer

new-silvermoon/android-data-layer

Guidance on implementing the Data Layer using Repository pattern, Room (Local), and Retrofit (Remote) with offline-first synchronization.

466 tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
910
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-data-layer

The instruction itself

7 sections, as written by the author

Android Data Layer & Offline-First

Instructions

The Data Layer coordinates data from multiple sources.

1. Repository Pattern

  • Role: Single Source of Truth (SSOT).
  • Logic: The repository decides whether to return cached data or fetch fresh data.
  • Implementation:
    class NewsRepository @Inject constructor(
        private val newsDao: NewsDao,
        private val newsApi: NewsApi
    ) {
        // Expose data from Local DB as the source of truth
        val newsStream: Flow<List<News>> = newsDao.getAllNews()

        // Sync operation
        suspend fun refreshNews() {
            val remoteNews = newsApi.fetchLatest()
            newsDao.insertAll(remoteNews)
        }
    }

2. Local Persistence (Room)

  • Usage: Primary cache and offline storage.
  • Entities: Define @Entity data classes.
  • DAOs: Return Flow<T> for observable data.

3. Remote Data (Retrofit)

  • Usage: Fetching data from backend.
  • Response: Use suspend functions in interfaces.
  • Error Handling: Wrap network calls in try-catch blocks or a Result wrapper to handle exceptions (NoInternet, 404, etc.) gracefully.

4. Synchronization

  • Read: "Stale-While-Revalidate". Show local data immediately, trigger a background refresh.
  • Write: "Outbox Pattern" (Advanced). Save local change immediately, mark as "unsynced", use WorkManager to push changes to server.

5. Dependency Injection

  • Bind Repository interfaces to implementations in a Hilt Module.
    @Binds
    abstract fun bindNewsRepository(impl: OfflineFirstNewsRepository): NewsRepository

How to use it

Copy the folder

Take new-silvermoon/android-data-layer from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.