Schema Overview
The database schema is defined inconvex/schema.ts and consists of 13 main tables:
- projects - User projects and configurations
- messages - Chat messages within projects
- fragments - Generated code fragments and previews
- fragmentDrafts - Draft code state for projects
- attachments - Images and files attached to messages
- oauthConnections - OAuth tokens for external services
- imports - Figma/GitHub import tracking
- usage - Credit usage and rate limiting
- rateLimits - API rate limit tracking
- subscriptions - Polar subscription data
- polarCustomers - Polar customer mappings
- webhookEvents - Webhook event processing log
- pendingSubscriptions - Subscription resolution queue
- agentRuns - AI agent execution tracking
Enum Types
Framework
Supported frontend frameworks:Message Role
Message author role:Message Type
Type of message content:Message Status
Message streaming/completion status:Attachment Type
Types of attachments:Import Source
External import sources:OAuth Provider
Supported OAuth providers:Import Status
Import processing status:Agent Run Status
AI agent execution status:Agent Run Source
Execution environment:Webhook Event Status
Webhook processing status:Subscription Status
Polar subscription status:Subscription Interval
Billing interval:Tables
projects
User projects with framework configuration.by_userId- Query projects by userby_userId_createdAt- Query projects by user sorted by creation date
messages
Chat messages within a project.by_projectId- Query messages for a projectby_projectId_createdAt- Query messages sorted by creation date
fragments
Generated code fragments with sandbox URLs.by_messageId- Get fragment for a message
fragmentDrafts
Draft code state for ongoing work.by_projectId- Get draft for a project
attachments
Files and images attached to messages.by_messageId- Query attachments for a message
oauthConnections
OAuth tokens for Figma and GitHub.by_userId- Query connections for a userby_userId_provider- Get specific provider connection
imports
Figma and GitHub import tracking.by_userId- Query imports by userby_projectId- Query imports for a projectby_status- Query imports by status
usage
Credit usage tracking (24-hour rolling window).by_userId- Get usage for a userby_expire- Cleanup expired records
- Free: 5 generations/day
- Pro: 100 generations/day
- Unlimited: No limit
rateLimits
API rate limiting storage.by_key- Lookup rate limit by keyby_windowStart- Cleanup old records
subscriptions
Polar subscription data.by_userId- Get user’s subscriptionsby_polarSubscriptionId- Lookup by Polar IDby_customerId- Lookup by customerby_status- Query by status
polarCustomers
Mapping between Clerk users and Polar customers.by_userId- Lookup by Clerk userby_polarCustomerId- Lookup by Polar customer
webhookEvents
Webhook event processing log.by_eventId- Lookup by event IDby_status- Query by statusby_eventType- Query by event typeby_createdAt- Query by timestamp
pendingSubscriptions
Subscription resolution queue for webhooks that arrive before user creation.by_polarSubscriptionId- Lookup by subscriptionby_customerId- Lookup by customerby_status- Query by status
agentRuns
AI agent execution tracking for WebContainer and Inngest runs.by_projectId- Query runs for a projectby_projectId_status- Query runs by project and statusby_status- Query all runs by statusby_projectId_createdAt- Query runs sorted by creation date
Relationships
Best Practices
Authentication
All queries and mutations should verify user ownership:Indexes
Always use indexes for queries - never use.filter() without an index:
Timestamps
Always setcreatedAt and updatedAt: