An offline-first mobile app that shows current location weather and 5-day forecast written 100% in Kotlin and Jetpack Compose using Android Jetpack Components.
To use this app, make sure you accept the location permission request to grant the app your location details.
-
Tech-stack
- Kotlin - a modern, cross-platform, statically typed, general-purpose programming language with type inference.
- Coroutines - lightweight threads to perform asynchronous tasks.
- Flow - a stream of data that emits multiple values sequentially.
- StateFlow - Flow APIs that enable flows to emit updated state and emit values to multiple consumers optimally.
- Dagger Hilt - a dependency injection library for Android built on top of Dagger that reduces the boilerplate of doing manual injection.
- Moshi Converter A JSON serialization converter which uses Moshi
- Jetpack
- Jetpack Compose - A modern toolkit for building native Android UI
- Lifecycle - perform actions in response to a change in the lifecycle state.
- ViewModel - store and manage UI-related data lifecycle in a conscious manner and survive configuration change.
- Room - An ORM that provides an abstraction layer over SQLite to allow fluent database access.
- Chucker An on-device Http inspector for Android and OkHttp.
- Timber - a highly extensible Android logger.
- Jacoco - A Gradle plugin that provides code coverage metrics for Java code.
-
Architecture
- MVVM - Model View ViewModel
-
Tests
-
Gradle
- Gradle Kotlin DSL - An alternative syntax for writing Gradle build scripts using Koltin.
- Version Catalogs - A scalable way of maintaining dependencies and plugins in a multi-module project.
- Convention Plugins - A way to encapsulate and reuse common build configuration in Gradle, see here
- Plugins
-
CI/CD
All the dependencies (external libraries) are managed using version catalogs and defined in a single place gradle/libs.versions.toml
file. This is a scalable approach to manage dependencies and use the same dependency version across all modules.
This repo uses ktlint, a Kotlin linter, to analyze the codebase and identify potential code style violations, code quality issues, etc. Before every commit, make sure you run the following bash script:
./codeAnalysis.sh
Before using it for the first time, you must guarantee some running permissions:
chmod +x codeAnalysis.sh
The screenshots below show test results for tests done on this repo
A well-planned architecture is extremely important for any Android project; It makes it easier to maintain the app as the codebase grows and the team expands. This repo uses the MVVM pattern with clean architecture to have decoupled, testable, and maintainable code. MVVM separates views (Activities, Fragments, or Composables) from the app's business logic. However, as the codebase grows, ViewModels start bloating, and separation of responsibilities becomes hard hence the need to use MVVM with clean architecture.
- Allows the app to scale easily
- Easier onboarding of new team members
- Easier to test code
- Makes it easier to enforce coder ownership This repo uses MVVM with Clean Architecture with the following modules:
Contains repositories, data sources, and model classes. This layer hides the implementation details and data sources from the outside.
This module encapsulates complex business logic or simple logic that multiple ViewModels reuse. It contains all the use cases of the application and models independent of any framework-specific dependencies and represents the business logic.
Contains views (in this app, Composable) and ViewModels. The views post events to the ViewModel and subscribe to the updated state.
Contains reusable UI components, Color, Typography, and Theme that can be reused across various modules
This module contains test code, test resources, and test dependencies.