Overview
The database schema is built on PostgreSQL via Supabase, with TypeScript types auto-generated from the schema. The design follows relational database best practices with foreign key constraints and enum types for data integrity.Type Generation
Database types are automatically generated using the Supabase CLI:database.types.ts with TypeScript interfaces for all tables, views, functions, and enums.
Core Tables
historicalFigures
Stores information about historical figures available for conversation.Primary key, auto-generated UUID
Full name of the historical figure (e.g., “Albert Einstein”)
Brief description of the figure’s role or contribution
Extended biography with historical context and achievements
Classification: ‘scientists’, ‘artists’, ‘philosophers’, ‘leaders’, or ‘others’
Birth date in ISO format
Death date in ISO format
Comma-separated list of major works or achievements
URL to profile image or portrait
ElevenLabs voice ID for voice synthesis
Record creation timestamp
quizzes and quizQuestions
quizzes
Tracks quiz sessions for each user-figure interaction.Primary key, auto-generated UUID
Foreign key to Supabase auth.users
Foreign key to historicalFigures.id
Quiz generation method: ‘ai’ (AI-generated) or ‘manual’ (pre-defined)
Quiz creation timestamp
Last update timestamp
- Foreign key:
historicalFigureId→historicalFigures.id - Referenced by:
quizQuestions,feedbacks
quizQuestions
Stores individual questions for each quiz.Primary key, auto-generated UUID
Foreign key to quizzes.id (nullable for pre-generated questions)
Foreign key to historicalFigures.id
The question text to be asked during the quiz
Question creation timestamp
Last update timestamp
- Foreign key:
quizId→quizzes.id - Foreign key:
historicalFigureId→historicalFigures.id
feedbacks
Stores AI-generated feedback for completed conversations.Primary key, auto-generated UUID
Foreign key to Supabase auth.users
Foreign key to quizzes.id
Overall performance score (0-100)
Array of category-specific scores and comments. Structure:
Array of strings highlighting user’s strong points
Array of strings identifying areas needing improvement
Overall summary and recommendations
Feedback generation timestamp
- Foreign key:
quizId→quizzes.id
Enums
categories
Classification for historical figures:historicalFigures.category to categorize figures and customize conversation prompts.
quizType
Quiz generation method:- ai: Questions generated dynamically by AI
- manual: Pre-defined questions from database
difficulty_type
Difficulty levels (defined but not currently used):mood_type
Mood classification (defined but not currently used):Composite Types
feedback_category_score
Structure for individual category scores in feedback:feedbacks.categoryScores as a JSON array
TypeScript Usage
Type Helpers
The schema exports several utility types:Supabase Client Typing
Database Relationships Diagram
Query Examples
Get Historical Figure with Quiz Count
Get Quiz with Questions and Feedback
Insert Feedback with Relationships
Row Level Security
Supabase RLS policies should be configured to:- historicalFigures: Public read access
- quizzes: Users can only access their own quizzes
- quizQuestions: Read access based on associated quiz permissions
- feedbacks: Users can only access their own feedback
Related Documentation
- Architecture Overview - System architecture and tech stack
- AI Integration - How AI services interact with the database