This document describes how modules must be structured.
Each module use Clean architecture aproach and contains at least 3 sub-packages. domain
, data
and presentation
.
Execute business logic which is independent of any layer
-
models
: Contains models annotated with Room annotations. These classes containstoPresentationModel()
which converts models to be usen inpresentation
layer.- Name convention:
<Name>Model.kt
- Dependencies: no dependencies
- Name convention:
-
repositories
: Behavior descriptions implemented by real repositories indata
layer. Only interfaces are allowed here.- Name convention:
<Name>Repository.kt
- Dependencies: no dependencies
- Name convention:
Dispense the required data for the application to the domain layer by implementing interface exposed by the domain
-
databases
: Contains Room database implementation. It should bind all required entities implemented indomain
layer. Each database should provide aDAO
object which will perfom queries in Database. 1.1daos
: Contains interfaces that works over the database to perform queries- Name convention:
<Name>Database.kt
- Dependencies: zero or more
DAO
interfaces
- Name convention:
-
repositories
: These aredomain
implementation of repositories. You should be use it only inusecases
.- Name convention:
<Name><BaseName>Repository.kt
(Basename
is thedomain
repository implemented) - Dependencies: a
Database
object
- Name convention:
-
usecases
: Classes which depends ondomain.repositories
implementations written indata.repositories
.- Name convention:
<Name>UseCase.kt
- Dependencies: zero or more
domain.repositories
objects implemented indata
layer
- Name convention:
Include both domain and data layer and is android specific which executes the UI logic
-
activities
: Contains at least oneActivity
class which will be the entry point of the module (does not apply for Services)- Name convention:
<Name>Activity.kt
- Dependencies: zero or one
ViewModel
object
- Name convention:
-
fragments
: ContainsFragment
classes that can be reached by adestination
described in some*_navigation.xml
in module.destination
s are references to fragment that are used by aCoordinator
(does not apply for Services).Fragments can be injected by one
ViewModel`- Name convention:
<Name>Fragment.kt
- Dependencies:
- zero or one
ViewModel
object - zero or one
Presenter
object
- zero or one
- Name convention:
-
models
: Presentation models used to render inView
provided by some Presenter.- Name convention:
<Name>PresentationModel.kt
- Dependencies: no dependencies
- Name convention:
-
presenters
: The "glue" between aViewState
andView
. Its classes must implementsPresenter
interface which provides methodsgetView()
which returns aView
to be usen in someFragment|Activity
anupdate(state: ViewState)
which changesView
rendering data described instate
. Name convention:<Name>Presenter.kt
Dependencies: no dependencies -
viewmodels
: These stores and manage UI-related data in a lifecycle conscious way. It allows data to survive configuration changes such as screen rotations. These classes must be implemented only inFragment
s orActivity
s. ViewModels should be injected only withdata.usecases
classes- Name convention:
<Name>ViewModel.kt
- Dependencies: zero or more
UseCase
objects
- Name convention:
Dependencies of all previous layers are injected by Kodein
. All dependencies are described in <module_name>/Dependencies.kt
which contains a object with dependency bindings.
Typical bindings
domain.repositories
implementationsdata.usecases
implementationsdata.database
implementationspresentation.presenters
implementationspresentation.viewmodels
implementations
- Modules should be named as
<name>Feature
or<name>Service
(lowercaseUppercase classic java notation). - The proposed directory structure per module is as follows:
<ModuleName>/
/domain
/models
/repositories
/data
/databases
/repositories
/usecases
/presentation
/activities
/fragments
/models
/presenters
/viewmodels
Dependencies.kt