# chefberke/pane architecture

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

- Interactive diagram: https://gitdiagram.com/chefberke/pane
- Repository: https://github.com/chefberke/pane

## Overview

1. **Overall shape**
   - This is a **Next.js App Router** application built as a collaborative workspace/canvas editor.
   - The repo is organized around a **feature-first client UI** in `app/features`, with a smaller set of **route handlers** in `app/api` and page shells in `app/`.

2. **Top-level application routes**
   - Public/auth flows live at `/`, `/sign-in`, `/sign-up`, and `/auth/callback`.
   - The main product areas appear to be:
     - `/w/[workspaceId]` for the workspace editor
     - `/w` for workspace landing/listing
     - `/s/[token]` for shared view links
     - `/s/invite/[token]` for invite acceptance
   - These routes likely assemble the same underlying workspace data into different access modes: owner/editor, invited user, or public/shared viewer.

3. **Editor runtime is client-side and feature-composed**
   - Most of the behavior is implemented in `app/features/*` as reusable UI + hooks rather than monolithic pages.
   - `app/features/canvas` is the central orchestration layer: it manages viewport, selection, history, persistence, presence, keyboard shortcuts, paste handling, and visible item calculation.
   - The editor screen is then layered with domain-specific systems: blocks, connectors, frames, comments, toolbar, context menu, search, sharing, menu panel, and workspace sidebar.

4. **Core data model: workspace canvas**
   - The primary content model is a **workspace containing visual objects**:
     - blocks
     - connectors between blocks
     - frames/groups
     - comments
     - user presence/cursors
   - Each domain has its own `types`, `utils`, `hooks`, and rendering components, which suggests the canvas state is normalized and manipulated through dedicated submodules rather than ad hoc props.

5. **Interaction and layout boundaries**
   - `app/features/canvas` and related hooks handle the low-level interaction layer: drag, resize, marquee selection, pinch zoom, viewport following, idle hints, and keyboard shortcuts.
   - `app/features/blocks`, `app/features/frames`, and `app/features/connectors` own the geometry and interaction for their respective objects.
   - This separation makes the diagram clearer: the canvas is the stage, and each object type is an independently interactive subsystem.

6. **Rendering system for content blocks**
   - Blocks are not just generic rectangles; they have specialized renderers for rich content:
     - text notes
     - images
     - links
     - embeds for GitHub, YouTube, Twitter, Spotify, maps, and PDFs
   - `app/features/blocks/renderers/*` is a content adaptation layer that turns URLs or block types into specific visual presentations.
   - The `preview` API and `preview/security.ts` likely support safe fetching of remote metadata for link/embed previews.

7. **Collaboration and sharing**
   - Real-time collaboration appears to be a first-class subsystem:
     - `usePresenceSync`, `usePresence`, `PeerLayer`, `FollowOverlay`, and avatar/member UI indicate live peer awareness.
   - Sharing is split into:
     - invite tokens and acceptance flow
     - share links/tokens
     - per-user roles/capabilities
     - member management
   - `docs/sharing-permissions.md` and the share feature hooks (`useMembers`, `useInvites`, `useShareLinks`, `useViewerCapability`) imply that access control is a core architectural concern, not just a UI detail.

8. **Workspace management and app-level chrome**
   - `app/features/workspace` and `app/features/menu-panel` handle workspace discovery, switching, CRUD, import/export, settings, delete/trash, and feedback.
   - This is the “control plane” around the editor: it governs which workspace is active and how users move data in/out.
   - Search, items panel, theme switching, and shortcuts help navigate large canvases and are treated as separate overlays/modals rather than part of the canvas core.

9. **Auth and session flow**
   - Authentication is built as a dedicated feature set under `app/features/auth`, with sign-in/sign-up pages and a callback page.
   - The UI suggests both **magic-code** and **OAuth** login paths.
   - Hooks like `useRedirectIfAuthed` and `useNextParam` indicate route-level gating and post-login redirect handling.
   - `app/lib/authedFetch.ts` is the likely boundary for authenticated client-to-server calls, keeping auth concerns out of feature code.

10. **Server/API boundaries**
   - Route handlers in `app/api` provide the mutation and privileged operations layer:
     - `workspace/save` and `workspace/import`
     - `share/[token]`
     - `invite/[token]/accept`
     - `preview`
     - `feedback`
   - These endpoints form the backend integration point for the client editor, especially for persistence, import/export, token-based access, and user feedback submission.

