Skip to main content

Architecture

Chive is an AT Protocol AppView that indexes and presents scholarly eprints from the decentralized network. This document provides a high-level overview of the system architecture.

System overview

Core components

API layer

The API layer handles all incoming requests through Hono:

ComponentPurpose
XRPC handlersAT Protocol native endpoints (/xrpc/pub.chive.*)
REST handlersTraditional HTTP endpoints (/api/v1/*)
AuthenticationOAuth 2.0 + PKCE, JWT sessions
Rate limitingTiered limits by user type
ValidationRequest/response schema validation

Firehose consumer

Subscribes to the AT Protocol relay to receive real-time events:

The consumer filters for pub.chive.* records and processes:

  • Eprint submissions
  • Document-level reviews
  • Inline annotations and entity links
  • Endorsements
  • Governance proposals and votes
  • User tags

Service layer

Business logic is encapsulated in services:

ServiceResponsibility
EprintServiceEprint CRUD, version management
SearchServiceFull-text search, faceted queries
DiscoveryServiceRecommendations, similar papers
KnowledgeGraphServiceField taxonomy, authority control
ReviewServiceDocument-level reviews, endorsements
AnnotationServiceInline annotations, entity links
GovernanceServiceProposals, voting
MetricsServiceView counts, trending
ClaimingServiceAuthorship verification

Storage layer

Four specialized storage systems:

SystemUse case
PostgreSQLStructured metadata, relationships, transactions
ElasticsearchFull-text search, faceted filtering
Neo4jKnowledge graph, citation networks
RedisSession cache, rate limiting, real-time data

Data flow

Write path (indexing)

  1. User creates a record in their PDS
  2. PDS syncs to the relay network
  3. Firehose consumer receives the event
  4. Event handler validates and routes to appropriate service
  5. Service writes to relevant storage systems

Read path (queries)

  1. Client sends request to API
  2. Handler authenticates and validates
  3. Service orchestrates data retrieval
  4. Storage adapter queries appropriate database
  5. Response formatted and returned

Key principles

AT Protocol compliance

Chive is a read-only indexer. It never:

  • Writes to user PDSes
  • Stores blob data (only BlobRefs)
  • Acts as source of truth for user content

All indexes can be rebuilt from the firehose.

Horizontal scalability

  • API servers scale horizontally
  • Single firehose consumer (with failover)
  • Managed database services with replication

Fault tolerance

FailureRecovery
API server crashLoad balancer routes to healthy nodes
Firehose disconnectAutomatic reconnect with cursor resume
Database unavailableCircuit breaker, graceful degradation
Cache missFallback to primary storage

Security architecture

Zero trust model

  • Every request authenticated
  • Mutual TLS between internal services
  • All actions audit logged
  • Secrets managed via HashiCorp Vault

Authentication flow

Plugin architecture

Plugins run in isolated-vm sandboxes with:

  • Declared permissions
  • Resource limits (CPU, memory)
  • Controlled API access

Observability

Technology choices

ComponentTechnologyRationale
RuntimeNode.js 22V8 performance, AT Protocol SDK
LanguageTypeScriptType safety, AT Protocol tooling
API frameworkHonoFast, lightweight, Edge-compatible
FrontendNext.js 15React 19, App Router, SSR
Primary DBPostgreSQLACID, JSON support, extensions
SearchElasticsearchFull-text, faceted, scalable
Graph DBNeo4jCitation networks, traversals
CacheRedisSessions, rate limiting, pub/sub
ContainerDockerConsistent environments
OrchestrationKubernetesScaling, self-healing
ObservabilityOpenTelemetryVendor-neutral telemetry

Next steps