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.
Permit.io docs · Permit.io · Appwrite · More examples · studio1hq.com
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.
- 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-sessiongrants 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.ymlruns the Permit.io PDP.
| 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 |
- Node.js 18.17 or later
- Docker (for the local PDP)
- A Permit.io account with a
documentresource, the actionsread,create,update,deleteand roles you define (the share dialog defaults toviewer) - An Appwrite project with a database and a documents collection
- A Liveblocks account
git clone https://github.com/Studio1HQ/collaborative-docs.git
cd collaborative-docs
npm installCreate 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.
Start the PDP, then the dev server:
docker compose up -d
npm run devOpen http://localhost:3000.
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
- When a document is created,
createResourceInstanceregistersdocument:<id>andassignResourceInstanceRoleToUsergives the creator a role. - On the document page,
getResourcePermissionscallsPERMITIO_SDK.checkforread,updateanddelete. Withoutread, the page shows a no-permission message. - The editor connects to a Liveblocks room through
/api/liveblock-session, which allowsroom:readif the user can read androom:writeif they can update. - Sharing calls
assignResourceInstanceRoleToUser, which syncs the user to Permit.io if needed and assigns the chosen role on the document instance.
- Permit.io docs: ReBAC, resource instances and the PDP.
- Permit.io: Account and API key.
- Appwrite docs: Auth and databases.
- Liveblocks docs: Rooms and authentication.
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.
studio1hq.com · Technical content, docs, video and DevRel for devtools