Skip to main content

What are Repositories?

Repositories are signed, authenticated data structures that store all of a user’s records in AT Protocol. Each user has one repository containing their posts, likes, follows, profile, and other data.

Why Repositories Matter

Self-Authenticating

Every repository is cryptographically signed, making it impossible to tamper with data without detection.

Portable

Users can export their entire repository and import it on a different server, maintaining their complete history.

Efficient Sync

Repositories use Merkle trees, allowing efficient synchronization by only transferring changed data.

Verifiable

Anyone can verify the integrity and authorship of repository data using cryptographic proofs.

Repository Structure

A repository consists of:
  1. Commit - Signed pointer to the current state
  2. MST (Merkle Search Tree) - Ordered tree of records
  3. Records - Individual data items (posts, likes, etc.)
  4. Blocks - CBOR-encoded data blocks

Merkle Search Tree (MST)

The MST is the core data structure that organizes records in a repository. It combines properties of:
  • Merkle Trees - Cryptographic verification
  • B-Trees - Efficient searching and insertion
  • Deterministic ordering - Same data always produces same tree

Key Properties

How It Works

The MST uses a clever algorithm:
  1. Hash each key with SHA-256
  2. Count leading zero bits in the hash
  3. Number of zeros determines tree layer
  4. More zeros = higher in the tree
This ensures:
  • Deterministic structure - Same records always produce same tree
  • Balanced tree - Probabilistically balanced by hash distribution
  • Efficient operations - O(log n) search, insert, delete

Using Repositories

Creating a Repository

Reading Records

Writing Records

Updating Records

Deleting Records

Batch Operations

Record Keys (rkeys)

Records are identified by their collection and rkey (record key):

TID-based Keys

Most records use TIDs (Timestamp Identifiers) as rkeys:

Literal Keys

Some records use fixed keys:

Commits

Each repository state is represented by a signed commit:
Commit Lifecycle:

CAR Files

Repositories are distributed as CAR (Content Addressed aRchive) files:
CAR files enable:
  • Repository export - Users can download their complete data
  • Efficient sync - Only transfer changed blocks
  • Backup and migration - Portable repository format

MST Operations

Direct MST usage (lower-level API):

Walking the Tree

Data Diff

Compute differences between repository states:
Useful for:
  • Computing repository updates
  • Generating sync payloads
  • Tracking changes

Proofs and Verification

MSTs support cryptographic proofs:

Repository Sync Protocol

Repositories sync using the following protocol: Event Format:

Best Practices

For posts, likes, and other time-series data, use TID-based rkeys for chronological ordering.
Combine multiple operations into a single commit to reduce overhead and improve atomicity.
Use Lexicon validation to ensure records conform to schemas before adding to repository.
Design your system to support repository export/import for user portability.
Large repositories can be expensive to sync. Consider archiving or pagination strategies.

Storage Backends

Repositories can use different storage implementations:
Storage Interface:

Error Handling

Additional Resources

@atproto/repo Package

NPM package documentation

Repository Spec

Official repository specification

MST Paper

Academic paper on Merkle Search Trees

CAR Format

Content Addressed aRchive specification