Skip to content
Showcase for Unidirectional Data Flow architecture for Android, powered by Kotlin Coroutines
Kotlin Other
  1. Kotlin 99.0%
  2. Other 1.0%
Branch: master
Clone or download
Latest commit 20b1772 Jul 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Should cache Gradle distribution Jul 8, 2019
.github Updated showcase screenshot Jul 1, 2019
app Fixing tests Jul 21, 2019
buildSrc Bumped Coroutines to 1.3.0-RC Jul 21, 2019
coroutines-testutils Lint Jul 21, 2019
domain Reworked FetchFacts, removing unused collaborator Jul 21, 2019
facts Reworked FetchFacts, removing unused collaborator Jul 21, 2019
gradle/wrapper Bumped Gradle to 5.5 Jul 7, 2019
logger Fixing all ktlint checks Jun 19, 2019
navigator Reworked Navigator APIs Jul 21, 2019
networking Improved tests using custom DSL Jul 23, 2019
onboarding Using StateMachine transitions Jul 21, 2019
persistance Improving tests which verify errored executions with custom DSL Jul 5, 2019
proguard Added rules for Kotlinx.Serialization Jul 7, 2019
rest-chucknorris Repackaging all classes Jul 7, 2019
search Search now uses new StateMachine/CommandProcessor Jul 21, 2019
shared-assets Enabled name spaced R classes and fixed cross module references Jul 7, 2019
shared-utilities Flattening modules structure Jun 30, 2019
unidirectional-dataflow Improving design Jul 23, 2019
.gitignore Project bootstrap Jun 15, 2019
LICENSE.md Project bootstrap Jun 15, 2019
README.md Updated use cases Jul 7, 2019
build.gradle.kts Revering JaCoCo version Jul 3, 2019
default-detekt-config.yml Ignoring some rules Jun 28, 2019
emulate-ci-build.sh Updating CI pipeline to use Detekt Jun 28, 2019
gradle.properties Enabled name spaced R classes and fixed cross module references Jul 7, 2019
gradlew Bumped Gradle to 5.5 Jul 7, 2019
gradlew.bat Bumped Gradle to 5.5 Jul 7, 2019
settings.gradle.kts Added simple onboarding module Jul 4, 2019

README.md

Norris

CircleCI ktlint Maintainability codecov codebeat badge Codacy Badge

Norris logo

An app that existed even before Android existed!

About

Norris is a showcase for modern and well-crafted Android code.

Here you will find a codebase powered by tests in all semantic levels (unit, integratation, acceptance) as well an architectural design that promotes discipline over state, using Kotlin Coroutines as foundation for a pragmatic unidirectional dataflow implementation.

Project Overview

This project leverages on api.chucknorris.io as remote data source to implement the following use cases

  • User can search for Chuck Norris facts and share them
  • Related categories are fetched in the application boostraped and cached
  • Application will offer suggestions for queries based on categories names and track query terms provided by user as well

showcase-norris

The code is structured in a multi-module fashion, with semantics guided by Clean Architecure; this means that high level modules (like facts or search) don't know anything about low-level ones (like networking or persistance).

The domain module defines the core protocols to be implemented by low level details, while aggregates them in high level policies like FetchFacts

A general representation of the module structure is such as follow. Beyond domain, there are modules shared between all features like navigator, shared-assets and others.

module-structure

This project uses a custom implementation of unidirectional data flow in order to organise the responsabilities of abstractions on top of UI layer. Beyond the semantics of the defined protocols, we leverage a custom StateMachine that will process states and send them over a ConflatedBroadcastChannel to consumers.

The design of abstractions enforce that Coroutine's Scopes related to the emission and consumption of states are decoupled; in this way, we also have a notion of StateContainer, that will provide both the emissionScope and the Flow<T> implementation for emissions.

You may want to check the ConfigChangesAwareStateContainer abstraction, which leverages on Jetpack's ViewModel to keep the reference of the aforementioned ConflatedChannel, as well to provide the proper emission scope for states. An unbounded implementation is also defined for test purposes.

In this way, none of the ViewModels of this project derives from AAC ViewModel, but AAC ViewModel ensures the UI state persistance across device configuration changes.

Last, but not least, the choice for the Flow<T> over the conflated channel allows us to follow the reactive way for UIs without any LiveDatas. Just beautiful and simple.

udf-architecture

This project has some remaining tasks. Follow the project board to learn about what is going on

Related blog posts

I'm writing a series of blog posts related to this project. They will explain some project decisions, as well dive into some details of implementation of this approach for unidirectional data flow, specially with learnings related to Coroutines and Channels.

Coming soon at ubiratansoares.dev

Building and Running

If you want a simple run, just use the companion script

./emulate-ci-build.sh

It will

  • Run static analysers (Ktlint and Detekt)
  • Run all unit tests and generate all JaCoCo reports
  • Assemble the debug APK

For running acceptance tests

./gradlew connectedCheck

Credits

  • Mathias Schilling, for the Chuck Norris facts REST api
  • Material Design Icons for the error states images
  • Jetbrains for the amazing developer experience around Kotlin and Coroutines
  • Someone in the Web for the Norris clipart ❤️ (I'll be happy to put your name here, ping me!)

Author

Coded by Ubiratan Soares (follow me on Twitter)

License

The MIT License (MIT)

Copyright (c) 2019 Dotanuki Labs

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can’t perform that action at this time.