How canvasxai/sketch works
1. Overall shape
- This is a TypeScript monorepo centered on packages/server, which runs the product backend, agent runtime, channel adapters, and HTTP API in one Node.js 24 process.
- packages/web is the React/Vite admin and conversation UI.
- packages/shared contains cross-cutting contracts and validation types.
- packages/ui is the shared design-system/component layer.
- apps/macos is a separate Swift companion app for local Sketch/Claude bridging and menu-bar UX.
2. Primary runtime boundary
- The server is the architectural core. Its entrypoint/bootstrap and http.ts wire together API routes, background services, queues, and agent execution.
- The README’s flow is accurate: external channel message → channel gateway/adapter → per-channel sequential queue → agent runner → Claude Agent SDK → workspace-scoped tools/memory.
3. Inbound channels
- packages/server/src/slack handles Slack via Bolt-style integration, including DMs, channel mentions, and thread handling.
- packages/server/src/whatsapp handles WhatsApp via Baileys plus managed/WATI provider support, including group chats, media, templates, and proactive delivery.
- These adapters normalize inbound messages into the server’s internal message/session model before the agent layer sees them.
4. Agent execution layer
- packages/server/src/agent is the core orchestration layer around the Claude Agent SDK.
- It owns prompt construction, permissions, environment, concurrency limits, tool progress, session management, runtime contracts, and tool wrappers.
- packages/server/src/agents adds higher-level agent definitions, scheduling, output rendering, and delivery policies.
5. Workspace and safety boundary
- The agent runtime is sandboxed per workspace, with file/path guards and tool अनुमति checks before any tool invocation can touch local resources.
- Workspaces are scoped per user and also shared at channel or team levels where needed.
- The repo emphasizes this boundary in packages/server/src/agent/runtime/path-guard.ts, workspace-tools.ts, and related permission/validation modules.
6. Persistence and domain model
- packages/server/src/db contains Kysely-based schema, migrations, and repositories.
- SQLite is the default persistence layer; PostgreSQL is supported for broader deployment/testing scenarios.
- The data model is broad: users, channels, sessions, scheduled tasks, connectors, entities, file access, API tokens, WhatsApp state, local devices, agent runs, and delivery records.
- Runtime state is stored under data/, including per-user workspaces and the database.
7. Connector and knowledge-ingestion plane
- packages/server/src/connectors is the large ingestion/sync subsystem for external systems like Gmail, Google Calendar/Drive, Microsoft Graph, Notion, Linear, ClickUp, Zoho CRM, Fireflies, and others.
- These connectors do more than fetch data: they normalize, enrich, embed, deduplicate, and map external objects into the internal entity graph.
- Subpackages like embeddings, search, enrichment, sync, hierarchy mapping, and entity linking show that this is a pipeline, not a simple API wrapper.
8. Entity graph and materialization
- packages/server/src/entities is where external facts and conversations are turned into durable org knowledge.
- It contains materializers for people, projects, tasks, features, decisions, commitments, mentions, relations, and replay/merge/review flows.
- This layer sits between raw connector data and the user-facing “knowledge graph” / review workflows in the web app.
9. Web application surfaces
- packages/web/src/routes defines the user-facing application: onboarding, dashboard, chat, channels, connections, files, projects, review queue, settings, skills, team, usage, and workspace browsing.
- The UI consumes the server API via packages/web/src/lib/api.ts and exposes operational/admin workflows for connecting integrations, configuring channels, and reviewing entity suggestions.
- The “files” and “workspace” routes are especially important because they expose the user’s isolated storage and graph-backed browsing experience.
10. Auth, identity, and per-user integrations
- packages/server/src/auth and packages/server/src/api/auth* implement login and identity flows including JWT, magic links, password/email verification, OAuth token handling, and API tokens.
- packages/server/src/api/connectors*, provider-identities.ts, and related repositories support per-user authorization so integrations act on a specific user’s behalf.
- The architecture strongly separates org-level capabilities from user-owned credentials and permissions.
11. Automation, scheduling, and delivery
- packages/server/src/scheduler, packages/server/src/workflows, packages/server/src/automation, and packages/server/src/agents cover background execution for scheduled tasks, daily briefs, delivery capture, and workflow steps.
- These jobs can target channels, conversations, inbox workflows, or external delivery endpoints.
- This is the main async/cron plane alongside live chat handling.
12. Local device and companion-client path
- packages/server/src/local-devices plus packages/server/src/api/local-devices.ts support local Claude session bridging and device tokens.
- apps/macos provides the native front-end for that local experience, with keychain storage and a relay client, implying a sidecar/companion relationship rather than a standalone app backend.
13. Operational and maintenance plane
- The repo includes many DB migrations plus backfill/eval scripts under scripts/ and packages/server/scripts, indicating active data correction and model-evolution workflows.
- GitHub Actions, Docker assets, and the self-hosting docs show the deployment model: self-hostable, typically one server process plus storage, with optional containerization.
- Biome, Vitest, pnpm workspaces, and tsdown are the main build/test toolchain, but they are secondary to the runtime architecture.
Main entry points: agent Agent Core · http.ts HTTP API · db Database · bootstrap.ts Bootstrap
Components 21
Server
Main Node.js backend: API, agent runtime, channels, persistence, connectors, and async jobs.
- Bootstrap · Starts the server process and wires the runtime together.
packages/server/src/bootstrap.ts - HTTP API · Top-level HTTP surface for auth, chats, settings, workspace, and operational endpoints.
packages/server/src/http.ts - Agent Core · Claude Agent SDK orchestration: prompts, permissions, sessions, tools, concurrency, and progress.
packages/server/src/agent - Channels · Slack and WhatsApp adapters that normalize external messages into internal conversations.
packages/server/src/slack - Connectors · Sync, enrich, embed, and normalize external systems into internal facts and entities.
packages/server/src/connectors - Entity Graph · Turns incoming facts and conversations into durable people, projects, tasks, decisions, and relations.
packages/server/src/entities - Automation · Scheduled tasks, delivery flows, and background workflow execution.
packages/server/src/workflows - Scheduler · Schedules and dispatches timed jobs and delivery capture.
packages/server/src/scheduler - Database · Schema, migrations, and repositories over SQLite/PostgreSQL.
packages/server/src/db - Auth · JWT, magic links, OAuth, API tokens, and per-user credential handling.
packages/server/src/auth - Local Devices · Local Claude session bridging and device token gateway.
packages/server/src/local-devices - Workspace · Workspace scoping, validation, and file/path guards for tool access.
packages/server/src/workspace - MCP · OAuth and server transport for MCP servers and tool exposure.
packages/server/src/mcp
Web App
React/Vite admin and conversation UI.
- Web Routes · User-facing routes for onboarding, chat, channels, connections, files, review, settings, team, and usage.
packages/web/src/routes - Web Components · Feature components for agents, briefs, entities, connections, skills, workspace, and chat surfaces.
packages/web/src/components - Web API Client · Typed client used by the web app to call the server API.
packages/web/src/lib/api.ts
Shared Packages
Cross-cutting contracts and reusable UI.
MacOS Companion
Native local bridge and menu-bar client.
- MacOS App · Swift menu-bar companion app for local bridging and UX.
apps/macos/Sources/SketchLocal
Operations
Scripts, migrations, and deployment/maintenance surface.
- Scripts · Backfills, checks, recomputation, and one-off maintenance tasks.
scripts - Migrations · Database evolution history and data corrections.
packages/server/src/db/migrations
Connections 27
- Bootstrap → HTTP API: wires · Bootstraps the HTTP surface and runtime services.
- Bootstrap → Agent Core: starts · Initializes agent runtime subsystems.
- Bootstrap → Channels: starts · Brings up Slack and WhatsApp listeners/adapters.
- HTTP API → Auth: auth · Handles login, tokens, OAuth, and session identity.
- HTTP API → Workspace: scope · Exposes workspace browsing and validation APIs.
- HTTP API → Local Devices: bridge · Manages local device/session bridging endpoints.
- HTTP API → Connectors: configure · Creates and manages external integrations.
- Channels → Agent Core: dispatch · Routes normalized inbound messages to agent execution.
- Channels → Database: persist · Stores channel/session state and message metadata.
- Agent Core → Workspace: guard · Constrains tools and file access to workspace boundaries.
- Agent Core → Database: store · Persists runs, sessions, messages, usage, and outputs.
- Agent Core → MCP: tools · Calls out through MCP tool transport when configured.
- Connectors → Entity Graph: materialize · Converts synced external data into durable knowledge objects.
- Connectors → Database: sync state · Keeps connector credentials, cursors, and sync state.
- Entity Graph → Database: persist · Writes entity graph, review, merge, and provenance records.
- Scheduler → Automation: run · Triggers scheduled execution and delivery capture.
- Automation → Agent Core: invoke · Uses agent runtime for scheduled briefs and automated outputs.
- Automation → Database: record · Stores automation runs and delivery results.
- Web Routes → Web API Client: calls · Consumes the server API from page-level routes.
- Web Routes → Web Components: composes · Builds screens from reusable feature components.
- Web Components → UI Kit: uses · Renders with shared design-system primitives.
- Web API Client → Contracts: types · Relies on shared request/response and validation contracts.
- HTTP API → Contracts: types · Uses shared contracts for API and workspace validation.
- Agent Core → Contracts: types · Shares agent and workspace contracts with the rest of the stack.
- MacOS App → Local Devices: relays · Acts as the native companion for local session/device bridging.
- Scripts → Database: repair · Runs backfills and consistency checks against stored data.
- Migrations → Database: evolve · Changes the persisted schema over time.