Data Management (Database)
Relevant source files
The following files were used as context for generating this wiki page:
- src/prompts/system_prompt.ts
- src/prompts/supabase_prompt.ts
- src/prompts/security_review_prompt.ts
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
- e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
- e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
System prompts are the foundational instructions that define the AI's role, capabilities, constraints, and output format within the Dyad application. They are crucial for ensuring the AI behaves as expected, follows project-specific guidelines, and uses the correct tools for the task at hand. The system is designed to be modular, allowing different prompts to be loaded based on the user's selected "chat mode," such as building code, answering questions, or performing security analysis.
This architecture allows for specialized AI behavior tailored to specific contexts. The prompts are dynamically constructed by combining a base template with project-specific rules defined in an AI_RULES.md file, providing a flexible yet consistent framework for AI interaction.
Sources: src/prompts/system_prompt.ts:405-423
Core Prompt Architecture
The central logic for assembling system prompts resides in the constructSystemPrompt function. This function dynamically creates the final prompt sent to the AI model based on the current chatMode and project-specific aiRules.
The process follows these steps:
- A base system prompt is selected corresponding to the active
chatMode(e.g.,build,ask,agent). - The system reads the
AI_RULES.mdfile from the project's root directory. If this file is not found, it falls back to a set of default rules. - The content from the AI Rules is injected into the base prompt, replacing the
[[AI_RULES]]placeholder. - For
buildmode, an additional prompt forTurboEditsV2can be appended if the feature is enabled.
Sources: src/prompts/system_prompt.ts:405-446
This diagram illustrates the prompt construction flow.
Sources: src/prompts/system_prompt.ts:405-446
AI Rules (AI_RULES.md)
The AI_RULES.md file provides project-specific context to the AI, such as the tech stack, preferred libraries, and coding conventions. The readAiRules function loads this file. If it doesn't exist, DEFAULT_AI_RULES are used as a fallback. This ensures the AI's output aligns with the project's architecture.
The default rules specify a tech stack including:
- React with TypeScript
- React Router for routing
shadcn/uiandlucide-reactfor components and icons- Tailwind CSS for styling
Sources: src/prompts/system_prompt.ts:30-66, src/prompts/system_prompt.ts:448-467
Chat Modes and Their Prompts
Dyad utilizes several distinct chat modes, each with a specialized system prompt that dictates the AI's behavior.
Build Mode (build)
This is the primary mode for generating and modifying code. The AI is instructed to act as "an AI editor that creates and modifies web applications."
Key Instructions & Tools:
- Thinking Process: The AI must use
<think>tags to outline its plan before generating a response. - File Operations: All code and file modifications must be enclosed in specific XML-like tags.
- App Commands: The AI can suggest actions like
rebuildorrestartusing the<dyad-command>tag.
The following table summarizes the file operation tags available in Build Mode:
| Tag | Description |
|---|---|
<dyad-write> | Creates a new file or completely overwrites an existing one. |
<dyad-rename> | Renames a file. |
<dyad-delete> | Deletes a file. |
<dyad-add-dependency> | Adds one or more npm packages to the project. |
<dyad-chat-summary> | Sets a concise summary for the current chat session. |
Sources: src/prompts/system_prompt.ts:68-301, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---default-build-mode-1.txt
Ask Mode (ask)
In Ask Mode, the AI's role shifts to that of a "helpful AI assistant that specializes in web development." Its primary directive is to provide explanations and guidance without writing any code.
Core Constraints:
- No Code Production: The prompt contains an "ABSOLUTE PRIMARY DIRECTIVE" strictly forbidding the generation of any code, code snippets, or syntax examples.
- No Tool Usage: All
<dyad-*>tags are prohibited. - Conceptual Focus: The AI must focus on explaining concepts, best practices, and problem-solving approaches in plain language.
This mode is designed for users who want to understand concepts rather than have the AI implement them directly.
Sources: src/prompts/system_prompt.ts:303-392, e2e-tests/snapshots/chat_mode.spec.ts_chat-mode-selector---ask-mode-1.txt
Agent Modes (agent & local-agent)
The agent modes are designed for analyzing a user's request to gather necessary information before the coding phase. The AI acts as an "AI App Builder Agent."
Core Mission:
- Determine what tools, APIs, data, or external resources are needed.
- Like Ask Mode, it is constrained from generating any code or using
<dyad-*>file modification tags. - If no external tools are needed, it responds with a standard message: "Ok, looks like I don't need any tools, I can start building."
The local-agent variant is constructed via the constructLocalAgentPrompt function, indicating a specialized version of this behavior.
Sources: src/prompts/system_prompt.ts:394-403, src/prompts/system_prompt.ts:413-415
Specialized Prompts
Beyond the primary chat modes, Dyad uses highly specialized prompts for complex, multi-step tasks like integrating services or performing security reviews.
Supabase Integration Prompt
When Supabase is available, this prompt provides detailed instructions for using its features.
Key Areas:
- Auth: Guides the AI to use
@supabase/auth-ui-reactfor login components and to manage sessions viaonAuthStateChange. - Database:
- Instructs the use of the
<dyad-execute-sql>tag for all database operations. - Mandates Row Level Security (RLS) on all tables for security, providing specific templates for creating tables with
SELECT,INSERT,UPDATE, andDELETEpolicies.
- Instructs the use of the
- Edge Functions: Provides a comprehensive guide for creating, deploying, and invoking server-side edge functions, including CORS handling and manual JWT verification.
The following diagram shows the mandatory flow for creating a database table with RLS.
Sources: src/prompts/supabase_prompt.ts
Security Review Prompt
For the /security-review command, the AI adopts the role of a "Security expert." This prompt directs the AI to analyze the codebase for vulnerabilities.
Key Features:
- Focus Areas: The prompt directs the AI to look for specific vulnerability classes like Injection Attacks, Broken Authentication, and Client-Side Secrets.
- Structured Output: All findings must be formatted using the
<dyad-security-finding>tag. - Severity Levels: Findings are categorized using a defined severity scale.
The structure of a security finding is as follows:
| Field | Description |
|---|---|
title | A brief, descriptive title of the vulnerability. |
level | The severity, one of critical, high, medium, or low. |
| What | A plain-language explanation of the issue. |
| Risk | The potential impact of the vulnerability. |
| Potential Solutions | A ranked list of remediation options. |
| Relevant Files | File paths where the vulnerability exists. |
Sources: src/prompts/security_review_prompt.ts, e2e-tests/snapshots/security_review.spec.ts_security-review-1.txt
Summary
The system prompt architecture in Dyad is a sophisticated system that enables flexible and context-aware AI behavior. By separating prompts by chat mode, allowing for project-specific rule injection, and creating highly specialized instructions for complex tasks, the system ensures that the AI can function effectively as a coder, a teacher, and a security analyst while maintaining consistency and adhering to best practices.