🚀 Sample Android Clean Architecture on Rorty App focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Overview

Android Clean Architecture

CodeStyle Kotlin Version Gradle API License

Android Clean Architecture in Rorty is a sample project that presents modern, 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.

Rorty-Android

An android app built using Kotlin that consumes Rick and Morty API to display characters,episodes,Location from the TV Series. It has been built following Clean Architecture Principle, Repository Pattern, MVVM Architecture in the presentation layer as well as Jetpack components.

Environment Setup

You require the Android Studio Bumblebee (2021.1.1) RC 1 to be able to build the app.

Architecture

A well planned architecture is extremely important for an app to scale and all architectures have one common goal- to manage complexity of your app. This isn't something to be worried about in smaller apps however it may prove very useful when working on apps with longer development lifecycle and a bigger team.

Clean architecture was proposed by Robert C. Martin in 2012 in the Clean Code Blog and it follow the SOLID principle.

Clean Architecture

The circles represent different layers of your app. Note that:

  • The center circle is the most abstract, and the outer circle is the most concrete. This is called the Abstraction Principle. The Abstraction Principle specifies that inner circles should contain business logic, and outer circles should contain implementation details.

  • Another principle of Clean Architecture is the Dependency Inversion. This rule specifies that each circle can depend only on the nearest inward circle ie. low-level modules do not depend on high-level modules but the other way around.

Clean Architecture Diagram

Why Clean Architecture?

  • Loose coupling between the code - The code can easily be modified without affecting any or a large part of the app's codebase thus easier to scale the application later on.
  • Easier to test code.
  • Separation of Concern - Different modules have specific responsibilities making it easier for modification and maintenance.

S.O.L.I.D Principles

  • Single Responsibility: Each software component should have only one reason to change – one responsibility.

  • Open-Closed: You should be able to extend the behavior of a component, without breaking its usage, or modifying its extensions.

  • Liskov Substitution: If you have a class of one type, and any subclasses of that class, you should be able to represent the base class usage with the subclass, without breaking the app.

  • Interface Segregation: It’s better to have many smaller interfaces than a large one, to prevent the class from implementing the methods that it doesn’t need.

  • Dependency Inversion: Components should depend on abstractions rather than concrete implementations. Also higher level modules shouldn’t depend on lower level modules.

Layers

Project Structure

Project Structure

1. Data

The data layer is responsible for selecting the proper data source for the domain layer. It contains the implementations of the repositories declared in the domain layer.

Components of data layer include:

  • model

    -dto: Defines dto of ui model, also perform data transformation between domain, response and entity models.

    -local: Defines the schema of SQLite database.

    -remote: Defines POJO of network responses.

  • local: This is responsible for performing caching operations using Room.

  • remote: This is responsible for performing network operations eg. defining API endpoints using Retrofit.

  • repository: Responsible for exposing data to the domain layer.

2. Domain

This is the core layer of the application. The domain layer is independent of any other layers thus ] domain business logic can be independent from other layers.This means that changes in other layers will have no effect on domain layer eg. screen UI (presentation layer) or changing database (data layer) will not result in any code change withing domain layer.

Components of domain layer include:

  • usecase: They enclose a single action, like getting data from a database or posting to a service. They use the repositories to resolve the action they are supposed to do. They usually override the operator invoke , so they can be called as a function.

3. Presentation

The app layer contains components involved in showing information to the user. The main part of this layer are the views(activity, fragment) and ViewModels.

Demo Screenshots

Mode Splash Characters Character Favorite
Light
Dark
Mode Character Detail Settings
Light
Dark

Tech Stacks

This project uses many of the popular libraries, plugins and tools of the android ecosystem.

  • 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.
    • Lifecycle - Perform actions in response to a change in the lifecycle status of another component, such as activities and fragments.
    • 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.
    • Room - Provides an abstraction layer over SQLite used for offline data caching.
    • Paging3 - The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView.
    • ViewBinding - View binding is a feature that allows you to more easily write code that interacts with views.
  • Hilt - Dependency Injection library.

  • Retrofit - Type-safe http client and supports coroutines out of the box.

  • OkHttp-Logging-Interceptor - Logs HTTP request and response data.

  • Coroutines - Library Support for coroutines.

  • Flow - Flows are built on top of coroutines and can provide multiple values. A flow is conceptually a stream of data that can be computed asynchronously.

  • Material Design - Build awesome beautiful UIs.

  • Coroutines - Library Support for coroutines,provides runBlocking coroutine builder used in tests.

  • Timber - A logger with a small, extensible API which provides utility on top of Android's normal Log class.

  • Moshi - A modern JSON library for Kotlin and Java.

  • Chucker - An HTTP inspector for Android & OkHTTP (like Charles but on device).

  • Coil - Image loading for Android backed by Kotlin Coroutines.

  • Gradle Kotlin DSL - makes it easy to manage dependency all module that we have

  • Test

    • Robolectric - Running tests on an Android emulator or device is slow! Building, deploying, and launching the app often takes a minute or more. That’s no way to do TDD. There must be a better way.
    • Mockk - A modern Mockk library for UnitTest.
    • Turbine - Turbine is a small testing library for kotlinx.coroutines Flow.
    • Truth - Truth makes your test assertions and failure messages more readable.
    • Coroutine-Test - Provides testing utilities for effectively testing coroutines.
    • ...

Plugin

Code Analyze Tools

  • Ktlint - A ktlint gradle plugin. Provides a convenient wrapper plugin over the ktlint project.
  • Spotless - It’s pretty useful in automating fixes for pretty simple (and common) formatting mistakes as in spaces, newlines, removing unnecessary imports, etc.
  • Detekt - Static code analysis for Kotlin.

