KnowMe
Section 03

Custom Rust AppView

The AppView is the read-optimized indexing layer that materializes the social graph and serves client queries. Building this in Rust ensures high performance, memory safety, and predictable latency under load.

Two-Tier Indexing Pipeline

The AppView consumes JSON events from Tap via WebSocket. Because the network supports dynamic lexicons, the indexer handles both known and unknown schemas through a two-tier approach.

Tier 1: Known Lexicons

Compile-time generated Rust types via ATrium. Strongly typed, zero-cost abstractions.

use atrium_api::app::bsky::feed::post; // Compile-time validated let record: post::Record = serde_json::from_value(event.record)?; indexer.insert_typed(&record).await?;

Tier 2: Dynamic Lexicons

Runtime JSON Schema validation with PostgreSQL JSONB storage. No migrations needed.

// Runtime validated against fetched schema let schema = registry .resolve(&event.collection).await?; schema.validate(&event.record)?; indexer.insert_dynamic( &event.collection, &event.record ).await?;

Core Components

tokio + tungstenite

Firehose Consumer

WebSocket client connecting to Tap. Receives JSON events, handles acks for delivery guarantees, routes events to the indexer pipeline.

sqlx + serde

Indexer Pipeline

Validates records against known types (ATrium) or dynamic schemas. Writes to PostgreSQL typed tables or JSONB columns. Maintains materialized views for query performance.

axum + tower

XRPC API Server

Serves custom lexicon query endpoints. Handles OAuth token validation. Implements hydration layer for complex views. Provides WebSocket subscriptions for real-time updates.

custom + jsonschema

Lexicon Registry

Watches firehose for com.atproto.lexicon.schema records. Indexes published schemas. Provides resolveLexicon endpoint. Triggers dynamic validator creation.

custom middleware

Agent Protocol Bridge

Maps A2A/AG-UI/A2UI protocols to AT Protocol lexicons. Manages agent lifecycle. Translates between protocol formats bidirectionally.

Recommended Crate Stack

CratePurposeWhy
axumHTTP/WebSocket serverTower ecosystem, async-first, production proven
sqlxDatabase accessCompile-time SQL verification, async PostgreSQL
tokioAsync runtimeIndustry standard, mature, excellent tooling
serde / serde_jsonSerializationZero-copy deserialization, ubiquitous
atrium-apiAT Protocol typesOfficial Rust types for all lexicons
tungsteniteWebSocket clientLightweight, async-compatible via tokio
jsonschemaDynamic validationRuntime schema validation for unknown lexicons
tracingObservabilityStructured logging, spans, OTEL export
loroCRDTsHigh-performance collaborative state