Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns.
.claude/skills/loulanyue-android-clean-architecture/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-08 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 69% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 54% | 0% |
| case-20 | ✗→✓ | ▲ Improved | 84% | 0% |
| case-09 | ✓→✓ | = Same ✓ | 48% | 0% |
Clean Architecture patterns for Android and KMP projects. Covers module boundaries, dependency inversion, UseCase/Repository patterns, and data layer design with Room, SQLDelight, and Ktor.
project/
├── app/ # Android entry point, DI wiring, Application class
├── core/ # Shared utilities, base classes, error types
├── domain/ # UseCases, domain models, repository interfaces (pure Kotlin)
├── data/ # Repository implementations, DataSources, DB, network
├── presentation/ # Screens, ViewModels, UI models, navigation
├── design-system/ # Reusable Compose components, theme, typography
└── feature/ # Feature modules (optional, for larger projects)
├── auth/
├── settings/
└── profile/app → presentation, domain, data, core
presentation → domain, design-system, core
data → domain, core
domain → core (or no dependencies)
core → (nothing)Critical: domain must NEVER depend on data, presentation, or any framework. It contains pure Kotlin only.
Each UseCase represents one business operation. Use operator fun invoke for clean call sites:
kotlinclass GetItemsByCategoryUseCase( private val repository: ItemRepository ) { suspend operator fun invoke(category: String): Result<List<Item>> { return repository.getItemsByCategory(category) } } // Flow-based UseCase for reactive streams class ObserveUserProgressUseCase( private val repository: UserRepository ) { operator fun invoke(userId: String): Flow<UserProgress> { return repository.observeProgress(userId) } }
Domain models are plain Kotlin data classes — no framework annotations:
kotlindata class Item( val id: String, val title: String, val description: String, val tags: List<String>, val status: Status, val category: String ) enum class Status { DRAFT, ACTIVE, ARCHIVED }
Defined in domain, implemented in data:
kotlininterface ItemRepository { suspend fun getItemsByCategory(category: String): Result<List<Item>> suspend fun saveItem(item: Item): Result<Unit> fun observeItems(): Flow<List<Item>> }
Coordinates between local and remote data sources:
kotlinclass ItemRepositoryImpl( private val localDataSource: ItemLocalDataSource, private val remoteDataSource: ItemRemoteDataSource ) : ItemRepository { override suspend fun getItemsByCategory(category: String): Result<List<Item>> { return runCatching { val remote = remoteDataSource.fetchItems(category) localDataSource.insertItems(remote.map { it.toEntity() }) localDataSource.getItemsByCategory(category).map { it.toDomain() } } } override suspend fun saveItem(item: Item): Result<Unit> { return runCatching { localDataSource.insertItems(listOf(item.toEntity())) } } override fun observeItems(): Flow<List<Item>> { return localDataSource.observeAll().map { entities -> entities.map { it.toDomain() } } } }
Keep mappers as extension functions near the data models:
kotlin// In data layer fun ItemEntity.toDomain() = Item( id = id, title = title, description = description, tags = tags.split("|"), status = Status.valueOf(status), category = category ) fun ItemDto.toEntity() = ItemEntity( id = id, title = title, description = description, tags = tags.joinToString("|"), status = status, category = category )
kotlin@Entity(tableName = "items") data class ItemEntity( @PrimaryKey val id: String, val title: String, val description: String, val tags: String, val status: String, val category: String ) @Dao interface ItemDao { @Query("SELECT * FROM items WHERE category = :category") suspend fun getByCategory(category: String): List<ItemEntity> @Upsert suspend fun upsert(items: List<ItemEntity>) @Query("SELECT * FROM items") fun observeAll(): Flow<List<ItemEntity>> }
sql-- Item.sq CREATE TABLE ItemEntity ( id TEXT NOT NULL PRIMARY KEY, title TEXT NOT NULL, description TEXT NOT NULL, tags TEXT NOT NULL, status TEXT NOT NULL, category TEXT NOT NULL ); getByCategory: SELECT * FROM ItemEntity WHERE category = ?; upsert: INSERT OR REPLACE INTO ItemEntity (id, title, description, tags, status, category) VALUES (?, ?, ?, ?, ?, ?); observeAll: SELECT * FROM ItemEntity;
kotlinclass ItemRemoteDataSource(private val client: HttpClient) { suspend fun fetchItems(category: String): List<ItemDto> { return client.get("api/items") { parameter("category", category) }.body() } } // HttpClient setup with content negotiation val httpClient = HttpClient { install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } install(Logging) { level = LogLevel.HEADERS } defaultRequest { url("https://api.example.com/") } }
kotlin// Domain module val domainModule = module { factory { GetItemsByCategoryUseCase(get()) } factory { ObserveUserProgressUseCase(get()) } } // Data module val dataModule = module { single<ItemRepository> { ItemRepositoryImpl(get(), get()) } single { ItemLocalDataSource(get()) } single { ItemRemoteDataSource(get()) } } // Presentation module val presentationModule = module { viewModelOf(::ItemListViewModel) viewModelOf(::DashboardViewModel) }
kotlin@Module @InstallIn(SingletonComponent::class) abstract class RepositoryModule { @Binds abstract fun bindItemRepository(impl: ItemRepositoryImpl): ItemRepository } @HiltViewModel class ItemListViewModel @Inject constructor( private val getItems: GetItemsByCategoryUseCase ) : ViewModel()
Use Result<T> or a custom sealed type for error propagation:
kotlinsealed interface Try<out T> { data class Success<T>(val value: T) : Try<T> data class Failure(val error: AppError) : Try<Nothing> } sealed interface AppError { data class Network(val message: String) : AppError data class Database(val message: String) : AppError data object Unauthorized : AppError } // In ViewModel — map to UI state viewModelScope.launch { when (val result = getItems(category)) { is Try.Success -> _state.update { it.copy(items = result.value, isLoading = false) } is Try.Failure -> _state.update { it.copy(error = result.error.toMessage(), isLoading = false) } } }
For KMP projects, use convention plugins to reduce build file duplication:
kotlin// build-logic/src/main/kotlin/kmp-library.gradle.kts plugins { id("org.jetbrains.kotlin.multiplatform") } kotlin { androidTarget() iosX64(); iosArm64(); iosSimulatorArm64() sourceSets { commonMain.dependencies { /* shared deps */ } commonTest.dependencies { implementation(kotlin("test")) } } }
Apply in modules:
kotlin// domain/build.gradle.kts plugins { id("kmp-library") }
domain — keep it pure KotlinGlobalScope or unstructured coroutines — use viewModelScope or structured concurrencySee skill: compose-multiplatform-patterns for UI patterns. See skill: kotlin-coroutines-flows for async patterns.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-09 | pass→pass | 11,570 | 6,225 | -46% | 1 | 1 | 0% | 2,277 | 3,379 | +48% | 0 | 0 | — |
case-08 | fail→pass | 12,459 | 7,860 | -37% | 1 | 1 | 0% | 2,221 | 3,720 | +67% | 0 | 0 | — |
case-01 | fail→pass | 15,064 | 10,923 | -27% | 1 | 1 | 0% | 2,605 | 4,400 | +69% | 0 | 0 | — |
case-02 | pass→pass | 15,744 | 10,104 | -36% | 1 | 1 | 0% | 2,600 | 4,032 | +55% | 0 | 0 | — |
case-03 | pass→pass | 11,823 | 4,231 | -64% | 1 | 1 | 0% | 2,078 | 2,912 | +40% | 0 | 0 | — |
case-04 | pass→pass | 14,402 | 9,857 | -32% | 1 | 1 | 0% | 2,568 | 3,953 | +54% | 0 | 0 | — |
case-05 | pass→pass | 14,193 | 12,925 | -9% | 1 | 1 | 0% | 2,108 | 4,088 | +94% | 0 | 0 | — |
case-06 | pass→pass | 15,598 | 9,035 | -42% | 1 | 1 | 0% | 2,653 | 3,830 | +44% | 0 | 0 | — |
case-07 | pass→pass | 9,649 | 8,515 | -12% | 1 | 1 | 0% | 1,700 | 3,892 | +129% | 0 | 0 | — |
case-10 | pass→pass | 16,054 | 13,057 | -19% | 1 | 1 | 0% | 2,901 | 4,703 | +62% | 0 | 0 | — |
case-11 | fail→pass | 17,377 | 12,934 | -26% | 1 | 1 | 0% | 2,593 | 3,994 | +54% | 0 | 0 | — |
case-12 | pass→pass | 13,203 | 12,707 | -4% | 1 | 1 | 0% | 2,120 | 4,587 | +116% | 0 | 0 | — |
case-13 | pass→pass | 14,541 | 11,203 | -23% | 1 | 1 | 0% | 2,631 | 4,276 | +63% | 0 | 0 | — |
case-14 | pass→pass | 15,345 | 11,298 | -26% | 1 | 1 | 0% | 2,455 | 4,162 | +70% | 0 | 0 | — |
case-20 | fail→pass | 13,709 | 12,955 | -6% | 1 | 1 | 0% | 2,536 | 4,660 | +84% | 0 | 0 | — |
case-15 | pass→pass | 13,448 | 5,388 | -60% | 1 | 1 | 0% | 2,052 | 3,177 | +55% | 0 | 0 | — |
case-16 | pass→pass | 8,513 | 5,665 | -33% | 1 | 1 | 0% | 1,467 | 3,205 | +118% | 0 | 0 | — |
case-17 | pass→pass | 11,061 | 8,098 | -27% | 1 | 1 | 0% | 1,859 | 3,639 | +96% | 0 | 0 | — |
case-18 | pass→pass | 12,085 | 12,693 | +5% | 1 | 1 | 0% | 2,042 | 4,373 | +114% | 0 | 0 | — |
case-19 | pass→pass | 12,684 | 11,215 | -12% | 1 | 1 | 0% | 2,193 | 4,150 | +89% | 0 | 0 | — |
case-21 | pass→pass | 9,193 | 9,316 | +1% | 1 | 1 | 0% | 1,591 | 3,767 | +137% | 0 | 0 | — |
case-22 | pass→pass | 11,742 | 11,183 | -5% | 1 | 1 | 0% | 2,030 | 4,130 | +103% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +18 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.