Skip to content

About

Next.js collaborative editor: Appwrite auth, Liveblocks sync, Permit.io per-document roles (ReBAC).

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

Collaborative Docs with Permit.io and Appwrite: A Google Docs-style editor with per-document sharing and roles

Collaborative Docs with Permit.io and Appwrite

A Google Docs-style editor with per-document sharing and roles

A Next.js document editor with Tiptap and Liveblocks real-time editing, Appwrite for auth and storage, and Permit.io resource-instance roles that decide who can read, edit, delete and share each document.


Built by Studio1 Built with Permit.io

Permit.io docs  ·  Permit.io  ·  Appwrite  ·  More examples  ·  studio1hq.com


Overview

A Google Docs-style collaborative editor with per-document sharing. Users sign up with Appwrite, create documents, edit them together in real time, and share each document as a viewer or editor.

Authorization uses Permit.io with a relationship-based model (ReBAC): every document is a Permit.io resource instance (document:<id>), and sharing assigns a role on that instance. The document page checks read, update and delete for the signed-in user. Those results decide whether the page loads and whether the Liveblocks room session allows room:read and room:write.

Features

  • Real-time editing: Tiptap editor with Yjs sync through Liveblocks, plus cursors and user avatars.
  • Per-document roles: Role assignment on document:<id> instances in Permit.io.
  • Permission-aware UI: Read, update and delete checks control what each user sees and can do.
  • Sharing: A dialog assigns a role to an email address and copies the document link.
  • Room authorization: /api/liveblock-session grants read-only or write access based on the permission checks.
  • Auth and data: Appwrite handles sign-up, login and document storage.
  • Local PDP: docker-compose.yml runs the Permit.io PDP.

Tech stack

Layer Tool
Framework Next.js 14, React, TypeScript
Authorization Permit.io ReBAC (permitio SDK, local PDP)
Auth and database Appwrite
Real-time sync Liveblocks with Yjs
Editor Tiptap
UI Tailwind CSS, shadcn/ui

Getting started

Prerequisites

  • Node.js 18.17 or later
  • Docker (for the local PDP)
  • A Permit.io account with a document resource, the actions read, create, update, delete and roles you define (the share dialog defaults to viewer)
  • An Appwrite project with a database and a documents collection
  • A Liveblocks account

Installation

git clone https://github.com/Studio1HQ/collaborative-docs.git
cd collaborative-docs
npm install

Environment variables

Create a .env.local file:

Variable Description
NEXT_PUBLIC_APPWRITE_ENDPOINT Appwrite API endpoint.
NEXT_PUBLIC_APPWRITE_PROJECT_ID Appwrite project ID.
NEXT_PUBLIC_APPWRITE_DATABASE_ID Appwrite database ID.
NEXT_PUBLIC_APPWRITE_COLLECTION_ID Collection that stores documents (roomId, title, storageData, created_by).
NEXT_PUBLIC_PERMIT_API_KEY Permit.io API key. Also used by the PDP container.
PDP_URL PDP URL. Defaults to http://localhost:7766.
NEXT_PUBLIC_LIVE_BLOCKS_SECRET_KEY Liveblocks secret key.

The NEXT_PUBLIC_ prefix exposes values to the browser. For anything beyond a demo, move the Permit.io key and the Liveblocks secret to server-only variables.

Run

Start the PDP, then the dev server:

docker compose up -d
npm run dev

Open http://localhost:3000.

How it works

app/
├── actions.ts                    # Permit.io server actions
├── api/liveblock-session/route.ts
├── dashboard/page.tsx            # list and create documents
├── document/[id]/page.tsx        # permission check, editor, share, delete
├── login/ and signup/
components/
├── editor/                       # collaborative editor, toolbar, avatars
└── share-document.tsx, delete-document.tsx
lib/
├── appwrite.ts, permitio.ts, liveblocks.ts
  1. When a document is created, createResourceInstance registers document:<id> and assignResourceInstanceRoleToUser gives the creator a role.
  2. On the document page, getResourcePermissions calls PERMITIO_SDK.check for read, update and delete. Without read, the page shows a no-permission message.
  3. The editor connects to a Liveblocks room through /api/liveblock-session, which allows room:read if the user can read and room:write if they can update.
  4. Sharing calls assignResourceInstanceRoleToUser, which syncs the user to Permit.io if needed and assigns the chosen role on the document instance.

Resources



Studio1

Built by Studio1, the technical content and DevRel partner for devtool teams. Made with Permit.io.
Browse more open-source examples at github.com/Studio1HQ.

Website Book a call X LinkedIn

studio1hq.com · Technical content, docs, video and DevRel for devtools

About

Next.js collaborative editor: Appwrite auth, Liveblocks sync, Permit.io per-document roles (ReBAC).

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages