#TECH

How to design the mobile app by using android clean architecture

I have seen lots of mobile apps that are not designed as per the best practices and need a lot of improvements. These apps don’t provide surety regarding their quality and can succumb to disaster any time. In such cases, it is important to improve the design part and make it better. After reading a lot of discussions about it and doing my share of R&D, I found out a better way to design the app by using Clean Architecture or Modular Architecture. I found it very useful when I applied this architecture in one of my existing projects by doing some refinement and inspiration.

Android Modular Architecture

When you have just started working on modular architecture, the main concern is how to split application in the modules. As a learner, you are always wondering how you can choose the best way to divide the application into several modules.

However, there is no fixed structure for this purpose. So instead of one single big module where all functionality is mixed up, it’s better to split the application into small modules according to the functionality or as per your requirement.

If you are working on a project from scratch then it’s easy to split the application into small modules to have a better design. One thumb rule is to break the module according to the functionality. Each module should follow the single principle for which it is created. For example, UI module should contain all UI related classes and stuff. Network module should only have the network related classes. By this way, each member of a team can work independently on their module.

So the package structure can be like-

com.android.app.resources

com.android.app.data

com.android.app.logic

As soon as you start working on the project with this structure, it is possible that you need to split the modules even further into submodules. For example, data module might have objects showing product and customer data, so according to that, you can split into product and customer module.

Modular architecture also minimizes the build time which is very helpful if we are working on a big project when each minute of development is very very crucial. Enhancing build time is very essential, not only for productivity but also for a faster product launch in the market.

In my current project, earlier there was the only developer, single repository but now team size has been increased and now there are 4 developers and 20 repositories. So we have split our app into modules like- dashboard, common, resources, auth, app.

It is quite satisfying to see that such a big monolithic code into small independent pieces. Each module is hosted in its own GIT repository. This is also helpful if you need the same functionality in your another project. So the app structure may be like this-

Modular-Example
|
 \ app
|
 \ dashboard

Modular-Example is the name of the application and app is the main app code and dashboard are the separated module. Each of the modules has its own build script. Also, the main project has its own build script. You can find the sample app here. Here is the diagram to show the same-

Modular-Example
|
 \ app
|   |
|    \ build.gradle
 \ dashboard
|   |
|    \ build.gradle
|
 \ build.gradle

To reduce coupling in the application’s design, smaller modules are easy to edit or you can say that they provide more flexibility. It’s very easy to build different versions of the application with different sets of features as per your requirements. For example- ‘basic’, ‘standard’ and ‘enterprise’. The same things are difficult to achieve if you are working on a monolithic application.

I hope you try to structure your application design according to modular structure and I am sure that this will provide you more flexibility in your project.

Reference-:

  1. https://proandroiddev.com/modular-architecture-for-faster-build-time-d58397cb7bfe
  2. http://five.agency/android-architecture-part-4-applying-clean-architecture-on-android-hands-on/

You might also like