A mobile app that shows a list of products and their details in an e-commerce environment written 100% in Kotlin and Jetpack Compose using Android Jetpack Components.
To inspect network requests, run the app, and Chucker will post a notification with all intercepted requests.
- Create a page to list all products, in the order in which they appear in the API response
- Create a page to view a single product once a product has been selected from the list.
-
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.
- Coil - An image-loading library for Android backed by Koltin Coroutines.
- 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 conscious manner and survives configuration change.
- Chucker An on-device Http inspector for Android and OkHttp.
- Timber - a highly extensible Android logger.
-
Architecture
- MVVM - Model View View Model
-
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
The screenshots below show test reports 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.
MIT License
Copyright (c) 2023 Daniel Waiguru
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.