How dyad-sh/dyad works
Project type and purpose
• This is “Dyad,” a local, open‑source AI app builder packaged as a desktop application.
• It uses a multi‐process architecture (main/preload/renderer), React/TypeScript on the front end, Vite as the build tool, an embedded SQLite database via Drizzle ORM for persistence, and IPC to bridge UI and core logic.
File structure
• Top‐level Vite/Electron configs: vite.main.config.mts, vite.preload.config.mts, vite.renderer.config.mts
• src/main & src/preload: Node/Electron main‐process code, IPC host setup, settings management.
• src/renderer (index.html, renderer.tsx, src/app, src/pages, src/components, src/hooks, src/routes): React UI with routing, components, atoms for state.
• src/ipc: Typed IPC client/host definitions, handlers (app, chat, shell, GitHub, settings), processors, and utils.
• src/db + drizzle/: Drizzle ORM schema, migrations, and SQLite store.
• scripts & tools: Build‐time helpers and OS integration scripts (macOS certs, code extraction).
README
• Confirms it’s a local, cross‑platform AI builder: privacy‑focused, bring‑your‑own API keys, no cloud lock‑in.
Main components and relationships
a. Renderer Process (UI)
• React components, pages and routes (src/pages, src/routes)
• State management via Jotai atoms (src/atoms) and custom hooks (src/hooks)
• Calls into exposed IPC methods to drive chats, app execution, settings, etc.
b. Preload Layer
• Exposes a secure, typed API surface (ipc_client, ipc_host, ipc_types) to the renderer
• Marshals messages between the sandboxed UI and the Node main process
c. Main Process (Core Logic)
• IPC handlers for chat, app loading, dependency management, proposals, GitHub integration, settings (src/ipc/handlers)
• IPC processors for heavy work (executeAddDependency, response_processor)
• Utilities for file IO, shell commands, lock management, environment reading (src/ipc/utils)
• Settings lifecycle (src/main/settings.ts)
d. Data Layer
• Drizzle ORM (drizzle.config.ts) managing SQLite migrations in drizzle/ and runtime schema in src/db
• File‐based storage of user apps, versions, and proposals
e. External Services
• AI API clients (OpenAI or user‑provided) invoked from handlers
• GitHub API integration
• System shell for running user apps
Architectural patterns and design principles
• Multi‑process separation (UI ↔ HTML/JS sandbox, Preload ↔ secure bridge, Main ↔ Node/Electron)
• Typed, modular IPC channels for each domain (chat, files, dependencies, settings)
• Code organization: Handlers (entry points) → Processors (business logic) → Utils (shared helpers)
• ORM + migrations ensure reproducible local database schema