/kotlin-template

Kotlin-template clean architecture

Primary LanguageKotlin

kotlin-template

Kotlin Clean Architecture Template Project. Uses dagger2 for dependency injection yall

Projects using this architecture:

  • warningapp-kotlin-android
  • dfds-channel-android

Live Templates

The Kotlin template comes supported with a its own set of live templates which can be found at

https://github.com/nodes-android/androidstudio-livetemplates

It should make generating the boilerplate for activities and fragments easy.

Nodes Architecture Library

The Template uses components from our Architecture library so be sure to read up on how that is used as well

https://github.com/nodes-android/nodes-architecture-android

Below information might be slightly out of date

Layers

This is a 4 layer onion architecture. Dependencies are only allowed to point inwards, meaning that the inner layer most not reference code in the outer layers directly. From inside out it consists of:

Entities

Models/POJOs implemented as data objects in kotlin.

Business Logic / Use Cases

Consist of interactors and repositories (the interfaces). The interactors encapsulates the business logic and perform operations on the entities. Interactors are scheduled to run in the background and return information to the outer layer through callbacks implemented in the outer layers.

Interface Adapters

ViewModel (as part of the MVVM pattern) are implemented in this layer. ViewModel holds information from the inner layers (business logic and entities) to the user interface etc. In other words they adapt the data for output to the outermost layer (Framework and Drivers)

Frameworks and Drivers

This is the outmost layer consisting of things such as the User interface (for android Activities, fragments etc), database libraries, retrofit, okhttp etc. This also contain specific implementations of the Repository interfaces the business logic layer needs to access data.

Flow of control

Example:

  1. User clicks a button that loads a list of posts in a view.
  2. OnClickListener executes a Interactor/UseCase asynchronously in the business logic layer.
  3. The Interactor runs in the background accessing a post repository which fetches a list of posts
  4. Presenter gets notified with the loaded posts or a message in case of error trough a callback
  5. Presenter instructs the view (if attached) to update itself with the new data, or display an error to the user

Patterns in use:

  • MVVM
  • Repository
  • Interactor (implemented with a pluggable executor)
  • Dependency Injection (and thus factory)
  • Inward dependency rule (all dependencies must point inwards)

Stuff

  • kotlin data classes as entities
  • Retrofit2/OkHttp3
  • Android kotlin extensions (views are automatically made into properties on the activity)
  • Uses nstack-kotlin
  • Mockito and junit for testing

Inspired/partially ripped off from the following sources: