Skip to content

This project is based on Android Jetpack(UI with Compose), Kotlin, Clean Architecture & Dependency Injection using Hilt.

Notifications You must be signed in to change notification settings

DanhDue/JetCleanArch

Repository files navigation

JetCleanArch - A modern base code.

This project uses many of the popular libraries, plugins, and tools of the Android ecosystem. It is based on Android Jetpack, Kotlin, Clean Architecture & Dependency Injection using Hilt.

I. Introduction

This base code implements the Clean Architecture, follows the SOLID principle and uses Android Jetpack. It presents a modern approach to Android application development using Kotlin and the latest tech stacks.

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.

II. Project Structure:

Clean Architecture Diagram

1. buildSrc

The buildSrc layer is responsible for dependency management. It control and manage all dependencies in one place with Kotlin.

2. Common

The common layer is responsible for common properties. It contains the implementations of the resources files, themes and components declared in the common layer.

  • component: This is responsible for common view components that using app.

  • provider: Defines navigation, resource and theme provider.

  • theme: Defines themes, colors, fonts and resource files.

3. Libraries

The libraries layer is responsible for base structure.

  • framework: Contains different utilities that can be used by the different modules and base structures.

  • jetframework: Contains different utilities that can be used by the different modules and base structures only for Jet Compose.

  • testing: Contains the definitions of the test utilities.

4. 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 includes:

  • 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.

5. 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.

6. Presentation

The presentation layer contains features involved in showing information to the user. The main part of this layer are the views(activity, compose) and ViewModels.

III. Technical Information used in this project:

  1. Programming Language: Android Kotlin.
  2. Architecture: Clean Architecture based on Android Jetpack. For more resources on learning Android development, visit the Developer Guides at developer.android.com.
  3. Multiple Threads: Kotlin Coroutine.
  4. Third Party Libraries: Retrofit, Hilt, Firebase, MockK, etc,...
  5. Unit Test: Android testing framework, MockK, and Robolectric; Unit Test coverage Analysis using JaCoCo; etc,....

Moreover, you can read more detail about some project components by clicking to links contained at References part.

IV. Libraries Used

  • Android Jetpack - 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.
    • 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.
    • ....
  • Compose

    • Material - Build Jetpack Compose UIs with ready to use Material Design Components.
    • Foundation - Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
    • UI - Fundamental components of compose UI needed to interact with the device, including layout, drawing, and input.
    • ConstraintLayout - ConstraintLayout-compose 1.0 provides ConstraintLayout functionalities in Jetpack Compose.
    • Lottie - Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile!
    • Coil - An image loading library for Android backed by Kotlin Coroutines.
    • Material Design - Build awesome beautiful UIs.
    • ....
  • Accompanist - a group of libraries that aim to supplement Jetpack Compose with features that are commonly required by developers but not yet available.

    • SwipeRefresh - A library which provides a layout which provides the swipe-to-refresh UX pattern, similar to Android's SwipeRefreshLayout.
    • Systemuicontroller - System UI Controller provides easy-to-use utilities for updating the System UI bar colors within Jetpack Compose.
    • Insets - Insets for Jetpack Compose takes a lot of the ideas which drove Insetter for views, and applies them for use in composables.
    • Placeholder - A library which provides a modifier for display 'placeholder' UI while content is loading.
    • Navigation - A library which provides Compose Material support for Jetpack Navigation Compose. This features composable bottom sheet destinations.
    • ....
  • Third party

    • Dagger Hilt - Dependency Injection library.
    • Gradle Kotlin DSL - makes it easy to manage dependency all module that we have
    • Google-KSP - Kotlin Symbol Processing API
    • Retrofit for Networking.
    • OkHttp-Logging-Interceptor - Logs HTTP request and response data.
    • Moshi - A modern JSON library for Kotlin and Java.
    • Chucker - An HTTP inspector for Android & OkHTTP (like Charles but on device).
    • JaCoCo for Unit Test Coverage Analysis.
    • Firebase for Crashlytics, Analytics, Push Notification,....
    • Timber - A logger with a small, extensible API which provides utility on top of Android's normal Log class.
    • And a few other libraries ....
  • Testing

    • MockK for unit test mocking. That provides DSL to mock behavior. Built from zero to fit Kotlin language. Supports named parameters, object mocks, coroutines and extension function mocking.
    • Coroutine-Test - Provides testing utilities for effectively testing coroutines.
    • 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.
    • Truth - Truth makes your test assertions and failure messages more readable.
    • Turbine - Turbine is a small testing library for kotlinx.coroutines Flow.
    • .....

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.

V. References

License

Copyright 2023 DanhDue ExOICTIF, [email protected]

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

This project is based on Android Jetpack(UI with Compose), Kotlin, Clean Architecture & Dependency Injection using Hilt.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages