convex-best-practices

Implements Convex function patterns covering validation, indexes, error handling, and TypeScript types.

1|Updated Feb 19, 2026
One-click install
npx skills add https://github.com/kausthubh-coder/kriyan-web --skill convex-best-practices-kausthubh-coder
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: convex-best-practices
Source: https://github.com/kausthubh-coder/kriyan-web/tree/main/.cursor/skills/convex-best-practices
Command: npx skills add https://github.com/kausthubh-coder/kriyan-web --skill convex-best-practices-kausthubh-coder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @convex-dev/eslint-plugin.

What problem does it solve? Developers building Convex backends often write inefficient queries, skip argument and return validation, or hit write conflicts because they are unfamiliar with Convex's reactive, OCC-based architecture. This Skill provides established patterns so Convex functions are structured, validated, and conflict-resistant from the start. ## Core Features & Use Cases - Function Organization & Validation: Enforces domain-based file organization, argument validators, and return validators on every query and mutation. - Query & Conflict Patterns: Provides index-based query patterns with withIndex, idempotent mutations, and direct patching to minimize optimistic concurrency control conflicts. - Error Handling & TypeScript: Standardizes ConvexError usage for user-facing errors and proper use of Id and Doc generated types. - Use Case: When adding a new tasks module to a Convex app, apply this Skill to generate schema indexes, validated CRUD functions, and idempotent mutations that pass the @convex-dev/eslint-plugin rules. ## Quick Start Apply the Convex best practices skill to review and refactor the functions in my convex/tasks.ts file.

Frequently Asked Questions about convex-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Convex functions for a production app?▼

Organize Convex functions by domain into files like users.ts or tasks.ts, using the object syntax with args, returns, and handler fields. Expose public queries and mutations to clients and use internalMutation for logic only callable from other Convex functions.

How to avoid write conflicts in Convex mutations?▼

Convex uses optimistic concurrency control, so make mutations idempotent by checking current state before updating, patch documents directly without reading first when possible, and use Promise.all for parallel independent updates to reduce conflict surface.

Should I use filter or withIndex for Convex queries?▼

Always define indexes in schema.ts and query them with withIndex instead of using filter. Index-based queries scale with data size, while filter scans every document in the table and becomes slow as tables grow.

Does Convex require argument and return validators?▼

Yes, every Convex function should define args and returns validators using the v builder from convex/values. The @convex-dev/eslint-plugin require-argument-validators rule enforces this at build time for type-safe, self-documenting APIs.

How do I throw user-facing errors in Convex?▼

Throw ConvexError from convex/values with a structured payload containing a code and message. Unlike generic exceptions, ConvexError data is serialized and delivered to the client so the UI can display meaningful feedback.