Android Clean Architecture in Evento is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.
An android app built using Kotlin that allows people to find events and pay for them.
You require the minimum Android Studio Electric Eel | 2022.1.1
to be able to build the app.
A well planned architecture is extremely important for an app to scale and all architectures have one common goal- to manage complexity of your app. This isn't something to be worried about in smaller apps however it may prove very useful when working on apps with longer development lifecycle and a bigger team.
Clean architecture was proposed by Robert C. Martin in 2012 in the Clean Code Blog and it follow the SOLID principle.
The circles represent different layers of your app. Note that:
-
The center circle is the most abstract, and the outer circle is the most concrete. This is called the Abstraction Principle. The Abstraction Principle specifies that inner circles should contain business logic, and outer circles should contain implementation details.
-
Another principle of Clean Architecture is the Dependency Inversion. This rule specifies that each circle can depend only on the nearest inward circle ie. low-level modules do not depend on high-level modules but the other way around.
Loose coupling between the code
- The code can easily be modified without affecting any or a large part of the app's codebase thus easier to scale the application later on.- Easier to
test
code. Separation of Concern
- Different modules have specific responsibilities making it easier for modification and maintenance.
-
Single Responsibility: Each software component should have only one reason to change – one responsibility.
-
Open-Closed: You should be able to extend the behavior of a component, without breaking its usage, or modifying its extensions.
-
Liskov Substitution: If you have a class of one type, and any subclasses of that class, you should be able to represent the base class usage with the subclass, without breaking the app.
-
Interface Segregation: It’s better to have many smaller interfaces than a large one, to prevent the class from implementing the methods that it doesn’t need.
-
Dependency Inversion: Components should depend on abstractions rather than concrete implementations. Also higher level modules shouldn’t depend on lower level modules.
The buildSrc
layer is responsible for dependency management. It control and manage all dependencies in one place with Kotlin.
The common
layer is responsible for common properties. It contains the implementations of the resources files, themes and components declared in the common layer.
-
component: This is responsible for common view components that using app.
-
provider: Defines navigation, resource and theme provider.
-
theme: Defines themes, colors, fonts and resource files.
The libraries
layer is responsible for base structure.
-
framework: Contains different utilities that can be used by the different modules and base structures.
-
jetframework: Contains different utilities that can be used by the different modules and base structures only for Jet Compose.
-
testing: Contains the definitions of the test utilities.
The data
layer is responsible for selecting the proper data source for the domain layer. It contains the implementations of the repositories declared in the domain layer.
Components of data layer include:
-
model
-dto: Defines dto of ui model, also perform data transformation between
domain
,response
andentity
models.-local: Defines the schema of SQLite database.
-remote: Defines POJO of network responses.
-
local: This is responsible for performing caching operations using Room.
-
remote: This is responsible for performing network operations eg. defining API endpoints using Retrofit.
-
repository: Responsible for exposing data to the domain layer.
This is the core layer of the application. The domain
layer is independent of any other layers thus ] domain business logic can be independent from other layers.This means that changes in other layers will have no effect on domain layer eg. screen UI (presentation layer) or changing database (data layer) will not result in any code change withing domain layer.
Components of domain layer include:
- usecase: They enclose a single action, like getting data from a database or posting to a service. They use the repositories to resolve the action they are supposed to do. They usually override the operator
invoke
, so they can be called as a function.
The features
layer contains components involved in showing information to the user. The main part of this layer are the views(activity, compose) and ViewModels.
This project uses many of the popular libraries, plugins and tools of the android ecosystem.
-
- Material - Build Jetpack Compose UIs with ready to use Material Design Components.
- Foundation - Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
- UI - Fundamental components of compose UI needed to interact with the device, including layout, drawing, and input.
- ConstraintLayout - ConstraintLayout-compose 1.0 provides ConstraintLayout functionalities in Jetpack Compose.
- Lifecycle-ViewModel - Perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
- Paging - The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView.
- Coil - An image loading library for Android backed by Kotlin Coroutines.
-
- SwipeRefresh - A library which provides a layout which provides the swipe-to-refresh UX pattern, similar to Android's SwipeRefreshLayout.
- Systemuicontroller - System UI Controller provides easy-to-use utilities for updating the System UI bar colors within Jetpack Compose.
- Insets - Insets for Jetpack Compose takes a lot of the ideas which drove Insetter for views, and applies them for use in composables.
- Placeholder - A library which provides a modifier for display 'placeholder' UI while content is loading.
- Navigation - A library which provides Compose Material support for Jetpack Navigation Compose. This features composable bottom sheet destinations.
-
- Android KTX - Provide concise, idiomatic Kotlin to Jetpack and Android platform APIs.
- AndroidX - Major improvement to the original Android Support Library, which is no longer maintained.
- Lifecycle - Perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
- ViewModel - Designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
- Room - Provides an abstraction layer over SQLite used for offline data caching.
-
Dagger Hilt - Dependency Injection library.
-
Google-KSP - Kotlin Symbol Processing API
-
Coroutines - Library Support for coroutines.
-
Flow - Flows are built on top of coroutines and can provide multiple values. A flow is conceptually a stream of data that can be computed asynchronously.
-
Material Design - Build awesome beautiful UIs.
-
Coroutines - Library Support for coroutines,provides runBlocking coroutine builder used in tests.
-
Gradle Kotlin DSL - makes it easy to manage dependency all module that we have
-
Navigation - Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
-
SplashScreen - Android 12 adds the SplashScreen API, which enables a new app launch animation for all apps when running on a device with Android 12 or higher.
- Check-Dependency-Versions - make easy to determine which dependencies have updates.