Overview
Theandroid-architecture skill provides expert guidance on structuring Android applications using modern architecture patterns. It focuses on Clean Architecture principles, proper layering, Hilt dependency injection, and modularization strategies for production apps.
When to use this skill:
- Setting up new Android projects
- Refactoring existing apps to modern architecture
- Implementing dependency injection with Hilt
- Designing multi-module project structures
- Establishing clear separation of concerns
High-Level Architecture Layers
The architecture is structured into three primary layers with strict dependency rules: dependencies must flow inwards (or downwards) toward the core logic.UI Layer (Presentation)
UI Layer (Presentation)
Responsibility: Displaying data and handling user interactionsComponents:
- Activities
- Fragments
- Composables
- ViewModels
Domain Layer (Business Logic) [Optional but Recommended]
Domain Layer (Business Logic) [Optional but Recommended]
Responsibility: Encapsulating complex business rules and reuseComponents:
- Use Cases (e.g.,
GetLatestNewsUseCase) - Domain Models (pure Kotlin data classes)
android.* imports)Dependencies: Depends on Repository Interfaces onlyData Layer
Data Layer
Responsibility: Managing application data (fetching, caching, saving)Components:
- Repositories (implementations)
- Data Sources (Retrofit APIs, Room DAOs)
Dependency Injection with Hilt
Use Hilt for all dependency injection in your Android app.Application Setup
Activity and Fragment Injection
ViewModel Injection
Hilt Modules
Modularization Strategy
For production apps, use a multi-module strategy to improve build times and separation of concerns.Module Responsibilities
:app
Main entry point that connects features together
: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 features with UI and ViewModels. Depends on
:core:domain and :core:uiImplementation Checklist
Ensure Pure Domain Layer
Verify that the
Domain layer has no Android dependencies - it should be pure Kotlin onlyMain-Safe Repository Functions
Repositories should default to main-safe suspend functions (use
Dispatchers.IO internally if needed)StateFlow for UI Communication
ViewModels should interact with the UI layer via
StateFlow (see android-viewmodel)Best Practices
- Keep the Domain Layer pure Kotlin with no Android framework dependencies
- Use Hilt for all dependency injection
- Follow the dependency rule: dependencies flow inward/downward
- Modularize production apps for better build times and separation
- Use
@Bindsfor interface binding in Hilt modules
Related Skills
ViewModel & State
Learn how to implement ViewModels with StateFlow and SharedFlow
Data Layer
Implement the Repository pattern with Room and Retrofit
