Skip to content

1. Architecture

Khoshnaw edited this page Mar 10, 2022 · 1 revision

Introduction

Starting the development of software without a clear architecture will cause a disaster. The same way that starting construction of a building without a clear architecture will cause a disaster. It is true that without an architecture you can go really fast for the first few features in the app but does that really matter! If you are not able to do any major changes in the software after a year. Logging with google took one week to implement but after one year of development logging in with Facebook took a month or two and even then it was really buggy. If you are too scared to do anything in the software after a few years. Does building the first few features fast really matter?

“The only way to go fast, is to go well.” ― Robert C. Martin, Clean Architecture

Clean Architecture

There are multiple common architectures that you can use for your software. But I think clean architecture is the most commonly used architecture in the android development community. So I choose to use clean architecture for this template. While studying Clean architecture I read multiple articles about implementing clean architecture in android. I also checked a few GitHub repositories but most of them didn't have what I wanted. I believe most of them are the wrong implementation of clean architecture and the implementation violated the architecture principles. So for this template, I will depend on this article by Robert C. Martin

Architecture

As shown in the above diagram the template consists of 4 architecture layers. Be careful that those layers are architecture layers AND YOU DON’T HAVE TO CREATE A MODULE FOR EACH LAYER. Software components (modules) are different from architecture layers. You can have as many software components as you need in each architecture layer. In android, we create software components by modules. So for example we can separate our entities into two different modules or even more. The same thing applies to use cases and other layers.

ComponentDiagram

For this template, eight different software components have been used as shown in the diagram.

  1. In the innermost layer, we have an entity which is a java module.
  2. Then In the second layer, we have useCase another java module.
  3. For the third layer, we have two modules: repository and ViewModel both of them are android module with as minimum dependency as possible on the android platform.
  4. And in the outermost layer, We have 4 heavily dependent on the android framework modules. The application is our actual application module. UI, Remote and DB are also android modules.

Of Course, you can have more layers but I don’t think having fewer layers will be a good idea. For this template, we are trying to have the most basic implementation possible so we go with 4 layers.

Clone this wiki locally