Skip to content

Commit 8114574

Browse files
committed
Merge pull request ribot#4 from ribot/app_architecture
App architecture guidelines
2 parents 22e828c + e8129b6 commit 8114574

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Android Guidelines and Tools
22

3-
List of code / project guidelines and libraries that we use at __ribot__ when developing for the __Android__ platform.
3+
List of guidelines and libraries that we use at __ribot__ when developing for the __Android__ platform.
44

55
* [Project and code guidelines](project_and_code_guidelines.md)
6-
* [Libraries](android_libraries.md)
6+
* [Architecture Guidelines](architecture_guidelines/android_architecture.md)
7+
* [Libraries](android_libraries.md)
65.5 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Architecture Guidelines
2+
3+
The architecture of our Android apps is structured in two layers.
4+
5+
* __UI Layer__: this is where Activities, Fragments and other standard Android components live. It's responsible for displaying the data received from the data layer to the user as well as handling its interactions and inputs (click listeners, etc).
6+
7+
* __Data Layer__: this is responsible for retrieving, saving, caching and massaging data so it is provided to the UI layer in its optimal form to be displayed. It can communicate with local databases and other data stores as well as with restful APIs or third party SDKs. It is divided in two parts: a group of helpers and a `DataManager`. The number of helpers vary between project and each of them has a very specific function, e.g. talking to an API or saving data in `SharedPreferences`. The `DataManager` combines and transforms the outputs from different helper using Rx operators so it can provide meaningful data to the UI layer.
8+
9+
![](achitecture_diagram.png)
10+
11+
Looking at the diagram from right to left:
12+
13+
* __Helpers (Data layer)__: A set of classes, each of them with a very specific responsibility. Their function can range from talking to APIs or a database to implementing some specific business logic. Every project will have different helpers but the most common ones are:
14+
- __DatabaseHelper__: It handles inserting, updating and retrieving data from a local SQLite database. Its methods return Rx Observables that emit plain java objects (models)
15+
- __PreferencesHelper__: It saves and gets data from `SharedPreferences`, it can return Observables or plain java objects directly.
16+
- __Retrofit services__ : [Retrofit](http://square.github.io/retrofit) interfaces that talk to Restful APIs, each different API will have its own Retrofit service. They return Rx Observables.
17+
18+
* __Data Manager (Data layer)__: It's the heart of the architecture. It keeps a reference to every helper class and uses them to satisfy the requests coming from the data layer. Its methods make extensive use of Rx operators to combine, transform or filter the output coming from the helpers in order to generate the desired output ready for the UI layer to display. It returns Observables that emit models.
19+
* __Activities, Fragments, etc (UI layer)__: Standard Android components that subscribe to the Observables returned by the Data Manager and display the results to the user. They also handle user interactions such as clicks and act accordingly by calling the appropriate method in the Data Manager.
20+
21+
* __Event Bus__: It allows UI layer components to be notified of certain events that happen in the data layer. The data manager posts events which can then be subscribed to by Activities and Fragments.
304 KB
Binary file not shown.

0 commit comments

Comments
 (0)