Convex
You are an expert in Convex — the open-source, reactive backend platform where queries are TypeScript code. You have deep knowledge of schema design, function authoring (queries, mutations, actions), real-time data subscriptions, authentication, file storage, scheduling, and deployment workflows across React, Next.js, Angular, Vue, Svelte, React Native, and server-side environments.
When to Use
- Use when building a new project with Convex as the backend
- Use when adding Convex to an existing React, Next.js, Angular, Vue, Svelte, or React Native app
- Use when designing schemas for a Convex document-relational database
- Use when writing or debugging Convex functions (queries, mutations, actions)
- Use when implementing real-time/reactive data patterns
- Use when setting up authentication with Convex Auth or third-party providers (Clerk, Auth0, etc.)
- Use when working with Convex file storage, scheduled functions, or cron jobs
- Use when deploying or managing Convex projects
Core Concepts
Convex is a document-relational database with a fully managed backend. Key differentiators:
- Reactive by default: Queries automatically re-run and push updates to all connected clients when underlying data changes
- TypeScript-first: All backend logic — queries, mutations, actions, schemas — is written in TypeScript
- ACID transactions: Serializable isolation with optimistic concurrency control
- No infrastructure to manage: Serverless, scales automatically, zero config
- End-to-end type safety: Types flow from schema → backend functions → client hooks
Function Types
| Type |
Purpose |
Can Read DB |
Can Write DB |
Can Call External APIs |
Cached/Reactive |
| Query |
Read data |
✅ |
❌ |
❌ |
✅ |
| Mutation |
Write data |
✅ |
✅ |
❌ |
❌ |
| Action |
Side effects |
via runQuery |
via runMutation |
✅ |
❌ |
| HTTP Action |
Webhooks/custom endpoints |
via runQuery |
via runMutation |
✅ |
❌ |
Project Setup
New Project (Next.js)
npx create-next-app@latest my-app
cd my-app && npm install convex
npx convex dev
Add to Existing Project
npm install convex
npx convex dev
The npx convex dev command:
- Prompts you to log in (GitHub)
- Creates a project and deployment
- Generates
convex/ folder for backend functions
- Syncs functions to your dev deployment in real-time
- Creates
.env.local with CONVEX_DEPLOYMENT and NEXT_PUBLIC_CONVEX_URL
Folder Structure
my-app/
├── convex/
│ ├── _generated/ ← Auto-generated (DO NOT EDIT)
│ │ ├── api.d.ts
│ │ ├── dataModel.d.ts
│ │ └── server.d.ts
│ ├── schema.ts ← Database schema definition
│ ├── tasks.ts ← Query/mutation functions
│ └── http.ts ← HTTP actions (optional)
├── .env.local ← CONVEX_DEPLOYMENT, NEXT_PUBLIC_CONVEX_URL
└── convex.json ← Project config (optional)
Schema Design
Define your schema in convex/schema.ts using the validator library:
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
export default defineSchema({
users: defineTable({
name: v.string(),
email: v.string(),
avatarUrl: v.optional(v.string()),
tokenIdentifier: v.string(),
})
.index("by_token", ["tokenIdentifier"])
.index("by_email", ["email"]),
messages: defineTable({
authorId: v.id("users"),
channelId: v.id("channels"),
body: v.string(),
attachmentId: v.optional(v.id("_storage")),
})
.index("by_channel", ["channelId"])
.searchIndex("search_body", { searchField: "body" }),
channels: defineTable({
name: v.string(),
description: v.optional(v.string()),
isPrivate: v.boolean(),
}),
});
Validator Types
| Validator |
TypeScript Type |
Notes |
v.string() |
string |
|
v.number() |
number |
IEEE 754 float |
v.bigint() |
bigint |
|
v.boolean() |
boolean |
|
v.null() |
null |
|
1---2name: convex3description: "Convex reactive backend expert: schema design, TypeScript functions, real-time subscriptions, auth, file storage, scheduling, and deployment."4category: Document Processing5source: antigravity6tags: [typescript, react, node, nextjs, api, ai, automation, workflow, template, design]7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/convex8metadata:9 source: https://skillmd.com/skills/ranbot-ai/convex10---111213# Convex1415You are an expert in Convex — the open-source, reactive backend platform where queries are TypeScript code. You have deep knowledge of schema design, function authoring (queries, mutations, actions), real-time data subscriptions, authentication, file storage, scheduling, and deployment workflows across React, Next.js, Angular, Vue, Svelte, React Native, and server-side environments.1617## When to Use18- Use when building a new project with Convex as the backend19- Use when adding Convex to an existing React, Next.js, Angular, Vue, Svelte, or React Native app20- Use when designing schemas for a Convex document-relational database21- Use when writing or debugging Convex functions (queries, mutations, actions)22- Use when implementing real-time/reactive data patterns23- Use when setting up authentication with Convex Auth or third-party providers (Clerk, Auth0, etc.)24- Use when working with Convex file storage, scheduled functions, or cron jobs25- Use when deploying or managing Convex projects2627## Core Concepts2829Convex is a **document-relational** database with a fully managed backend. Key differentiators:3031- **Reactive by default**: Queries automatically re-run and push updates to all connected clients when underlying data changes32- **TypeScript-first**: All backend logic — queries, mutations, actions, schemas — is written in TypeScript33- **ACID transactions**: Serializable isolation with optimistic concurrency control34- **No infrastructure to manage**: Serverless, scales automatically, zero config35- **End-to-end type safety**: Types flow from schema → backend functions → client hooks3637### Function Types3839| Type | Purpose | Can Read DB | Can Write DB | Can Call External APIs | Cached/Reactive |40| :-------------- | :------------------------ | :------------- | :---------------- | :--------------------- | :-------------- |41| **Query** | Read data | ✅ | ❌ | ❌ | ✅ |42| **Mutation** | Write data | ✅ | ✅ | ❌ | ❌ |43| **Action** | Side effects | via `runQuery` | via `runMutation` | ✅ | ❌ |44| **HTTP Action** | Webhooks/custom endpoints | via `runQuery` | via `runMutation` | ✅ | ❌ |4546## Project Setup4748### New Project (Next.js)4950```bash51npx create-next-app@latest my-app52cd my-app && npm install convex53npx convex dev54```5556### Add to Existing Project5758```bash59npm install convex60npx convex dev61```6263The `npx convex dev` command:64651. Prompts you to log in (GitHub)662. Creates a project and deployment673. Generates `convex/` folder for backend functions684. Syncs functions to your dev deployment in real-time695. Creates `.env.local` with `CONVEX_DEPLOYMENT` and `NEXT_PUBLIC_CONVEX_URL`7071### Folder Structure7273```74my-app/75├── convex/76│ ├── _generated/ ← Auto-generated (DO NOT EDIT)77│ │ ├── api.d.ts78│ │ ├── dataModel.d.ts79│ │ └── server.d.ts80│ ├── schema.ts ← Database schema definition81│ ├── tasks.ts ← Query/mutation functions82│ └── http.ts ← HTTP actions (optional)83├── .env.local ← CONVEX_DEPLOYMENT, NEXT_PUBLIC_CONVEX_URL84└── convex.json ← Project config (optional)85```8687## Schema Design8889Define your schema in `convex/schema.ts` using the validator library:9091```typescript92import { defineSchema, defineTable } from "convex/server";93import { v } from "convex/values";9495export default defineSchema({96 users: defineTable({97 name: v.string(),98 email: v.string(),99 avatarUrl: v.optional(v.string()),100 tokenIdentifier: v.string(),101 })102 .index("by_token", ["tokenIdentifier"])103 .index("by_email", ["email"]),104105 messages: defineTable({106 authorId: v.id("users"),107 channelId: v.id("channels"),108 body: v.string(),109 attachmentId: v.optional(v.id("_storage")),110 })111 .index("by_channel", ["channelId"])112 .searchIndex("search_body", { searchField: "body" }),113114 channels: defineTable({115 name: v.string(),116 description: v.optional(v.string()),117 isPrivate: v.boolean(),118 }),119});120```121122### Validator Types123124| Validator | TypeScript Type | Notes |125| :-------------------------------- | :-------------------- | :--------------------------------------------- |126| `v.string()` | `string` | |127| `v.number()` | `number` | IEEE 754 float |128| `v.bigint()` | `bigint` | |129| `v.boolean()` | `boolean` | |130| `v.null()` | `null` |