Git Product home page Git Product logo

ferprieto / spacex-prepare-for-clean-architecture-liftoff Goto Github PK

View Code? Open in Web Editor NEW
684.0 6.0 86.0 94.96 MB

Clean Architecture Modular Project: MVVM + Jetpack Compose + Coroutines + Flows + Dagger2 + LiveData + UnitTests + UITests + Screenshot Tests + MockWebServer

Kotlin 100.00%
mvvm mvvm-android mockwebserver espresso retrofit2 coroutines-android clean-architecture clean-code kotlin-flow junit4 kotlin android coroutines android-architecture dagger-hilt jetpack-compose android-compose

spacex-prepare-for-clean-architecture-liftoff's Introduction

SpaceX prepare for Clean Architecture liftoff:rocket:

JetpackCompose Platform Android Studio Dolphin License Build Status

The purpose of this project is to consolidate some of the learned insights throughout the years about the Clean Architecture principles and reflect those lessons on Android, taking advantage of the Kotlin programming language features too.

This project summarises some of the general use cases and demands on a typical production project using: Jetpack Compose, Functional Programming,MVVM, Kotlin Coroutines and Kotlin Flows (check the branches section for more information).

Libraries Used ๐Ÿ“š

  • Compose Toolkit for building native UI (in a declarative way - 100% Kotlin).
  • Coroutines Library support for Kotlin coroutines.
  • Flows Stream processing API, built on top of Coroutines.
  • Compose Navigation for tabs navigation using Jetpack Compose.
  • Dagger Hilt Dependency injection library for Android.
  • Retrofit Type-safe REST client for Android to consume RESTful web services.
  • Timber Logger with a small API which provides utility on top of Android's normal Log class.
  • Espresso Android UI Testing framework.
  • MockK mocking framework for testing.
  • MockWebServer A scriptable web server for testing HTTP clients, used for Instrumentation tests in this project.
  • Coil Compose Image downloading and caching library supported by Jetpack Compose.
  • Lottie Compose Library that provides that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile.
  • JodaTime Date library that lets manage more extensively and easily dates
  • Shot Shot is a Gradle plugin and a core android library thought to run screenshot tests for Android.

Modules ๐Ÿ“‘

  • app - The application module with access to all the application
  • data - Android module that can only access domain module
  • data-api - Android module that can only access data module
  • domain - Kotlin module that cannot access any other module

And two extra modules:

  • core - Base classes module (factories, events, etc.) that cannot access any other module
  • core-android-test - Tests classes module (rules, date builders,etc.) that cannot access any other module

Branches :octocat:

There are three options depending on different tech-stack desired. The latest codebase will be updated in master. These are the three options available (all of them maintained):

  • master

    • Jetpack Compose (declarative UI)
    • Dagger Hilt
    • VM approach using UI States and Effects
    • Kotlin Flows (removed LiveData)
    • Modules simplification
    • The rest of modules remain the same (Tests)
  • SpaceX-Coroutines-Flows

    • Imperative UI
    • Dagger2
    • Kotlin Coroutines and Flows
    • Granular modularisation (CleanArchitecture approach)
    • Unit Tests + UI Tests + MockWebServer + Robot Pattern
  • SpaceX-RxJava

    • VMs and Fragments communication via RxJava
    • Dagger2
    • Granular modularisation (CleanArchitecture approach)
    • Unit Tests + UI Tests + MockWebServer + Robot Pattern

Testing ๐Ÿ”

Unit Testing

There are some highlights:

  • Every layer in the architecture has been tested.
  • MockK has been used for mocking | stubbing.
  • Given | When | Then code presentation order, in order to give a more structured style.
  • Code Coverage (WORK IN PROGRESS).

UI Testing (Compose)

I opted to use three types of approaches:

  • MockWebserver, where real connection scenarios are setup. More information in my MockWebServer Medium Article!
  • Tests in Isolation, where it's possible to mock and set any content, UI state, etc. Which allows to emulate very specific edge cases.
  • Screenshot Testing ๐Ÿ“ธ

In the two first types of tests I used Robot Pattern to improve cleanliness and ease of readability. More information in my RobotPattern Medium Article!

License ๐Ÿš”

Copyright 2022 Fernando Prieto Moyano

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.

spacex-prepare-for-clean-architecture-liftoff's People

Contributors

ferprieto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

spacex-prepare-for-clean-architecture-liftoff's Issues

Issues with Connected Android Test

This might be an issue with my environment.
I have checked out the latest version of master 0cc02b3.

When I run:
./gradlew connectedAndroidTest

I get the error:

Duplicate class org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey found in modules checker-3.1

If I try to run them from Android Studio, I get a different error

Unable to find explicit activity class {prieto.fernando.spacex.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared ?

@Singleton annotation

Hi,

Thanks for good project. I want to give some suggestions. If you want singleton component, you must use @singleton annotation. Maybe this can be your choice. I think it should at least be a retrofit singleton.

package prieto.fernando.data_api.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import prieto.fernando.data.SpaceXRemoteSource
import prieto.fernando.data_api.ApiService
import prieto.fernando.data_api.data.SpaceXRemoteSourceImpl
import prieto.fernando.data_api.mapper.*
import retrofit2.Retrofit

@module
@Installin(SingletonComponent::class)
object ApiModule {
@provides
fun provideSpaceXRemoteSource(
apiService: ApiService,
companyInfoRepositoryMapper: CompanyInfoResponseToRepositoryModelMapper,
launchesRepositoryMapper: LaunchesResponseToRepositoryModelMapper
): SpaceXRemoteSource =
SpaceXRemoteSourceImpl(apiService, companyInfoRepositoryMapper, launchesRepositoryMapper)

@Provides
fun provideCompanyInfoResponseToRepositoryModelMapper(): CompanyInfoResponseToRepositoryModelMapper =
    CompanyInfoResponseToRepositoryModelMapperImpl()

@Provides
fun provideLaunchesResponseToRepositoryModelMapper(
    dateFormatter: DateFormatter
): LaunchesResponseToRepositoryModelMapper =
    LaunchesResponseToRepositoryModelMapperImpl(dateFormatter)

@Provides
fun provideDateFormatter(): DateFormatter =
    DateFormatterImpl()

@Provides
@JvmStatic
internal fun provideApi(retrofit: Retrofit): ApiService =
    retrofit.create(ApiService::class.java)

@Provides
@JvmStatic
internal fun provideRetrofit(
    httpBuilder: OkHttpClient.Builder,
    retrofitBuilder: Retrofit.Builder
): Retrofit = retrofitBuilder
    .client(httpBuilder.build())
    .build()

}

Issues with Connected Android Test

This might be an issue with my environment.
I have checked out the latest version of master 0cc02b3.
When I run:

gradle --version

I get:


Gradle 7.5.1

Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918>

Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.17 (Oracle Corporation 11.0.17+10-LTS-269)
OS: Mac OS X 13.2.1 x86_64

When I run:
./gradlew connectedAndroidTest

I get the error:

Duplicate class org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey found in modules checker-3.1

If I try to run them from Android Studio, I get a different error

Unable to find explicit activity class {prieto.fernando.spacex.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.