The current structure of my app is as follows:
- One activity and multiple fragments (about 25 fragments)
- One huge monolithic repository
- One huge monolithic viewmodel
- Databinding is being used but with one huge monolithic handler class
- Navigation Component with one nav graph for the entire application
I've been learning as I go and I now realize my architecture is very poor. I want to achieve proper MVVM and also to modularize the project. My end goal is to have an architecture that is more maintainable and testable. I'm aiming for the following:
- Separate viewmodels for each fragment
- Separate repositories for each entity (or roughly each data access object)
- Separate data binding handlers for each fragment
- The entire project split into different library modules, with each module being specific to a feature or core function
In order to achieve the above outcome, is the following a reasonable plan?
- Create separate viewmodels for each fragment
- Create separate repositories for each entity
- Create separate handler classes for each fragment
- Divide the entire project into separate modules
Some of the sources I have come across while researching are:
- https://developer.android.com/jetpack/guide
- https://proandroiddev.com/intro-to-app-modularization-42411e4c421e
- https://stackoverflow.com/questions/44375276/when-using-mvvm-on-android-should-each-activity-have-one-and-only-one-viewmod?rq=1
- https://stackoverflow.com/questions/51263301/multi-module-navigation-with-architecture-components
- https://medium.com/swlh/using-the-navigation-component-in-a-modular-world-e7578825962
- https://stackoverflow.com/questions/50466743/should-we-create-a-separate-repository-for-each-activity-or-single-repository-fo
Please could you advise whether the above rough plan is a good one and any pitfalls I should be on the look out for?