Clean Architecture - Kotlin, MVVM, Use cases

Last update: May 13, 2022

CleanArchitecture

Screenshot

Is Clean Architecture only MVVM ?

NO, MVVM is a part of clean architecture. MVVM includes Model, View and ViewModel and in addition to this, Clean architecture has one more layer which is USE CASES.

What is a USE CASE & Why do we need them ?

In MVVM, we use to put all our business logic into our ViewModels but the problem with that is, the bigger your project gets, the more number of ViewModels you have and all your business logic is divided into various viewModels. That’s where clean architecture comes into the picture, we use USE CASES instead of ViewModels for all our Business logic.

Now, we understood why do we need use cases? But What are Use Cases?

Screenshot

Use case is an action we can do within a feature.

For ex. We have feature called “Profile” which can have actions such as

  • Getting user profile data
  • Updating user profile photo
  • Editing user profile

All the above are USE CASES of a feature.

Advantages of Use Cases :

  1. Helps removing code Duplication : Now if we want to get User Profile data in two different ViewModels, we can easily call one method from our USE_CASE class instead of putting the same method in two separate ViewModels.

  2. Screaming Architecture : The term “screaming architecture” is used when we can, just by looking at a new project at a glance, get the core idea of what the project does and what it is about. Similarly, Use Case should be made in a way that anyone can understand just by looking at the class name that what it does . For ex. GetUsersUseCase is used to get list of users from a data source.

Screenshot

HOW SHOULD YOU DIVIDE YOUR PROJECT ?

The code is divided into three separate layers:

  1. Presentation Layer which includes all UI stuff, Composables, XMLs, Views & ViewModels.

Screenshot

  1. Domain Layer contains our Business Logic (most important our USE CASES)

Screenshot

  1. Data Layer contains our data, all our Databases and Repository Implementation.

Screenshot


Screenshot

GitHub

https://github.com/Deepanshibajaj1503/CleanArchitecture
You might also like...

Template for MVVM Architecture Clean Code.

Template for MVVM Architecture Clean Code.

Template for MVVM Architecture. This is basic template for android app follwing MVVM architecture and latest tech stack. You don't need to create and add basic code and depency for start project using MVVM architecture. Just use this template and boost your productivity.

May 3, 2022

MVVM RECIPE ANDROID APP Is an app where I show how to use MVVM, retrofit, dagger hilt, coroutine, liveData, Kotlin, navigation component, and so on...

MVVM RECIPE ANDROID APP Is an app where I show how to use MVVM, retrofit, dagger hilt, coroutine, liveData, Kotlin, navigation component, and so on...

MVVM RECIPE ANDROID APP Is an app where I show how to use MVVM, retrofit, dagger hilt, coroutine, liveData, kotlin, navigation component, and so on...

Apr 4, 2022

📝 A demo todo/notes app which demonstrates the use of MVVM architecture, Navigation Component Library, Room Database, LiveData, Coroutines

📝 A demo todo/notes app which demonstrates the use of MVVM architecture, Navigation Component Library, Room Database, LiveData, Coroutines

📝 MyNotes A demo notes/todo app which demonstrates the use of MVVM architecture, Navigation Component Library, Room Database, LiveData, Coroutines et

May 9, 2022

A more lightweight and simpler to use MVVM architecture for Android.

A more lightweight and simpler to use MVVM architecture for Android.

A more lightweight and simpler to use MVVM architecture for Android, Data and views are two-way bound.

May 17, 2022

A full-featured framework that allows building android applications following the principles of Clean Architecture.

EasyMVP A powerful, and very simple MVP library with annotation processing and bytecode weaving. EasyMVP eliminates the boilerplate code for dealing w

Apr 24, 2022

Template for using Clean Architecture Concepts in Android

Template for using Clean Architecture Concepts in Android

AndroidCleanArchitecture Template for using Clean Architecture Concepts in Android We have separated the layers into three main group Presentation/App

Apr 4, 2022

Playground project built with MVVM with Clean Artchitect to try out new tech in Android 🌍

