InstantDB Usage Rules
Database Schema Rules
MUST
- All schema changes MUST be made in
instant.schema.ts - All entities MUST include
teamIdfor multi-tenancy - All user-generated content MUST include
creatorIdwhen possible - Timestamps (
createdAt,updatedAt,deletedAt) MUST be optional but indexed when present - Unique fields MUST be marked as both
.unique()and.indexed() - Frequently queried fields MUST be indexed
MUST NOT
- Never modify schema directly in production without migration strategy
- Never create entities without considering team-based access control
- Never use hard deletes - always use soft deletes with
deletedAt
Query Rules
MUST
- Always handle
isLoadingstate in components usinguseQuery - Always handle
errorstate in components usinguseQuery - Use deferred queries (
query = user ? {...} : null) when dependencies aren’t ready - Include team filtering in all queries to maintain multi-tenancy
MUST NOT
- Never ignore loading or error states in UI components
- Never query without considering team-based permissions
- Never use client-side filtering for large datasets - use server-side
whereclauses
Transaction Rules
MUST
- Use
transactinsideuseEffector event handlers only - Always use
id()for generating new entity IDs - Include
teamIdin all entity creation transactions - Use batch transactions for related operations
MUST NOT
- Never call
transactduring component render - Never create entities without proper team association
- Never use string literals for entity IDs
Authentication Rules
MUST
- Always check
userexistence before rendering authenticated content - Handle authentication loading states with proper UI feedback
- Use
db.useAuth()hook for authentication state management
MUST NOT
- Never store sensitive data in client-side state
- Never bypass authentication checks for protected operations