Skip to content

joeblew999/automerge-wazero-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

81 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Automerge + WASI + wazero: Complete CRDT Demo

Production-ready collaborative CRDT demo powered by Automerge (Rust), WASI, and wazero (Go).

Why This Matters

Build truly collaborative apps without complex backend infrastructure. This project solves the hardest problems in distributed systems:

  • โœ… No conflict resolution logic - CRDTs mathematically guarantee consistency
  • โœ… Offline-first by default - Work disconnected, sync seamlessly when reconnected
  • โœ… Local-first architecture - Data stays on your device, no cloud dependency
  • โœ… Cross-platform from one codebase - Desktop, mobile, and web from the same Go server
  • โœ… Real-time collaboration - Like Google Docs, but you control the infrastructure

Perfect for:

  • ๐Ÿ“ฑ Mobile apps that need offline capability
  • ๐ŸŽฎ Real-time multiplayer experiences
  • ๐Ÿ“ Collaborative editing tools
  • ๐Ÿฅ Healthcare/field apps with intermittent connectivity
  • ๐Ÿ” Privacy-focused apps where data stays local

How It Works: CRDTs Handle the Hard Part

Core Architecture:

  • CRDTs handle data merge - Automerge automatically merges changes without conflicts
  • Any transport works - HTTP, WebSockets, Bluetooth, files on USB drives... it doesn't matter!
  • Great with NATS - Pair with NATS for lightweight pub/sub signaling (separate project)
Device A makes changes โ”€โ”€> Automerge CRDT state
                                โ”‚
                                โ”œโ”€โ”€> Share via ANY transport โ”€โ”€> Device B
                                โ”‚    (NATS, HTTP, files, etc.)
                                โ”‚
                                โ””โ”€โ”€> Automerge merges changes
                                     โœ… Guaranteed consistency

Why this matters: Traditional sync needs complex operational transforms, vector clocks, or central coordination. CRDTs just need to exchange state - the math guarantees consistency regardless of network timing or failures. You could use HTTP polling, WebSockets, file sharing, or pair with NATS for real-time pub/sub signaling. Each device runs its own local Go server with embedded CRDT state.

The Stack: This project demonstrates running Automerge - a mature CRDT library - compiled to WebAssembly (WASI) and hosted in a Go server using wazero. Features a complete web UI showcasing 8 different CRDT types with real-time collaboration via Server-Sent Events (SSE).

License Go Version Rust


๐ŸŽฏ Live Demo

After running make run, open http://localhost:8080 to see all 8 CRDT types in action:

๐Ÿ“ Text CRDT

Basic collaborative text editing with character count and real-time sync.

Text CRDT

๐Ÿ—บ๏ธ Map CRDT

Key-value storage with CRDT conflict resolution. Put, get, delete, and list keys.

Map CRDT

๐Ÿ“‹ List CRDT

Ordered list with CRDT semantics. Push, insert at index, and delete operations.

List CRDT

๐Ÿ”ข Counter CRDT

Conflict-free counter with increment/decrement. Features animated display and quick action buttons.

Counter CRDT

๐ŸŽฏ Cursor Operations

Stable position tracking across concurrent edits. Interactive demo shows cursor adjusting as text changes.

Cursor Operations

๐Ÿ“š Document History

View version history, heads (DAG tips), and changes. Download .am snapshots for offline storage.

History

Plus ๐Ÿ”„ Sync Protocol (M1) and โœจ Rich Text (M2) tabs!


๐Ÿš€ Quick Start

Prerequisites

  • Rust (stable): Install via rustup
  • Go 1.21+: Download Go
  • Make: Usually pre-installed on macOS/Linux

Installation & Run

# Clone the repository
git clone https://github.com/joeblew999/automerge-wazero-example.git
cd automerge-wazero-example

# Build and run (builds WASI module + starts server)
make run

The server will start on http://localhost:8080 ๐ŸŽ‰

Open multiple browser tabs to see real-time collaboration!


๐Ÿ—๏ธ Architecture

Perfect 1:1 mapping across 6 layers - every file has an exact counterpart in each layer:

