Skip to content
Agentmart
Submit a tool

kmp-data-layer

Kotlin data layer patterns: data classes in shared-core, repository pattern, StateFlow, CatalogService, and content wiring

Skill by giolaq

IndexedMIT-0★ 4
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/giolaq-kmp-data-layer

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Kotlin data layer patterns: data classes in shared-core, repository pattern, StateFlow, CatalogService, and content wiring

Use cases: data, writing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/kmp-data-layer

What's inside

Skill name
kmp-data-layer
Description
Kotlin data layer patterns: data classes in shared-core, repository pattern, StateFlow, CatalogService, and content wiring
License
MIT-0
Instructions
252 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# KMP Data Layer

> Content flows: JSON catalog -> CatalogService -> ContentRepository -> UI (Compose/SwiftUI). The shared-core module owns all data logic. Platform apps only consume repositories via ServiceLocator.

## Architecture overview

```
JSON / API
    |
CatalogService (implements CatalogSource interface)
    |
ContentRepository (caches + queries)
    |
ServiceLocator (provides singleton instances)
    |
UI Layer (MainActivity / SwiftUI views)
```

## Core data model: ContentItem

```kotlin
// shared-core/src/commonMain/kotlin/models/ContentItem.kt

data class ContentItem(
    val id: String,
    val title: String,
    val description: String? = null,
    val thumbnailUrl: String? = null,
    val contentType: ContentType,          // Video, Audio, Image, Mixed
    val metadata: ContentMetadata = ContentMetadata(),
    val isOfflineAvailable: Boolean = false,
    val lastAccessed: Long? = null,
    val focusable: Boolean = true,
    val collections: List<String> = emptyList(),
    val tags: List<String> = emptyList(),
    val priority: Int = 0,                 // Higher = more prominent in UI
    val videoUrl: String? = null,
)
```

### ContentMetadata

```kotlin
data class ContentMetadata(
    val genre: String? = null,
    val rating: String? = null,
    val releaseDate: String? = null,
    val duration: Long? = null,
    val director: String? = null,
    val cast: List<String> = emptyList(),
)
```

### ContentType enum

```kotlin
enum class ContentType { Video, Audio, Image, Mixed }
```

## Repository pattern

### Interface

```kotlin
// shared-core/src/commonMain/kotlin/repositories/ContentRepository.kt

interface ContentRepository {
    suspend fun getContentItems(limit: Int = 50, offset: Int = 0): Result<List<ContentItem>>
    suspend fun getContentItem(id: String): Result<ContentItem?>
    suspend fun searchContent(query: String): Result<List<ContentItem>>
    suspend fun markContentAccessed(contentId: String): Result<Unit>
}
```

### Implementation

`ContentRepositoryImpl` wraps a `CatalogSource` and adds:
- **Lazy loading:** catalog is fetched once, then cached in-memory
- **Thread safety:** `Mutex` protects the content map
- **Sorting:** items returned sorted by `priority` descending
- **Search:** filters by title, description, and tags (case-insensitive)

### Result type

```kotlin
sealed class Result<out T> {
    data class Success<T>(val data: T) : Result<T>()
    data class Error(val exception: Exception? = null, val message: String? = null) : Result<Nothing>()
}
```

UI code uses `onSuccess`/`onFailure` extension methods for clean handling.

## CatalogService — loading content

```kotlin
interface CatalogSource {
    suspend fun fetchCatalog(): Result<List<ContentItem>>
}
```

The default `CatalogService` implementation loads content from a JSON endpoint or bundled file. To wire custom content:

### Option 1: Replace the JSON source

Implement `CatalogSource` to read from your content.json:

```kotlin
class CustomCatalogSource(private val jsonString: String) : CatalogSource {
    override suspend fun fetchCatalog(): Result<List<ContentItem>> {
        return try {
            val items = Json.decodeFromString<List<ContentItem>>(jsonString)
            Result.Success(items)
        } catch (e: Exception) {
            Result.Error(e, "Failed to parse catalog")
        }
    }
}
```

From giolaq/tv-build-harness, MIT-0.

More from giolaq/tv-build-harness

Signals

Stars
4
Forks
0
Open issues
3
Last commit (this folder)
Jun 24, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT-0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from giolaq

Cite this page

kmp-data-layer skill. Agent Mart. https://agentmart.dev/skills/giolaq-kmp-data-layer (last updated 2026-10-24)