# tanmaybuilds14/inkwell architecture

> Architecture diagram of the GitHub repository tanmaybuilds14/inkwell, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanmaybuilds14/inkwell
- Repository: https://github.com/tanmaybuilds14/inkwell

## Overview

Inkwell is a self-hostable collaborative document platform: users organize documents, open an editor, and collaborate through Yjs-backed live rooms, with changes persisted for later access. The Next.js app serves the UI and CRUD APIs; a separate WebSocket service handles live collaboration. Sharing, permissions, offline editing, versions, trash, activity, inbox, and background jobs are distinct product capabilities. Several subsystem links below come from the README architecture; unsampled implementation details are represented at their existing directory paths.

Main entry points: [`src/components/editor/editor-client.jsx`](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/editor/editor-client.jsx) (Collaborative editor), [`src/components/documents/dashboard.jsx`](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/documents/dashboard.jsx) (Document dashboard), [`sync-service/src/server.js`](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/server.js) (WebSocket entry), [`src/app/api/documents/[id]/share/route.js`](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/documents/%5Bid%5D/share/route.js) (Sharing and permissions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js app"]
  node_dashboard["Document dashboard<br/>[dashboard.jsx]"]
end

subgraph group_collaboration["Live collaboration"]
  node_editor["Collaborative editor<br/>[editor-client.jsx]"]
  node_editor_surface["Editor surface<br/>[collab-editor.jsx]"]
  node_offline_cache["Offline document cache<br/>[offline-docs.js]"]
  node_sync_server["WebSocket entry<br/>[server.js]"]
  node_live_rooms["Yjs rooms<br/>[rooms.js]"]
  node_sync_broadcast["Cross-instance relay<br/>[broadcast.js]"]
  node_sync_persistence["Snapshot persistence<br/>[db.js]"]
  node_shared_contract["Shared wire contract<br/>[protocol.js]"]
end

subgraph group_document_features["Document features"]
  node_documents_api["Document API<br/>[route.js]"]
  node_folders_api["Folder API<br/>[route.js]"]
  node_version_history["Version history"]
  node_trash_api["Trash and restore<br/>[route.js]"]
end

subgraph group_identity["Identity and access"]
  node_handshake_auth["Handshake authorization<br/>[auth.js]"]
  node_sharing_api["Sharing and permissions<br/>[route.js]"]
  node_share_page["Public share access<br/>[share-page.js]"]
  node_profile_api["Profile and onboarding<br/>[route.js]"]
end

subgraph group_operations["Background and records"]
  node_inbox["Inbox and mentions<br/>[inbox.js]"]
  node_activity["Activity history<br/>[activity.js]"]
  node_background_jobs["Scheduled jobs and invites<br/>[functions.js]"]
end

node_user(("Document user"))
node_postgres[("PostgreSQL")]
node_redis[("Redis")]
node_inngest_service["Inngest"]

node_user -->|"uses"| node_dashboard
node_dashboard -->|"lists and creates"| node_documents_api
node_dashboard -.->|"organizes"| node_folders_api
node_dashboard -.->|"opens document"| node_editor
node_editor -->|"renders"| node_editor_surface
node_editor -->|"caches edits"| node_offline_cache
node_editor -->|"sends updates"| node_sync_server
node_sync_server -->|"authenticates"| node_handshake_auth
node_sync_server -->|"joins room"| node_live_rooms
node_live_rooms -.->|"relays updates"| node_sync_broadcast
node_sync_broadcast -.->|"publishes and subscribes"| node_redis
node_live_rooms -.->|"persists snapshots"| node_sync_persistence
node_sync_persistence -.->|"writes snapshots"| node_postgres
node_sync_server -->|"uses protocol"| node_shared_contract
node_documents_api -->|"reads and writes"| node_postgres
node_folders_api -->|"reads and writes"| node_postgres
node_sharing_api -->|"updates access"| node_postgres
node_sharing_api -->|"records invitations"| node_inbox
node_sharing_api -->|"records sharing"| node_activity
node_editor -->|"opens timeline"| node_version_history
node_version_history -.->|"loads and restores versions"| node_postgres
node_trash_api -.->|"soft deletes and restores"| node_postgres
node_user -.->|"opens shared link"| node_share_page
node_profile_api -->|"updates profile"| node_postgres
node_profile_api -->|"logs profile changes"| node_activity
node_activity -->|"stores and queries events"| node_postgres
node_inbox -->|"stores inbox items"| node_postgres
node_inngest_service -.->|"dispatches jobs"| node_background_jobs
node_background_jobs -.->|"purges and prunes"| node_postgres
node_background_jobs -.->|"sends invite email"| node_inngest_service

click node_dashboard "https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/documents/dashboard.jsx"
click node_editor "https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/editor/editor-client.jsx"
click node_editor_surface "https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/editor/collab-editor.jsx"
click node_offline_cache "https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/offline-docs.js"
click node_sync_server "https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/server.js"
click node_handshake_auth "https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/auth.js"
click node_live_rooms "https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/rooms.js"
click node_sync_broadcast "https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/broadcast.js"
click node_sync_persistence "https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/db.js"
click node_documents_api "https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/documents/route.js"
click node_folders_api "https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/folders/route.js"
click node_sharing_api "https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/documents/%5Bid%5D/share/route.js"
click node_version_history "https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/documents/version-history.jsx"
click node_trash_api "https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/trash/route.js"
click node_share_page "https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/share-page.js"
click node_profile_api "https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/profile/route.js"
click node_inbox "https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/inbox.js"
click node_activity "https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/activity.js"
click node_background_jobs "https://github.com/tanmaybuilds14/inkwell/blob/main/src/inngest/functions.js"
click node_shared_contract "https://github.com/tanmaybuilds14/inkwell/blob/main/shared/protocol.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_user toneBlue
class node_editor,node_editor_surface,node_offline_cache,node_sync_server,node_live_rooms,node_sync_broadcast,node_sync_persistence,node_shared_contract,node_postgres,node_redis toneAmber
class node_documents_api,node_folders_api,node_version_history,node_trash_api toneMint
class node_handshake_auth,node_sharing_api,node_share_page,node_profile_api toneRose
class node_inbox,node_activity,node_background_jobs,node_inngest_service toneIndigo
```

## Components

### Next.js app

- [Document dashboard](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/documents/dashboard.jsx): `src/components/documents/dashboard.jsx`

### Live collaboration

- [Collaborative editor](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/editor/editor-client.jsx): `src/components/editor/editor-client.jsx`
- [Editor surface](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/editor/collab-editor.jsx): `src/components/editor/collab-editor.jsx`
- [Offline document cache](https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/offline-docs.js): `src/lib/offline-docs.js`
- [WebSocket entry](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/server.js): `sync-service/src/server.js`
- [Yjs rooms](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/rooms.js): `sync-service/src/rooms.js`
- [Cross-instance relay](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/broadcast.js): `sync-service/src/broadcast.js`
- [Snapshot persistence](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/db.js): `sync-service/src/db.js`
- [Shared wire contract](https://github.com/tanmaybuilds14/inkwell/blob/main/shared/protocol.js): `shared/protocol.js`

### Document features

- [Document API](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/documents/route.js): `src/app/api/documents/route.js`
- [Folder API](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/folders/route.js): `src/app/api/folders/route.js`
- [Version history](https://github.com/tanmaybuilds14/inkwell/blob/main/src/components/documents/version-history.jsx): `src/components/documents/version-history.jsx`
- [Trash and restore](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/trash/route.js): `src/app/api/trash/route.js`

### Identity and access

- [Handshake authorization](https://github.com/tanmaybuilds14/inkwell/blob/main/sync-service/src/auth.js): `sync-service/src/auth.js`
- [Sharing and permissions](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/documents/%5Bid%5D/share/route.js): `src/app/api/documents/[id]/share/route.js`
- [Public share access](https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/share-page.js): `src/lib/share-page.js`
- [Profile and onboarding](https://github.com/tanmaybuilds14/inkwell/blob/main/src/app/api/profile/route.js): `src/app/api/profile/route.js`

### Background and records

- [Inbox and mentions](https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/inbox.js): `src/lib/inbox.js`
- [Activity history](https://github.com/tanmaybuilds14/inkwell/blob/main/src/lib/activity.js): `src/lib/activity.js`
- [Scheduled jobs and invites](https://github.com/tanmaybuilds14/inkwell/blob/main/src/inngest/functions.js): `src/inngest/functions.js`

### Other components

- **Document user**
- **PostgreSQL**
- **Redis**
- **Inngest**

## Connections

- Document user → Document dashboard: uses
- Document dashboard → Document API: lists and creates (evidence: `src/components/documents/dashboard.jsx`)
- Document dashboard → Folder API: organizes
- Document dashboard → Collaborative editor: opens document
- Collaborative editor → Editor surface: renders (evidence: `src/components/editor/editor-client.jsx`)
- Collaborative editor → Offline document cache: caches edits (evidence: `src/components/editor/editor-client.jsx`)
- Collaborative editor → WebSocket entry: sends updates
- WebSocket entry → Handshake authorization: authenticates (evidence: `sync-service/src/server.js`)
- WebSocket entry → Yjs rooms: joins room (evidence: `sync-service/src/server.js`)
- Yjs rooms → Cross-instance relay: relays updates (evidence: `sync-service/src/rooms.js`)
- Cross-instance relay → Redis: publishes and subscribes
- Yjs rooms → Snapshot persistence: persists snapshots (evidence: `sync-service/src/rooms.js`)
- Snapshot persistence → PostgreSQL: writes snapshots
- WebSocket entry → Shared wire contract: uses protocol (evidence: `sync-service/src/server.js`)
- Document API → PostgreSQL: reads and writes (evidence: `src/app/api/documents/route.js`)
- Folder API → PostgreSQL: reads and writes (evidence: `src/app/api/folders/route.js`)
- Sharing and permissions → PostgreSQL: updates access (evidence: `src/app/api/documents/[id]/share/route.js`)
- Sharing and permissions → Inbox and mentions: records invitations (evidence: `src/app/api/documents/[id]/share/route.js`)
- Sharing and permissions → Activity history: records sharing (evidence: `src/app/api/documents/[id]/share/route.js`)
- Collaborative editor → Version history: opens timeline (evidence: `src/components/editor/editor-client.jsx`)
- Version history → PostgreSQL: loads and restores versions
- Trash and restore → PostgreSQL: soft deletes and restores
- Document user → Public share access: opens shared link
- Profile and onboarding → PostgreSQL: updates profile (evidence: `src/app/api/profile/route.js`)
- Profile and onboarding → Activity history: logs profile changes (evidence: `src/app/api/profile/route.js`)
- Activity history → PostgreSQL: stores and queries events (evidence: `src/lib/activity.js`)
- Inbox and mentions → PostgreSQL: stores inbox items (evidence: `src/lib/inbox.js`)
- Inngest → Scheduled jobs and invites: dispatches jobs
- Scheduled jobs and invites → PostgreSQL: purges and prunes
- Scheduled jobs and invites → Inngest: sends invite email
