Skip to content
Agentmart
Submit a tool

android-clean-architecture

适用于 Android 和 Kotlin 多平台 (KMP) 项目的整洁架构 (Clean Architecture) 模式 —— 包括模块结构、依赖规则、UseCase、Repository 以及数据层模式。

Skill by lza6

IndexedApache-2.0★ 8
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/lza6-android-clean-architecture

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

适用于 Android 和 Kotlin 多平台 (KMP) 项目的整洁架构 (Clean Architecture) 模式 —— 包括模块结构、依赖规则、UseCase、Repository 以及数据层模式。

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/android-clean-architecture

What's inside

Skill name
android-clean-architecture
Description
适用于 Android 和 Kotlin 多平台 (KMP) 项目的整洁架构 (Clean Architecture) 模式 —— 包括模块结构、依赖规则、UseCase、Repository 以及数据层模式。
License
Apache-2.0
Instructions
335 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Android 整洁架构 (Android Clean Architecture)

适用于 Android 和 KMP 项目的整洁架构模式。涵盖模块边界、依赖倒置、UseCase/Repository 模式,以及使用 Room、SQLDelight 和 Ktor 进行的数据层设计。

## 何时激活

- 规划 Android 或 KMP 项目的模块结构
- 实现 UseCase、Repository 或 DataSource
- 设计各层(领域层、数据层、表现层)之间的数据流
- 使用 Koin 或 Hilt 设置依赖注入
- 在分层架构中使用 Room、SQLDelight 或 Ktor

## 模块结构 (Module Structure)

### 推荐布局

```
project/
├── app/                  # Android 入口点、依赖注入配置、Application 类
├── core/                 # 共享工具类、基类、错误类型
├── domain/               # UseCase、领域模型、Repository 接口(纯 Kotlin)
├── data/                 # Repository 实现、DataSource、数据库、网络
├── presentation/         # 界面、ViewModel、UI 模型、导航
├── design-system/        # 可重用的 Compose 组件、主题、排版
31	└── feature/              # 功能模块(可选,用于大型项目)
32	    ├── auth/
33	    ├── settings/
34	    └── profile/
```

### 依赖规则

```
app → presentation, domain, data, core
presentation → domain, design-system, core
data → domain, core
domain → core (或无依赖)
core → (无)
```

**关键原则**:`domain` 层绝不能依赖 `data` 层、`presentation` 层或任何框架。它应仅包含纯 Kotlin 代码。

## 领域层 (Domain Layer)

### UseCase 模式

每个 UseCase 代表一个业务操作。使用 `operator fun invoke` 使调用更简洁:

```kotlin
class GetItemsByCategoryUseCase(
    private val repository: ItemRepository
) {
    suspend operator fun invoke(category: String): Result<List<Item>> {
        return repository.getItemsByCategory(category)
    }
}

// 基于 Flow 的 UseCase,用于响应式流
class ObserveUserProgressUseCase(
    private val repository: UserRepository
) {
    operator fun invoke(userId: String): Flow<UserProgress> {
        return repository.observeProgress(userId)
    }
}
```

### 领域模型 (Domain Models)

领域模型是纯 Kotlin 数据类 —— 无需任何框架注解:

```kotlin
data 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 }
```

### Repository 接口

在领域层定义,在数据层实现:

```kotlin
interface ItemRepository {
    suspend fun getItemsByCategory(category: String): Result<List<Item>>
    suspend fun saveItem(item: Item): Result<Unit>
    fun observeItems(): Flow<List<Item>>
}
```

## 数据层 (Data Layer)

### Repository 实现

负责协调本地和远程数据源:

```kotlin
class 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()))

From lza6/Claude-code-cli-config, Apache-2.0.

More from lza6/Claude-code-cli-config

Signals

Stars
8
Forks
1
Open issues
0
Last commit (this folder)
Apr 13, 2026 (6 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from lza6

Cite this page

android-clean-architecture skill. Agent Mart. https://agentmart.dev/skills/lza6-android-clean-architecture (last updated 2026-10-24)