🚀 Posts In Medium

Article

🤝 Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Open an issue first to discuss what you would like to change.
  2. Fork the Project
  3. Create your feature branch (git checkout -b feature/amazing-feature)
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a pull request

Please make sure to update tests as appropriate.

✍️ Authors

👤 developersancho

Linkedin Medium

Feel free to ping me 😉

License

Copyright © 2022 - developersancho

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

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Animal-Kingdom - CLEAN Architecture with MVVM and Jetpack-Compose
Animal-Kingdom - CLEAN Architecture with MVVM and Jetpack-Compose

CLEAN Architecture with MVVM and Jetpack-Compose. About the app I have created t

Snapchat Clone with Jetpack Compose and Clean Architecture
Snapchat Clone with Jetpack Compose and Clean Architecture

Snapchat Clone with Jetpack Compose and Clean Architecture - Navigation Components, CamaraX, android-maps-compose, Exoplayer, Detekt, Coil, Gradle Secrets, Permission Handling.

Android Clean Architecture That Screams (MVVM + JetPack Compose UI + Flow + State)

Android Clean Architecture That Screams (MVVM + JetPack Compose UI + Flow + State)

FirebaseSignInWithGoogle app it's written in Kotlin and shows a simple solution for implementing Firebase Authentication with Google, using Jetpack Compose on Android.
FirebaseSignInWithGoogle app it's written in Kotlin and shows a simple solution for implementing Firebase Authentication with Google, using Jetpack Compose on Android.

FirebaseSignInWithGoogle It's an app built with Kotlin that shows how to authenticate users with Firebase using Android Architecture Components and th

It's a simple app written in Kotlin that shows a simple solution for how to save an image into Firebase Storage, save the URL in Firestore, and read it back using Jetpack Compose.
It's a simple app written in Kotlin that shows a simple solution for how to save an image into Firebase Storage, save the URL in Firestore, and read it back using Jetpack Compose.

It's a simple app written in Kotlin that shows a simple solution for how to save an image into Firebase Storage, save the URL in Firestore, and read it back using Jetpack Compose.

This is a sample app(For beginners - App #1) built using Jetpack Compose
This is a sample app(For beginners - App #1) built using Jetpack Compose

This is a sample app(For beginners - App #1) built using Jetpack Compose. It is a simple - single screen app to demonstrate use of basic Jetpack Compose UI elements like Text, Image and Button & LazyColumn (Vertical Recyclerview). It also demonstrates how compose manages state with a Boolean State.

A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose
A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose

Authentication A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose Scree

A LibrePhotos android client written using Jetpack Compose and all the latest Android technologies
A LibrePhotos android client written using Jetpack Compose and all the latest Android technologies

UhuruPhotos. A LibrePhotos client UhuruPhotos is an Android client for LibrePhotos written using the latest Android technologies, like Jetpack Compose

TipperCompose - A simple & clean tip calculator using Jetpack Compose
TipperCompose - A simple & clean tip calculator using Jetpack Compose

TipperCompose - A simple & clean tip calculator using Jetpack Compose

Owner
Mr.Sanchez
The Target is Red Apple =) Android & iOS | Kotlin | Flutter | Swift | .NET Core | .NET MVC *** continue as long as we can. living in shadow ***
Mr.Sanchez
A Clean Architecture App to show use of multi module architecture in a Jetpack Compose

Nextflix-Composable A Clean Architecture App to show use of multi-module-archite

Talha Fakıoğlu 196 Dec 19, 2022
This is a simple video games discovery app showcasing UI using Jetpack Compose with Clean Architecture and also tests for composable UI.

Jetpack-Compose-Video-Games-Example ?? This is a simple video games discovery app showcasing UI using Jetpack Compose and also tests for composable UI

Ruben Quadros 60 Dec 27, 2022
Jetpack Compose app gets data from REST API using KTOR Client. Clean Architecture, Dependency Injection...

posts-ktor-client Jetpack Compose app gets data from REST API using KTOR Client. Clean Architecture, Dependency Injection... Posts KTOR Client Demo ap

Raheem 12 Dec 12, 2022
Jetpack compose theming following a google codelab

Jetpack Compose Codelabs This repository contains a set of Android Studio projects to help you learn about Compose in Android. Each sample contains th

Gilbert Ssenyonjo 0 Apr 30, 2022
Android Clean Architecture with MVVM using Jetpack component

Android Clean Architecture with MVVM using Jetpack component ?? What is Clean Architecture? Clean architecture is a category of software design patter

Jbsolutions 6 Dec 10, 2022
CoinList is a simple app based on Jetpack Compose, modern tech-stack and Clean Architecture.

CoinList is a simple app based on Jetpack Compose, modern tech-stack and Clean Architecture. The project is quite simple which shows the list of crypto currencies and their general info details gets from API.

Yıldırım Tam 18 Aug 28, 2022
Jet-CoinList is a simple app based on Jetpack Compose, modern tech-stack and Clean Architecture.

Jet-CoinList is a simple app based on Jetpack Compose, modern tech-stack and Clean Architecture. The project is quite simple which shows the list of crypto currencies and their general info details gets from API.

Yıldırım Tam 18 Aug 28, 2022
PapriCoin demonstrates Jetpack Compose usage to build modern app based on Clean Architecture and newest Tech-Stack

PapriCoin demonstrates Jetpack Compose usage to build modern app based on Clean Architecture and newest Tech-Stack. Repository also has loca

Malik Mukhametzyanov 15 Nov 9, 2022
Carol 12 Sep 25, 2022
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

BHAVNA THACKER 3 Dec 31, 2022