11. **Data, permissions, and admin infrastructure**
   - `instant.schema.ts` and `instant.perms.ts` are strong indicators of a **schema-driven realtime backend** with explicit permission rules.
   - `app/lib/db.ts`, `app/lib/admin.ts`, and `app/lib/env.ts` separate normal app access from privileged/admin operations and environment wiring.
   - `app/lib/rateLimit.ts` suggests at least some API routes are protected against abuse, which matters for public share/invite/preview endpoints.

12. **Operational/supporting assets**
   - `scripts/backfill-links.ts` indicates a maintenance/migration script for stored link data.
   - `.github/workflows/ci.yml` provides CI automation.
   - `docs/design-system.md` and `docs/sharing-permissions.md` are useful for architecture intent, especially around UI consistency and access control.

13. **How data likely flows through the system**
   - A user enters a workspace route → the page mounts the canvas/editor shell → feature hooks load workspace state and presence data → local interactions mutate selection/layout/content → changes are persisted through backend APIs or realtime DB hooks → collaborators see updates through presence/sync layers.
   - Public invite/share flows follow a separate token-based path, with the server validating access and the client rendering a restricted or shared view.

14. **What to diagram as the main subsystems**
   - App routing/auth shell
   - Workspace/editor canvas runtime
   - Domain object systems: blocks, frames, connectors, comments
   - Collaboration/share/permissions
   - Workspace management and modals/overlays
   - Server route handlers and realtime/data backend
   - Supporting admin/env/rate-limit infrastructure

