plans/convex-backend-support.md
Generated by swarm planning session on 2026-02-12
Add Convex as a third backend option in Dyad (alongside Supabase and Neon), enabling users to build apps with real-time reactive data, serverless functions, and file storage — all without SQL. This positions Dyad as the long-term successor to Chef (the Convex-native builder in chef/), porting Chef's battle-tested prompts and patterns into Dyad's backend-flexible architecture.
Dyad users currently have two backend options: Supabase and Neon, both PostgreSQL-based. Users building apps that need real-time reactivity, serverless functions, or document-based data models are forced into SQL paradigms or must leave Dyad entirely (using Chef or building manually). Adding Convex expands Dyad's addressable use cases and aligns with the Backend-Flexible design principle.
Target users:
ipc.system.openExternalUrl for easy key retrieval. Deploy key field uses type="password" with show/hide toggle. Inline validation errors (not toasts).convexGuidelines.ts (~960 lines) and solutionConstraints.ts for Dyad's tool set and execution model. This is the highest-value item. Since Dyad is the long-term Chef successor, invest in prompt quality (budget 3-4 days, not a quick copy).convex/schema.ts from the app's files and inject schema context into the AI prompt.concurrently — Template start script runs both npx convex dev and npx vite via concurrently --names "vite,convex". Uses existing startCommand column — no process manager changes needed. Console output prefixed with process names for error attribution.npx convex deploy. Leverages existing tool consent system.chef/template/) as starting point. Pre-wired with convex/ directory, convex.config.ts, ConvexProvider, correct start scripts, convex + concurrently npm dependencies, Tailwind + shadcn/ui compatibility. Production-quality since Dyad replaces Chef long-term.ConvexConnection.tsx pattern).get_convex_project_info, get_convex_schema, deploy_convex for local-agent mode. Also <dyad-add-integration provider="convex"> support in agent responses for suggesting Convex when appropriate.handleUnsetProject pattern).npm install convex when adding Convex to an app. Template includes convex and concurrently as dependencies.oauth.dyad.sh (v2)@convex-dev/auth with username/password/OAuth login (v2)npx convex dev) so that I see live data in the preview immediately.Primary flow: Connecting Convex to an existing app
ipc.system.openExternalUrl) with inline instructions: "Copy your deployment URL and deploy key from the Convex Dashboard"hasSeenConvexOnboarding flag)convex/schema.ts in the existing CodeView panel (Monaco editor, read-only). No custom schema visualization component needed — the schema IS the TypeScript file.mcp_tool_consents).[Convex] prefix for visual differentiation. Console component can filter/color-code based on source tag.<label> elements, placeholder text, aria-describedby for instructionsaria-live region[Convex]Follows Dyad's existing layered IPC pattern:
UI (ConvexConnector.tsx) → IPC Contracts (convex.ts) → Handlers (convex_handlers.ts) → CLI/API
CLI-driven approach (not full API client): Use npx convex CLI commands for deploy operations, read convex/schema.ts directly for schema introspection. This mirrors how Chef works and minimizes API surface risk.
Dual dev server: Template's package.json uses concurrently to run both npx convex dev and npx vite. Dyad's existing startCommand column supports custom start scripts — no changes to app_handlers.ts process management.
New files (6 + template):
| File | Purpose | Size |
|---|---|---|
src/ipc/types/convex.ts | IPC contracts (connect, disconnect, get-info, deploy, get-schema) | Small |
src/ipc/handlers/convex_handlers.ts | Handler implementations | Medium |
src/convex_admin/convex_management_client.ts | Deploy key validation, deployment status checks via HTTP API | Small |
src/convex_admin/convex_context.ts | Context generator — reads convex/schema.ts, formats for AI prompt | Small |
src/prompts/convex_prompt.ts | Convex-specific system prompt (high-fidelity port from Chef's convexGuidelines.ts + solutionConstraints.ts) | Large |
src/components/ConvexConnector.tsx | Deploy key paste UI + connected state (no separate integration file needed — scope is smaller than Supabase) | Medium |
| Convex template repo | Fork of Chef's template, adapted for Dyad: convex/, ConvexProvider, concurrently start scripts, Tailwind | Medium |
Note: No convex_return_handler.ts needed (no OAuth). No separate ConvexIntegration.tsx needed (folded into ConvexConnector since scope is simpler). Deploy key storage is per-app in the apps table, NOT in global settings.
Modified files:
| File | Change | Size |
|---|---|---|
src/db/schema.ts | Add convexDeploymentUrl, convexProjectSlug, convexTeamSlug to apps table | Small |
src/ipc/handlers/chat_stream_handlers.ts | Add Convex context injection branch (parallel to Supabase block ~line 726) | Small |
src/pro/main/ipc/handlers/local_agent/tool_definitions.ts | Add Convex agent tools | Medium |
src/prompts/local_agent_prompt.ts | Add Convex-aware instructions | Small |
src/pages/app-details.tsx | Add ConvexConnector to integrations section | Small |
SQLite schema (apps table) — new nullable text columns:
ALTER TABLE apps ADD COLUMN convex_deployment_url TEXT;
ALTER TABLE apps ADD COLUMN convex_deploy_key TEXT;
ALTER TABLE apps ADD COLUMN convex_project_slug TEXT;
ALTER TABLE apps ADD COLUMN convex_team_slug TEXT;
Deploy keys stored at the app level (not settings level) since Convex uses per-deployment keys. This differs from Supabase (org-level) and Neon (account-level) credential storage.
Drizzle migration required — straightforward ALTER TABLE ADD COLUMN for nullable text fields.
Security note: Deploy keys are stored as plain text in SQLite for v1 (same trust model as local git credentials). For v2, consider using Electron's safeStorage API to encrypt sensitive tokens at rest — this would benefit all backend integrations, not just Convex.
Settings additions:
hasSeenConvexOnboarding: boolean — tracks whether user has dismissed onboarding cardNew IPC contracts (src/ipc/types/convex.ts):
convex:connect-project — Validate and store deploy key + deployment URL for an appconvex:disconnect-project — Remove Convex association from an appconvex:get-project-info — Return deployment URL, project slug, team slugconvex:deploy — Execute npx convex deploy in the app directoryconvex:get-schema — Read and return contents of convex/schema.tsNew agent tools:
get_convex_project_info — Returns deployment info for contextget_convex_schema — Returns schema file contentsdeploy_convex — Triggers npx convex deploy (with approval gate)npx convex for operations. No official management SDK exists for Convex. Raw HTTP calls where needed.convex/schema.ts IS the schema. Simpler than Supabase/Neon.concurrently for dual process: Template start script handles both dev servers. Existing startCommand column supports this without architecture changes.convexGuidelines.ts and solutionConstraints.ts reference WebContainer and Chef-specific tools. Needs dedicated adaptation for Dyad's tool set (3-4 days). Since Dyad replaces Chef long-term, invest in prompt quality and track Chef's prompt updates for backporting improvements.convex/_generated/ directory: Must be in .gitignore, agent prompt must say "never edit files in convex/_generated/", file tree UI should hide or gray out generated files.Estimated effort: 14-20 engineering days (3-4 weeks). Checkpoint at week 2 to assess pace.
chef/template/), adapt for Dyad: convex/ directory, convex.config.ts, ConvexProvider setup, concurrently --names "vite,convex" in start script, convex + concurrently dependencies, Tailwind + shadcn/ui compatibilityapps table (convex_deployment_url, convex_deploy_key, convex_project_slug, convex_team_slug) via Drizzle migrationsrc/ipc/types/convex.ts following Neon patternconvex_handlers.ts with connect/disconnect/get-info/deploy/get-schema handlersconvex_management_client.ts for deploy key validationConvexConnector.tsx with deploy key paste flow (type="password" input, inline validation, "Open Convex Dashboard" link)convexGuidelines.ts + solutionConstraints.ts to src/prompts/convex_prompt.ts — systematically replace WebContainer/Chef tool references with Dyad equivalents (budget 3-4 days)convex_context.ts — reads convex/schema.ts and formats for AI promptchat_stream_handlers.ts (mutually exclusive with Supabase/Neon)local_agent_prompt.tsget_convex_project_info, get_convex_schema, deploy_convex<dyad-add-integration provider="convex"> support in agent responsesconvex_management_client.ts (mocked HTTP)fakeConnect test-only handlers following Neon/Supabase patternconvex/_generated/ in gitignore, agent prompts, and file tree UIfakeConnect pattern from existing backendsConvexProvider setup)convex/schema.ts not found, destructive schema changes| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| AI generates incorrect Convex code (wrong validators, invalid function signatures) | Medium | High | Port Chef's battle-tested ~960-line prompt; dedicated prompt adaptation time (2-3 days) |
| Console log interleaving confuses users (Vite vs Convex output) | High | Medium | Tag Convex output with [Convex] prefix; add log source filtering in Console component |
| Users hit Convex free tier limits during rapid AI iteration | Medium | Medium | Surface pricing info in onboarding card; link to Convex pricing docs |
| Convex CLI not available / wrong Node.js version | Medium | Medium | Clear error message: "Convex CLI not found"; prerequisite check before connecting |
Network failure during npx convex dev breaks live preview | High | Medium | Clear error state in console; retry guidance; note in onboarding card that Convex requires internet |
| Chef prompt assumes WebContainer / Chef-specific tools | High | High | Dedicated prompt adaptation sprint; do NOT copy-paste — systematically replace tool references |
convex/_generated/ files edited by agent or committed to git | Medium | Medium | Agent prompt exclusion rule; .gitignore entry in template; file tree UI grays out generated files |
| Deploy key stored as plain text in SQLite | Low | Medium | Acceptable for v1 (local desktop app trust model). v2: use Electron safeStorage API for encryption at rest |
| No offline development possible with Convex | High | Low | Clear messaging in onboarding card: "Convex requires internet connection during development" |
CONVEX_URL env var needs to be set. Should this be automated or manual? (Follow-up work.)| Decision | Reasoning | Alternatives Considered |
|---|---|---|
| Deploy key paste for auth (v1) | Simplest to implement, proven in Chef, no server-side OAuth work needed. OAuth deferred to v2. | OAuth via oauth.dyad.sh (too much server-side work for v1), CLI login (breaks Dyad UX pattern), hybrid deep-link (middle ground — we DO deep-link to the Dashboard page) |
| Connect existing project only (v1) | Auto-provisioning requires account-level auth, significantly expanding scope. Users create projects on Convex Dashboard first. | Auto-provision like Chef (requires full Convex account auth) |
Dual dev server via concurrently (MVP) | Without npx convex dev, live preview is non-functional for Convex apps. Uses existing startCommand column — no process manager refactor needed. | Manual deploy button only (broken default DX), modify process manager (too large a refactor) |
| Backend mutual exclusivity (v1) | Simpler conditional logic, clearer mental model, avoids conflicting prompts. Just another branch in chat_stream_handlers.ts. | Allow Convex + Supabase (massively complicates prompts and UX) |
| CLI-driven approach (not API client) | Mirrors how Chef works, minimizes API surface risk, no official Convex management SDK. Uses npx convex for deploy. | Full API client (more work, fragile against Convex API changes) |
| Schema = file read (not SQL introspection) | Convex schema IS the convex/schema.ts file. Reading it directly is instant and always in sync. Simpler than Supabase/Neon SQL introspection. | Query deployment API for schema (requires running deployment, adds latency) |
| Replace Chef long-term | Dyad's Convex integration is the long-term successor to Chef. Invest in feature parity. Port prompts and patterns. | Keep Chef and Dyad complementary (duplicated effort), port Chef into Dyad entirely (too large) |
| High-fidelity prompt port (3-4 days) | Chef's prompt references WebContainer and Chef-specific tools. Naive copy causes broken tool references. Since Dyad replaces Chef, invest in prompt quality. | Verbatim copy (broken references), write from scratch (loses battle-tested content), quick adaptation (insufficient for Chef replacement goal) |
| Onboarding card in v1 | Near-zero engineering overhead (pure React component + boolean flag). High UX value for explaining Convex differences from SQL backends. | Defer to v2 (users confused by paradigm differences) |
| Template from Chef fork (step 1) | Having a working template unblocks all subsequent testing. Chef's template is battle-tested for Convex. | Build from scratch (slower), use generic Convex starter (may not match Dyad's needs) |
| Per-app deploy key storage | Convex uses per-deployment keys (unlike Supabase org-level or Neon account-level). Store in apps table, not global settings. Settings page should NOT show Convex — it only makes sense per-app. | Global settings (wrong abstraction for per-deployment keys) |
Generated by dyad:swarm-to-plan