Overview
Polaris uses Convex as its real-time database backend. Convex provides instant updates, type-safe queries, and seamless integration with React and authentication.Prerequisites
- A Convex account (sign up here)
- Node.js 20.09 or later
- Clerk authentication configured (see Authentication Setup)
Initial Setup
Create a Convex Project
- Go to the Convex Dashboard
- Click New Project
- Name your project (e.g., “polaris”)
- Click Create Project
Initialize Convex in Your Project
Terminal
- Link your local project to the Convex deployment
- Generate a
NEXT_PUBLIC_CONVEX_URLandCONVEX_DEPLOYMENTfor you - Start watching for schema and function changes
Database Schema
Polaris uses four main tables to manage projects, files, conversations, and messages.Projects Table
Stores user projects with import/export status tracking:convex/schema.ts
by_owner: Query projects by user ID
Files Table
Stores project files and folders in a tree structure:convex/schema.ts
by_project: Get all files in a projectby_parent: Get children of a folderby_project_parent: Efficiently query files by project and parent (used for creating/checking duplicates)
- Text files: Stored in the
contentfield - Binary files: Stored in Convex File Storage with reference in
storageId
Conversations Table
Stores AI conversation threads per project:convex/schema.ts
by_project: Get all conversations for a project
Messages Table
Stores individual messages within conversations:convex/schema.ts
by_conversation: Get all messages in a conversationby_project_status: Find processing messages for cancellation
Common Database Operations
Creating a Project
Querying Projects
Real-time Updates
Convex automatically updates React components when data changes:Internal API System
Polaris uses an internal API layer (convex/system.ts) to allow Inngest background jobs to interact with Convex. These functions validate a shared secret key before executing:
convex/system.ts
- AI agents to modify files through Inngest
- Background processing of messages
- GitHub import/export operations
Environment Variables Reference
Your Convex deployment URL (generated during
npx convex dev)Your Convex deployment identifier (generated during
npx convex dev)Random secret string for securing internal API calls. Must be set both in
.env.local and in Convex environment.Development Workflow
Running Convex Locally
Always keep the Convex dev server running during development:Terminal
- Watches for changes to
convex/files - Syncs schema and function changes to your deployment
- Provides type generation for the frontend
- Shows real-time logs
Making Schema Changes
- Edit
convex/schema.ts - Save the file
- Convex automatically validates and applies the changes
- Your TypeScript types update automatically
Viewing Data
Use the Convex Dashboard to browse and query your data:- Go to dashboard.convex.dev
- Select your project
- Click Data to view tables
- Use the query console to test queries
Troubleshooting
”POLARIS_CONVEX_INTERNAL_KEY is not configured”
This error means the internal key isn’t set in Convex:Terminal
“Unauthorized” Errors
Check that:- Clerk authentication is properly configured
CLERK_JWT_ISSUER_DOMAINis set in Convex- The user is signed in
Schema Validation Errors
If schema changes fail:- Check the error message in the Convex dev terminal
- Ensure all required fields are present
- Verify index names don’t conflict
Production Deployment
When deploying to production:Update Environment Variables
Update your production environment with the new
NEXT_PUBLIC_CONVEX_URL and CONVEX_DEPLOYMENT values.Next Steps
- Authentication Setup - Configure Clerk authentication
- Environment Variables - Complete .env reference