Convex Development
Workflow
- Starting a project - See patterns for structure, types, validators
- Database queries - See queries for indexes, filtering, performance
- Actions and scheduling - See actions for external APIs, transactions
- Realtime features - See realtime for subscriptions, optimistic updates
- HTTP endpoints - See http for webhooks, REST, CORS
- File handling - See file-storage for uploads, serving
- Background jobs - See cron for scheduled functions
- Schema changes - See migrations for data evolution
- AI integration - See agents for LLM chat, RAG, tool calling
- Security - See security for auth, ConvexError, ESLint, access control
- Code review - See review for production readiness checklist
- Components - See components for reusable Convex packages
convex-helpers (npm package)
- Custom functions & Zod - See helpers-functions for middleware, auth wrappers, Zod validation
- Data helpers - See helpers-data for relationships, CRUD, triggers, filter, pagination
- Security helpers - See helpers-security for RLS, rate limiting, sessions, CORS
- Async helpers - See helpers-async for workpool, action retries, migrations
- Validation helpers - See helpers-validation for validator utils, Standard Schema, codegen
- Integration helpers - See helpers-integrations for Hono, query caching, useQuery, QueryStreams
Key Principles
- Always define
argsANDreturnsvalidators on every function - Use
ConvexErrorwith structured codes, not plainError - Use
.withIndex()not.filter()for database queries - Use
internal.*(neverapi.*) for scheduling andctx.run*calls - Use
"use node";only when you need Node.js APIs - Keep business logic in
convex/model/helpers, thin public API wrappers - Always
awaitpromises (ctx.db.*,ctx.scheduler.*) - Install
@convex-dev/eslint-pluginfor build-time validation
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Security | CRITICAL | security- |
| 2 | Validation | HIGH | validation- |
| 3 | Performance | HIGH | performance- |
| 4 | Code Quality | MEDIUM | code-quality- |
1. Security (CRITICAL)
security-auth-check- Always check authentication in public functionssecurity-internal-functions- Use internal functions for scheduling and ctx.run callssecurity-row-level-access- Verify row-level ownership before mutationssecurity-convex-error- Use ConvexError instead of plain Errorsecurity-rate-limiting- Implement rate limiting for public mutationssecurity-table-name- Include table name in ctx.db calls
2. Validation (HIGH)
validation-return-types- Always define return validators on functions
3. Performance (HIGH)
performance-no-filter- Use .withIndex() instead of .filter() on queriesperformance-bounded-collect- Only use .collect() with bounded result setsperformance-no-date-now- Don't use Date.now() in query functions
4. Code Quality (MEDIUM)
code-quality-await-promises- Always await async operations
How to Use
Read individual rule files for detailed explanations and code examples:
rules/security-auth-check.md
rules/performance-no-filter.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation