---
title: "Design your schema"
description: "Define Convex tables, validators, and indexes that support the queries and mutations used from Nuxt or Vue."
canonical_url: "https://nuxt-convex.onmax.me/convex-patterns/schema"
---
# Design your schema

> Define Convex tables, validators, and indexes that support the queries and mutations used from Nuxt or Vue.

Your frontend API is only as predictable as the schema behind it. Use this page to shape the tables and indexes that the shared runtime will query.

<note>

These examples scope data to the signed-in user, so they need [auth](https://nuxt-convex.onmax.me/integrations/better-auth). Without it, `list` returns `[]` and `add` throws `UNAUTHENTICATED`. To prototype first, drop `userId` and the identity checks, and add them back with auth.

</note>

## Start with the fields you actually read

```ts [convex/schema.ts]
import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'

export default defineSchema({
  tasks: defineTable({
    title: v.string(),
    userId: v.string(),
    isCompleted: v.boolean(),
    createdAt: v.number(),
  }).index('by_user', ['userId']),
})
```

Keep `npx convex dev` running while you edit: it pushes schema changes and regenerates the types your app imports through `#convex/api` or `convex/_generated/api`.

## Add indexes for the queries you expect

The frontend helpers do not hide slow query design. If your UI filters or sorts by a field, design the index for that access pattern.

```ts
ctx.db
  .query('tasks')
  .withIndex('by_user', q => q.eq('userId', identity.subject))
  .order('desc')
  .take(20)
```

For compound filters, define a compound index in the same order as the equality filters you apply before the range or sort behavior.

## Add related tables deliberately

Use `v.id('tableName')` for document relationships and keep the shape consistent with the mutations and queries you plan to expose.

## Next steps

- Read [Design your functions](https://nuxt-convex.onmax.me/convex-patterns/functions) to expose the schema through queries, mutations, and actions
- Read [Realtime and SSR](https://nuxt-convex.onmax.me/convex-patterns/realtime-and-ssr) to understand how those reads behave in the frontend


## Sitemap

See the full [sitemap](https://nuxt-convex.onmax.me/sitemap.md) for all pages.
