Files
books/.cursorrules
T
rmcamposandClaude Sonnet 4.6 20a5b165f0 feat: implement spec 001 — project scaffold
TanStack Start + Convex + Clerk + Tailwind + shadcn/ui wired up and
working. Auth flow (sign-in/sign-out/redirect) confirmed. Convex
getCurrentUser query validates the Clerk JWT integration end-to-end.

Key implementation notes:
- All Clerk imports use @clerk/react (v6), not @clerk/clerk-react (v5),
  to match @clerk/tanstack-react-start's internal dependency
- ConvexProviderWithClerk is SSR-guarded via import.meta.env.SSR to
  avoid useAuth being called server-side
- Convex + auth hooks isolated in a client-only Dashboard sub-component

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-23 17:40:55 -03:00

101 lines
3.3 KiB
Plaintext

This document serves as some special instructions when working with Convex.
# Schemas
When designing the schema please see this page on built in System fields and data types available: https://docs.convex.dev/database/types
Here are some specifics that are often mishandled:
## v (https://docs.convex.dev/api/modules/values#v)
The validator builder.
This builder allows you to build validators for Convex values.
Validators can be used in schema definitions and as input validators for Convex functions.
Type declaration
Name Type
id <TableName>(tableName: TableName) => VId<GenericId<TableName>, "required">
null () => VNull<null, "required">
number () => VFloat64<number, "required">
float64 () => VFloat64<number, "required">
bigint () => VInt64<bigint, "required">
int64 () => VInt64<bigint, "required">
boolean () => VBoolean<boolean, "required">
string () => VString<string, "required">
bytes () => VBytes<ArrayBuffer, "required">
literal <T>(literal: T) => VLiteral<T, "required">
array <T>(element: T) => VArray<T["type"][], T, "required">
object <T>(fields: T) => VObject<Expand<{ [Property in string | number | symbol]?: Exclude<Infer<T[Property]>, undefined> } & { [Property in string | number | symbol]: Infer<T[Property]> }>, T, "required", { [Property in string | number | symbol]: Property | `${Property & string}.${T[Property]["fieldPaths"]}` }[keyof T] & string>
record <Key, Value>(keys: Key, values: Value) => VRecord<Record<Infer<Key>, Value["type"]>, Key, Value, "required", string>
union <T>(...members: T) => VUnion<T[number]["type"], T, "required", T[number]["fieldPaths"]>
any () => VAny<any, "required", string>
optional <T>(value: T) => VOptional<T>
## System fields (https://docs.convex.dev/database/types#system-fields)
Every document in Convex has two automatically-generated system fields:
_id: The document ID of the document.
_creationTime: The time this document was created, in milliseconds since the Unix epoch.
You do not need to add indices as these are added automatically.
## Example Schema
This is an example of a well crafted schema.
```ts
import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";
export default defineSchema(
{
users: defineTable({
name: v.string(),
}),
sessions: defineTable({
userId: v.id("users"),
sessionId: v.string(),
}).index("sessionId", ["sessionId"]),
threads: defineTable({
uuid: v.string(),
summary: v.optional(v.string()),
summarizer: v.optional(v.id("_scheduled_functions")),
}).index("uuid", ["uuid"]),
messages: defineTable({
message: v.string(),
threadId: v.id("threads"),
author: v.union(
v.object({
role: v.literal("system"),
}),
v.object({
role: v.literal("assistant"),
context: v.array(v.id("messages")),
model: v.optional(v.string()),
}),
v.object({
role: v.literal("user"),
userId: v.id("users"),
}),
),
})
.index("threadId", ["threadId"]),
},
);
```
Sourced from: https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/convex-cursorrules-prompt-file/.cursorrules
# shadcn instructions
Use the latest version of Shadcn to install new components, like this command to add a button component:
```bash
pnpm dlx shadcn@latest add button
```