mcpField
A
android-data-layer

android-data-layer

github.com/new-silvermoonDevelopment992511 installsUpdated 13w ago
Repository

About android-data-layer

An Android data-layer skill describing repository-based, offline-first app architecture. It guides developers in combining local Room storage with Retrofit data and coordinating synchronization through background work.

Key features

  1. 01Repository as single source of truth
  2. 02Room persistence with observable flows
  3. 03Retrofit network fetching
  4. 04Stale-while-revalidate reads
  5. 05Outbox synchronization with WorkManager
  6. 06Hilt repository bindings

Use cases

  1. 01Designing offline-first data layers
  2. 02Serving cached data during refresh
  3. 03Queuing local changes for sync

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-data-layer

After installing, type/android-data-layerin Claude Code to confirm it loaded.

Details

From the project README

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
    

Comments

Markdown supported