-
Notifications
You must be signed in to change notification settings - Fork 0
Data Layer Agent
Ali Sadeghi edited this page Jan 6, 2026
·
3 revisions
Implements the data layer for KMP features.
Invoked by: creating-kmp-feature skill (Phase 3)
- Domain models with
@Serializable - Ktor Resources (type-safe API routes)
- RemoteDataSource (interface + implementation)
- Repository (interface + implementation)
- Either error handling
Feature: Product Catalog
Models: Product (id, name, price, imageUrl)
Endpoints: GET /products, GET /products/{id}
// 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)
}- Build passes:
./gradlew :feature:productcatalog:assembleAndroidMain - Ktlint formatting applied
Back to Agents