Overview
The Interview Simulator uses SQLAlchemy ORM with SQLite for development (PostgreSQL recommended for production). The schema consists of four main tables that track users, interview sessions, conversation messages, and feedback results.Entity Relationship Diagram
Tables
User
Stores optional user information for future authentication features.User Table Schema
User Table Schema
User Model Definition
User Model Definition
| Field | Type | Description |
|---|---|---|
id | INTEGER | Primary key, auto-incremented |
email | VARCHAR(120) | User email address (unique, nullable) |
created_at | DATETIME | Account creation timestamp |
- One-to-many with
Session(a user can have multiple interview sessions) - Cascade delete: Deleting a user removes all their sessions
Session
Represents a single interview session with associated job details and documents.Session Table Schema
Session Table Schema
Session Model Definition
Session Model Definition
| Field | Type | Description |
|---|---|---|
id | INTEGER | Primary key, auto-incremented |
user_id | INTEGER | Foreign key to users.id (nullable) |
job_title | VARCHAR(200) | Target job position (e.g., “Senior Backend Engineer”) |
company_name | VARCHAR(200) | Target company (e.g., “Google”) |
cv_text | TEXT | Extracted text from uploaded CV/resume |
job_description_text | TEXT | Full job posting text |
created_at | DATETIME | Session creation timestamp |
- Many-to-one with
User(optional association) - One-to-many with
Message(conversation history) - One-to-one with
Feedback(interview results) - Cascade delete: Deleting a session removes all messages and feedback
job_titlemust be non-empty and ≤ 200 characterscompany_namemust be non-empty- Session is “ready for interview” when both
cv_textandjob_description_textare populated
Message
Stores conversation messages between the user and AI interviewer.Message Table Schema
Message Table Schema
Message Model Definition
Message Model Definition
| Field | Type | Description |
|---|---|---|
id | INTEGER | Primary key, auto-incremented |
session_id | INTEGER | Foreign key to sessions.id |
role | VARCHAR(20) | Message sender: 'assistant' (AI), 'user' (candidate), or 'system' |
content | TEXT | Full message text |
timestamp | DATETIME | Message creation time |
- Many-to-one with
Session
assistant: Questions from the AI intervieweruser: Answers from the candidatesystem: Internal system messages (rarely used)
- Interview completes after 8
assistantmessages (MAX_QUESTIONS = 8) - Messages are ordered by
timestampfor conversation flow - Message count determines interview progress
Feedback
Stores AI-generated feedback and scores for completed interviews.Feedback Table Schema
Feedback Table Schema
Feedback Model Definition
Feedback Model Definition
| Field | Type | Description |
|---|---|---|
id | INTEGER | Primary key, auto-incremented |
session_id | INTEGER | Foreign key to sessions.id (unique - one feedback per session) |
interview_score | INTEGER | Overall performance score (1-10 scale) |
strengths | TEXT | What the candidate did well (markdown formatted) |
weaknesses | TEXT | Areas for improvement (markdown formatted) |
cv_improvements | TEXT | Specific CV optimization suggestions for the role |
created_at | DATETIME | Feedback generation timestamp |
- One-to-one with
Session(enforced byuselist=False)
- 1-3: Needs significant improvement
- 4-6: Moderate performance, room for growth
- 7-8: Strong performance
- 9-10: Exceptional performance
- Interview must be complete (8 questions answered)
- AI analyzes all conversation messages
- Compares responses against CV and job description
- Generates structured feedback
- Stored as single feedback record per session
Indexes and Performance
Recommended indexes for production:- Use
db.joinedload()for eager loading relationships (see repositories) - Filter by role when counting messages:
count_messages(session_id, role='assistant') - Order sessions by
created_at DESCfor recent sessions query
Data Lifecycle
- Session Creation: User submits job title and company name →
Sessionrecord created - Document Upload: CV and job description uploaded →
cv_textandjob_description_textpopulated - Interview Start: First AI question generated → First
Messagewithrole='assistant'created - Conversation: User answers → Alternating
Messagerecords withrole='user'androle='assistant' - Completion: 8 questions answered →
Feedbackrecord generated - Viewing: User views results → Session loaded with messages and feedback
Database Migrations
The application uses SQLAlchemy’sdb.create_all() for development. For production:
- Alembic: SQLAlchemy’s migration tool
- Flask-Migrate: Flask wrapper around Alembic
Backup and Retention
Development:- SQLite file stored at
instance/app.db - Simple file backup with
cp instance/app.db backups/app.db.$(date +%Y%m%d)
- Use PostgreSQL with automated backups
- Implement soft deletes for sessions (add
deleted_atcolumn) - Archive old sessions after 90 days
- Anonymize CV text for privacy compliance
Related Resources
- Architecture Overview - Understanding the layered architecture
- Project Structure - Navigate repository and models
- API Reference - Endpoints that interact with these tables