{"id":31645620,"url":"https://github.com/typecellos/blocknote-electric-example","last_synced_at":"2025-10-07T05:15:21.667Z","repository":{"id":316209139,"uuid":"1023574180","full_name":"TypeCellOS/blocknote-electric-example","owner":"TypeCellOS","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-23T08:57:11.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-23T10:26:41.204Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://blocknote-electric-example.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TypeCellOS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-21T11:15:10.000Z","updated_at":"2025-09-23T08:57:14.000Z","dependencies_parsed_at":"2025-09-23T10:27:05.084Z","dependency_job_id":null,"html_url":"https://github.com/TypeCellOS/blocknote-electric-example","commit_stats":null,"previous_names":["typecellos/blocknote-electric-example"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/TypeCellOS/blocknote-electric-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeCellOS%2Fblocknote-electric-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeCellOS%2Fblocknote-electric-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeCellOS%2Fblocknote-electric-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeCellOS%2Fblocknote-electric-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TypeCellOS","download_url":"https://codeload.github.com/TypeCellOS/blocknote-electric-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TypeCellOS%2Fblocknote-electric-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278722757,"owners_count":26034463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-07T05:15:04.991Z","updated_at":"2025-10-07T05:15:21.659Z","avatar_url":"https://github.com/TypeCellOS.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlockNote + Electric SQL: Real-time Collaborative Rich Text Editing\n\nThis example showcases a multiplayer [BlockNote](https://blocknotejs.org/) rich text editor with [YJS](https://github.com/yjs/yjs) and [Electric SQL](https://electric-sql.com/). All collaborative data is synchronized through [PostgreSQL](https://www.postgresql.org/), providing real-time editing with cursor awareness without requiring additional real-time infrastructure.\n\n## 🚀 Features\n\n- **Real-time Collaborative Editing**: Multiple users can edit documents simultaneously\n- **Cursor Awareness**: See other users' cursors and selections in real-time\n- **Rich Text Editor**: Full-featured editor based on ProseMirror with BlockNote\n- **Offline Support**: Works offline with automatic sync when reconnected\n- **CRDT-based**: Conflict-free editing using YJS CRDT technology\n- **Database-backed**: All data persisted in PostgreSQL with Electric SQL\n\n## 🏗️ Architecture\n\nThis application demonstrates the powerful combination of:\n\n- **[BlockNote](https://blocknotejs.org/)**: A modern, extensible rich text editor built on ProseMirror\n- **[YJS](https://github.com/yjs/yjs)**: A CRDT library that enables real-time collaboration\n- **[Electric SQL](https://electric-sql.com/)**: A local-first database that syncs with PostgreSQL\n- **[Y-Electric](https://github.com/electric-sql/electric/tree/main/packages/y-electric)**: A YJS connection provider that integrates YJS with Electric SQL\n\nThe integration works by:\n\n1. BlockNote uses YJS for collaborative editing via the `y-prosemirror` binding\n2. Y-Electric handles the synchronization between YJS documents and PostgreSQL\n3. Electric SQL provides offline-first database capabilities with automatic sync\n4. All collaboration data flows through PostgreSQL, eliminating the need for WebSocket servers\n\n## 🛠️ Setup\n\n### Prerequisites\n\n- [Node.js](https://nodejs.org/) (v18 or higher)\n- [pnpm](https://pnpm.io/) (v8 or higher)\n- [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/)\n\n### Installation\n\n1. Install dependencies:\n\n   ```shell\n   pnpm install\n   ```\n\n2. Build the application:\n\n   ```shell\n   pnpm build\n   ```\n\n### Running the Application\n\n1. Start the backend services using Docker Compose:\n\n   ```shell\n   pnpm backend:up\n   ```\n\n   \u003e **Note**: This stops and deletes volumes from any other running example backend containers to ensure a clean database state.\n\n2. Start the development server:\n\n   ```shell\n   pnpm dev:server\n   ```\n\n3. In a new terminal, start the client application:\n\n   ```shell\n   pnpm dev:client\n   ```\n\n4. Open your browser and navigate to the application URL (typically `http://localhost:5173`)\n\n5. When you're done, stop the backend services:\n\n   ```shell\n   pnpm backend:down\n   ```\n\n## 🔧 Key Components\n\n### BlockNote Integration\n\nThe editor is implemented in `src/client/components/editor/EditorView.tsx`:\n\n```typescript\nconst editor = useCreateBlockNote({\n  collaboration: {\n    provider: {\n      awareness, // YJS awareness for cursor/selection sync\n    },\n    fragment: ydoc.getXmlFragment(`document-store`), // YJS fragment for document data\n    user: {\n      name: user.name,\n      color: user.color,\n    },\n  },\n})\n```\n\n### Electric SQL Integration\n\nThe YJS-Electric integration is handled in `src/client/common/useElectric.ts`:\n\n```typescript\nconst provider = new ElectricProvider({\n  doc: ydoc,\n  documentUpdates: {\n    shape: { /* Electric SQL shape configuration */ },\n    sendUrl: /* API endpoint for updates */,\n  },\n  awarenessUpdates: {\n    shape: { /* Awareness sync configuration */ },\n    sendUrl: /* API endpoint for awareness updates */,\n  },\n})\n```\n\n### Database Schema\n\nThe PostgreSQL schema (`db/migrations/01-create_yjs_tables.sql`) includes:\n\n- `ydoc_update`: Stores YJS document updates\n- `ydoc_awareness`: Stores user awareness data (cursors, selections)\n- `files`: Document metadata\n- `users`: User information\n\n## 🎯 Usage\n\n1. **Create a User**: Select a user from the dropdown in the sidebar\n2. **Edit Documents**: Start typing in the editor - changes sync in real-time\n3. **Collaborate**: Open multiple browser tabs/windows with different users to see real-time collaboration\n4. **Cursor Awareness**: See other users' cursors and selections in real-time\n5. **Offline Mode**: Disconnect and continue editing - changes sync when reconnected\n\n## 🔍 How It Works\n\n1. **Document Creation**: Each document is represented as a YJS document with an XML fragment\n2. **Real-time Sync**: Y-Electric syncs YJS updates with PostgreSQL via Electric SQL\n3. **Awareness**: User cursors and selections are synced through the awareness protocol\n4. **Conflict Resolution**: YJS CRDT automatically resolves conflicts between concurrent edits\n5. **Offline Support**: Changes are stored locally and synced when connectivity is restored\n\n## 📚 Learn More\n\n- [BlockNote Documentation](https://blocknotejs.org/docs)\n- [YJS Documentation](https://docs.yjs.dev/)\n- [Electric SQL Documentation](https://electric-sql.com/docs)\n- [Y-Electric Package](https://github.com/electric-sql/electric/tree/main/packages/y-electric)\n\n## 🤝 Contributing\n\nThis is an example application demonstrating the integration of BlockNote with Electric SQL. For issues or contributions related to:\n\n- **BlockNote**: Visit the [BlockNote repository](https://github.com/TypeCellOS/BlockNote)\n- **Electric SQL**: Visit the [Electric SQL repository](https://github.com/electric-sql/electric)\n- **This Example**: [Open an issue](https://github.com/TypeCellOS/blocknote-electric-example/issues)\n\n## 📄 License\n\nThis project is licensed under the Apache 2.0 License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypecellos%2Fblocknote-electric-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftypecellos%2Fblocknote-electric-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftypecellos%2Fblocknote-electric-example/lists"}