mcpField
C
convex-tanstack

convex-tanstack

github.com/sstoboDevelopment24224 installsUpdated 40w ago
Repository

About convex-tanstack

A development skill for building real-time full-stack apps with Convex and TanStack Start. It guides developers through backend functions, authentication, routing, data fetching, and SSR, with task-specific reference files and implementation patterns.

Key features

  1. 01Convex query, mutation, and action guidance
  2. 02TanStack Router route configuration
  3. 03Better Auth setup
  4. 04Data fetching and SSR patterns
  5. 05Storage, scheduling, and agent guides

Use cases

  1. 01Starting a Convex and TanStack Start project
  2. 02Troubleshooting SSR or hydration
  3. 03Implementing authentication and data operations
  4. 04Adding file storage or scheduled jobs

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/sstobo/convex-skills --skill convex-tanstack

After installing, type/convex-tanstackin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
01-setup.md
02-router.md
03-auth.md
04-data-fetching.md
05-backend.md
06-types.md
07-storage.md
08-scheduling.md
09-agents.md
10-frontend.md
11-permissions.md
12-deployment.md
13-quick-reference.md

Details

From the project README

Convex + TanStack Start

Overview

This skill provides guidance for building reactive, real-time full-stack applications using Convex (reactive backend-as-a-service) with TanStack Start (full-stack React meta-framework). The stack provides live-updating queries, type-safe end-to-end development, SSR support, and automatic cache invalidation.

When to Use This Skill

  • Implementing Convex queries, mutations, or actions
  • Setting up or troubleshooting Better Auth authentication
  • Configuring TanStack Router routes and loaders
  • Writing schema definitions and indexes
  • Implementing data fetching patterns (useQuery, useSuspenseQuery)
  • Working with file storage, scheduling, or cron jobs
  • Building AI agents with @convex-dev/agent
  • Debugging SSR or hydration issues

Quick Reference

Essential Imports
// Data fetching (always use cached version)
import { useQuery } from 'convex-helpers/react/cache'
import { useMutation, useAction } from 'convex/react'

// SSR with React Query
import { useSuspenseQuery } from '@tanstack/react-query'
import { convexQuery } from '@convex-dev/react-query'

// API and types
import { api } from '~/convex/_generated/api'
import type { Id, Doc } from '~/convex/_generated/dataModel'

// Backend functions
import { query, mutation, action } from "./_generated/server"
import { v } from "convex/values"
The Skip Pattern

Never call hooks conditionally. Use "skip" instead:

const user = useQuery(api.users.get, userId ? { userId } : "skip")
const org = useQuery(api.orgs.get, user?.orgId ? { orgId: user.orgId } : "skip")
Three-State Query Handling
if (data === undefined) return <Skeleton />  // Loading
if (data === null) return <NotFound />       // Not found
return <Content data={data} />               // Success
Function Syntax (Always Include Returns Validator)
export const getUser = query({
  args: { userId: v.id("users") },
  returns: v.union(
    v.object({ _id: v.id("users"), name: v.string() }),
    v.null()
  ),
  handler: async (ctx, args) => {
    return await ctx.db.get(args.userId)
  },
})
Index Best Practices
// Schema - name includes all fields
.index("by_organizationId_status", ["organizationId", "status"])

// Query - fields in same order as index
.withIndex("by_organizationId_status", (q) =>
  q.eq("organizationId", orgId).eq("status", "published")
)
Auth Check (Backend)
import { authComponent } from "./auth"

const user = await authComponent.getAuthUser(ctx)
if (!user) throw new Error("Not authenticated")

Core Principles

  1. Use queries for reads - Queries are reactive, cacheable, and consistent
  2. Keep functions fast - Finish in < 100ms, work with < a few hundred records
  3. Prefer queries/mutations over actions - Actions are for external API calls only
  4. Always use indexes - Never do table scans with .filter()
  5. Minimize client state - Rely on Convex's real-time sync

Common Anti-Patterns

WrongCorrect
import { useQuery } from 'convex/react'import { useQuery } from 'convex-helpers/react/cache'
if (id) useQuery(...)useQuery(..., id ? {...} : "skip")
.filter(x => x.field === val).withIndex("by_field", q => q.eq("field", val))
Action with ctx.dbUse ctx.runQuery/runMutation
`count

Reference Files

Load the appropriate reference file based on the task:

FileUse When
references/01-setup.mdProject setup, config files, environment variables
references/02-router.mdRouter setup, root route, file-based routing, layouts
references/03-auth.mdBetter Auth setup, sign up/in/out, protected routes, SSR auth
references/04-data-fetching.mduseQuery, useSuspenseQuery, mutations, loaders, prefetching
references/05-backend.mdSchema, queries, mutations, actions, internal functions, HTTP endpoints
references/06-types.mdTypeScript patterns, validators, type mapping
references/07-storage.mdFile upload, download, metadata, deletion
references/08-scheduling.mdscheduler.runAfter, cron jobs
references/09-agents.mdAI agents, tools, RAG setup
references/10-frontend.mdComponent patterns, loading states, Tailwind/shadcn
references/11-permissions.mdRole hierarchy, feature access patterns
references/12-deployment.mdDev commands, Convex CLI, Vercel deployment
references/13-quick-reference.mdImport cheatsheet, common patterns summary
When to Load References
  • Starting a new project: Load 01-setup.md
  • Adding authentication: Load 03-auth.md
  • Writing backend functions: Load 05-backend.md
  • Implementing data fetching: Load 04-data-fetching.md
  • Building UI components: Load 10-frontend.md
  • Need quick syntax: Load 13-quick-reference.md

Comments

Markdown supported