AiVault uses Convex as its database with three main tables:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/seyarhasir/AiVault/llms.txt
Use this file to discover all available pages before exploring further.
tools, bookmarks, and reviews.
Schema Overview
The schema is defined inconvex/schema.ts using Convex’s type-safe schema builder.
convex/schema.ts
Tools Table
Stores all AI tools submitted to the directory.Fields
convex/schema.ts
Indices
Convex uses indices for efficient querying:convex/schema.ts
Indices are required for efficient filtering in Convex. Every query should use an index as the starting point.
Key Patterns
| Field | Type | Purpose |
|---|---|---|
slug | string | Unique URL-friendly identifier |
approved | boolean | Admin approval status (moderation) |
submittedBy | string | Clerk user ID of submitter |
upvotes | number | Popularity metric |
createdAt | number | Unix timestamp (milliseconds) |
pricing | string | ”Free”, “Freemium”, or “Paid” |
platforms | string[] | ”Web”, “iOS”, “Android”, “Desktop”, “API”, “Chrome Extension” |
Bookmarks Table
Tracks user-saved tools.convex/schema.ts
Relationships
- userId → Clerk user identifier
- toolId → Foreign key reference to
toolstable
Query Patterns
Reviews Table
User-submitted ratings and comments.convex/schema.ts
Fields
| Field | Type | Description |
|---|---|---|
userId | string | Clerk user ID |
toolId | Id<"tools"> | Reference to tool |
rating | number | 1-5 star rating |
comment | string | Review text |
createdAt | number | Timestamp |
Query Examples
Relationships Diagram
Convex doesn’t enforce foreign key constraints at the database level. Referential integrity is maintained through application logic.
Type Safety
Convex automatically generates TypeScript types from the schema:Schema Migrations
Convex handles schema changes automatically:- Update
schema.ts - Push changes:
npx convex dev - Convex validates and migrates data
Best Practices
Always use indices
Always use indices
Start every query with
.withIndex(). Table scans are slow and may hit Convex limits.Use optional fields for nullable data
Use optional fields for nullable data
Mark fields that may not always be present as optional with
v.optional().Store timestamps as numbers
Store timestamps as numbers
Use
Date.now() for timestamps (Unix milliseconds) for efficient sorting and filtering.Create composite indices for multi-field queries
Create composite indices for multi-field queries
If you frequently query by multiple fields, create a composite index.
Next Steps
Convex Backend
Learn how to query and mutate data
Authentication
Understand user identity and permissions