Skip to content

Commit 8e311bb

Browse files
authored
Add architecture documentation [ci skip]
1 parent c104d36 commit 8e311bb

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

README.md

+41-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Kotlin Sample App (work-in-progress 👷🔧️👷‍♀️⛏)
1+
## Kotlin Sample App
22
[![CircleCI](https://circleci.com/gh/VMadalin/kotlin-sample-app/tree/master.svg?style=shield)](https://circleci.com/gh/VMadalin/kotlin-sample-app/tree/master)
33
[![Codecov](https://codecov.io/gh/VMadalin/kotlin-sample-app/coverage.svg)](https://codecov.io/gh/VMadalin/kotlin-sample-app)
44
[![Codacy](https://api.codacy.com/project/badge/Grade/5970b6648df0465588f9781ae6e3332e)](https://www.codacy.com/manual/VMadalin/kotlin-sample-app?utm_source=github.com&utm_medium=referral&utm_content=VMadalin/kotlin-sample-app&utm_campaign=Badge_Grade)
@@ -107,20 +107,58 @@ Moreover, has been implemented support for [dark theme](https://developer.androi
107107

108108
The architecture of the application is based, apply and strictly complies with each of the following 5 points:
109109

110+
<img src="screenshots/architecture/project_structure.png" width="300" align="right" hspace="20">
111+
110112
- A single-activity architecture, using the [Navigation component](https://developer.android.com/guide/navigation/navigation-getting-started) to manage fragment operations.
111113
- [Android architecture components](https://developer.android.com/topic/libraries/architecture/), part of Android Jetpack for give to project a robust design, testable and maintainable.
112-
- Pattern [Model-View-ViewModel](](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel)) (MVVM) facilitating a [separation](https://en.wikipedia.org/wiki/Separation_of_concerns) of development of the graphical user interface.
114+
- Pattern [Model-View-ViewModel](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel) (MVVM) facilitating a [separation](https://en.wikipedia.org/wiki/Separation_of_concerns) of development of the graphical user interface.
113115
- [S.O.L.I.D](https://en.wikipedia.org/wiki/SOLID) design principles intended to make software designs more understandable, flexible and maintainable.
114116
- [Modular app architecture](https://proandroiddev.com/build-a-modular-android-app-architecture-25342d99de82) allows to be developed features in isolation, independently from other features.
115117

116118
### Modules
117119

118-
Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing dependence between them:
120+
Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing the following dependence between them:
119121

120122
<p align="center">
121123
<img src="screenshots/architecture/modules_diagram.png">
122124
</p>
123125

126+
The above graph shows the app modularisation:
127+
- `:app` depends on `:core` and indirectly depends on `:features` by dynamic-features.
128+
- `:features` modules depends on `:commons`, `:core`, `:libraries` and `:app`.
129+
- `:core` and `:commons` only depends for possible utils on `:libraries`.
130+
- `:libraries` don’t have any dependency.
131+
132+
#### App module
133+
134+
The `:app` module is an [com.android.application](https://developer.android.com/studio/build/), which is needed to create the app bundle. It is also responsible for initiating the [dependency graph](https://github.com/google/dagger), [play core](https://developer.android.com/reference/com/google/android/play/core/release-notes) and another project global libraries, differentiating especially between different app environments.
135+
136+
#### Core module
137+
138+
The `:core` module is an [com.android.library](https://developer.android.com/studio/projects/android-library) for serving network requests or accessing to the database. Providing the data source for the many features that require it.
139+
140+
#### Features modules
141+
142+
The `:features` module are an [com.android.dynamic-feature](https://developer.android.com/studio/projects/dynamic-delivery) is essentially a gradle module which can be downloaded independently from the base application module. It can hold code and resources and include dependencies, just like any other gradle module.
143+
144+
#### Commons modules
145+
146+
The `:commons` modules are an [com.android.library](https://developer.android.com/studio/projects/android-library) only contains code and resources which are shared between feature modules. Reusing this way resources, layouts, views, and components in the different features modules, without the need to duplicate code.
147+
148+
#### Libraries modules
149+
150+
The `:libraries` modules are an [com.android.library](https://developer.android.com/studio/projects/android-library), basically contains different utilities that can be used by the different modules.
151+
152+
### Architecture components
153+
154+
Ideally, ViewModels shouldn’t know anything about Android. This improves testability, leak safety and modularity. ViewModels have different scopes than activities or fragments. While a ViewModel is alive and running, an activity can be in any of its lifecycle states. Activities and fragments can be destroyed and created again while the ViewModel is unaware.
155+
156+
Passing a reference of the View (activity or fragment) to the ViewModel is a serious risk. Lets assume the ViewModel requests data from the network and the data comes back some time later. At that moment, the View reference might be destroyed or might be an old activity that is no longer visible, generating a memory leak and, possibly, a crash.
157+
158+
<img src="screenshots/architecture/communication_diagram.png">
159+
160+
The communication between the different layers follow the above diagram using the reactive paradigm, observing changes on components without need of callbacks avoiding leaks and edge cases related with them.
161+
124162
### Build variants
125163

126164
The application has different product flavours: `Dev`, `QA`, `Prod`. Each variant has a specific target environment and to make easier to distinguish them the app uses a specific icon colour for `debug` and `release` build variant with descriptive app name. In this case and given that it's a sample, all variants have the same Marvel API endpoint. But the idea is to have different environments target for Development and QA respectively, what doesn't affect the production environment. This is applicable to any tool, platform, service what is being used. For more information about build variant, check this [link](https://developer.android.com/studio/build/build-variants).

0 commit comments

Comments
 (0)