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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
---
title: Interview Bot
emoji: 🤖
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
---


# Interview Bot - AI Mock Interview Trainer

An end-to-end AI-powered mock interview platform for students and job seekers.

Interview Bot combines resume intelligence, job-description alignment, adaptive questioning, speech interaction, and detailed post-interview evaluation in a single full-stack application.

The project includes:
- A FastAPI backend for auth, interview orchestration, speech services, analytics, and admin operations
- A Next.js frontend for student and admin workflows
- MongoDB Atlas for persistent records
- Redis for low-latency in-progress interview session state
- Gemini for resume parsing, follow-up generation, and final evaluation

---

## Table of Contents

1. [Problem Statement](#problem-statement)
2. [Project Overview](#project-overview)
3. [Key Features](#key-features)
4. [System Architecture](#system-architecture)
5. [Interview Engine Design](#interview-engine-design)
6. [Speech Pipeline](#speech-pipeline)
7. [Tech Stack](#tech-stack)
8. [Repository Structure](#repository-structure)
9. [Environment Configuration](#environment-configuration)
10. [Setup and Installation](#setup-and-installation)
11. [How to Run](#how-to-run)
12. [API Endpoints](#api-endpoints)
13. [Data Model](#data-model)
14. [Reliability and Resilience](#reliability-and-resilience)
15. [Troubleshooting](#troubleshooting)
16. [Deployment Notes](#deployment-notes)
17. [License](#license)

---

## Problem Statement

Most interview preparation tools are static and generic. They do not adapt to:
- A candidate's actual resume
- A specific target job description
- The quality and depth of previous answers

Interview Bot addresses this by generating dynamic, role-targeted interviews that adapt in real time and produce actionable feedback after completion.

---

## Project Overview

Interview Bot supports two interview modes:

1. Resume Interview
- Uses resume data + selected job description
- Creates personalized role-specific questions
- Applies adaptive follow-up logic per answer

2. Topic Interview
- Uses admin-published topics
- Supports optional timed interviews per topic
- Mixes topic bank questions with AI-generated follow-ups

The platform provides:
- Secure user authentication with JWT
- Resume upload and AI parsing
- AI-recommended role suggestions
- Resume-vs-job-description alignment checks
- Real-time interview state management via Redis queues
- Voice-enabled interviewing (TTS + STT)
- Detailed interview reports with per-question scoring
- Admin dashboards for analytics, content management, and user oversight

---

## Key Features

### Student Features

- Signup and login flow
- Resume upload (PDF/DOCX/TXT) and structured parsing
- Skill extraction and manual skill editing
- AI recommended role list from resume
- Personal job description management (create/update/delete)
- Pre-interview JD compatibility check
- Resume interview and topic interview modes
- Optional speech interaction:
	- Backend TTS question playback
	- Backend STT answer transcription
	- Editable transcript before final submit
- Report history and detailed report views

### Admin Features

- Role CRUD and requirement management
- Topic CRUD and publish/hide controls
- Optional per-topic timer configuration
- Resume/topic question CRUD
- Bulk question import from PDF using Gemini extraction
- Job description management across users
- User management (student deletion with related data cleanup)
- Analytics dashboard:
	- Total students
	- Live users
	- New users today
	- Average scores
	- Top performers
	- Common weak areas
- Quit interview monitoring and report auditing

---

## System Architecture

The platform is split into frontend and backend layers with AI and data services:

```mermaid
flowchart LR
	A[Next.js Frontend] --> B[FastAPI Backend]
	B --> C[MongoDB Atlas]
	B --> D[Redis]
	B --> E[Gemini API]
	B --> F[Speech Models: XTTS + Whisper]
```

### High-Level Runtime Flow

```mermaid
flowchart TD
	U[User Login] --> R[Upload Resume]
	R --> P[Resume Parsing via Gemini]
	P --> S[Skills + Recommended Roles Saved]
	S --> J[Select Job Description]
	J --> V[Optional Resume-JD Verification]
	V --> I[Start Interview]
	I --> Q[Redis Queue Orchestration]
	Q --> A1[Answer Submission]
	A1 --> F1[Adaptive Follow-up Generation]
	F1 --> Q
	Q --> C{Interview Complete?}
	C -- No --> A1
	C -- Yes --> E1[Final Evaluation via Gemini]
	E1 --> M[Report Stored in MongoDB]
	M --> UI[Report UI and Analytics]
```

---

## Interview Engine Design

Core orchestration lives in backend services and uses:
- Redis question queues and backlog lists
- LangGraph state flow for question generation
- Gemini for AI follow-up generation and final scoring
- Deterministic fallback questions when AI output is unavailable

### Resume Interview Flow

- Requires a resume and selected job description
- Starts with a personalized intro question
- Seeds an initial AI question batch in background
- Maintains max 10 questions by default
- Stores answers immediately and processes follow-up generation asynchronously

Queue-first strategy:
- `question_queue` keeps the next questions ready for low-latency response
- `question_backlog` stores overflow to avoid generation stalls
- Deduplication prevents repeated or near-duplicate questions

### Topic Interview Flow

- Requires a published topic
- Starts with DB topic question bank
- After initial stage, generates additional follow-ups
- Maintains max 10 questions
- Supports optional timer (configured per topic by admin)

### Follow-up Diversity Policy

Resume mode prevents repetitive drilling on the same skill/topic:
- Up to 2 consecutive same-topic follow-ups are allowed
- A third consecutive same-topic follow-up is allowed only when follow-up need score >= 95
- Otherwise, the system switches to an alternate focus skill

### Evaluation and Completion

- Per-answer evaluation can run in background while interview continues
- Final report is generated at completion (or partial report on quit if answers exist)
- Redis session data is cleaned after final report generation

---

## Speech Pipeline

Speech features are backend-powered for consistency across browsers:

### Text-to-Speech (TTS)

- Uses Coqui XTTS (`xtts_v2`) with warmup on startup
- Uses voice presets by gender (`female`, `male`, `auto`)
- Includes fallback synthesis models if XTTS fails transiently
- Audio caching improves repeat playback latency

### Speech-to-Text (STT)

- Uses `faster-whisper`
- Handles CUDA runtime issues and falls back to CPU automatically
- Returns transcription text + latency metrics

### UX Safeguards

- Spoken text normalization strips prefixes like `Question 3:` before playback
- Candidate can edit transcript before submission
- Frontend prefetches upcoming question audio where possible

---

## Tech Stack

### Backend

- FastAPI
- Uvicorn
- Motor (MongoDB async)
- redis-py asyncio client
- Pydantic + pydantic-settings
- python-jose + passlib + bcrypt
- Google Gemini (`google-genai`)
- LangGraph + LangChain Core
- Coqui TTS + faster-whisper
- pypdf + python-docx

### Frontend

- Next.js 16 (App Router)
- React 19 + TypeScript
- Tailwind CSS v4
- Axios
- React Query
- Framer Motion
- Sonner notifications
- Lucide icons

---

## Repository Structure

```text
interview-bot/
|- backend/
|  |- main.py
|  |- config.py
|  |- database.py
|  |- auth/
|  |- routers/
|  |- schemas/
|  |- services/
|  |- utils/
|  |- models/
|  |- uploads/
|  |- requirements.txt
|  |- Dockerfile
|- frontend/
|  |- src/
|  |  |- app/
|  |  |- components/
|  |  |- lib/
|  |  |- types/
|  |- public/
|  |- package.json
|- README.md
|- LICENSE
|- WORKFLOW.md
|- LANGGRAPH_AND_TOOLS.md
```

---

## Environment Configuration

Create and configure environment files before running.

### Backend: `backend/.env`

```env
# App
APP_ENV=development
APP_HOST=0.0.0.0
APP_PORT=8000

# Gemini
GEMINI_API_KEY=your_gemini_api_key
GEMINI_MODEL=gemini-2.5-flash
GEMINI_FALLBACK_MODELS=gemini-2.0-flash,gemini-2.0-flash-lite,gemini-flash-latest

# MongoDB (cloud only)
MONGO_URI=mongodb+srv://<user>:<password>@<cluster>/<db>?retryWrites=true&w=majority
MONGO_DB_NAME=interview_bot

# Redis (cloud URL)
REDIS_URL=rediss://:<password>@<host>:<port>

# JWT
JWT_SECRET=replace_with_strong_secret
JWT_ALGORITHM=HS256
JWT_EXPIRY=3600

# File storage
UPLOAD_DIR=./uploads

# Speech
COQUI_TOS_AGREED=1
XTTS_USE_GPU=auto
WHISPER_DEVICE=auto
```

Important validation rules in backend config:
- `MONGO_URI` must use `mongodb+srv://` and must not be localhost
- `REDIS_URL` must use `redis://` or `rediss://` and must not be localhost

### Frontend: `frontend/.env.local`

```env
NEXT_PUBLIC_API_URL=http://127.0.0.1:8000
```

---

## Setup and Installation

### Prerequisites

- Python 3.10+
- Node.js 18+
- npm
- MongoDB Atlas instance
- Cloud Redis instance
- Gemini API key

### 1) Clone Repository

```bash
git clone <your-repo-url>
cd interview-bot
```

### 2) Backend Setup

```bash
cd backend
python -m venv ../inter
..\inter\Scripts\activate
pip install -r requirements.txt
```

Linux/macOS equivalent:

```bash
python -m venv inter
source inter/bin/activate
pip install -r backend/requirements.txt
```

### 3) Frontend Setup

```bash
cd ../frontend
npm install
```

---

## How to Run

### Start Backend API

From `backend/` directory:

```bash
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
```

Backend endpoints:
- API root health: `http://localhost:8000/health`
- Swagger docs: `http://localhost:8000/docs`

### Start Frontend

From `frontend/` directory:

```bash
npm run dev
```

Frontend app: `http://localhost:3000`

### First Run Checklist

1. Register a user account
2. Upload resume in Settings
3. Add at least one Job Description
4. Start Resume Interview from Dashboard or Bot's Help
5. Complete interview and open Reports

---

## API Endpoints

All secured endpoints require `Authorization: Bearer <token>`.

### Health

| Method | Path | Description |
|---|---|---|
| GET | `/health` | Service health check |

### Authentication

| Method | Path | Description |
|---|---|---|
| POST | `/auth/signup` | Register user |
| POST | `/auth/login` | Login and receive JWT |

Note: By default, emails ending with `@admin.com` are created with admin role.

### Resume

| Method | Path | Description |
|---|---|---|
| POST | `/resume/upload` | Upload and parse resume |

### Profile

| Method | Path | Description |
|---|---|---|
| GET | `/profile` | Get profile, resume, skills |
| PUT | `/profile/speech-settings` | Update voice preference |
| PUT | `/profile/skills` | Update user skill list |
| PUT | `/profile/resume-data` | Update structured resume fields |
| GET | `/profile/job-descriptions` | List user's JDs |
| POST | `/profile/job-descriptions` | Create JD |
| PUT | `/profile/job-descriptions/{jd_id}` | Update JD |
| DELETE | `/profile/job-descriptions/{jd_id}` | Delete JD |

### Interview

| Method | Path | Description |
|---|---|---|
| POST | `/interview/start` | Start interview session |
| POST | `/interview/start_interview` | Compatibility alias for start |
| POST | `/interview/verify` | Resume-vs-JD verification |
| POST | `/interview/answer` | Submit answer and get next question |
| POST | `/interview/submit_answer` | Compatibility alias for answer |
| GET | `/interview/next_question` | Peek next queued question |
| POST | `/interview/quit` | Quit interview; optional partial report |
| GET | `/interview/report` | Generate/get report |
| GET | `/interview/latency` | Latency summary (p50/p95) |
| POST | `/interview/latency/reset` | Reset latency metrics |

### Reports

| Method | Path | Description |
|---|---|---|
| GET | `/reports/history` | Student report history |

### Speech

| Method | Path | Description |
|---|---|---|
| GET | `/speech/health` | Speech service health |
| POST | `/speech/warmup` | Warm TTS/STT models |
| POST | `/speech/synthesize` | Convert text to WAV |
| POST | `/speech/transcribe` | Transcribe uploaded audio |

### Admin (selected)

| Method | Path | Description |
|---|---|---|
| GET/POST/PUT/DELETE | `/admin/roles` (+ `/{id}`) | Role management |
| GET/POST/PUT/DELETE | `/admin/questions` (+ `/{id}`) | Question management |
| POST | `/admin/questions/upload` | Import questions from PDF |
| GET/POST/PUT/DELETE | `/admin/topics` (+ `/{id}`) | Topic management |
| PUT | `/admin/topics/{topic_id}/publish` | Publish/hide topic + timer |
| GET/POST/DELETE | `/admin/requirements` | Role requirement management |
| GET | `/admin/analytics` | Admin dashboard analytics |
| GET | `/admin/quit-interviews` | Quit interview details |
| GET | `/admin/reports` | Report summaries |
| GET | `/admin/reports/{session_id}` | Report detail |
| GET | `/admin/users` | Student list |
| DELETE | `/admin/users/{user_id}` | Delete student and linked data |
| GET/POST/PUT/DELETE | `/admin/job-descriptions` | Admin JD management |

---

## Data Model

Primary MongoDB collections:

- `users`
- `resumes`
- `skills`
- `job_roles`
- `job_descriptions`
- `jd_verifications`
- `role_requirements`
- `questions`
- `topics`
- `topic_questions`
- `sessions`
- `answers`
- `results`

Redis stores in-progress interview state with TTL, including:
- Session metadata
- Question queue/backlog
- Asked question fingerprints
- Q/A hashes
- Context cache

---

## Reliability and Resilience

This project includes multiple runtime safeguards:

- Gemini model fallback chain for transient provider failures
- Retry logic for 503/high-demand conditions
- Loose JSON extraction/parsing to recover from malformed model output
- Deterministic fallback question templates when AI output is empty/duplicate
- Question deduplication using normalized fingerprinting
- Queue/backlog buffering to avoid blocking next question delivery
- Placeholder report detection and regeneration logic
- Report generation fallback from MongoDB answers when Redis session data is unavailable
- TTS and STT warmup with graceful fallback paths
- STT automatic CPU fallback on CUDA runtime issues

---

## Troubleshooting

### 1) Login fails despite valid credentials

Symptom:
- Frontend shows auth error even though credentials are correct.

Likely cause:
- Frontend cannot reach backend API.

Fix:
1. Ensure backend is running on the configured host/port.
2. Verify `frontend/.env.local`:
	 - `NEXT_PUBLIC_API_URL=http://127.0.0.1:8000`
3. Restart frontend after changing env.

### 2) Resume interview start fails

Check:
- Resume is uploaded
- Job Description is selected
- Job Description includes `required_skills`

### 3) No recommended roles in Start Interview dropdown

Check:
- Resume parsing succeeded
- `recommended_roles` exists in profile resume parsed data

If missing, re-upload resume from Settings.

### 4) Speech is slow on first request

Use:
- `POST /speech/warmup` after login

The frontend also warms speech automatically, but manual warmup helps during diagnostics.

### 5) Mongo/Redis config validation errors at startup

Ensure:
- Mongo uses `mongodb+srv://`
- Redis uses `redis://` or `rediss://`
- Neither uses localhost in current backend validation rules

### 6) CUDA errors during transcription

The service automatically falls back to CPU. Transcription will continue but can be slower.

---

## Deployment Notes

- Backend includes a Dockerfile (`backend/Dockerfile`)
- Configure production secrets via environment variables
- Use strong JWT secret in production
- Restrict CORS origins for production deployments
- Ensure cloud MongoDB/Redis endpoints are reachable from deployment network

Example backend container run:

```bash
cd backend
docker build -t interview-bot-backend .
docker run -p 8000:8000 --env-file .env interview-bot-backend
```

---

## License

This project is licensed under the MIT License.
See [LICENSE](LICENSE) for details.