Expand description
§Bothy
Bothy is a local-first sync engine for applications that have no server of their own. Each device keeps its data in a local SQLite database, and devices exchange immutable, append-only files through the user’s own cloud storage (Google Drive first).
Status: early development. The local store, the merge rules, the file formats and the
sync engine work against a local or shared folder (remote::FolderRemote). The Google
Drive backend and the CLI are in progress at https://github.com/bothy-sync/bothy.
use std::sync::Arc;
use bothy::{Config, Database, remote::FolderRemote};
use serde_json::json;
let remote = Arc::new(FolderRemote::new(shared)?);
// Device A creates the database and writes a note.
let a = Database::open(Config::new(local_a, "com.example.notes"), remote.clone()).await?;
let db_id = a.init().await?;
a.collection("notes")?.put("n1", json!({"title": "Hello"})).await?;
a.sync().await?;
// Device B joins and receives it.
let b = Database::open(Config::new(local_b, "com.example.notes"), remote).await?;
b.join(db_id).await?;
let note = b.collection("notes")?.get("n1").await?.unwrap();
assert_eq!(note.to_json(), json!({"title": "Hello"}));Re-exports§
pub use model::CollectionName;pub use model::DbId;pub use model::DeviceId;pub use model::DocId;pub use model::FieldName;pub use model::Op;pub use model::OpKind;pub use model::Stamp;pub use model::Value;
Modules§
- auth
- Access tokens for remote backends. OAuth flows live outside the core (CLI, app, binding); the core only asks for a token and reports a rejected one.
- blocking
- Synchronous API for callers without an async runtime (CLI, Python, C).
- codec
- Wire encodings and remote file formats.
- crypto
- Client-side encryption (feature
crypto): Argon2id key derivation and XChaCha20-Poly1305. - merge
- Field-level last-writer-wins merge with delete stamps. Pure: no I/O.
- model
- Data model: values, identifiers, operations.
- p2p
- Direct channel between online devices (WebRTC data channel,
str0mon itsaws-lc-rscrypto backend). - remote
- Remote storage backends. Every file is immutable once written; there is no overwrite.
- store
- Local SQLite store: merge state, read view and outbox, kept consistent in one transaction.
Structs§
- Auto
Sync - Timing of background sync.
- Change
Event - A document’s visible content changed.
- Collection
- A collection of documents in a
Database. - Compact
Report - Files a compaction run deleted (or would delete, for a dry run).
- Config
- Settings for
Database::open. - Database
- A local-first database that syncs through a
RemoteStore. - Error
- A Bothy error: a
ErrorKind, a message and an optional underlying cause. - Hlc
- A hybrid logical clock timestamp.
- HlcClock
- Produces monotonically increasing
Hlctimestamps for one device. - List
Options - Options for
Collection::list. - Parse
HlcError - Error returned when parsing an
Hlcfrom its hex form fails. - Snapshot
Policy - When to snapshot and how long to keep covered files.
- Sync
Handle - Controls a background sync task. Dropping it stops the task.
- Sync
Report - What one
Database::synccall did. - System
Clock - The operating system clock.
Enums§
- Error
Kind - Broad error category. Callers branch on this; the message is for humans.
- Origin
- Where a change came from.
- Sync
Status - Outcome of the latest background sync.
Constants§
- DEFAULT_
MAX_ DRIFT_ MS - Default limit on how far a remote timestamp may pull the local clock ahead of the wall clock.
- FORMAT_
VERSION - Version of the on-remote file format written by this crate (
bothy_formatinmanifest.json). Draft: the format is not frozen untilSPEC.mdv1.
Traits§
- Clock
- Wall-clock source in milliseconds since the Unix epoch. Tests inject a fake one.
- Into
Document - Types that can be written as a whole document.
Type Aliases§
- Result
- Result type used throughout Bothy.