Logo Architecture Crdts

Architecture Crdts

Cộng đồng
j4flmao
architecture-crdts

Use this skill when the user says 'CRDT', 'real-time collaboration', 'collaborative editing', 'Yjs', 'Automerge', 'local-first', 'offline sync with merge', 'conflict-free merge', 'operational transformation vs CRDT'. Designs replicated data that merges without coordination: choosing CRDT types, library (Yjs, Automerge, Loro), sync and persistence architecture, and handling tombstones, schema evolution, and authorization. Do NOT use for: server-authoritative consistency/consensus (system-design distributed-consensus), mobile offline caching without concurrent edits (mobile/universal/offline-first), or event sourcing (backend/universal/event-sourcing).

Tổng quan

Nhà phát hànhj4flmao
Kho mãagent-skills
Tên kỹ năngarchitecture-crdts
Sao
41
Bản fork
6
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được j4flmao công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Architecture Crdts trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/j4flmao/agent-skills/tree/main/skills/architecture/crdts
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/architecture/crdts .claude/skills/architecture-crdts
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Architecture Crdts trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Architecture Crdts ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Architecture Crdts với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Conflict-free Replicated Data Types (CRDTs)

Purpose

CRDTs let replicas accept writes independently (offline, peer-to-peer, multi-region) and still converge to the same state once they have seen the same updates, with no central lock or transform server. They trade some storage and semantic control for availability and simple sync. Use proven libraries; design the document model, sync transport, persistence, and access control around them.

Agent Protocol

Trigger

"CRDT", "collaborative editor", "multiplayer editing", "Yjs", "Automerge", "Loro", "local-first", "offline merge", "OT vs CRDT", "conflict resolution without server".

Input Context

  • Data shape (text, rich text, lists, maps, counters, trees/canvas).
  • Concurrency: number of simultaneous editors, offline duration.
  • Topology: client-server relay, peer-to-peer, multi-region servers.
  • Auth model and audit/history requirements.

Output Artifact

CRDT design: per-field type, library choice, sync/persistence architecture, compaction and auth plan.

Response Format

Document model: {field: CRDT type}
Library: {Yjs|Automerge|Loro}  Transport: {WebSocket relay|WebRTC|HTTP sync}
Persistence: {updates log + snapshots}  Compaction: {policy}
Auth: {room-level|server-validated updates}
Semantics caveats: {e.g. LWW on title, interleaving}

Completion Criteria

  • Each field's merge semantics stated (what happens on concurrent edits).
  • Server validates who may write which document.
  • Persistence keeps update log + periodic snapshots; growth bounded.
  • Convergence tested with randomized concurrent operations.

Two Families

