SKILL

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects: module structure, dependency rules, use cases, repositories, and data-layer patterns.

Translation reviewed
Read the original Chinese text

适用于Android和Kotlin多平台项目的Clean Architecture模式——模块结构、依赖规则、用例、仓库以及数据层模式。

Target: Mobile development. Automatically collected · unverified.

Excerpt from the author’s documentation

Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.

Read the original Chinese text

Topics in the source

  • Android 整洁架构
  • 何时启用
  • 模块结构
  • 推荐布局
  • 依赖规则
  • 领域层
  • UseCase 模式
  • 领域模型

适用于 Android 和 KMP 项目的整洁架构模式。涵盖模块边界、依赖反转、UseCase/Repository 模式,以及使用 Room、SQLDelight 和 Ktor 的数据层设计。 构建 Android 或 KMP 项目模块结构 实现 UseCases、Repositories 或 DataSources 设计各层(领域层、数据层、表示层)之间的数据流 使用 Koin 或 Hilt 设置依赖注入 在分层架构中使用 Room、SQLDelight 或 Ktor 关键:domain 绝不能依赖 data、presentation 或任何框架。它仅包含纯 Kotlin 代码。 每个 UseCase 代表一个业务操作。使用 operator fun invoke 以获得简洁的调用点: 领域模型是普通的 Kotlin 数据类——没有框架注解: 在领域层定义,在数据层实现: 协调本地和远程数据源: 将映射器作为扩展函数放在数据模型附近: 使用 Result 或自定义密封类型进行错误传播: 对于 KMP 项目,使用约定插件以减少构建文件重复: 在模块中应用: 在 domain 中导入 Android 框架类——保持其为纯 Kotlin 向 UI 层暴露数据库实体或 DTO——始终映射到领域模型 将业务逻辑放在 ViewModels 中——提取到 UseCases 使用 GlobalScope 或非结构化协程——使用 viewModelScope 或结构化并发 臃肿的仓库实现——拆分为专注的 DataSources 循环模块依赖——如果 A 依赖 B,则 B 绝不能依赖 A 查看技能:compose-multiplatform-patterns 了解 UI 模式。 查看技能:kotlin-coroutines-flows 了解异步模式。

Source repository
affaan-m/ECC
Source file
docs/zh-CN/skills/android-clean-architecture/SKILL.md
Fixed revision
d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Read the complete original documentation ↗

Sources and evidence

This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.

Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T14:01:50.126Z.

Categories are inferred from names, descriptions and paths. They do not establish compatibility.

License and attribution

MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.

Original license ↗

Synchronization, copying and user-reported success do not mark a resource as runtime-tested.

Limitations and notes

  • Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.