home / skills / nilecui / skillsbase / convex-backend

convex-backend skill

/.cursor/skills/convex-backend

This skill helps you build real-time Convex backends with reactive queries, mutations, and serverless functions using type-safe workflows.

npx playbooks add skill nilecui/skillsbase --skill convex-backend

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.3 KB
---
name: convex-backend
description: Build real-time, reactive backend applications with Convex using TypeScript queries, mutations, and actions with automatic reactivity and optimistic updates. Use when building real-time collaborative applications, implementing reactive data synchronization, writing serverless backend functions, creating queries that auto-update, implementing mutations with transactional guarantees, handling file uploads with Convex storage, implementing authentication with Convex Auth, designing reactive database schemas, or building applications requiring instant data synchronization.
---

# Convex Backend - Realtime Database & Functions

## When to use this skill

- Building real-time collaborative applications
- Implementing reactive data that auto-updates
- Writing Convex queries, mutations, and actions
- Creating serverless backend functions with TypeScript
- Implementing optimistic UI updates
- Handling file uploads with Convex storage
- Implementing authentication with Convex Auth
- Designing Convex database schemas
- Building chat applications or live dashboards
- Creating applications with instant data sync
- Implementing scheduled functions (crons)
- Building backends without managing infrastructure

## When to use this skill

- Building realtime apps with Convex, implementing reactive queries, or managing backend logic with type-safe functions.
- When working on related tasks or features
- During development that requires this expertise

**Use when**: Building realtime apps with Convex, implementing reactive queries, or managing backend logic with type-safe functions.

## Core Concepts

### Queries (Read Data)
\`\`\`typescript
import { query } from './_generated/server';
import { v } from 'convex/values';

export const list = query({
  args: {},
  handler: async (ctx) => {
    return await ctx.db.query('users').collect();
  }
});

export const get = query({
  args: { id: v.id('users') },
  handler: async (ctx, args) => {
    return await ctx.db.get(args.id);
  }
});
\`\`\`

### Mutations (Write Data)
\`\`\`typescript
import { mutation } from './_generated/server';

export const create = mutation({
  args: { name: v.string(), email: v.string() },
  handler: async (ctx, args) => {
    return await ctx.db.insert('users', args);
  }
});
\`\`\`

## Resources
- [Convex Docs](https://docs.convex.dev/)

Overview

This skill helps you build real-time, reactive backends with Convex using TypeScript queries, mutations, and actions. It focuses on automatic reactivity, optimistic updates, and serverless backend functions for collaborative apps and live dashboards. Use it to implement instant data synchronization, transactional mutations, file uploads, and Convex Auth-based authentication.

How this skill works

The skill guides you to author Convex queries for reactive reads, mutations for transactional writes, and actions for longer-running server-side logic. Queries automatically re-run and push updates to clients when underlying data changes, while optimistic updates let the UI reflect changes immediately. It also covers Convex storage for file uploads, scheduled functions, and integrating Convex Auth for secure user flows.

When to use it

  • Building real-time collaborative apps (chat, document editing, live dashboards)
  • Implementing reactive queries that auto-update client views
  • Creating serverless backend logic with type-safe TypeScript functions
  • Needing optimistic UI updates and transactional mutation guarantees
  • Handling file uploads and authentication through Convex
  • Scheduling background tasks or crons without managing servers

Best practices

  • Model schemas with reactivity in mind: keep frequently-updated fields fine-grained
  • Use queries for reads, mutations for single-transaction writes, and actions for longer tasks
  • Apply optimistic updates sparingly and reconcile on server-confirmed results
  • Index fields you query frequently and limit result sizes for efficient reactivity
  • Use Convex Auth for user identity and validate permissions inside resolvers

Example use cases

  • A collaborative text editor where user cursors and content update instantly across clients
  • A live analytics dashboard that auto-refreshes with minimal client code
  • Chat app with optimistic message sending and server-side moderation actions
  • File upload flow using Convex storage plus a mutation to record metadata
  • Background cleanup or aggregation tasks implemented as scheduled Convex functions

FAQ

How do queries stay up to date on the client?

Queries subscribe to changes in the Convex database and re-run automatically when relevant data updates, pushing new results to connected clients.

When should I use an action instead of a mutation?

Use mutations for single-transaction, quick writes. Use actions for longer-running work, external API calls, or operations that should not block a transaction.