+6
-62
TUTORIAL.md
+6
-62
TUTORIAL.md
···We're going to accomplish this using OAuth ([spec](#todo)). You can find a [more extensive OAuth guide here](#todo), but for now just know that most of the OAuth flows are going to be handled for us using the [@atproto/oauth-client-node](#todo) library. This is the arrangement we're aiming toward:When the user logs in, the OAuth client will create a new session with their repo server and give us read/write access along with basic user info.······Remember how we referred to our app as being like a Google, crawling around the repos to get their records? One advantage we have in the AT Protocol is that each repo publishes an event log of their updates.Using a [Relay service](#todo) we can listen to an aggregated firehose of these events across all users in the network. In our case what we're looking for are valid `com.example.status` records.···Why read from the event log? Because there are other apps in the network that will write the records we're interested in. By subscribing to the event log, we ensure that we catch all the data we're interested in -- including data published by other apps.···As a final optimization, let's introduce "optimistic updates." Remember the information flow loop with the repo write and the event log? Since we're updating our users' repos locally, we can short-circuit that flow to our own database:This is an important optimization to make, because it ensures that the user sees their own changes while using your app. When the event eventually arrives from the firehose, we just discard it since we already have it saved locally.···This is how every app in the Atmosphere works, including the [Bluesky social app](https://bsky.app).
···We're going to accomplish this using OAuth ([spec](#todo)). You can find a [more extensive OAuth guide here](#todo), but for now just know that most of the OAuth flows are going to be handled for us using the [@atproto/oauth-client-node](#todo) library. This is the arrangement we're aiming toward:When the user logs in, the OAuth client will create a new session with their repo server and give us read/write access along with basic user info.······Remember how we referred to our app as being like a Google, crawling around the repos to get their records? One advantage we have in the AT Protocol is that each repo publishes an event log of their updates.Using a [Relay service](#todo) we can listen to an aggregated firehose of these events across all users in the network. In our case what we're looking for are valid `com.example.status` records.···Why read from the event log? Because there are other apps in the network that will write the records we're interested in. By subscribing to the event log, we ensure that we catch all the data we're interested in -- including data published by other apps.···As a final optimization, let's introduce "optimistic updates." Remember the information flow loop with the repo write and the event log? Since we're updating our users' repos locally, we can short-circuit that flow to our own database:This is an important optimization to make, because it ensures that the user sees their own changes while using your app. When the event eventually arrives from the firehose, we just discard it since we already have it saved locally.···This is how every app in the Atmosphere works, including the [Bluesky social app](https://bsky.app).
docs/diagram-event-stream.png
docs/diagram-event-stream.png
This is a binary file and will not be displayed.
docs/diagram-info-flow.png
docs/diagram-info-flow.png
This is a binary file and will not be displayed.
docs/diagram-oauth.png
docs/diagram-oauth.png
This is a binary file and will not be displayed.
docs/diagram-optimistic-update.png
docs/diagram-optimistic-update.png
This is a binary file and will not be displayed.
docs/diagram-repo.png
docs/diagram-repo.png
This is a binary file and will not be displayed.