MCPcopy Index your code
hub / github.com/everyside/swirldb

github.com/everyside/swirldb @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
791 symbols 2,129 edges 53 files 336 documented · 42%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

SwirlDB

Cross-platform CRDT database built on Automerge. Runs in browsers via WebAssembly and as a native Rust sync server.

⚠️ UNDER ACTIVE DEVELOPMENT ⚠️

SwirlDB is in early development and not ready for production use. The API is unstable and subject to breaking changes.

📚 Full Documentation

Design

  • CRDT-based: Built on Automerge for automatic conflict resolution
  • Cross-platform: Browser WASM (~489KB gzipped) and native Rust server with different optimizations
  • Pluggable storage: In-memory, LocalStorage, IndexedDB, or redb
  • Real-time sync: WebSocket-based synchronization server
  • Observable: Field-level change tracking via observers
  • Policy engine: Access control for subscriptions

Architecture

Browser and Server Builds

  • Browser: WebAssembly module with JavaScript bindings
  • Server: Native Rust binary for WebSocket/HTTP sync

Crate Structure

  • swirldb-core: Platform-agnostic CRDT engine and storage traits
  • swirldb-browser: WASM bindings with localStorage and IndexedDB adapters
  • swirldb-server: Sync server with redb storage and subscription management

See BUILD.md for build instructions.

Prerequisites

  • Rust - Install from rustup.rs
  • pnpm - Install with npm install -g pnpm or brew install pnpm

Quick Start

Browser (WASM)

1. Build the WASM package:

# From repository root
pnpm run build:wasm

2. Use in your application:

import { SwirlDB } from '@swirldb/js';

// Configure with LocalStorage adapter (data persists automatically)
const db = await SwirlDB.withLocalStorage('my-app');

// Use natural property access via Proxies
db.data.user.name = 'Alice';
db.data.user.age = 30;

// Read values
console.log(db.data.user.name.$value); // 'Alice'

// Observe changes reactively
db.data.user.name.$observe((newValue) => {
  console.log('Name changed:', newValue);
});

// Data is automatically persisted to localStorage
// No manual save/load needed!

Or with in-memory storage:

// Volatile storage (nothing persists)
const db = await SwirlDB.create();

Development

Building from Source

Build Browser WASM:

cd native/swirldb-browser
wasm-pack build --target web --out-dir pkg

Build Server:

cd native/swirldb-server
cargo build --release

Running Tests

Prerequisites for Integration Tests:

# Install Node.js dependencies for browser tests
cd tests/integration
npm install

# Install Playwright for headless browser testing
npx playwright install chromium

Run All Integration Tests:

cd tests
cargo test --test integration

Run Specific Test Suites:

# Browser WebAssembly ↔ Server sync tests
cargo test --test integration browser_sync

# Subscription filtering tests
cargo test --test integration subscription_filtering

# Multi-client sync tests
cargo test --test integration multi_client_sync

# Network resilience tests
cargo test --test integration network_resilience

Run a Single Test:

cargo test --test integration test_browser_to_server_sync -- --nocapture

The integration test suite includes: - 32 passing tests covering Browser WASM and Rust native clients - Real headless browser testing with Playwright - Cross-platform CRDT synchronization validation - Subscription filtering and policy enforcement - Network disconnect/reconnect scenarios

See BUILD.md for detailed build instructions.

Storage and Sync Adapters

SwirlDB is built entirely from swappable adapters:

Storage Adapters

Implemented: - ✅ In-memory (volatile, fast) - ✅ LocalStorage (browser, 5-10MB) - ✅ IndexedDB (browser, 50MB-1GB) - ✅ redb (server, embedded, persistent) - ✅ Memory adapter (server, multi-threaded)

Planned: - 🔜 SQLite (portable, queryable) - 🔜 Sharded files (large datasets) - 🔜 S3 (cloud-native)

Sync Adapters

Implemented: - ✅ WebSocket (real-time, bi-directional) - ✅ HTTP long-polling (fallback)

Planned: - 🔜 WebRTC (peer-to-peer) - 🔜 Custom protocols

Auth & Policy Adapters

Planned: - 🔜 JWT validation - 🔜 OAuth integration - 🔜 ABAC (attribute-based access control) - 🔜 Custom policy engines

Encryption Adapters

Planned: - 🔜 AES-GCM (document-level) - 🔜 Field-level encryption - 🔜 Custom crypto implementations

License

Apache 2.0

Copyright 2025 Everyside Innovations, LLC

Extension points exported contracts — how you extend this code

EncryptionProviderMarker (Interface)
(no doc) [6 implementers]
native/swirldb-core/src/encryption/mod.rs
AuthProvider (Interface)
Trait for authentication providers Auth providers are responsible for determining the current actor (who is performing [3 …
native/swirldb-core/src/auth/mod.rs
DocumentStorageMarker (Interface)
(no doc) [4 implementers]
native/swirldb-core/src/storage/mod.rs
DocumentStorage (Interface)
(no doc) [4 implementers]
native/swirldb-core/src/storage/mod.rs
EncryptionProvider (Interface)
(no doc) [3 implementers]
native/swirldb-core/src/encryption/mod.rs

Core symbols most depended-on inside this repo

close
called by 62
tests/integration/rust_client.rs
get
called by 56
native/swirldb-browser/src/wrapper.ts
is_empty
called by 54
native/swirldb-core/src/paths/types.rs
as_str
called by 50
native/swirldb-core/src/transport.rs
len
called by 47
native/swirldb-core/src/paths/types.rs
encode
called by 42
native/swirldb-core/src/protocol/mod.rs
set_path
called by 40
native/swirldb-core/src/core.rs
set_path
called by 37
tests/integration/rust_client.rs

Shape

Method 425
Function 258
Class 81
Enum 18
Interface 9

Languages

Rust83%
TypeScript17%

Modules by API surface

native/swirldb-core/src/transport.rs67 symbols
native/swirldb-server/src/peer_manager.rs51 symbols
native/swirldb-core/src/core.rs50 symbols
native/swirldb-browser/src/wrapper.ts44 symbols
docs/public/swirldb.js44 symbols
admin/public/swirldb.js44 symbols
native/swirldb-browser/src/lib.rs43 symbols
native/swirldb-server/src/transport/lan.rs42 symbols
native/swirldb-core/src/policy.rs42 symbols
native/swirldb-server/src/state.rs38 symbols
native/swirldb-core/src/protocol/mod.rs32 symbols
native/swirldb-core/src/sync.rs28 symbols

For agents

$ claude mcp add swirldb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact