CRDT LF

crdt_lf_badge pub points pub likes codecov ci_badge License: MIT pub publisher

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.

Read the full documentation

πŸ“– 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.

Open the live demo

Greyhound Markdown home screen

Every handler on two simulated peers, in the browser: live Flutter examples.

flutter_document_example

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

Contributing

Bug reports, ideas and pull requests are welcome: read the contributing guide and the roadmap.

Roadmap

Roadmap: done, in progress, to do

πŸ—ΊοΈ 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

Packages

Other bricks of the crdt "system" are:

Libraries

crdt_lf