StarterApp Docs
CodebaseFoundations

Convex

Real-time database platform with automatic synchronization and type-safe serverless functions

Convex combines database, real-time synchronization, and serverless functions in one platform. The system eliminates traditional backend complexity through integrated architecture.

Integrated Backend

Convex replaces separate database, API server, and WebSocket infrastructure with a unified platform. Schema definitions generate TypeScript types, queries subscribe to live data, and mutations execute as serverless functions.

Real-Time by Default

Data synchronizes automatically across all connected clients:

Live Query Subscriptions
// Query updates automatically when data changes
const tickets = useQuery(api.tickets.getUserTickets);

// No polling, WebSocket setup, or manual refreshes

When data changes anywhere, all clients receive updates instantly. The platform handles connection management, reconnection logic, and state synchronization.

Type-Safe Schema

Schema definitions generate TypeScript types throughout the stack:

Schema-Driven Types
// convex/schema.ts
export default defineSchema({
  users: defineTable({
    name: v.string(),
    email: v.string(),
    role: v.union(v.literal("admin"), v.literal("user")),
  }),
});

// Types flow everywhere automatically
const user = await ctx.db.get(userId);
// TypeScript knows: user.role is "admin" | "user"

AI assistants parse these schemas to understand data structures. Generated code matches the schema precisely. Type mismatches fail at compile time.

Serverless Functions

Backend logic lives in typed functions that replace traditional API layers:

Convex Mutation
export const create = mutation({
  args: {
    subject: v.string(),
    description: v.string(),
  },
  handler: async (ctx, args) => {
    const user = await getCurrentUser(ctx);
    if (!user) throw new Error("Not authenticated");

    return await ctx.db.insert("tickets", {
      ...args,
      userId: user._id,
      status: "open",
      createdAt: Date.now(),
    });
  },
});

Functions execute in isolated environments with automatic scaling. The platform manages infrastructure, deployment, and monitoring.

ACID Transactions

Every mutation runs in a transaction automatically:

Transactional Mutations
export const transferCredits = mutation({
  handler: async (ctx, { from, to, amount }) => {
    const sender = await ctx.db.get(from);
    const receiver = await ctx.db.get(to);

    if (sender.credits < amount) {
      throw new Error("Insufficient credits");
    }

    // Both updates succeed or both fail
    await ctx.db.patch(from, { credits: sender.credits - amount });
    await ctx.db.patch(to, { credits: receiver.credits + amount });
  },
});

No explicit transaction management. No deadlocks. Consistency guarantees built into every operation.

Offline Support

Applications work without network connectivity:

  1. Mutations queue locally when offline
  2. UI updates optimistically
  3. Changes sync when connection returns
  4. Conflicts resolve automatically

The platform handles offline complexity transparently. Applications remain responsive regardless of network conditions.

AI-Assisted Development

Convex patterns enable accurate AI code generation through consistent function structures and explicit type definitions. Schema files provide complete context for data relationships. Mutation patterns repeat predictably across features.

AI assistants generate Convex code that works immediately because type safety prevents invalid implementations. The schema acts as a specification that AI follows precisely. Generated functions match existing patterns automatically.

Query Performance

The platform optimizes queries automatically through:

  • Index generation from usage patterns
  • Query result caching
  • Incremental computation
  • Subscription efficiency

Developers write straightforward queries. The system handles optimization based on runtime behavior.

Additional Resources