$npx -y skills add hanamizuki/solopreneur --skill architectureExpert 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.
| 1 | # Android Modern Architecture & Modularization |
| 2 | |
| 3 | ## Instructions |
| 4 | |
| 5 | When designing or refactoring an Android application, adhere to the **Guide to App Architecture** and **Clean Architecture** principles. |
| 6 | |
| 7 | ### 1. High-Level Layers |
| 8 | Structure the application into three primary layers. Dependencies must strictly flow **inwards** (or downwards) to the core logic. |
| 9 | |
| 10 | * **UI Layer (Presentation)**: |
| 11 | * **Responsibility**: Displaying data and handling user interactions. |
| 12 | * **Components**: Activities, Fragments, Composables, ViewModels. |
| 13 | * **Dependencies**: Depends on the Domain Layer (or Data Layer if simple). **Never** depends on the Data Layer implementation details directly. |
| 14 | * **Domain Layer (Business Logic) [Optional but Recommended]**: |
| 15 | * **Responsibility**: Encapsulating complex business rules and reuse. |
| 16 | * **Components**: Use Cases (e.g., `GetLatestNewsUseCase`), Domain Models (pure Kotlin data classes). |
| 17 | * **Pure Kotlin**: Must NOT contain any Android framework dependencies (no `android.*` imports). |
| 18 | * **Dependencies**: Depends on Repository Interfaces. |
| 19 | * **Data Layer**: |
| 20 | * **Responsibility**: Managing application data (fetching, caching, saving). |
| 21 | * **Components**: Repositories (implementations), Data Sources (Retrofit APIs, Room DAOs). |
| 22 | * **Dependencies**: Depends only on external sources and libraries. |
| 23 | |
| 24 | ### 2. Dependency Injection with Hilt |
| 25 | Use **Hilt** for all dependency injection. |
| 26 | |
| 27 | * **@HiltAndroidApp**: Annotate the `Application` class. |
| 28 | * **@AndroidEntryPoint**: Annotate Activities and Fragments. |
| 29 | * **@HiltViewModel**: Annotate ViewModels; use standard `constructor` injection. |
| 30 | * **Modules**: |
| 31 | * Use `@Module` and `@InstallIn(SingletonComponent::class)` for app-wide singletons (e.g., Network, Database). |
| 32 | * Use `@Binds` in an abstract class to bind interface implementations (cleaner than `@Provides`). |
| 33 | |
| 34 | ### 3. Modularization Strategy |
| 35 | For production apps, use a multi-module strategy to improve build times and separation of concerns. |
| 36 | |
| 37 | * **:app**: The main entry point, connects features. |
| 38 | * **:core:model**: Shared domain models (Pure Kotlin). |
| 39 | * **:core:data**: Repositories, Data Sources, Database, Network. |
| 40 | * **:core:domain**: Use Cases and Repository Interfaces. |
| 41 | * **:core:ui**: Shared Composables, Theme, Resources. |
| 42 | * **:feature:[name]**: Standalone feature modules containing their own UI and ViewModels. Depends on `:core:domain` and `:core:ui`. |
| 43 | |
| 44 | ### 4. Checklist for implementation |
| 45 | - [ ] Ensure `Domain` layer has no Android dependencies. |
| 46 | - [ ] Repositories should default to main-safe suspend functions (use `Dispatchers.IO` internally if needed). |
| 47 | - [ ] ViewModels should interact with the UI layer via `StateFlow` (see `android-viewmodel` skill). |