Member-only story
Clean Architecture in Android — A Beginner Approach
As a developer, I’ve always been fascinated by architectures and clean code in general, even before I decided to become a native android developer.
“The goal of software architecture is to minimize the human resources required to build and maintain the required system”
However, writing code that is easy to test, maintainable and that facilitates team collaboration on the code can be hard.
Robert Martin (a.k.a. Uncle Bob) has theorized a solution to reach these goals, writing three books about taking a “clean” approach in the software development world. One of these books is called “Clean Architecture, a Craftsman’s Guide to Software Structure and Design” and inspired the writing of this article.
Yes, but I already have my MVVM architecture in my app, why should I bother?
Well, probably if you are working on a simple project Clean Architecture might seem overkill, but what if you need to decouple modules, testing the modules in isolation, and helping your team to work on separated code containers? Clean Architecture helps developers to avoid spelunking through the software code trying to figure out functionalities and business logic.
A bit of theory (not much I promise)

Probably you’ve seen this layer diagram a lot of times, in my case, it didn’t help very much to understand how to convert these layers in an organized android project, but let’s stay on theory and definitions for the moment.
- Entities: encapsulate enterprise-wide critical business rules. An entity can be an object with methods or a set of data structures and functions
- Use cases: orchestrate the flow of data to and from the entities
- Controllers, Gateways, Presenters: a set of adapters that convert data from the use cases and entities format to a most convenient way, in order to pass the data to the upper level (typically the UI)
- UI, External Interfaces, DB, Web, Devices: the outermost layer of the architecture, generally composed of frameworks such as database and web frameworks.
The dependencies between the layers must be inwards, a lower-level module should not depend on…