# Architecture Learning Journey In this learning journey you will learn about the Now in Android app architecture: its layers, key classes and the interactions between them. ## Goals and requirements The goals for the app architecture are: * Follow the [official architecture guidance](https://developer.android.com/jetpack/guide) as closely as possible. * Easy for developers to understand, nothing too experimental. * Support multiple developers working on the same codebase. * Facilitate local and instrumented tests, both on the developer’s machine and using Continuous Integration (CI). * Minimize build times. ## Architecture overview The app architecture has two layers: a [data layer](https://developer.android.com/jetpack/guide/data-layer) and [UI layer](https://developer.android.com/jetpack/guide/ui-layer) (a third, [the domain layer](https://developer.android.com/jetpack/guide/domain-layer), is currently in development).
Step | Description | Code |
1 | On app startup, a WorkManager job to sync all repositories is enqueued. | SyncInitializer.create
|
2 | The initial news feed state is set to Loading , which causes the UI to show a loading spinner on the screen.
|
Search for usages of NewsFeedUiState.Loading
|
3 | WorkManager executes the sync job which calls OfflineFirstNewsRepository to start synchronizing data with the remote data source.
|
SyncWorker.doWork
|
4 | OfflineFirstNewsRepository calls RetrofitNiaNetwork to execute the actual API request using Retrofit.
|
OfflineFirstNewsRepository.syncWith
|
5 | RetrofitNiaNetwork calls the REST API on the remote server.
|
RetrofitNiaNetwork.getNewsResources
|
6 | RetrofitNiaNetwork receives the network response from the remote server.
|
RetrofitNiaNetwork.getNewsResources
|
7 | OfflineFirstNewsRepository syncs the remote data with NewsResourceDao by inserting, updating or deleting data in a local Room database.
|
OfflineFirstNewsRepository.syncWith
|
8 | When data changes in NewsResourceDao it is emitted into the news resources data stream (which is a Flow).
|
NewsResourceDao.getNewsResourcesStream
|
9 | OfflineFirstNewsRepository acts as an intermediate operator on this stream, transforming the incoming PopulatedNewsResource (a database model, internal to the data layer) to the public NewsResource model which is consumed by other layers.
|
OfflineFirstNewsRepository.getNewsResourcesStream
|
10 | When ForYouViewModel receives the news resources it updates the feed state to Success . ForYouScreen then uses the news resources in the state to render the screen.
The screen shows the newly retrieved news resources (as long as the user has chosen at least one topic or author). |
Search for instances of NewsFeedUiState.Success
|
Name | Backed by | Purpose |
TopicsDao | Room/SQLite | Persistent relational data associated with Topics |
NiaPreferencesDataSource | Proto DataStore | Persistent unstructured data associated with user preferences, specifically which Topics the user is interested in. This is defined and modeled in a .proto file, using the protobuf syntax. |
NiaNetworkDataSource | Remote API accessed using Retrofit | Data for topics, provided through REST API endpoints as JSON. |