Main entry points: [`app/features/canvas/Canvas.tsx`](https://github.com/chefberke/pane/blob/main/app/features/canvas/Canvas.tsx) (Canvas), [`app/features/share/Share.tsx`](https://github.com/chefberke/pane/blob/main/app/features/share/Share.tsx) (Share), [`app/features/menu-panel/MenuPanel.tsx`](https://github.com/chefberke/pane/blob/main/app/features/menu-panel/MenuPanel.tsx) (Menu Panel), [`app/api/invite/[token]/accept/route.ts`](https://github.com/chefberke/pane/blob/main/app/api/invite/[token]/accept/route.ts) (Invite API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Shell"]
  node_page_home["Home<br/>route<br/>[page.tsx]"]
  node_page_sign_in["Sign In<br/>route<br/>[page.tsx]"]
  node_page_sign_up["Sign Up<br/>route<br/>[page.tsx]"]
  node_page_auth_callback["Callback<br/>auth route<br/>[page.tsx]"]
  node_page_workspace["Workspace<br/>route<br/>[page.tsx]"]
  node_page_workspace_list["Workspaces<br/>route<br/>[page.tsx]"]
  node_page_share_view["Shared View<br/>route<br/>[page.tsx]"]
  node_page_invite_accept["Invite Accept<br/>route<br/>[page.tsx]"]
end

subgraph group_editor["Editor Runtime"]
  node_canvas["Canvas<br/>runtime<br/>[Canvas.tsx]"]
  node_canvas_world["World<br/>view layer<br/>[CanvasWorld.tsx]"]
  node_blocks["Blocks<br/>content system<br/>[Block.tsx]"]
  node_frames["Frames<br/>grouping system<br/>[Frame.tsx]"]
  node_connectors["Connectors<br/>link system<br/>[Connectors.tsx]"]
  node_comments["Comments<br/>discussion system<br/>[CommentsSheet.tsx]"]
  node_toolbar["Toolbar<br/>editor controls<br/>[Toolbar.tsx]"]
  node_workspace_mgmt["Workspace Mgmt<br/>control plane"]
  node_menu_panel["Menu Panel<br/>workspace chrome<br/>[MenuPanel.tsx]"]
end

subgraph group_sharing["Collaboration"]
  node_share["Share<br/>collaboration<br/>[Share.tsx]"]
  node_presence["Presence<br/>live sync<br/>[usePresence.ts]"]
end

subgraph group_backend["Server & Infra"]
  node_api_workspace_save["Save<br/>route handler<br/>[route.ts]"]
  node_api_workspace_import["Import<br/>route handler<br/>[route.ts]"]
  node_api_share["Share API<br/>route handler<br/>[route.ts]"]
  node_api_invite_accept["Invite API<br/>route handler<br/>[route.ts]"]
  node_api_preview["Preview API<br/>route handler<br/>[route.ts]"]
  node_api_feedback["Feedback API<br/>route handler<br/>[route.ts]"]
  node_lib_runtime["App Lib<br/>infra<br/>[db.ts]"]
  node_schema[("Schema<br/>[instant.schema.ts]")]
  node_permissions["Permissions<br/>policy<br/>[instant.perms.ts]"]
end

node_page_workspace -->|"mounts"| node_canvas
node_page_workspace_list -->|"uses"| node_workspace_mgmt
node_page_share_view -->|"renders"| node_canvas
node_page_invite_accept -->|"calls"| node_api_invite_accept
node_page_sign_in -->|"returns to"| node_page_auth_callback
node_page_sign_up -->|"returns to"| node_page_auth_callback
node_canvas -->|"composes"| node_canvas_world
node_canvas -->|"manages"| node_blocks
node_canvas -->|"manages"| node_frames
node_canvas -->|"manages"| node_connectors
node_canvas -->|"manages"| node_comments
node_canvas -->|"drives"| node_toolbar
node_canvas -->|"syncs"| node_presence
node_canvas -->|"persists via"| node_api_workspace_save
node_canvas -->|"fetches via"| node_api_preview
node_blocks -->|"uses"| node_api_preview
node_share -->|"shows"| node_presence
node_share -->|"reads"| node_api_share
node_share -->|"invites via"| node_api_invite_accept
node_workspace_mgmt -->|"opens"| node_menu_panel
node_menu_panel -->|"imports via"| node_api_workspace_import
node_menu_panel -->|"submits via"| node_api_feedback
node_api_workspace_save -->|"uses"| node_lib_runtime
node_api_workspace_import -->|"uses"| node_lib_runtime
node_api_share -->|"guards by"| node_schema
node_api_invite_accept -->|"guards by"| node_permissions
node_lib_runtime -->|"connects to"| node_schema
node_schema -->|"enforced by"| node_permissions

click node_page_home "https://github.com/chefberke/pane/blob/main/app/page.tsx"
click node_page_sign_in "https://github.com/chefberke/pane/blob/main/app/sign-in/page.tsx"
click node_page_sign_up "https://github.com/chefberke/pane/blob/main/app/sign-up/page.tsx"
click node_page_auth_callback "https://github.com/chefberke/pane/blob/main/app/auth/callback/page.tsx"
click node_page_workspace "https://github.com/chefberke/pane/blob/main/app/w/[workspaceId]/page.tsx"
click node_page_workspace_list "https://github.com/chefberke/pane/blob/main/app/w/page.tsx"
click node_page_share_view "https://github.com/chefberke/pane/blob/main/app/s/[token]/page.tsx"
click node_page_invite_accept "https://github.com/chefberke/pane/blob/main/app/s/invite/[token]/page.tsx"
click node_canvas "https://github.com/chefberke/pane/blob/main/app/features/canvas/Canvas.tsx"
click node_canvas_world "https://github.com/chefberke/pane/blob/main/app/features/canvas/CanvasWorld.tsx"
click node_blocks "https://github.com/chefberke/pane/blob/main/app/features/blocks/Block.tsx"
click node_frames "https://github.com/chefberke/pane/blob/main/app/features/frames/Frame.tsx"
click node_connectors "https://github.com/chefberke/pane/blob/main/app/features/connectors/Connectors.tsx"
click node_comments "https://github.com/chefberke/pane/blob/main/app/features/comments/CommentsSheet.tsx"
click node_toolbar "https://github.com/chefberke/pane/blob/main/app/features/toolbar/Toolbar.tsx"
click node_workspace_mgmt "https://github.com/chefberke/pane/blob/main/app/features/workspace/WorkspaceSidebar.tsx"
click node_menu_panel "https://github.com/chefberke/pane/blob/main/app/features/menu-panel/MenuPanel.tsx"
click node_share "https://github.com/chefberke/pane/blob/main/app/features/share/Share.tsx"
click node_presence "https://github.com/chefberke/pane/blob/main/app/features/share/hooks/usePresence.ts"
click node_api_workspace_save "https://github.com/chefberke/pane/blob/main/app/api/workspace/save/route.ts"
click node_api_workspace_import "https://github.com/chefberke/pane/blob/main/app/api/workspace/import/route.ts"
click node_api_share "https://github.com/chefberke/pane/blob/main/app/api/share/[token]/route.ts"
click node_api_invite_accept "https://github.com/chefberke/pane/blob/main/app/api/invite/[token]/accept/route.ts"
click node_api_preview "https://github.com/chefberke/pane/blob/main/app/api/preview/route.ts"
click node_api_feedback "https://github.com/chefberke/pane/blob/main/app/api/feedback/route.ts"
click node_lib_runtime "https://github.com/chefberke/pane/blob/main/app/lib/db.ts"
click node_schema "https://github.com/chefberke/pane/blob/main/instant.schema.ts"
click node_permissions "https://github.com/chefberke/pane/blob/main/instant.perms.ts"

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_page_home,node_page_sign_in,node_page_sign_up,node_page_auth_callback,node_page_workspace,node_page_workspace_list,node_page_share_view,node_page_invite_accept toneBlue
class node_canvas,node_canvas_world,node_blocks,node_frames,node_connectors,node_comments,node_toolbar,node_workspace_mgmt,node_menu_panel toneAmber
class node_share,node_presence toneMint
class node_api_workspace_save,node_api_workspace_import,node_api_share,node_api_invite_accept,node_api_preview,node_api_feedback,node_lib_runtime,node_schema,node_permissions toneRose
```

## Components

### App Shell

Route shells, entry pages, and auth flows

- [Home](https://github.com/chefberke/pane/blob/main/app/page.tsx): route · Landing page and top-level entry · `app/page.tsx`
- [Sign In](https://github.com/chefberke/pane/blob/main/app/sign-in/page.tsx): route · Authentication page · `app/sign-in/page.tsx`
- [Sign Up](https://github.com/chefberke/pane/blob/main/app/sign-up/page.tsx): route · Account creation page · `app/sign-up/page.tsx`
- [Callback](https://github.com/chefberke/pane/blob/main/app/auth/callback/page.tsx): auth route · OAuth or magic-code callback handling · `app/auth/callback/page.tsx`
- [Workspace](https://github.com/chefberke/pane/blob/main/app/w/[workspaceId]/page.tsx): route · Main workspace editor shell · `app/w/[workspaceId]/page.tsx`
- [Workspaces](https://github.com/chefberke/pane/blob/main/app/w/page.tsx): route · Workspace landing and list view · `app/w/page.tsx`
- [Shared View](https://github.com/chefberke/pane/blob/main/app/s/[token]/page.tsx): route · Public shared workspace view · `app/s/[token]/page.tsx`
- [Invite Accept](https://github.com/chefberke/pane/blob/main/app/s/invite/[token]/page.tsx): route · Invite token acceptance page · `app/s/invite/[token]/page.tsx`

### Editor Runtime

Client-side canvas orchestration and interactive object systems

- [Canvas](https://github.com/chefberke/pane/blob/main/app/features/canvas/Canvas.tsx): runtime · Central editor orchestration and interaction layer · `app/features/canvas/Canvas.tsx`
- [World](https://github.com/chefberke/pane/blob/main/app/features/canvas/CanvasWorld.tsx): view layer · Canvas composition and overlay structure · `app/features/canvas/CanvasWorld.tsx`
- [Blocks](https://github.com/chefberke/pane/blob/main/app/features/blocks/Block.tsx): content system · Movable content blocks and rich renderers · `app/features/blocks/Block.tsx`
- [Frames](https://github.com/chefberke/pane/blob/main/app/features/frames/Frame.tsx): grouping system · Resizable framed regions and thumbnails · `app/features/frames/Frame.tsx`
- [Connectors](https://github.com/chefberke/pane/blob/main/app/features/connectors/Connectors.tsx): link system · Edges and endpoint editing between items · `app/features/connectors/Connectors.tsx`
- [Comments](https://github.com/chefberke/pane/blob/main/app/features/comments/CommentsSheet.tsx): discussion system · Comment bubbles, threads, and composer · `app/features/comments/CommentsSheet.tsx`
- [Toolbar](https://github.com/chefberke/pane/blob/main/app/features/toolbar/Toolbar.tsx): editor controls · Alignment and quick editing actions · `app/features/toolbar/Toolbar.tsx`
- [Workspace Mgmt](https://github.com/chefberke/pane/blob/main/app/features/workspace/WorkspaceSidebar.tsx): control plane · Workspace discovery, CRUD, transfer, and redirect · `app/features/workspace/WorkspaceSidebar.tsx`
- [Menu Panel](https://github.com/chefberke/pane/blob/main/app/features/menu-panel/MenuPanel.tsx): workspace chrome · Import, export, settings, feedback, and trash · `app/features/menu-panel/MenuPanel.tsx`

### Collaboration

Presence, sharing, invites, and permissions

- [Share](https://github.com/chefberke/pane/blob/main/app/features/share/Share.tsx): collaboration · Members, invites, links, and viewer capability · `app/features/share/Share.tsx`
- [Presence](https://github.com/chefberke/pane/blob/main/app/features/share/hooks/usePresence.ts): live sync · Peer awareness and follow overlays · `app/features/share/hooks/usePresence.ts`

### Server & Infra

API handlers and app-level integration boundaries

- [Save](https://github.com/chefberke/pane/blob/main/app/api/workspace/save/route.ts): route handler · Persist workspace state · `app/api/workspace/save/route.ts`
- [Import](https://github.com/chefberke/pane/blob/main/app/api/workspace/import/route.ts): route handler · Import workspace data · `app/api/workspace/import/route.ts`
- [Share API](https://github.com/chefberke/pane/blob/main/app/api/share/[token]/route.ts): route handler · Resolve shared workspace access · `app/api/share/[token]/route.ts`
- [Invite API](https://github.com/chefberke/pane/blob/main/app/api/invite/[token]/accept/route.ts): route handler · Accept invite tokens · `app/api/invite/[token]/accept/route.ts`
- [Preview API](https://github.com/chefberke/pane/blob/main/app/api/preview/route.ts): route handler · Fetch safe link and embed metadata · `app/api/preview/route.ts`
- [Feedback API](https://github.com/chefberke/pane/blob/main/app/api/feedback/route.ts): route handler · Submit user feedback · `app/api/feedback/route.ts`
- [App Lib](https://github.com/chefberke/pane/blob/main/app/lib/db.ts): infra · Auth fetch, db, env, admin, and rate limits · `app/lib/db.ts`
- [Schema](https://github.com/chefberke/pane/blob/main/instant.schema.ts): realtime schema · Backend schema and permission rules · `instant.schema.ts`
- [Permissions](https://github.com/chefberke/pane/blob/main/instant.perms.ts): policy · Realtime access control rules · `instant.perms.ts`

## Connections

- Workspace → Canvas: mounts · Workspace route composes the editor runtime
- Workspaces → Workspace Mgmt: uses · Workspace list is driven by workspace management features
- Shared View → Canvas: renders · Shared view reuses the canvas runtime
- Invite Accept → Invite API: calls · Invite acceptance page completes via token endpoint
- Sign In → Callback: returns to · Login flow redirects through callback handling
- Sign Up → Callback: returns to · Signup flow redirects through callback handling
- Canvas → World: composes · Canvas assembles the main world and overlay layers
- Canvas → Blocks: manages · Canvas coordinates block state and interactions
- Canvas → Frames: manages · Canvas coordinates frame interactions and layout
- Canvas → Connectors: manages · Canvas coordinates connector geometry and edits
- Canvas → Comments: manages · Canvas integrates comment rendering and activity
- Canvas → Toolbar: drives · Canvas feeds selection and context into the toolbar
- Canvas → Presence: syncs · Canvas runtime syncs peer presence and follow state
- Canvas → Save: persists via · Editor changes are saved through workspace mutations
- Canvas → Preview API: fetches via · Block previews and embeds use preview metadata
- Blocks → Preview API: uses · Rich block renderers depend on safe preview fetches
- Share → Presence: shows · Sharing UI exposes collaborators and live presence
- Share → Share API: reads · Shared access is resolved through token endpoint
- Share → Invite API: invites via · Invite workflow is backed by acceptance endpoint
- Workspace Mgmt → Menu Panel: opens · Workspace control plane is surfaced in the menu panel
- Menu Panel → Import: imports via · Import modal uses the workspace import route
- Menu Panel → Feedback API: submits via · Feedback modal sends submissions to the feedback route
- Save → App Lib: uses · API routes rely on shared app libraries
- Import → App Lib: uses · API routes rely on shared app libraries
- Share API → Schema: guards by · Shared access is constrained by schema-backed permissions
- Invite API → Permissions: guards by · Invite acceptance is validated against permission rules
- App Lib → Schema: connects to · App libraries bridge to the realtime backend
- Schema → Permissions: enforced by · Permission rules define access boundaries over the schema
