data implements repository interfaces from domain.
- Put API calls, local storage, and mappers here.
- Use
@Inject constructorand@Singletonfor data sources. - Preserve the repository's existing exception-handling style, but map failures to domain exceptions in new code.
- Keep business rules out of this layer.
- Use DTOs and mapping functions to translate between API and domain models.
- Retrofit APIs and request/response models
- Remote and local data sources
- Repository implementations
- Authentication, token storage, and error mapping
- New repositories: add
@Binds @SingletoninBindsRepositoryModule - Legacy repositories wired via
@ProvidesinRepositoryModule— don't add new entries here - Data sources:
@Inject constructorwith@Singleton; register inRemoteDataSourceModule/LocalDataSourceModule
- Wrap remote calls with
suspendRunCatching { }fromdata/util/ResultUtil.kt— it returnsResult<T>and re-throwsCancellationExceptionautomatically - Map HTTP failures to domain exceptions with the
mapHttpFailure { }DSL fromdata/util/NetworkUtil.kt(e.g.on(404) throws KoinFooException.NotFoundException()) - Don't add manual
.onFailure { if (it is CancellationException) throw it }blocks —suspendRunCatchingalready handles cancellation
- Place all mapping logic in
data/mapper/{Feature}Mapper.kt - Use extension functions:
fun FooResponse.toFoo(): Foo - Never put mapping logic inside DTO classes
- Use Room for relational/structured data (see
data/entity/) - Use DataStore for simple key-value preferences (see
data/source/local/)
- Root
AGENTS.md domain/AGENTS.md