📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.


Android Components Architecture in a Modular Word

CircleCI Codecov Codacy CodeStyle Kotlin Version Gradle API License

Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 approach to Android application development using Kotlin and latest tech-stack.

The goal of the project is to demonstrate best practices, provide a set of guidelines, and present modern Android application architecture that is modular, scalable, maintainable and testable. This application may look simple, but it has all of these small details that will set the rock-solid foundation of the larger app suitable for bigger teams and long application lifecycle management.

Table of Contents


The project received different mentions/reference from Android Developer Community:

  • Android Weekly Newsletter that helps you to stay cutting-edge with your Android Development.
  • AndroidSweets Fresh news from Droid zone.
  • Android Awesome A curated list of awesome Android libraries and resources.
  • Droidcon Blog posts from leading authorities and video archive from droidcons around the world.
  • DroidconKE The official DroidconKE 2020 conference App.
  • Github trending See what the GitHub community is most excited about today.
  • KotlinBy A curated list of awesome Kotlin related stuff.
  • Reddit: Discussion about Kotlin, a statically typed programming language for the JVM, Android, JavaScript, and native.


Environment setup

First off, you require the latest Android Studio 4.1.0 (or newer) to be able to build the app.

You need to supply keys for Marvel API. You can find information about how to gain access by using the link.

When you obtain the keys, you can provide them to the app by putting the following in the local.properties project root file:

#Marvel API KEYS
marvel.key.public = <insert>
marvel.key.private = <insert>

Code style

To maintain the style and quality of the code, are used the bellow static analysis tools. All of them use properly configuration and you find them in the project root directory .{toolName}.

Tools Config file Check command Fix command
detekt /.detekt ./gradlew detekt -
ktlint - ./gradlew ktlint ./gradlew ktlintFormat
spotless /.spotless ./gradlew spotlessCheck ./gradlew spotlessApply
lint /.lint ./gradlew lint -

All these tools are integrated in pre-commit git hook, in order ensure that all static analysis and tests passes before you can commit your changes. To skip them for specific commit add this option at your git command:

git commit --no-verify

The pre-commit git hooks have exactly the same checks as CircleCI and are defined in this script. This step ensures that all commits comply with the established rules. However the continuous integration will ultimately be validated that the changes are correct.


App support different screen sizes and the content has been adapted to fit for mobile devices and tablets. To do that, it has been created a flexible layout using one or more of the following concepts:

In terms of design has been followed recommendations android material design comprehensive guide for visual, motion, and interaction design across platforms and devices. Granting the project in this way a great user experience (UX) and user interface (UI). For more info about UX best practices visit link.

Moreover, has been implemented support for dark theme with the following benefits:

  • Can reduce power usage by a significant amount (depending on the device’s screen technology).
  • Improves visibility for users with low vision and those who are sensitive to bright light.
  • Makes it easier for anyone to use a device in a low-light environment.
Mode Characters list Characters favorite Character detail


The architecture of the application is based, apply and strictly complies with each of the following 5 points:


Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing the following dependence between them:

The above graph shows the app modularisation:

  • :app depends on :core and indirectly depends on :features by dynamic-features.
  • :features modules depends on :commons, :core, :libraries and :app.
  • :core and :commons only depends for possible utils on :libraries.
  • :libraries don’t have any dependency.

App module

The :app module is an com.android.application, which is needed to create the app bundle. It is also responsible for initiating the dependency graph, play core and another project global libraries, differentiating especially between different app environments.

Core module

The :core module is an com.android.library for serving network requests or accessing to the database. Providing the data source for the many features that require it.

Features modules

The :features module are an com.android.dynamic-feature is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module.


Commons modules

The :commons modules are an com.android.library only contains code and resources which are shared between feature modules. Reusing this way resources, layouts, views, and components in the different features modules, without the need to duplicate code.

ui views

Libraries modules

The :libraries modules are an com.android.library, basically contains different utilities that can be used by the different modules.

Architecture components

