|
1 | | -# CLAUDE.md |
| 1 | +# Yorkie JavaScript SDK |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +pnpm monorepo with multiple packages for building collaborative editing applications. |
4 | 4 |
|
5 | | -## Project Overview |
| 5 | +## Development Commands |
6 | 6 |
|
7 | | -Yorkie JavaScript SDK — client-side libraries for building collaborative editing applications with the [Yorkie](https://yorkie.dev) platform. This is a **pnpm monorepo** with multiple publishable packages and example apps. |
| 7 | +```sh |
| 8 | +pnpm i # Install (pnpm enforced) |
| 9 | +pnpm sdk build # Build core SDK |
| 10 | +pnpm sdk build:proto # Regenerate protobuf code (buf generate) |
| 11 | +pnpm lint # ESLint with auto-fix (zero warnings enforced) |
8 | 12 |
|
9 | | -## Common Commands |
10 | | - |
11 | | -### Setup |
12 | | -```bash |
13 | | -pnpm i # Install all dependencies (pnpm is enforced) |
14 | | -``` |
15 | | - |
16 | | -### Build |
17 | | -```bash |
18 | | -pnpm sdk build # Build the core SDK |
19 | | -pnpm build:packages # Build all packages |
20 | | -pnpm sdk build:proto # Regenerate protobuf code (buf generate) |
| 13 | +# Tests require a running Yorkie server: |
| 14 | +docker compose -f docker/docker-compose.yml up --build -d |
| 15 | +pnpm sdk test # Run all SDK tests |
| 16 | +pnpm sdk test test/integration/tree_test.ts # Specific test file |
21 | 17 | ``` |
22 | 18 |
|
23 | | -### Test |
24 | | -Tests require a running Yorkie server (Docker): |
25 | | -```bash |
26 | | -docker compose -f docker/docker-compose.yml up --build -d # Start Yorkie server |
27 | | -pnpm sdk test # Run all SDK tests |
28 | | -pnpm sdk test test/integration/tree_test.ts # Run a specific test file |
29 | | -pnpm sdk test:watch # Watch mode |
30 | | -pnpm sdk test:bench # Run benchmarks |
31 | | -``` |
32 | | - |
33 | | -Use `.only` on `describe`/`it` blocks to run specific suites or tests within a file. |
| 19 | +Package filters: `pnpm sdk`, `pnpm react`, `pnpm schema`, `pnpm prosemirror`, `pnpm devtools` |
34 | 20 |
|
35 | | -### Lint |
36 | | -```bash |
37 | | -pnpm lint # ESLint with auto-fix (zero warnings enforced) |
38 | | -``` |
| 21 | +## After Making Changes |
39 | 22 |
|
40 | | -### Run Examples |
41 | | -```bash |
42 | | -docker compose -f docker/docker-compose.yml up --build -d # Needs Yorkie server |
43 | | -pnpm sdk dev # Start dev server at http://0.0.0.0:9000/ |
| 23 | +Always run before submitting: |
| 24 | +```sh |
| 25 | +pnpm lint && pnpm sdk build && pnpm sdk test |
44 | 26 | ``` |
45 | 27 |
|
46 | | -### Package-specific Commands |
47 | | -Use the root shorthand filters: `pnpm sdk <cmd>`, `pnpm react <cmd>`, `pnpm schema <cmd>`, `pnpm prosemirror <cmd>`, `pnpm devtools <cmd>`. |
48 | | - |
49 | | -## Architecture |
50 | | - |
51 | | -### Packages (`packages/`) |
52 | | - |
53 | | -- **`sdk`** (`@yorkie-js/sdk`) — Core SDK. Client connection, document management, CRDT implementations, and protobuf API layer. |
54 | | -- **`react`** (`@yorkie-js/react`) — React hooks/providers: `YorkieProvider`, `DocumentProvider`, `ChannelProvider`, `useYorkieDoc`, `useSelector`, `useRevisions`. |
55 | | -- **`prosemirror`** (`@yorkie-js/prosemirror`) — ProseMirror editor binding. |
56 | | -- **`schema`** (`@yorkie-js/schema`) — ANTLR-based schema definition and validation (`antlr/YorkieSchema.g4`). |
57 | | -- **`devtools`** (`@yorkie-js/devtools`) — Chrome extension for debugging (built with Plasmo). |
58 | | -- **`mcp`** — Model Context Protocol integration. |
59 | | - |
60 | | -### Core SDK Structure (`packages/sdk/src/`) |
61 | | - |
62 | | -- **`client/`** — `Client` class: manages server connection, document attachment/detachment, sync. |
63 | | -- **`document/`** — Central module: |
64 | | - - `document.ts` — `Document` class: the main collaborative document abstraction. |
65 | | - - `crdt/` — CRDT type implementations: `CRDTObject`, `CRDTArray`, `CRDTText`, `CRDTTree`, `CRDTCounter`, `Primitive`. |
66 | | - - `json/` — User-facing JSON proxy wrappers over CRDTs: `JSONObject`, `JSONArray`, `Text`, `Tree`, `Counter`. |
67 | | - - `operation/` — Operation types (Add, Remove, Set, Edit, Style, TreeEdit, etc.). |
68 | | - - `change/` — Change tracking, changepacks, and checkpoints. |
69 | | - - `time/` — Logical clocks: `TimeTicket`, `VersionVector`, `ActorID`. |
70 | | - - `presence/` — Presence/session data structures. |
71 | | - - `history.ts` — Undo/redo history management. |
72 | | -- **`channel/`** — Channel management for presence/broadcast. |
73 | | -- **`api/`** — Protobuf generated code and `converter.ts` for serialization. |
74 | | -- **`util/`** — Observable pattern, logger, validators, tree utilities. |
75 | | - |
76 | | -### Test Structure (`packages/sdk/test/`) |
| 28 | +## Packages |
77 | 29 |
|
78 | | -- `unit/` — Unit tests for individual CRDT types and utilities. |
79 | | -- `integration/` — Integration tests requiring a running Yorkie server. |
80 | | -- `bench/` — Vitest benchmarks. |
81 | | -- `helper/` — Shared test utilities and helpers. |
| 30 | +- **`sdk`** (`@yorkie-js/sdk`) — Core: client, documents, CRDTs, protobuf API |
| 31 | +- **`react`** (`@yorkie-js/react`) — React hooks/providers |
| 32 | +- **`prosemirror`** (`@yorkie-js/prosemirror`) — ProseMirror binding |
| 33 | +- **`schema`** (`@yorkie-js/schema`) — ANTLR-based schema validation (`antlr/YorkieSchema.g4`) |
| 34 | +- **`devtools`** (`@yorkie-js/devtools`) — Chrome extension (Plasmo) |
| 35 | +- **`mcp`** — Model Context Protocol integration |
82 | 36 |
|
83 | | -### Key Design Patterns |
| 37 | +## Gotchas |
84 | 38 |
|
85 | | -- **CRDT + JSON proxy**: Internal state uses CRDTs (`crdt/`). Users interact through JSON proxies (`json/`) that automatically generate operations on mutation. |
86 | | -- **Operation-based sync**: Document changes produce operations that are collected into changes, packed into changepacks, and synced via protobuf API. |
87 | | -- **Logical timestamps**: Every operation is tagged with a `TimeTicket` (lamport timestamp + actorID) for conflict resolution. |
| 39 | +- Protobuf source of truth is in [yorkie-team/yorkie](https://github.com/yorkie-team/yorkie/tree/main/api), not this repo |
| 40 | +- ESLint enforces zero warnings — CI and pre-commit hooks will reject any warnings |
| 41 | +- Tests use Vitest with custom-jsdom environment |
| 42 | +- Use `.only` on `describe`/`it` blocks to run specific tests within a file |
| 43 | +- Prettier config: single quotes, trailing commas, 80 char width |
88 | 44 |
|
89 | | -## Code Conventions |
| 45 | +## Key Design Pattern |
90 | 46 |
|
91 | | -- **TypeScript strict mode**, target ES2020. |
92 | | -- **Prettier**: single quotes, trailing commas, 80 char width. |
93 | | -- **ESLint**: zero warnings policy, enforced in CI and pre-commit hooks. |
94 | | -- **Commit messages**: subject line < 70 chars (what changed), body explains why. |
95 | | -- **Test framework**: Vitest with custom-jsdom environment. |
96 | | -- **Build**: Vite library mode outputting UMD + ES modules. |
97 | | -- **Protobuf source of truth**: [yorkie-team/yorkie](https://github.com/yorkie-team/yorkie/tree/main/api) repo. |
| 47 | +Internal state uses CRDTs (`crdt/`). Users interact through JSON proxies (`json/`) that automatically generate operations on mutation. Every operation is tagged with a `TimeTicket` (lamport timestamp + actorID). |
0 commit comments