Skip to content

Latest commit

 

History

History
70 lines (41 loc) · 3.38 KB

File metadata and controls

70 lines (41 loc) · 3.38 KB

This is an image

Clean Architecture with MVVM in Android

  • In this repository, I am going to combine MVVM with Clean Architecture to build a sample app in Android. The app has 2 main screen: coin list and coin detail. Video demo app will show in the section below.
  • You can click the above link to learn more about Clean Architecture theory

Data flow

This is an image


Diagram of app architecture

There are 3 layers in the structure of project: Presentation layer, Domain layer and Data layer

This is an image

- Presentation layer:

  • This layer includes Android UIs (Activity, Fragment, View,...) and ViewModel.
  • The role of the UIs is to display the application data on the screen. Never put your business logic in Activitys or Fragments.
  • Besides, this layer has a component, which is State holders. In this project, I use State holder to hold data, expose it to the UI via Kotlin Flow.

- Domain layer:

  • Domain layer sits between the Presentation layer and Data layer. It contains all the use case of your application. Each particular features can be considered as a Use case.
  • This layer executes business logic. It receives events from UIs and communicates with Data layer to perform this event, or gets data from Data layer to update UIs.
  • Different from the plain MVVM, most of business logic will execute in Domain layer instead of in ViewModel. ViewModel still has business logic, but less.
  • Repository in Domain layer contains interfaces which have methods to communicate with Data layer.

- Data layer:

  • Data layer will manage data sources: remote, local, etc.
  • Repository in Data layer contains the classes that will implement from interfaces in repository of the Domain layer.

Library


API


Demo app

This is an image


Conclusion

This is a simple project implemented Clean Architecture and MVVM. It has 2 main features: show list coin and view coin detail. I hope the project helps you understand about how to implement MVVM with Clean Architecture in Android Development.

Thanks and best regards.