API Reference Overview
ZapDev uses Convex as its primary backend and API layer. Convex provides:- Real-time reactive queries that automatically update when data changes
- Type-safe mutations for data modification
- Server-side actions for background processing and external API calls
- Built-in authentication with Clerk integration
Architecture Overview
Convex Backend
Convex provides real-time database operations with reactive queries that automatically update when data changes. Location:convex/
Core Function Types:
- Queries: Read operations that are reactive and cached
- Mutations: Write operations that modify database state
- Actions: Server-side logic with external API calls (Node.js runtime)
convex/projects.ts:282):
API Conventions
Convex Conventions
- Function Syntax: Always use object-based syntax with explicit
argsandhandler - Validators: Every argument must have a
v.*validator fromconvex/values - Authentication: Use
requireAuth(ctx)at the start of protected handlers - Indexes: Always use
withIndex()for queries - never use.filter()for performance
Database Schema
The database schema is defined inconvex/schema.ts with type-safe table definitions:
Core Tables:
projects: User projects with framework and settingsmessages: Conversation messages for each projectfragments: Generated code fragments with sandbox URLsattachments: Images and design files linked to messagesusage: Credit tracking for free/pro/unlimited tierssubscriptions: Polar subscription dataagentRuns: AI agent execution tracking
Client Usage
Using Convex in Client Components
Using in Server Components
For Convex in server components:Anti-Patterns
Never do this:- Use
.filter()in Convex queries (use indexes instead) - Call
ctx.dbinside a Convex action (usectx.runQueryorctx.runMutation) - Expose Clerk user IDs in public API responses
- Use
anytype in function signatures - Perform side effects (API calls, emails) in queries/mutations (use actions)
Type Safety
Convex provides full end-to-end type safety by generating types from your schema definitions inconvex/_generated/dataModel.d.ts and convex/_generated/api.d.ts.
Use TypeScript’s type inference to get autocomplete and type checking throughout your application. All query and mutation functions are fully typed, including arguments and return values.
Next Steps
- Authentication - Learn about Clerk JWT authentication
- Projects API - Project management endpoints
- Messages API - Conversation and chat operations
- Usage API - Credit tracking and limits