FamilyReplicas exchangeRequirement on merge/delivery
State-based (CvRDT)Whole state (or deltas)Merge is commutative, associative, idempotent (a join-semilattice); any delivery order, duplicates OK
Operation-based (CmRDT)OperationsConcurrent ops commute; delivery exactly-once and causally ordered (usually provided by the library's sync protocol)

Delta-state CRDTs ship only the changed part of the state; Yjs and Automerge use compact update encodings with state vectors/heads so peers send only what the other side lacks.

Common Types

TypeMerge ruleCaveat
G-CounterPer-replica counts, merge = elementwise max, value = sumIncrement only
PN-CounterTwo G-Counters (inc, dec)Can go negative
LWW-RegisterHighest (timestamp, replica id) winsNeeds good clocks (hybrid logical clocks); silently drops one write
MV-RegisterKeep all concurrent valuesApp must resolve
OR-Set (add-wins)Adds tagged uniquely; remove deletes observed tagsMetadata grows
Sequence (RGA, YATA, Fugue)Elements get unique ids ordered relative to neighboursTombstones; concurrent inserts must not interleave badly
JSON/map CRDTNested maps/lists of the aboveConcurrent move/reparent is hard (tree CRDTs)
typescript
// G-Counter: the canonical state-based CRDT
type GCounter = Record<string, number>;

export const increment = (c: GCounter, replica: string, by = 1): GCounter => {
  if (by < 0) throw new RangeError(`G-Counter cannot decrement (replica=${replica}, by=${by})`);
  return { ...c, [replica]: (c[replica] ?? 0) + by };
};

export const merge = (a: GCounter, b: GCounter): GCounter => {
  const out: GCounter = { ...a };
  for (const [r, n] of Object.entries(b)) out[r] = Math.max(out[r] ?? 0, n);
  return out;
};

export const value = (c: GCounter): number => Object.values(c).reduce((s, n) => s + n, 0);

CRDT vs Operational Transformation

OTCRDT
CoordinationCentral server orders and transforms opsNone required
Offline / P2PPoorNative
MetadataSmallIds/tombstones per element (modern libs compress heavily)
Intent controlServer can enforceMerge rule is fixed by type
ExamplesGoogle Docs (historically), ShareDBYjs, Automerge, Loro

If you already have a single authoritative server and no offline requirement, server-ordered ops (OT or simple last-write with versioning) can be simpler.

Library Usage

Yjs (shared types + y-websocket relay):

typescript
import * as Y from "yjs";
import { WebsocketProvider } from "y-websocket";
import { IndexeddbPersistence } from "y-indexeddb";

const doc = new Y.Doc();
new IndexeddbPersistence("doc-42", doc);                       // offline cache
const provider = new WebsocketProvider("wss://sync.example.com", "doc-42", doc);

const text = doc.getText("body");
const meta = doc.getMap("meta");
doc.transact(() => {                                            // one update event
  text.insert(0, "Hello");
  meta.set("title", "Draft");                                   // map keys: last-writer-wins
});
provider.awareness.setLocalStateField("user", { name: "Ana" }); // presence, not persisted

// Server-side or tests: exchange binary updates
const update = Y.encodeStateAsUpdate(doc);
const replica = new Y.Doc();
Y.applyUpdate(replica, update);

Automerge (JSON-like documents, full history):

typescript
import * as A from "@automerge/automerge";

let a = A.from({ tasks: [] as { title: string; done: boolean }[], votes: new A.Counter(0) });
let b = A.clone(a);
a = A.change(a, d => { d.tasks.push({ title: "Write spec", done: false }); });
b = A.change(b, d => { d.votes.increment(1); });
const merged = A.merge(a, b);   // contains both changes

For networking and storage, Automerge Repo (@automerge/automerge-repo) provides sync adapters.

Architecture

  • The server is a relay plus persistence, but it is still the place for authorization: check the user may write the room before accepting updates; validate update size and rate.
  • Persist incremental updates; periodically merge them into a snapshot (Y.encodeStateAsUpdate) and truncate the log.
  • Project CRDT state into ordinary tables for search, reporting, and server-side business rules.

Pitfalls

  • Valid merge ≠ valid business state: two users each book the last seat; both merges are "correct". Invariants needing exclusivity (uniqueness, balances) need a server-side authority or reservation.
  • Tombstone growth: deleted text still has metadata; enable garbage collection (Yjs gc: true, default) unless you need full history, and snapshot.
  • Clock skew in LWW: use hybrid logical clocks, never raw wall clocks alone.
  • Schema evolution: field renames are new fields; write migrations that copy data inside a change, version the document schema.
  • Undo: must be per-user (Y.UndoManager with tracked origins), not global.
  • Large docs: split into sub-documents (one per page/board) to bound load time.

Checklist

  • Field-by-field CRDT type and concurrent-edit semantics documented.
  • Library chosen; no hand-rolled sequence CRDT.
  • Relay authorizes per document; rate and size limits.
  • Update log + snapshot compaction; GC policy.
  • Business invariants needing exclusivity handled server-side.
  • Property-based tests: random concurrent ops on N replicas converge.
  • Presence/awareness kept out of persisted state.

References

  • Shapiro et al., "Conflict-free Replicated Data Types" (SSS 2011).
  • Kleppmann et al., "Local-first software" (Onward! 2019).
  • Nicolaescu et al., YATA (GROUP 2016); Weidner & Kleppmann, "The Art of the Fugue" (2023).
  • Yjs docs (shared types, providers, awareness); Automerge docs.

Câu hỏi thường gặp

Kỹ năng AI Architecture Crdts làm được gì?

Use this skill when the user says 'CRDT', 'real-time collaboration', 'collaborative editing', 'Yjs', 'Automerge', 'local-first', 'offline sync with merge', 'conflict-free merge', 'operational transformation vs CRDT'. Designs replicated data that merges without coordination: choosing CRDT types, library (Yjs, Automerge, Loro), sync and persistence architecture, and handling tombstones, schema evolution, and authorization. Do NOT use for: server-authoritative consistency/consensus (system-design distributed-consensus), mobile offline caching without concurrent edits (mobile/universal/offline-...

Vì sao nên dùng Architecture Crdts trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Architecture Crdts là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Architecture Crdts trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/j4flmao/agent-skills/tree/main/skills/architecture/crdts. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Architecture Crdts?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Architecture Crdts với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Architecture Crdts với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Architecture Crdts có miễn phí không?

Có. Kỹ năng này được j4flmao phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