Convex
Overview
Convex is a reactive backend platform where database queries, mutations, and actions are defined in TypeScript and data automatically syncs to connected clients in real-time. It eliminates WebSocket code, polling, and cache invalidation, providing ACID transactions and optimistic updates out of the box.
Instructions
- When defining schemas, use
defineSchema() with defineTable() and typed validators (v.string(), v.number(), v.id("tableName")), and define indexes for all filtered and sorted queries.
- When writing functions, use queries for reads (automatically reactive), mutations for writes (transactional, triggers reactive updates), and actions for external API calls (non-transactional).
- When building React UIs, use
useQuery() for reactive data subscriptions that auto-update, useMutation() for writes with optimistic updates, and usePaginatedQuery() for infinite scroll.
- When handling authentication, use
convex-auth for built-in auth or integrate Clerk/Auth0, and validate user identity at the start of every mutation with ctx.auth.getUserIdentity().
- When processing background work, use
ctx.scheduler.runAfter() for delayed execution and cron jobs for recurring tasks instead of making mutations slow.
- When storing files, use
ctx.storage.store() for upload and ctx.storage.getUrl() for serving URLs without S3 or CDN configuration.
- When implementing search, use full-text search indexes with
searchIndex() or vector search with vectorIndex() for AI/RAG applications, with metadata filtering.
Examples
Example 1: Build a real-time chat application
User request: "Create a real-time chat app with Convex and React"
Actions:
- Define
messages table with schema, author reference, and timestamp index
- Create a query function that returns messages sorted by timestamp
- Create a mutation for sending messages with auth validation
- Use
useQuery() in React to subscribe to messages with automatic real-time updates
Output: A chat application where messages appear instantly for all connected users without WebSocket code.
Example 2: Add full-text and vector search
User request: "Implement search across articles with both keyword and semantic search"
Actions:
- Define search index on article body field with
searchIndex()
- Define vector index on embedding field with
vectorIndex()
- Create query functions for text search and vector similarity search
- Combine metadata filtering with search for scoped results
Output: A dual search system supporting both keyword matching and semantic similarity queries.
Guidelines
- Use schema validation in production:
defineSchema() catches type errors at deploy time, not runtime.
- Define indexes for all filtered/sorted queries to ensure efficient data access.
- Use queries for reads, mutations for writes, actions for external APIs; never mix concerns.
- Keep mutations small and fast since they hold a database lock; move heavy processing to actions.
- Use
ctx.scheduler.runAfter() for background work instead of making mutations slow.
- Validate user identity at the start of every mutation to prevent unauthorized writes.
- Use optimistic updates for interactive UIs; the client sees the change instantly while the server confirms.
1---2name: convex3description: >-4 Assists with building real-time reactive backends using Convex. Use when creating databases5 with automatic client sync, reactive queries, file storage, scheduled functions, or full-text6 and vector search. Trigger words: convex, reactive backend, real-time database, useQuery,7 useMutation, convex functions, convex schema.8license: Apache-2.09compatibility: "Works with React, Next.js, Remix, React Native"10metadata:11 source: https://skillmd.com/skills/eliferjunior/convex12 author: terminal-skills13 version: "1.0.0"14 category: data-ai15 tags: ["convex", "real-time", "reactive", "backend", "database"]16---1718# Convex1920## Overview2122Convex is a reactive backend platform where database queries, mutations, and actions are defined in TypeScript and data automatically syncs to connected clients in real-time. It eliminates WebSocket code, polling, and cache invalidation, providing ACID transactions and optimistic updates out of the box.2324## Instructions2526- When defining schemas, use `defineSchema()` with `defineTable()` and typed validators (`v.string()`, `v.number()`, `v.id("tableName")`), and define indexes for all filtered and sorted queries.27- When writing functions, use queries for reads (automatically reactive), mutations for writes (transactional, triggers reactive updates), and actions for external API calls (non-transactional).28- When building React UIs, use `useQuery()` for reactive data subscriptions that auto-update, `useMutation()` for writes with optimistic updates, and `usePaginatedQuery()` for infinite scroll.29- When handling authentication, use `convex-auth` for built-in auth or integrate Clerk/Auth0, and validate user identity at the start of every mutation with `ctx.auth.getUserIdentity()`.30- When processing background work, use `ctx.scheduler.runAfter()` for delayed execution and cron jobs for recurring tasks instead of making mutations slow.31- When storing files, use `ctx.storage.store()` for upload and `ctx.storage.getUrl()` for serving URLs without S3 or CDN configuration.32- When implementing search, use full-text search indexes with `searchIndex()` or vector search with `vectorIndex()` for AI/RAG applications, with metadata filtering.3334## Examples3536### Example 1: Build a real-time chat application3738**User request:** "Create a real-time chat app with Convex and React"3940**Actions:**411. Define `messages` table with schema, author reference, and timestamp index422. Create a query function that returns messages sorted by timestamp433. Create a mutation for sending messages with auth validation444. Use `useQuery()` in React to subscribe to messages with automatic real-time updates4546**Output:** A chat application where messages appear instantly for all connected users without WebSocket code.4748### Example 2: Add full-text and vector search4950**User request:** "Implement search across articles with both keyword and semantic search"5152**Actions:**531. Define search index on article body field with `searchIndex()`542. Define vector index on embedding field with `vectorIndex()`553. Create query functions for text search and vector similarity search564. Combine metadata filtering with search for scoped results5758**Output:** A dual search system supporting both keyword matching and semantic similarity queries.5960## Guidelines6162- Use schema validation in production: `defineSchema()` catches type errors at deploy time, not runtime.63- Define indexes for all filtered/sorted queries to ensure efficient data access.64- Use queries for reads, mutations for writes, actions for external APIs; never mix concerns.65- Keep mutations small and fast since they hold a database lock; move heavy processing to actions.66- Use `ctx.scheduler.runAfter()` for background work instead of making mutations slow.67- Validate user identity at the start of every mutation to prevent unauthorized writes.68- Use optimistic updates for interactive UIs; the client sees the change instantly while the server confirms.