diff --git a/docs/ArchitectureLearningJourney.md b/docs/ArchitectureLearningJourney.md index dbfe9e80d..9b1619e01 100644 --- a/docs/ArchitectureLearningJourney.md +++ b/docs/ArchitectureLearningJourney.md @@ -2,10 +2,13 @@ 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. @@ -17,62 +20,154 @@ The goals for the app architecture are: 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). -![Diagram showing overall app architecture](images/architecture-1-overall.png "Diagram showing overall app architecture") + +
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 ForYouFeedState.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 ForYouFeedState.Success
+ |
+