A modern Android application template built with Jetpack Compose, following Clean Architecture principles. This template provides a solid foundation for building scalable Android applications with type-safe navigation, dependency injection, networking, local data persistence, and more.
- Overview
- Features
- Architecture
- Project Structure
- Modules
- Getting Started
- Technology Stack
- Build System
- Usage Examples
- Testing
- Contributing
This template is designed to help developers quickly start building Android applications with:
- Modern Android Development: Jetpack Compose, Kotlin, Coroutines
- Clean Architecture: Separation of concerns with clear module boundaries
- Type-Safe Navigation: Navigation3 with sealed classes
- Dependency Injection: Hilt for DI
- Networking: Retrofit with custom API response handling
- Local Storage: Room database and DataStore Preferences
- Modular Design: Feature-based and core module structure
- β Jetpack Compose UI - Modern declarative UI framework
- β Navigation3 - Type-safe navigation with sealed classes
- β Hilt Dependency Injection - Clean DI setup
- β Retrofit Networking - Custom API response wrapper
- β Room Database - Local SQLite database with caching
- β DataStore Preferences - Encrypted key-value storage
- β Kotlin Coroutines - Async operations and Flow support
- β Kotlinx Serialization - JSON serialization/deserialization
- β Material Design 3 - Modern Material Design components
- β Modular Architecture - Feature-based module structure
- β Clean Architecture - Clear separation of layers
- β Repository Pattern - Data abstraction layer
- β MVVM Pattern - ViewModel for state management
- β Type-Safe State Management - Custom StateFlow implementation
- β Error Handling - Comprehensive error handling system
- β Offline Support - Local data caching and persistence
The project follows Clean Architecture principles with clear separation of concerns:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Presentation Layer β
β (UI, ViewModels, Composables) β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β Domain Layer β
β (Use Cases, Business Logic, Models) β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β Data Layer β
β (Repositories, Data Sources, Network, Database) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
-
Presentation Layer (
app,features)- UI components (Composables)
- ViewModels
- Navigation
- User interactions
-
Domain Layer (
core:model,core:common)- Business logic
- Domain models
- Use cases (if needed)
- Common utilities
-
Data Layer (
core:data,core:network,core:database,core:datastore)- Repository implementations
- Network services
- Local database
- Data sources
AndroidComposeTemplate/
βββ app/ # Main application module
β βββ src/main/
β β βββ java/com/example/androidcomposetemplate/
β β β βββ AndroidApplication.kt # Hilt application
β β β βββ MainActivity.kt # Main activity
β β β βββ navigation/
β β β β βββ AppNavHost.kt # Navigation setup
β β β βββ ui/
β β β βββ ApplicationMain.kt # Main composable
β β βββ res/ # Resources
β βββ build.gradle.kts
β
βββ build-logic/ # Gradle convention plugins
β βββ convention/
β βββ src/main/kotlin/
β βββ AndroidApplicationConventionPlugin.kt
β βββ AndroidLibraryConventionPlugin.kt
β βββ AndroidHiltConventionPlugin.kt
β βββ compose/
β
βββ core/ # Core modules
β βββ common/ # Common utilities and extensions
β βββ data/ # Data layer (repositories)
β βββ database/ # Room database
β βββ datastore/ # DataStore preferences
β βββ designsystem/ # Design system and theme
β βββ model/ # Domain models
β βββ navigation/ # Navigation setup
β βββ network/ # Networking layer
β βββ test/ # Testing utilities
β βββ ui/ # UI components
β βββ viewmodel/ # Base ViewModel
β
βββ features/ # Feature modules
β βββ auth/ # Authentication feature
β
βββ gradle/ # Gradle configuration
β βββ libs.versions.toml # Version catalog
β βββ wrapper/
β
βββ settings.gradle.kts # Project settings
βββ build.gradle.kts # Root build file
βββ README.md # This file
The main application module that ties everything together.
Key Components:
AndroidApplication- Hilt application classMainActivity- Main activity with Compose setupAppNavHost- Navigation host configurationApplicationMain- Root composable
Dependencies:
- All feature modules
- Core modules (navigation, designsystem, common)
Common utilities, extensions, and shared code.
Features:
- Extension functions
- Common utilities
- Event handling
- Exception handling
Domain models shared across the application.
Features:
- Data classes for domain models
- Enums for state management
- Shared model definitions
Networking layer with Retrofit and custom API response handling.
Features:
- Custom
ApiResponsesealed interface - Retrofit services
- Response mappers
- Error handling
- Retry mechanisms
- Global operators
Key Components:
ApiResponse<T>- Type-safe response wrapperNetworkModule- Hilt module for network dependenciesAuthService- Example service interface- Response transformers and mappers
Data layer implementing repository pattern.
Features:
- Repository interfaces
- Repository implementations
- Data mappers
- Integration with network and local storage
Key Components:
AuthRepository- Example repository interfaceAuthRepositoryImpl- Repository implementation- Mappers for data transformation
Room database for local data persistence.
Features:
- Room database setup
- Entities and DAOs
- Repository with caching
- Entity-Domain model mappers
Key Components:
AppDatabase- Room databaseUserEntity- Example entityUserDao- Data access objectUserRoomRepository- Repository with LRU cache
DataStore Preferences for key-value storage with encryption.
Features:
- Encrypted token storage
- Onboarding state management
- CryptoManager for encryption
- Flow-based reactive streams
Key Components:
TokenDataSource- Token storage interfaceOnboardingDataSource- Onboarding state interfaceCryptoManager- AES encryption manager- DataStore implementations
Type-safe navigation using Navigation3.
Features:
- Navigator interface
- AppNavigator implementation
- ApplicationScreen sealed class
- CompositionLocal integration
Key Components:
Navigator- Navigation interfaceAppNavigator- Navigation implementationApplicationScreen- Screen definitionsLocalComposeNavigator- Compose integration
Base ViewModel with state management.
Features:
- BaseViewModel class
- ViewModelStateFlow for scoped state
- ViewModelKey for instance identification
Key Components:
BaseViewModel- Base class for ViewModelsViewModelStateFlow<T>- Custom StateFlowViewModelKey- Key for ViewModel instances
Design system and theming.
Features:
- Material Design 3 theme
- Color schemes
- Typography
- Component styles
Reusable UI components.
Features:
- Common composables
- UI utilities
- Shared components
Testing utilities and helpers.
Features:
- Test utilities
- Mock helpers
- Testing extensions
Authentication feature module.
Features:
- Auth screen
- Auth ViewModel
- Auth components
Structure:
- Feature-specific screens
- Feature-specific ViewModels
- Feature-specific components
Gradle convention plugins for consistent build configuration.
Plugins:
convention.android.application- Application module conventionsconvention.android.library- Library module conventionsconvention.android.compose- Compose setupconvention.android.hilt- Hilt setup
- Android Studio Hedgehog (2023.1.1) or later
- JDK 17 or later
- Android SDK API 24+ (minimum), API 34+ (target)
- Gradle 8.10.1+
-
Clone the repository
git clone <repository-url> cd AndroidComposeTemplate
-
Open in Android Studio
- Open Android Studio
- Select "Open an Existing Project"
- Navigate to the cloned directory
- Wait for Gradle sync to complete
-
Configure Application
- Update
applicationIdinapp/build.gradle.ktsif needed - Update package names if needed
- Configure signing if needed for release builds
- Update
-
Run the Application
- Connect an Android device or start an emulator
- Click "Run" or press
Shift+F10 - The app should build and launch
Edit core/network/src/main/java/com/example/core/network/di/NetworkModule.kt:
fun provideRetrofit(...): Retrofit {
return Retrofit.Builder()
.baseUrl("https://your-api-url.com/") // Update this
// ...
}Edit core/database/src/main/java/com/goz247/database/di/DatabaseModule.kt:
fun provideAppDatabase(...): AppDatabase {
return Room
.databaseBuilder(application, AppDatabase::class.java, "your_database_name")
// ...
}- Kotlin 2.2.21 - Programming language
- Jetpack Compose 1.9.5 - UI framework
- Material Design 3 1.4.0 - Design system
- Kotlin Coroutines 1.9.0 - Async programming
- Kotlinx Serialization 1.6.0 - JSON serialization
- Navigation3 1.0.0 - Type-safe navigation
- Room 2.6.1 - Local database
- DataStore 1.1.0 - Preferences storage
- Lifecycle 2.10.0 - Lifecycle-aware components
- ViewModel - State management
- Hilt 2.51.1 - Dependency injection framework
- KSP 2.2.21-2.0.4 - Kotlin Symbol Processing
- Retrofit 2.9.0 - HTTP client
- OkHttp 4.11.0 - HTTP client library
- Kotlinx Serialization Converter 0.8.0 - JSON converter
- Android Gradle Plugin 8.10.1
- Gradle 8.10.1+
- KSP - Code generation
- Create feature module in
features/directory - Add to settings.gradle.kts:
include(":features:yourfeature") - Create feature structure:
features/yourfeature/ βββ build.gradle.kts βββ src/main/java/com/example/yourfeature/ βββ YourFeatureScreen.kt βββ YourFeatureViewModel.kt βββ component/ - Add screen to ApplicationScreen:
@Serializable data object YourFeature: ApplicationScreen()
- Add to AppNavHost:
entry<ApplicationScreen.YourFeature> { YourFeatureScreen() }
- Add to ApplicationScreen:
sealed class ApplicationScreen: NavKey { @Serializable data class YourScreen(val param: String): ApplicationScreen() }
- Create screen composable:
@Composable fun YourScreen(param: String) { // Your screen content }
- Add to AppNavHost:
entry<ApplicationScreen.YourScreen> { YourScreen(it.param) }
- Navigate to screen:
navigator.navigateTo(ApplicationScreen.YourScreen(param = "value"))
- Create interface in
core:data/api/:interface YourRepository { suspend fun getData(): Result<YourModel> }
- Create implementation in
core:data/impl/repository/:class YourRepositoryImpl @Inject constructor( private val yourService: YourService ): YourRepository { override suspend fun getData(): Result<YourModel> { // Implementation } }
- Bind in DataModule:
@Binds fun bindYourRepository(impl: YourRepositoryImpl): YourRepository
- Create service interface in
core:network/service/:interface YourService { @GET("/your/endpoint") suspend fun getData(): ApiResponse<YourResponse> }
- Add to NetworkModule:
@Provides @Singleton fun provideYourService(retrofit: Retrofit): YourService { return retrofit.create(YourService::class.java) }
When contributing to this project:
- Follow the existing code style
- Write tests for new features
- Update documentation
- Follow Clean Architecture principles
- Keep modules focused and cohesive
This project is a template and can be used as a starting point for your Android applications.
Built with modern Android development best practices and following Google's recommended architecture patterns.
Happy Coding! π