Android Architecture

new-silvermoon/awesome-android-agent-skills/.github/skills/architecture/android-architecture

作者 new-silvermoon82900eacc8dbe13de93c6310af27b9df4b2bd2f6无许可证收录于 2026年10月9日更新于 2026年10月9日

Expert guidance on setting up and maintaining a modern Android application architecture using Clean Architecture and Hilt. Use this when asked about project structure, module setup, or dependency injection.

AI 生成的概览

指导 Android 应用架构,涵盖 Clean Architecture 分层、Hilt 依赖注入和多模块项目结构。

功能
提供设置和维护现代 Android 应用架构的专业指导。它定义 UI、Domain 和 Data 三层及严格的内向依赖流向,规定 Hilt 注解和模块模式用于依赖注入,并概述包含核心模块和功能模块的多模块策略。还包含实现检查清单,涉及分层纯净性、主线程安全的挂起函数和 StateFlow 使用。
适用场景
适用于设计或重构 Android 应用的项目结构、模块设置或依赖注入时。面向关于 Clean Architecture 分层、Hilt 配置或模块化策略的问题。
运行要求
无需脚本或工具,仅为指导说明。假定使用 Kotlin、Hilt 的 Android 项目,可选使用 Retrofit、Room 和 Jetpack Compose。

Android Modern Architecture & Modularization

Instructions

When designing or refactoring an Android application, adhere to the Guide to App Architecture and Clean Architecture principles.

1. High-Level Layers

Structure the application into three primary layers. Dependencies must strictly flow inwards (or downwards) to the core logic.

  • UI Layer (Presentation):
    • Responsibility: Displaying data and handling user interactions.
    • Components: Activities, Fragments, Composables, ViewModels.
    • Dependencies: Depends on the Domain Layer (or Data Layer if simple). Never depends on the Data Layer implementation details directly.
  • Domain Layer (Business Logic) [Optional but Recommended]:
    • Responsibility: Encapsulating complex business rules and reuse.
    • Components: Use Cases (e.g., GetLatestNewsUseCase), Domain Models (pure Kotlin data classes).
    • Pure Kotlin: Must NOT contain any Android framework dependencies (no android.* imports).
    • Dependencies: Depends on Repository Interfaces.
  • Data Layer:
    • Responsibility: Managing application data (fetching, caching, saving).
    • Components: Repositories (implementations), Data Sources (Retrofit APIs, Room DAOs).
    • Dependencies: Depends only on external sources and libraries.

2. Dependency Injection with Hilt

Use Hilt for all dependency injection.

  • @HiltAndroidApp: Annotate the Application class.
  • @AndroidEntryPoint: Annotate Activities and Fragments.
  • @HiltViewModel: Annotate ViewModels; use standard constructor injection.
  • Modules:
    • Use @Module and @InstallIn(SingletonComponent::class) for app-wide singletons (e.g., Network, Database).
    • Use @Binds in an abstract class to bind interface implementations (cleaner than @Provides).

3. Modularization Strategy

For production apps, use a multi-module strategy to improve build times and separation of concerns.

  • :app: The main entry point, connects features.
  • :core:model: Shared domain models (Pure Kotlin).
  • :core:data: Repositories, Data Sources, Database, Network.
  • :core:domain: Use Cases and Repository Interfaces.
  • :core:ui: Shared Composables, Theme, Resources.
  • :feature:[name]: Standalone feature modules containing their own UI and ViewModels. Depends on :core:domain and :core:ui.

4. Checklist for implementation

  • Ensure Domain layer has no Android dependencies.
  • Repositories should default to main-safe suspend functions (use Dispatchers.IO internally if needed).
  • ViewModels should interact with the UI layer via StateFlow (see android-viewmodel skill).

来源与署名

来源:new-silvermoon/awesome-android-agent-skills位于.github/skills/architecture/android-architecture提交82900ea

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架