Skip to content

Data Layer Agent

Ali Sadeghi edited this page Jan 6, 2026 · 3 revisions

Data Layer Agent

Implements the data layer for KMP features.

Invoked by: creating-kmp-feature skill (Phase 3)

Generates

  • Domain models with @Serializable
  • Ktor Resources (type-safe API routes)
  • RemoteDataSource (interface + implementation)
  • Repository (interface + implementation)
  • Either error handling

Example Input

Feature: Product Catalog
Models: Product (id, name, price, imageUrl)
Endpoints: GET /products, GET /products/{id}

Example Output

// feature/productcatalog/data/model/Product.kt
@Serializable
data class Product(
    val id: String,
    val name: String,
    val price: Double,
    val imageUrl: String?
)

// feature/productcatalog/data/remote/ProductResource.kt
@Resource("/products")
class ProductResource {
    @Resource("{id}")
    data class Id(val parent: ProductResource, val id: String)
}

// feature/productcatalog/data/remote/ProductRemoteDataSource.kt
interface ProductRemoteDataSource {
    suspend fun getProducts(): Either<List<Product>>
    suspend fun getProduct(id: String): Either<Product>
}

class ProductRemoteDataSourceImpl(
    private val client: ApiClient
) : ProductRemoteDataSource {
    override suspend fun getProducts(): Either<List<Product>> =
        client.get(ProductResource())

    override suspend fun getProduct(id: String): Either<Product> =
        client.get(ProductResource.Id(ProductResource(), id))
}

// feature/productcatalog/data/repository/ProductRepository.kt
interface ProductRepository {
    suspend fun getProducts(): Either<List<Product>>
    suspend fun getProduct(id: String): Either<Product>
}

class ProductRepositoryImpl(
    private val dataSource: ProductRemoteDataSource
) : ProductRepository {
    override suspend fun getProducts(): Either<List<Product>> =
        dataSource.getProducts()

    override suspend fun getProduct(id: String): Either<Product> =
        dataSource.getProduct(id)
}

Validates

  • Build passes: ./gradlew :feature:productcatalog:assembleAndroidMain
  • Ktlint formatting applied

Back to Agents

Clone this wiki locally