Web UI โ†’ HTTP API โ†’ Go Server โ†’ Go API โ†’ Go FFI โ†’ Rust WASI โ†’ Automerge Core
(*.js)   (api/*.go)  (server/*) (automerge/*)(wazero/*)(*.rs)

Key Stats:

  • ๐ŸŽฏ 57 WASI exports covering ~80% of Automerge API
  • ๐Ÿ”’ 13 modules with perfect 1:1 file mapping
  • ๐Ÿงช 103+ tests (36 Rust + 67+ Go), all passing
  • ๐Ÿ“ฆ Binary persistence with .am snapshots
  • ๐Ÿ”„ Real-time SSE broadcasts to all clients
  • ๐ŸŒ 8-tab web UI with gradient design

๐Ÿ“Š Complete Feature Matrix

Feature WASI Exports Go API HTTP Web UI Status
Text 4/4 โœ… โœ… โœ… 100%
Map 6/6 โœ… โœ… โœ… 100%
List 8/8 โœ… โœ… โœ… 100%
Counter 3/3 โœ… โœ… โœ… 100%
Cursor 3/3 โœ… โœ… โœ… 100%
History 4/4 โœ… โœ… โœ… 100%
Sync 5/5 โœ… โœ… โœ… 100%
RichText 7/7 โœ… โœ… โœ… 100%

Total: 57/57 WASI exports implemented!


๐ŸŒ HTTP API Examples

Text Operations

curl http://localhost:8080/api/text
curl -X POST http://localhost:8080/api/text -H 'Content-Type: application/json' -d '{"text":"Hello!"}'

Map Operations

curl -X POST http://localhost:8080/api/map -d '{"path":"ROOT","key":"user","value":"Alice"}'
curl "http://localhost:8080/api/map?path=ROOT&key=user"
curl "http://localhost:8080/api/map/keys?path=ROOT"

Counter Operations

curl -X POST http://localhost:8080/api/counter -d '{"path":"ROOT","key":"clicks","delta":1}'
curl "http://localhost:8080/api/counter?path=ROOT&key=clicks"

23 HTTP endpoints total - see HTTP API Complete Guide


๐Ÿ“ Project Structure

.
โ”œโ”€โ”€ Makefile                # Build automation + tests
โ”œโ”€โ”€ CLAUDE.md               # AI agent instructions
โ”œโ”€โ”€ README.md               # This file
โ”‚
โ”œโ”€โ”€ go/                     # Go server
โ”‚   โ”œโ”€โ”€ cmd/server/         # HTTP server (23 routes)
โ”‚   โ””โ”€โ”€ pkg/
โ”‚       โ”œโ”€โ”€ automerge/      # High-level API (13 files)
โ”‚       โ”œโ”€โ”€ server/         # Server layer (13 files)  
โ”‚       โ”œโ”€โ”€ api/            # HTTP handlers (13 files)
โ”‚       โ””โ”€โ”€ wazero/         # FFI wrappers (13 files)
โ”‚
โ”œโ”€โ”€ rust/automerge_wasi/    # Rust WASI module
โ”‚   โ””โ”€โ”€ src/                # 13 modules (1:1 with Go)
โ”‚
โ”œโ”€โ”€ web/                    # Modern web UI
โ”‚   โ”œโ”€โ”€ index.html          # Tab navigation
โ”‚   โ”œโ”€โ”€ js/                 # 8 component modules
โ”‚   โ””โ”€โ”€ components/         # 8 HTML templates
โ”‚
โ”œโ”€โ”€ docs/                   # Comprehensive docs
โ”‚   โ”œโ”€โ”€ tutorials/          # Getting started
โ”‚   โ”œโ”€โ”€ how-to/             # Recipes
โ”‚   โ”œโ”€โ”€ reference/          # API docs
โ”‚   โ””โ”€โ”€ development/        # Testing, roadmap
โ”‚
โ””โ”€โ”€ screenshots/            # Component screenshots

๐Ÿงช Testing

make test-go        # 67+ Go tests โœ…
make test-rust      # 36 Rust tests โœ…
make verify-web     # Web structure โœ…
make verify-docs    # Doc links โœ…

All tests passing! See Testing Guide


๐Ÿ“š Documentation

๐Ÿ“š Full Documentation Index โ†’


๐Ÿšฆ Commands

make build-wasi      # Build Rust WASI
make run             # Build + start server
make test-go         # Run Go tests
make test-rust       # Run Rust tests
make clean           # Clean artifacts

๐Ÿ”ฎ Status

  • โœ… M0: Core CRDTs (Text, Map, List, Counter, Cursor, History)
  • โœ… M1: Sync protocol (delta-based sync)
  • โœ… M2: Rich text (marks/spans)
  • โœ… Web UI: All 8 components with screenshots
  • ๐Ÿšง M3: NATS transport (planned)
  • ๐Ÿšง M4: Datastar UI (planned)

๐Ÿ”— Links

  • Automerge - CRDT library
  • wazero - Go WASM runtime
  • WASI - WebAssembly System Interface
  • NATS - Messaging system (great transport partner)

๐Ÿค Collaboration

This project is part of a larger local-first architecture combining:

  • Automerge CRDTs (this repo) - Conflict-free data layer
  • NATS - Lightweight messaging and sync signaling
  • Datastar - Reactive UI components
  • goup-util - Cross-platform app bundling (iOS, Android, macOS, Windows, Linux)
  • wellknown - Data sovereignty and platform-agnostic publishing

Complete Stack = Own Your Data, Reach Everyone:

  • Write once โ†’ HTML/CSS/JS deploys to mobile, desktop, and web
  • Own your data โ†’ CRDTs sync locally, you control the infrastructure
  • Publish optionally โ†’ Use wellknown URIs to route to your apps or mirror to Google/Apple services
  • Stay portable โ†’ Your links work regardless of which platforms you use
  • ~95% web tech, ~4% Go backend, ~1% build commands

Looking for partners and organizations interested in:

  • Building local-first applications
  • Offline-capable mobile/desktop solutions
  • Privacy-focused collaborative tools
  • Edge computing and distributed systems

Open to collaboration, consulting, and commercial partnerships. Reach out via GitHub Issues or explore the codebase to see if it fits your needs.


๐Ÿ“„ License

MIT License - See LICENSE


Built with โค๏ธ using Rust, Go, and WebAssembly

Perfect 1:1 mapping across 6 layers with 103+ passing tests

About

Production-ready collaborative CRDT demo** powered by Automerge (Rust), WASI, and wazero (Go).

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published