botdb

botdb docs

What botdb is, how it works, and the concepts used throughout these docs.

botdb is a command-line tool for end-to-end encrypted, local-first SQL databases that sync across machines. It is built for AI agents: anything an agent needs to remember with structure (a watchlist, a reading log, a task queue, preferences) goes into a real SQL table instead of a JSON file or a paid memory API.

botdb is a single static Rust binary, botdb, with SQLite bundled.

How it works

 machine A               remote                 machine B
 SQLite copy  ─push─▶  relay or folder  ─pull─▶  SQLite copy
 and keys     ◀─pull─  ciphertext only  ◀─push─  and keys

Concepts

Term Meaning
Database A named SQL database with its own random id and encryption key.
Vault Your master secret (256 bits, shown as a 24-word BIP39 recovery phrase). Stored in the OS keychain on macOS and Windows, or in ~/.botdb/vault.key (mode 0600) elsewhere.
Catalog A botdb database whose id and keys derive from the vault. It lists your databases, their keys and remotes, plus your default remotes, and syncs to the default remotes like any other database.
Remote Where encrypted changes are exchanged: botdb cloud (cloud), a relay URL (https://...) or a folder path. A database can have several.
Relay A small HTTP server that stores encrypted batches and snapshots. Run your own with botdb relay or Docker.
Invite A bdb1_... string carrying one database’s key and remotes. Anyone holding it can read that database. Read-only invites can’t write.
Replica One copy of a database on a device or agent, with its own random id (the site). Every change batch is tagged with that id and a per-replica sequence number.
Epoch The key generation of a database. botdb rotate-key starts a new epoch.

Example

An agent tracking the movies you’ve watched. A SQL table fits this better than paying for a memory system or juggling JSON files with no backups:

botdb create movies
botdb sql -d movies "CREATE TABLE watched (
  id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
  title TEXT NOT NULL DEFAULT '',
  rating INTEGER,
  watched_at TEXT DEFAULT (datetime('now'))
)"
botdb sql -d movies "INSERT INTO watched (title, rating) VALUES (?, ?)" -p "Dune: Part Two" -p 5
botdb sql -d movies "SELECT title, rating FROM watched WHERE rating >= 4 ORDER BY watched_at DESC"

The same table is available on your other machines, to other agents you invite, and in every backup.

Architecture

botdb is a set of Rust crates: botdb-core (ids, clocks, the change model, crypto, the relay protocol), botdb-sqlite (the storage engine), botdb-sync (the sync loop and transports), botdb-relay (the relay server), botdb (vault, catalog, sharing, backups) and botdb-cli (the botdb binary, including relay and mcp).

The pieces meet at a few traits:

Trait Role
Replica Storage engine boundary: apply logical change batches, report what it has, snapshot.
Transport Moves encrypted batches and snapshots to and from a remote (relay or folder).
RelayStorage The relay’s storage backend (SQLite by default).

The change log references tables and columns by stable ids and rows by primary key, never by engine internals. SQLite could be swapped for another engine that implements Replica (for example PGlite or Turso) without changing the change-log format.

There is no daemon. botdb pulls before reads when its copy may be stale and pushes after writes from a short-lived background process. See Automatic sync.

Intended scale: databases up to about 100 MB, and dozens of devices per database.

Next steps

start

guides

reference

security