android-data-layer

Coordinate Room and Retrofit data sources into a repository-based single source of truth.

8|1|Updated Jun 12, 2018
One-click install
npx skills add https://github.com/SheTieJun/BaseKit --skill android-data-layer-shetiejun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-data-layer
Source: https://github.com/SheTieJun/BaseKit/tree/main/.trae/skills/android-data-layer
Command: npx skills add https://github.com/SheTieJun/BaseKit --skill android-data-layer-shetiejun

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Android developers implement a clean Data Layer using the Repository pattern, Room for local persistence, and Retrofit for remote access, enabling offline-first synchronization and a reliable single source of truth.

Core Features & Use Cases

  • Single Source of Truth via a Repository that decides whether to serve cached data or fetch fresh results.
  • Local Persistence (Room) for offline storage with observable data through Flow-enabled DAOs.
  • Remote Data (Retrofit) for backend communication using suspend functions and robust error handling.
  • Synchronization with stale-while-revalidate strategy and optional outbox approach for resilient writes.
  • DI with Koin to wire dependencies across ViewModels and data sources.

Quick Start

Create a NewsRepository with NewsDao and NewsApi, then call refreshNews() to sync data. Observe newsStream for updated data in your UI via collect or Flow collection.

Frequently Asked Questions about android-data-layer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement an offline-first repository pattern in Android using Room and Retrofit?

An offline-first repository coordinates Room persistence and Retrofit calls, using Flow-enabled DAOs to serve local data as a single source of truth while suspend functions fetch remote updates.

What is the stale-while-revalidate strategy for Android data synchronization?

Stale-while-revalidate synchronization serves cached Room data immediately via Flow, then triggers Retrofit suspend calls in the background to fetch fresh remote data and update the local database.

How do I wire an offline-first data layer with Koin dependency injection?

Koin wires your offline-first data layer by injecting Room DAOs, Retrofit APIs, and the Repository into ViewModels, establishing a single source of truth across your Android app architecture.

Does this offline-first repository approach handle network errors during data synchronization?

The repository pattern handles network errors through robust Retrofit suspend call error handling and an optional outbox approach, ensuring resilient local writes and synchronization when connectivity returns.

Can I use Flow-based DAOs to observe Room database changes in an offline-first app?

Flow-based DAOs enable offline-first apps to observe Room database changes reactively, allowing the UI to collect updates automatically when the repository syncs fresh data from the remote source.