This document describes the CodeProject block architecture in v0, which serves as the primary mechanism for grouping files and rendering React and Next.js applications within the v0 environment. It covers file lifecycle operations (create, edit, delete, move), the special syntax for file manipulation, required attributes for task tracking, and conventions for assets and executable scripts.
For information about v0's overall design system and integration ecosystem, see 4.1.4 and 4.1.6. For context gathering and search strategies, see 4.1.3.
The CodeProject block is v0's fundamental unit for organizing and executing code. All React component code blocks must be grouped inside a CodeProject block, which provides the runtime environment for rendering and executing Next.js applications.
| Characteristic | Description | Reference |
|---|---|---|
| Purpose | Groups files and renders React/Next.js apps | v0 Prompts and Tools/Prompt.txt5-7 |
| Required Usage | MUST group React Component code blocks | v0 Prompts and Tools/Prompt.txt7 |
| Task Tracking | Uses taskNameActive and taskNameComplete attributes | v0 Prompts and Tools/Prompt.txt28-30 |
| UI Feedback | Task names shown in UI (2-5 words) | v0 Prompts and Tools/Prompt.txt29-30 |
Every CodeProject operation requires two descriptive attributes:
taskNameActive: 2-5 words describing code changes as they happen (displayed during execution)taskNameComplete: 2-5 words describing code changes when complete (displayed after completion)Diagram: CodeProject Block Architecture
Sources: v0 Prompts and Tools/Prompt.txt5-30
Files are written using code fence notation with a special file attribute:
```lang file="path/to/file"
[file contents]
```
This syntax is used for both creating new files and editing existing files.
Diagram: File Write Operation Flow
Sources: v0 Prompts and Tools/Prompt.txt12-98
| Convention | Format | Example |
|---|---|---|
| Preferred Case | kebab-case | login-form.tsx |
| Avoids | camelCase, PascalCase for filenames | ❌ LoginForm.tsx |
| Component Files | .tsx extension for React | user-profile.tsx |
Sources: v0 Prompts and Tools/Prompt.txt15
v0 follows an efficiency-first approach to file editing:
Sources: v0 Prompts and Tools/Prompt.txt16-24
// ... existing code ... PatternThis marker (called "my ability to quickly edit" in the system prompt) indicates sections of unchanged code that should be preserved during merging.
Critical Rules:
// ... existing code ...Example:
Sources: v0 Prompts and Tools/Prompt.txt18-314
When edits are not obvious, v0 includes inline // <CHANGE> comments:
Guidelines:
Sources: v0 Prompts and Tools/Prompt.txt25-76
Diagram: File Edit Workflow with Quick Edit Markers
Sources: v0 Prompts and Tools/Prompt.txt18-98
Deletion uses a special marker within the CodeProject block.
Syntax:
```
Constraints:
Sources: v0 Prompts and Tools/Prompt.txt101-112
```
Attributes:
from: Original file pathto: New file pathWhen using MoveFile, v0 MUST:
Diagram: Move File Operation with Import Updates
Sources: v0 Prompts and Tools/Prompt.txt116-131
Used to import read-only reference files from the user context into the active CodeProject.
Syntax:
Use Cases:
Sources: v0 Prompts and Tools/Prompt.txt136-141
v0 may ONLY write/edit a file after reading it first. This is enforced to prevent breaking user code.
Workflow:
Risk if violated: Overwriting important code without context
Example Pattern:
Prompt: Add a login page to my sports website
*Launches Search Repo to read the files first*
[CodeProject with new login page]
Sources: v0 Prompts and Tools/Prompt.txt96-98
Table: Read-Before-Write Enforcement
| Stage | Action | Tool | Purpose |
|---|---|---|---|
| 1 | Read | SearchRepo, ReadFile | Understand current state |
| 2 | Analyze | Internal processing | Determine changes needed |
| 3 | Write | CodeProject with file="..." | Apply changes safely |
| 4 | Validate | System merge | Ensure code integrity |
Sources: v0 Prompts and Tools/Prompt.txt36-98
Images and other assets use special embedding syntax:
This adds the asset to the virtual file system at the specified path.
When a user provides an image or asset:
/images/dashboard.png)Can generate images by passing a query to the file metadata:
This generates an image for the query and places it at the specified path.
Note: Image generation can be used outside CodeProject for standalone images (e.g., "make me an image for a hero").
Sources: v0 Prompts and Tools/Prompt.txt145-173
Diagram: Asset Handling in CodeProject
Sources: v0 Prompts and Tools/Prompt.txt145-173
The /scripts folder enables execution of Python, Node.js, and SQL code within CodeProjects.
Requirements:
/scripts folderDiagram: Script Execution Architecture
Sources: v0 Prompts and Tools/Prompt.txt176-213
print() for output (execution environment captures logs)fetch for HTTP requestsimport statements (NEVER require)sharp library for image processingconsole.log() for outputSources: v0 Prompts and Tools/Prompt.txt187-211
| Use Case | Language | Typical Tools |
|---|---|---|
| Database creation/seeding | SQL | CREATE TABLE, INSERT |
| Database migrations | SQL | ALTER TABLE, UPDATE |
| Data processing | Python | NumPy, Pandas |
| Algorithm demos | Python/Node.js | Pure functions |
| Individual functions | Node.js | ES6 modules |
| Immediate execution tasks | Any | Direct output capture |
Sources: v0 Prompts and Tools/Prompt.txt218-226
v0 uses a special debug pattern: console.log("[v0] ...") statements to receive feedback during development.
Purpose:
Best Practices:
Examples:
Lifecycle:
<v0_app_debug_logs>Sources: v0 Prompts and Tools/Prompt.txt228-253
CodeProjects come with a default set of files that are NEVER generated unless explicitly requested by the user:
| Category | Files/Folders |
|---|---|
| Layout | app/layout.tsx |
| UI Components | components/ui/* (accordion, alert, avatar, button, card, dropdown-menu, etc.) |
| Hooks | hooks/use-mobile.tsx, hooks/use-mobile.ts, hooks/use-toast.ts |
| Utilities | lib/utils.ts (includes cn function for class names) |
| Styles | app/globals.css (shadcn styles with Tailwind CSS v4) |
| Config | next.config.mjs, package.json, tsconfig.json |
Rationale: These files are pre-configured in every CodeProject, so regenerating them wastes time and may override user customizations.
Sources: v0 Prompts and Tools/Prompt.txt276-473
Diagram: Complete File Operation Workflow
Sources: v0 Prompts and Tools/Prompt.txt5-253
Refresh this wiki