Overview
The application uses SQLAlchemy as the ORM (Object-Relational Mapping) layer with SQLite as the database backend. The database schema is designed to support adaptive interview sessions, user mastery tracking, and comprehensive performance analytics.Database Technology Stack
- ORM: Flask-SQLAlchemy (SQLAlchemy wrapper for Flask)
- Database: SQLite (file-based relational database)
- Location: Configured via
SQLALCHEMY_DATABASE_URIenvironment variable - Migrations: Manual schema updates via SQLAlchemy model definitions
Core Models
User Model
TheUser model represents registered users in the system. It integrates with Flask-Login for authentication.
| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique user identifier |
username | String(80) | Unique, Not Null | Unique username for login |
email | String(120) | Unique, Not Null | User’s email address |
password_hash | String(120) | Not Null | Hashed password (bcrypt/werkzeug) |
full_name | String(100) | Nullable | User’s full name |
phone | String(20) | Nullable | Contact phone number |
experience_years | Integer | Default: 0 | Years of professional experience |
skills | Text | Nullable | JSON-encoded list of skills |
resume_filename | String(255) | Nullable | Uploaded resume filename |
reset_token | String(100) | Unique, Nullable | Password reset token |
reset_token_expiry | DateTime | Nullable | Token expiration timestamp |
created_at | DateTime | Default: utcnow | Account creation timestamp |
interviews→ One-to-Many withInterviewSessionmasteries→ One-to-Many withUserMastery(via backref)adaptive_sessions→ One-to-Many withAdaptiveInterviewSession(via backref)question_history→ One-to-Many withQuestionHistory(via backref)subtopic_masteries→ One-to-Many withSubtopicMastery(via backref)study_plans→ One-to-Many withStudyActionPlan(via backref)
InterviewSession Model
Tracks traditional interview sessions (legacy model for basic interviews).| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique session identifier |
user_id | Integer | Foreign Key (user.id), Not Null | Reference to User |
session_type | String(50) | Not Null | Type of interview (e.g., “technical”, “behavioral”) |
questions | Text | Nullable | JSON-encoded list of questions |
score | Float | Nullable | Overall interview score (0-1) |
feedback | Text | Nullable | Interview feedback text |
duration | Integer | Nullable | Session duration in seconds |
created_at | DateTime | Default: utcnow | Session start timestamp |
completed_at | DateTime | Nullable | Session completion timestamp |
speech_metrics | Text | Nullable | JSON with research-grade speech metrics |
user→ Many-to-One withUser
UserMastery Model
Critical Model: Tracks user’s mastery across topics with complete concept-level data.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique mastery record ID |
user_id | Integer | Foreign Key (user.id), Not Null | Reference to User |
topic | String(50) | Not Null | Topic name (e.g., “DBMS”, “OS”) |
sessions_attempted | Integer | Default: 0 | Number of sessions for this topic |
last_session_date | DateTime | Nullable | Last session timestamp |
| Field | Type | Default | Description |
|---|---|---|---|
mastery_level | Float | 0.0 | Overall mastery: semantic_avg * 0.7 + keyword_avg * 0.3 |
semantic_avg | Float | 0.0 | Exponential moving average of semantic scores |
keyword_avg | Float | 0.0 | Exponential moving average of keyword scores |
| Field | Type | Default | Description |
|---|---|---|---|
questions_attempted | Integer | 0 | Total questions answered for this topic |
correct_count | Integer | 0 | Questions with keyword score > 0.6 |
avg_response_time | Float | 0.0 | Exponential moving average of response times |
| Field | Type | Default | Description |
|---|---|---|---|
mastery_velocity | Float | 0.0 | Rate of mastery change: mastery_level - last_mastery |
last_mastery | Float | 0.0 | Previous mastery level before last update |
| Field | Type | Default | Description |
|---|---|---|---|
current_difficulty | String(20) | “medium” | Current difficulty level: “easy”, “medium”, or “hard” |
consecutive_good | Integer | 0 | Consecutive high-scoring answers (>0.7) |
consecutive_poor | Integer | 0 | Consecutive low-scoring answers (<0.4) |
| Field | Type | Default | Description |
|---|---|---|---|
concept_masteries | Text | '' | PRIMARY: Complete concept-level mastery data (see User Mastery Tracking) |
missing_concepts | Text | ’[]‘ | LEGACY: List of weak concepts (derived from concept_masteries) |
weak_concepts | Text | ’[]‘ | LEGACY: List of weak concepts |
strong_concepts | Text | ’[]‘ | LEGACY: List of strong concepts |
concept_stagnation | Text | '' | LEGACY: Concept stagnation counts |
| Field | Type | Default | Description |
|---|---|---|---|
first_attempt | DateTime | utcnow | First attempt timestamp |
last_attempt | DateTime | utcnow | Most recent attempt timestamp |
last_seen | Float | 0.0 | Unix timestamp of last activity |
- Unique constraint on
(user_id, topic)→ One mastery record per user per topic
user→ Many-to-One withUser
AdaptiveInterviewSession Model
Tracks enhanced adaptive interview sessions with comprehensive metrics.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique session identifier |
user_id | Integer | Foreign Key (user.id), Not Null | Reference to User |
session_id | String(100) | Unique, Not Null, Indexed | UUID for session tracking |
start_time | DateTime | Default: utcnow | Session start timestamp |
end_time | DateTime | Nullable | Session end timestamp |
duration | Integer | Default: 0 | Total duration in seconds |
questions_asked | Integer | Default: 0 | Number of questions asked |
avg_semantic | Float | Default: 0.0 | Average semantic similarity score |
avg_keyword | Float | Default: 0.0 | Average keyword coverage score |
overall_score | Float | Default: 0.0 | avg_semantic * 0.7 + avg_keyword * 0.3 |
learning_velocity | Float | Default: 0.0 | Rate of learning improvement |
attention_score | Float | Default: 1.0 | Attention/engagement score |
topics_covered | Text | ’[]‘ | JSON list of topics covered |
weakest_topics | Text | ’[]‘ | JSON list of weakest 3 topics |
strongest_topics | Text | ’[]‘ | JSON list of strongest 3 topics |
user→ Many-to-One withUser
QuestionHistory Model
Tracks every individual question asked across all sessions.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique question record ID |
user_id | Integer | Foreign Key (user.id), Not Null, Indexed | Reference to User |
session_id | String(100) | Not Null, Indexed | Session UUID |
topic | String(50) | Not Null | Topic name |
subtopic | String(100) | Nullable | Subtopic name |
question | Text | Not Null | Question text |
answer | Text | Nullable | User’s answer |
expected_answer | Text | Nullable | AI-generated expected answer |
sampled_concepts | Text | ’[]‘ | JSON list of concepts sampled in question |
semantic_score | Float | Default: 0.0 | Semantic similarity score (0-1) |
keyword_score | Float | Default: 0.0 | Keyword coverage score (0-1) |
depth | String(20) | Default: “medium” | Answer depth analysis |
confidence | String(20) | Default: “medium” | Answer confidence level |
key_terms | Text | ’[]‘ | JSON list of key terms mentioned |
difficulty | String(20) | Default: “medium” | Question difficulty |
response_time | Float | Default: 0.0 | Response time in seconds |
timestamp | DateTime | Default: utcnow, Indexed | Question timestamp |
missing_concepts | Text | ’[]‘ | JSON list of concepts missing from answer |
user→ Many-to-One withUser
SubtopicMastery Model
Tracks mastery at the subtopic level within each topic.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique record ID |
user_id | Integer | Foreign Key (user.id), Not Null, Indexed | Reference to User |
topic | String(50) | Not Null | Parent topic name |
subtopic | String(200) | Not Null | Subtopic name |
mastery_level | Float | Default: 0.0 | Subtopic mastery score (0-1) |
attempts | Integer | Default: 0 | Number of attempts |
last_asked | DateTime | Default: utcnow | Last question timestamp |
subtopic_status | String(20) | Default: ‘not_started’ | Status: ‘not_started’, ‘ongoing’, ‘mastered’ |
concept_data | Text | '' | JSON with concept-level data for quick access |
- Unique constraint on
(user_id, topic, subtopic)
user→ Many-to-One withUser
StudyActionPlan Model
Stores AI-generated personalized study plans for users.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique plan ID |
user_id | Integer | Foreign Key (user.id), Not Null, Indexed | Reference to User |
days | Integer | Not Null | Plan duration in days |
topics | String(255) | Not Null | Comma-separated list of topics |
plan_markdown | Text | Not Null | Full plan in Markdown format |
created_at | DateTime | Default: utcnow, Indexed | Creation timestamp |
user→ Many-to-One withUser
DebuggingSession Model
Tracks full debugging interview sessions.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique session ID |
user_id | Integer | Foreign Key (user.id), Not Null | Reference to User |
start_time | DateTime | Default: utcnow | Session start |
end_time | DateTime | Nullable | Session end |
count | Integer | Default: 0 | Number of challenges |
avg_score | Float | Default: 0.0 | Average score across challenges |
summary | Text | Nullable | Session summary |
challenges→ One-to-Many withDebuggingChallenge(cascade delete)
DebuggingChallenge Model
Tracks individual debugging challenges within a session.| Field | Type | Constraints | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique challenge ID |
session_id | Integer | Foreign Key (debugging_session.id), Not Null | Reference to DebuggingSession |
language | String(20) | Default: ‘python’ | Programming language |
topic | String(100) | Nullable | Topic/concept being tested |
buggy_code | Text | Not Null | Code with bug |
expected_answer | Text | Not Null | Expected explanation |
correct_code | Text | Nullable | Corrected code |
user_explanation | Text | Nullable | User’s bug explanation |
ai_score | Float | Default: 0.0 | AI-evaluated score |
ai_feedback | Text | Nullable | AI feedback |
created_at | DateTime | Default: utcnow | Creation timestamp |
session→ Many-to-One withDebuggingSession
Database Indexes
The following indexes are automatically created for optimal query performance:user.username(unique index)user.email(unique index)user.reset_token(unique index)adaptive_interview_session.session_id(unique index)adaptive_interview_session.user_idquestion_history.user_idquestion_history.session_idquestion_history.timestampsubtopic_mastery.user_idstudy_action_plan.user_idstudy_action_plan.created_at
Common Database Operations
Initialize Database
Query with Relationships
Bulk Insert
Database Configuration
Typical SQLAlchemy configuration inapp.py:
Migration Best Practices
- Always backup the database before schema changes
- Test migrations on a development database first
- Use transactions for data migrations
- Add new fields as nullable first, then populate, then add constraints
Related Documentation
- User Mastery Tracking - Deep dive into the UserMastery model and concept tracking
- Adaptive Learning - How the database supports adaptive learning