CRDT LF
Conflict-free Replicated Data Types for Dart and Flutter. Build local-first, collaborative apps: every user edits their own copy, even offline, and every copy converges to the same state.
π This README is a short entry point. The complete documentation β use cases, connectors, deep dives β is on mattiapispisa.it/crdt.
Features
- βοΈ Collaborative text: the Fugue algorithm keeps concurrent typing readable
- π ±οΈ Rich text: formats, links, headings, images and videos, merged with Peritext
- π Lists: ordered and movable lists; concurrent moves never duplicate an item
- π·οΈ Maps, sets and registers: observed-removed (add-wins) and last-writer-wins
- π³ Nested data: trees of handlers, through containers and references
- π¦ Aggregates: domain objects built from events, with versions and migrations
- β©οΈ Undo and redo: takes back your own edits, and leaves everyone else's alone
- π Handler deltas: what each change did to your copy, for carets and lists
- β±οΈ Hybrid logical clock: a causal order with no central server
- πΈ Snapshots and a compact binary format: prune the history, store and send bytes
- β β¦and more: everything else is in the documentation
See it live
Greyhound Markdown, a real-time collaborative markdown editor built on
crdt_lf. Open it on two devices, join the same room and type together.
Every handler on two simulated peers, in the browser: live Flutter examples.
Quick start
dart pub add crdt_lf
import 'dart:io';
import 'package:crdt_lf/crdt_lf.dart';
final alice = CRDTDocument();
final bob = CRDTDocument();
// The same handler id on both peers: it is the same text.
final aliceText = CRDTFugueTextHandler(alice, 'note');
final bobText = CRDTFugueTextHandler(bob, 'note');
aliceText.insert(0, 'Hello world');
bob.importChanges(alice.exportChanges()); // Bob now reads "Hello world"
// Both edit at the same time, with no connection.
aliceText.insert(0, 'Big ');
bobText.insert(11, '!');
// They meet again and exchange what the other is missing.
bob.importChanges(alice.exportChanges());
alice.importChanges(bob.exportChanges());
stdout
..writeln(aliceText.value) // Big Hello world!
..writeln(bobText.value); // Big Hello world!
Two documents in one program stand for two devices: in an app the changes
travel over the network (crdt_socket_sync).
The program is a recipe, tested in CI.
Connect it
| You want to | Add |
|---|---|
| keep the document on the device | crdt_lf_hive, crdt_lf_sqlite, crdt_lf_drift, β¦ (all the adapters) |
| sync it with other peers | crdt_socket_sync, served from Dart Frog or Serverpod |
| show it in Flutter | crdt_lf_flutter, and crdt_lf_quill for a rich text editor |
Documentation
- The document: what it holds, and a map of its API
- Which handler do you need?: text, rich text, lists, maps and sets, nested data, aggregates, undo, history, β¦
- Open a replica: document, storage and sync in one call
- Deep dive: transactions, deltas, state cache, snapshots, binary format, custom handlers, β¦
- Migrations: one guide for each major version
- Benchmarks
Contributing
Bug reports, ideas and pull requests are welcome: read the contributing guide and the roadmap.
Roadmap
πΊοΈ The project board shows what is done, what is in progress and what comes next, for this package and the rest of the workspace. Missing something? Open an issue: requests go on the board too.
Apps
- greyhound_markdown β Real-time collaborative markdown editor built on crdt_lf
Packages
Other bricks of the crdt "system" are: