/Architecture-With-MVI

Architecture With MVI using Kotlin, Coroutines, Retrofit and Unit test

Primary LanguageKotlin

Architecture With MVI using Kotlin, Coroutines, Retrofit and Unit test

MVI (Model-View-Intent) streamlines the process of creating and developing applications by introducing a reactive approach

This repository contains a sample app that implements MVI architecture using Kotlin, ViewModel, Retrofit, Coroutines, Hilt and etc to make login screen and receive the results.

How does the MVI work?

User does an action which will be an Intent → Intent is a state which is an input to model → Model stores state and send the requested state to the View → View Loads the state from Model → Displays to the user. If we observe, the data will always flow from the user and end with the user through intent. It cannot be the other way, Hence it's called Unidirectional architecture. If the user does one more action the same cycle is repeated, hence it is Cyclic.

MVI Cycle Description

The app has the following packages:

  1. core: It contains (Dependency injection modules, Constants class, and Main App class).
  2. Features: It contains packages of screens we have in the application each screen package contains
  • data: it contains APIs and modules related to that screen
  • UI: it contains intents, states, and UI classes like activity, fragments..etc, and view models
  • use-cases: it contains the use cases classes responsible for the business and logic of the data we received from the models.
  1. helpers: Helper classes.

Unit Test: Unit-test for LoginUseCase class done as a sample you can use to have a good step with the real implementation.

  1. LoginUseCase class Code

Note:

The API link is only as an example for the explanation but it does not work You can use your own link, you can set your API link in Build.gradle

Reference resources:

  1. Coroutines: Check here
  2. Retrofit: Check here
  3. Hilt: Check here
  4. MVI: Check here