Ideally, ViewModels shouldn’t know anything about Android. This improves testability, leak safety and modularity. ViewModels have different scopes than activities or fragments. While a ViewModel is alive and running, an activity can be in any of its lifecycle states. Activities and fragments can be destroyed and created again while the ViewModel is unaware.

Passing a reference of the View (activity or fragment) to the ViewModel is a serious risk. Lets assume the ViewModel requests data from the network and the data comes back some time later. At that moment, the View reference might be destroyed or might be an old activity that is no longer visible, generating a memory leak and, possibly, a crash.

The communication between the different layers follow the above diagram using the reactive paradigm, observing changes on components without need of callbacks avoiding leaks and edge cases related with them.

Build variants

The application has different product flavours: Dev, QA, Prod. Each variant has a specific target environment and to make easier to distinguish them the app uses a specific icon colour for debug and release build variant with descriptive app name. In this case and given that it's a sample, all variants have the same Marvel API endpoint. But the idea is to have different environments target for Development and QA respectively, what doesn't affect the production environment. This is applicable to any tool, platform, service what is being used. For more information about build variant, check this link.










The documentation is generated following KDoc language (the equivalent of Java's JavaDoc) via documentation engine for Kotlin Dokka.

To consult it check this link or open the project /docs directory.


This project takes advantage of many popular libraries, plugins and tools of the Android ecosystem. Most of the libraries are in the stable version, unless there is a good reason to use non-stable dependency.


  • Jetpack:
    • Android KTX - provide concise, idiomatic Kotlin to Jetpack and Android platform APIs.
    • AndroidX - major improvement to the original Android Support Library, which is no longer maintained.
    • Benchmark - handles warmup, measures your code performance, and outputs benchmarking results to the Android Studio console.
    • Data Binding - allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.
    • Lifecycle - perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
    • LiveData - lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services.
    • Navigation - helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer.
    • Paging - helps you load and display small chunks of data at a time. Loading partial data on demand reduces usage of network bandwidth and system resources.
    • Room - persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite.
    • ViewModel - designed to store and manage UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations.
  • Coroutines - managing background threads with simplified code and reducing needs for callbacks.
  • Dagger2 - dependency injector for replacement all FactoryFactory classes.
  • Retrofit - type-safe HTTP client.
  • Coil - image loading library for Android backed by Kotlin Coroutines.
  • Moshi - makes it easy to parse JSON into Kotlin objects.
  • Timber - a logger with a small, extensible API which provides utility on top of Android's normal Log class.
  • Stetho - debug bridge for applications via Chrome Developer Tools.
  • and more...

Test dependencies

  • UIAutomator - a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
  • Espresso - to write concise, beautiful, and reliable Android UI tests
  • Robolectric - industry-standard unit testing framework for Android.
  • JUnit - a simple framework to write repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks.
  • Mockk - provides DSL to mock behavior. Built from zero to fit Kotlin language.
  • AndroidX - the androidx test library provides an extensive framework for testing Android apps.
  • and more...


  • Ktlint - an anti-bikeshedding Kotlin linter with built-in formatter.
  • Detekt - a static code analysis tool for the Kotlin programming language.
  • Spotless - a code formatter can do more than just find formatting errors.
  • Versions - make easy to determine which dependencies have updates.
  • SafeArgs - generates simple object and builder classes for type-safe navigation and access to any associated arguments.
  • Jacoco - code coverage library
  • and more...



This is project is a sample, to inspire you and should handle most of the common cases, but obviously not all. If you need to take a look at additional resources to find solutions for your project, visit these interesting projects:


A collection of very interesting articles related last android community tendencies and recommendations for start to take in consideration for your current/next project:


The open-source community create and maintains tons of awesome libraries making your job more easy, giving the opportunity to use them in your developments. Here are a very important collection of them:

Best practices

Avoid reinventing the wheel by following these guidelines:


Google Developers Codelabs provide a guided, tutorial, hands-on coding experience. Most codelabs will step you through the process of building a small application, or adding a new feature to an existing application. They cover a wide range of android concepts to learn and practice:


All contributions are welcome! Please feel free to post questions, recommendations, ideas, bugs by create new issue following the template or if you want create directly new pull request.


Madalin Valceleanu

Linkedin Twitter Medium Web


Copyright 2019-2020 vmadalin.com

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
  • How to inject shared one instance of ViewModule to different fragments?

    How to inject shared one instance of ViewModule to different fragments?

    is it possible to inject the same veivmodel into different fragments? I mean BaseFragment<FragmentSomeBinding, SharedViewModel>

    opened by DigitalKoi 4
  • Add projectDependencyGraph Gradle

    Add projectDependencyGraph Gradle


    Add a new Gradle task to the project, which generates image with dependency graph from the project modules structure. Implementation by Jake Wharton https://github.com/JakeWharton/SdkSearch/blob/master/gradle/projectDependencyGraph.gradle

    Type of change

    Please delete options that are not relevant.

    • [ ] New feature (non-breaking change which adds functionality)

    How Has This Been Tested

    • [ ] Readme file contains a new generated picture


    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] My changes generate no new warnings
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    • [x] Any dependent changes have been merged and published in downstream modules
    opened by michalharakal 3
  • fix to create a release apk

    fix to create a release apk


    A fix to allow assign and run successfully production apk, obfuscation need to be optimized

    Fixes #10

    Type of change

    • added coil as a dependency on app module
    • dynamic features are declared not instant so
    • added proguard rule on app module

    How Has This Been Tested

    • [ ] to generate an universal apk run this gradle task: packageProdReleaseUniversalApk (I don't know why but in my case the traditional step by step release project from the IDE generate an apk that does not include all the features)


    • [x] My code follows the style guidelines of this project
    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] My changes generate no new warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] New and existing unit tests pass locally with my changes
    • [ ] Any dependent changes have been merged and published in downstream modules
    opened by tidoemanuele 3
  • Migrating from Fabric to Firebase

    Migrating from Fabric to Firebase


    I wanted to request that you migrate your code from Fabric to Firebase.

    Basic Information

    • Device type: Android
    • OS version:
    • App version:
    enhancement good first issue 
    opened by ssakhavi 2
  • PayPal donation link doesn't work.

    PayPal donation link doesn't work.


    PayPal donation link doesn't work. Please update the PayPal link at FUNDING.yml Thank you

    opened by ofir-bar 2
  • Question about code coverage

    Question about code coverage


    Can you elaborate on how you exclude the app directory from your code coverage in codecov?

    Basic Information

    • Device type: Android
    • OS version:
    • App version: latest


    I see that in your diagram you don't have things like SampleMainActivity tested because they are excluded from the graph?


    I was wonder how you did this because I see no ignore flags in your codecov/config.yml nor are there any exclusions in your jacoco configurations, at least that I can find!


    opened by Stegnerd 2
  • Question about using plugin in the id of plugins

    Question about using plugin in the id of plugins


    In regards to this project it is a great learning tool and I was curious to walk through it! My question is in the BuildPlugins file you set all the plugins to use plugins.xxxx. for example BuildPlugins.detekt, yet when I try to build it says that it cannot find a plugin with an id plugin.detekt. But if I use the following: io.gitlab.arturbosch.detekt it is found and moves to the next error in the build. Can you elaborate on that?

    Thank you so much

    opened by Stegnerd 2
  • Question: Migration to koin or Gson

    Question: Migration to koin or Gson

    Is there any ongoing thinking to refractor/migrate the project to Koin/ Moshi. As Moshi seems to be GSON 3.0 and possibly Koin will replace dagger in the near future.

    opened by mwshubham 2
  • How to create a release apk that can be installed on device

    How to create a release apk that can be installed on device


    I'm trying to use this project as a sort of bootstrap for a new android project, when a signed release apk is created by android studio and installed it crashes instantly due to being unable to find the dynamic module fragments.

    Basic Information

    • OS version: Linux
    • App version: android studio 3.5.3


    Using android studios Build -> generate signed apk -> normal apk If you install that generated apk it will crash with a classpath issue with Coil, if you fix that (I added it to core's dependencies) then you get

    Process: com.vmadalin.android, PID: 18602
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vmadalin.android/com.vmadalin.android.SampleMainActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
            at android.os.Handler.dispatchMessage(Handler.java:112)
            at android.os.Looper.loop(Looper.java:216)
            at android.app.ActivityThread.main(ActivityThread.java:7625)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
         Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
         Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
         Caused by: androidx.fragment.app.Fragment$e: Unable to instantiate fragment com.vmadalin.dynamicfeatures.home.ui.HomeFragment: make sure class name exists

    I assumed as all dynamic modules are set to install time delivery a monolith apk should work. I also tried creating an aab, using bundletool to create a universal apk and installing that but I ended up with the same error.

    What is the correct way to do a release APK?

    opened by bobthekingofegypt 2
  • Project doesn't compile and give 6 errors

    Project doesn't compile and give 6 errors


    Downloaded the latest Master branch and got a marvel API key. Then I was prompted to update to Android Studio 4.0 which is still in early phases. After that I got 6 compile errors and tried to downgrade gradle. This project is not compiling!

    Basic Information

    • Device type: Mac
    • OS version: OSX Catalina
    • App version:



    opened by JimClermonts 2
  • Repository is not glued to Interface

    Repository is not glued to Interface

    Thank you for the great sample. I wonder why You do not have an interface for MarvelRepository or any other Repositories in your core module. You are following SOLID principles, and that is D is SOLID to follow dependency inversion.

    High-level modules should not depend on low-level modules. Both should depend on abstractions (e.g., interfaces)

    Using interfaces will also simplify unit testing.

    Were there any specific reason that you did not use interface for Repository?

    opened by Ali-Rezaei 0
  • Add client to retrofit

    Add client to retrofit

    Fixes bug of not adding the client to retrofit

    opened by razavioo 1
  • Why not Hilt?

    Why not Hilt?

    Why don't you use Hilt? Google says

    Dagger and Hilt code can coexist in the same codebase. However, in most cases it is best to use Hilt to manage all of your usage of Dagger on Android.

    enhancement good first issue 
    opened by Piasy 6
Madalin Valceleanu
Mobile Software Developer @Vonage Enthusiast and passionate about clean code, modular architecture, design patterns and automation. 🇷🇴 - 🇪🇸 - 🇬🇧
Madalin Valceleanu
Saga of Star wars - An Android sample repo showcasing Clean Arch with MVVM and Epoxy models

Star Wars Universe This is a showcase android application written in Kotlin and follows Clean Code architecture to showcase Characters from the StarWa

Adit Lal 5 Jul 24, 2021
MVVM(Model View ViewModel) sample in Kotlin using the components ViewModel, LiveData and Retrofit library

kotlin-mvvm Languages: English, Spanish MVVM(Model View ViewModel) sample in Kotlin using the components ViewModel, LiveData, the libraries Retrofit,

Eduardo José Medina Alfaro 334 Aug 4, 2021
A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

Android Architecture Blueprints v2 Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android a

Android 39.1k Jul 27, 2021
Android Viper template with Kotlin, Dagger 2, Retrofit & RxJava

Android VIPER Architecture Example This repository contains a detailed sample client-server app that implements VIPER(View-Interactor-Presenter-Entity

OmiSoft 26 Jul 12, 2021

组件化+Jetpack+Kotlin+MVVM 一、项目简介 该项目主要以组件化+Jetpack+MVVM为架构,使用Kotlin语言,集合了最新的Jetpack组件,如Navigation、Paging3、Room等,另外还加上了依赖注入框架Koin和图片加载框架Coil。 网络请求部分使用OkH

fuusy 277 Aug 4, 2021
Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Next 108 Jul 26, 2021