Data layer

From hanamizuki/solopreneur · View interactive version

Data layer is an AI agent skill from the GitHub repository hanamizuki/solopreneur. Guidance on implementing the Data Layer using Repository pattern, Room (Local), and Retrofit (Remote) with offline-first synchronization.

How to use this skill

Skill file

Android Data Layer & Offline-First

Instructions

The Data Layer coordinates data from multiple sources.

1. Repository Pattern

```kotlin

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)

3. Remote Data (Retrofit)

4. Synchronization

5. Dependency Injection

```kotlin

@Binds

abstract fun bindNewsRepository(impl: OfflineFirstNewsRepository): NewsRepository

```

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.