bachhoan88 / CleanArchitecture

Android Kotlin Clean Architecture

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Android Kotlin Clean Architecture & Components Example

CircleCI codecov.io

This is a sample app & basic code that uses Clean Architecture & Components, that is part of a blog post I have written about how to architect android application using the Uncle Bob's clean architecture approach.

NOTE It is a relatively more complex and complete example so if you are not familiar with [Architecture Components][arch], you are highly recommended to check other examples in this repository first.

Introduction

Data-Flow

Structure

Work-Flow

Structure

Handler-Error-Flow

Structure

Domain Layer

  • Contains business model
  • Contains business RULEs
  • Repository interface adapt

Data Layer

  • Implementation Repository
  • Executor API data
  • Storage data to local: Share preferences, database, external storage
  • Mapper data model to domain model
  • Contains data service, third party data service

Presentation Layer

  • View (Activity/Fragment/Layout) Adapt data to view
  • Validate/Submit data input from view via UseCase

Base Code

Base code designed one Activity and multiple Fragment, using Navigation Component to UI navigate Use Dagger2 (version 2.23.2) for Dependencies Injection, You can easily switch to using Koin (I suggestion Dagger for big, super projects) Base code

  • Has created a flow that handles all of the corner cases, you can easily customize them via CleanException, it extends Throwable
  • Added Authorization, Interceptor easily handler and implementations for your project if needed
  • Use ktlint, kotlin-offical for check code conventions, you can run ./gradlew ktlint
  • Use jacoco for full Unit and Instrument test
  • Added basically circle-ci, gitlab-ci with some work-flows
  • Report bugs into Crashlytics via Timber.e

Building

Work from Android Studio 3.2 and above

Unit Test

You can easily write Unit Test up to 70% code coverage lines of code (LOC), if you write focus on

  • Data: API service, Local (database, share preferences), RepositoryImpl, Model Mapper
  • Domain: UseCases, Repository, Exception handlers
  • Presentation: ViewModel, Model Mapper

Libraries used


  • Foundation - Components for core system capabilities, Kotlin extensions and support for multidex and automated testing.
    • AppCompat - Degrade gracefully on older versions of Android.
    • Android KTX - Write more concise, idiomatic Kotlin code.
    • Test - An Android testing framework for unit and runtime UI tests.
  • Architecture - A collection of libraries that help you design robust, testable, and maintainable apps. Start with classes for managing your UI component lifecycle and handling data persistence.
    • Data Binding - Declaratively bind observable data to UI elements.
    • Lifecycles - Create a UI that automatically responds to lifecycle events.
    • LiveData - Build data objects that notify views when the underlying database changes.
    • Navigation - Handle everything needed for in-app navigation.
    • Room - Access your app's SQLite database with in-app objects and compile-time checks.
    • ViewModel - Store UI-related data that isn't destroyed on app rotations. Easily schedule asynchronous tasks for optimal execution.
    • WorkManager - Manage your Android background jobs.
  • UI - Details on why and how to use UI Components in your apps - together or separate
  • Third party
    • Glide for image loading
    • Kotlin Coroutines for managing background threads with simplified code and reducing needs for callbacks
    • ReactiveX library for composing asynchronous and event-based programs by using observable sequences.
    • Dagger2 for dependencies injection
    • Retrofit Type-safe HTTP client for Android
    • EasyPermission is a wrapper library to simplify basic system permissions logic when targeting Android M or higher.

Upcoming features

  • Build layer for library aar

  • Make design support for all application: styles, fonts, theme

  • Interested in seeing a particular feature of the Architecture or Base Code implemented in this app? Please open a new issue.

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.

About

Android Kotlin Clean Architecture

License:Apache License 2.0


Languages

Language:Kotlin 97.8%Language:Java 1.7%Language:Ruby 0.5%