repository-pattern

Implements offline-first Repository pattern coordinating RemoteDataSource and LocalDataSource in Kotlin Multiplatform.

Updated Sep 12, 2026
One-click install
npx skills add https://github.com/Vierco/citoVisionApp --skill repository-pattern-vierco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: repository-pattern
Source: https://github.com/Vierco/citoVisionApp/tree/main/.claude/skills/repository-pattern
Command: npx skills add https://github.com/Vierco/citoVisionApp --skill repository-pattern-vierco

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Deciding how to structure a Repository that combines a remote API and a local Room KMP cache without breaking the single source of truth is a recurring source of architectural inconsistency in Kotlin Multiplatform projects. This Skill provides concrete rules, decision criteria, and code examples for building offline-first repositories. ## Core Features & Use Cases - Offline-first coordination: Defines how the Repository reads exclusively from the LocalDataSource (Room KMP) while the RemoteDataSource (Ktor) only synchronizes the local cache. - Flow vs suspend decisions: Provides automatic decision rules for when an operation should return Flow<Result<T, DomainError>> versus a suspend function. - Layer boundaries and mapping: Enforces that DTOs and Room entities never leak outside Infrastructure, with mappers translating to Domain entities. - Use Case: When creating a new Repository for a Domain entity, follow the checklist to define the Port in Domain, implement DataSources in Infrastructure, and ensure writes persist locally before reporting success. ## Quick Start Ask the AI to create an offline-first Repository for a Domain entity following the repository-pattern skill, with Flow-based observation from Room and suspend functions for sync operations.

Frequently Asked Questions about repository-pattern

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

FAQPage Schema
How do I implement an offline-first repository in Kotlin Multiplatform?▼

Define a Repository interface in Domain, then implement it in Infrastructure by injecting a RemoteDataSource and a LocalDataSource. Reads always observe the local Room cache as a Flow, while writes call the remote API first and persist results locally before returning success.

When should a repository method return Flow versus suspend?▼

Use Flow<Result<T, DomainError>> for observable data like lists or reactive detail screens, always sourced from the LocalDataSource. Use suspend functions returning Result for one-shot actions such as create, update, delete, or manual refresh.

Should the repository interface live in Domain or Infrastructure?▼

The Repository interface (Port) must live in Domain, while its implementation lives in Infrastructure. The DataSources are internal Infrastructure interfaces, never exposed as Domain ports or injected directly into Application code.

What happens when the network fails but local cache exists?▼

The observed Flow continues emitting the existing local data without interruption. The network failure is reported only in the Result of the refresh operation, so the UI never loses its cached data due to connectivity issues.

Can DTOs or Room entities be returned from a repository?▼

No. DTOs from Ktor and Room entities must never cross the Infrastructure boundary. The Repository maps them to Domain entities via dedicated mappers, and technical exceptions are translated to DomainError instead of being rethrown.