Clean-MVVM-Playground Playground project built with MVVM with Clean Artchitect to try out new tech in Android 🌍 Features 🕹 100% Kotlin Following MVV

May 5, 2022

MVVM + Clean + Hilt + Mockk

Android - MarvelApp What is this repository for? This repository is to show you my skills programming native Android. If you are interested in my prof

Nov 6, 2021

Ceci est une application d'actualités de l'architecture MVVM avec Kotlin

Ceci est une application d'actualités de l'architecture MVVM avec Kotlin

MVVM-Appli Infos Ceci est une application d'actualités de l'architecture MVVM avec Kotlin utilisant des composants : Retrofit, Room, Coroutines, et Na

Nov 4, 2021
Chat App MVVM + Clean ArchitectureChat App MVVM + Clean Architecture
Chat App MVVM + Clean ArchitectureChat App MVVM + Clean Architecture

Chat App MVVM + Clean Architecture This Android application built using MVVM + Clean Architecture architecture approach and is written 100% in Kotlin.

Oct 14, 2021
🎯 Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of Jetpack Compose with Modern Android Architecture Components & MVVM Architecture.
🎯 Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of Jetpack Compose with Modern Android Architecture Components & MVVM Architecture.

?? Einsen Einsen is a prioritization app that uses Eisenhower matrix technique as workflow to prioritize a list of tasks & built to Demonstrate use of

May 15, 2022
📊 A Minimal Expense Tracker App built to demonstrate the use of modern android architecture component with MVVM Architecture
📊 A Minimal Expense Tracker App built to demonstrate the use of modern android architecture component with MVVM Architecture

Expenso ?? A Simple Expense Tracker App ?? built to demonstrate the use of modern android architecture component with MVVM Architecture ?? . Made with

May 22, 2022
An android app built using Kotlin following Multi-Module Clean Architecture MVVM
An android app built using Kotlin following Multi-Module Clean Architecture MVVM

RickyandMorty An android app built using Kotlin that consumes RickyadMorty API to display characters.It has been built following Clean Architecture Pr

Feb 3, 2022
JeTaxi is built on Clean Architecture-MVVM with Kotlin and follows modern android development trends.
 JeTaxi is built on Clean Architecture-MVVM with Kotlin and follows modern android development trends.

JeTaxi is built on Clean Architecture-MVVM with Kotlin and follows modern android development trends. Also, It uses some of Jetpack and popular libraries. These are Kotlin Coroutine-Flow, kotlinx.serialization, Hilt, Compose, Accompanist, Retrofit2, OkHttp3, Chucker, MockWebServer, Truth.

May 19, 2022
AAC MVVM + Clean Architecture + Coroutine Flow

GithubBrowser MVVM Clean Architecture Sample AAC MVVM + Clean Architecture + Coroutine Flow 본 샘플 프로젝트는 https://github.com/omjoonkim/GitHubBrowserApp 을

May 3, 2022
An Android Template with MVVM and Clean Architecture
An Android Template with MVVM and Clean Architecture

MVVMTemplate ??‍ A simple Android template that lets you create an Android project quickly. How to use ?? Just click on button to create a new repo st

May 16, 2022
A simple Cat Search app, performed the search by cat breed name, using MVVM clean Architecture.
 A simple Cat Search app, performed the search by cat breed name, using MVVM clean Architecture.

CatSearchApp A simple Cat Search app, performed the search by cat breed name, using MVVM clean Architecture. The App is using the The Cat Api for sear

Oct 21, 2021
Image Search used MVVM with Clean Architecture

ImageSearchCleanArch Readme In this project I used MVVM with Clean Architecture. MVVM provides a clean separation of concerns between user interface a

Nov 19, 2021
Retrieve Data from an API using MVVM Clean Architecture and Jetpack Compose
Retrieve Data from an API using MVVM Clean Architecture and Jetpack Compose

MVVM Clean Architecture Demo Retrieve Data from an API using MVVM Clean Architecture and Jetpack Compose. It simply shows a list of movies fetched fro

Mar 27, 2022