# subodhnarayan/ai-interviewer architecture

> Architecture diagram of the GitHub repository subodhnarayan/ai-interviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/subodhnarayan/ai-interviewer
- Repository: https://github.com/subodhnarayan/ai-interviewer

## Overview

#### Purpose and Entry Points
AI Interviewer is a local, voice-enabled technical interview application with adaptive questioning, transcript evaluation, topic plans, history, and planned coding-round support. The FastAPI server starts at `backend/main.py`; the browser UI is served from `frontend/index.html`. Primary operational entry points are the root UI and `/api/health`.

#### HTTP Application Boundary
`backend/main.py` owns the FastAPI application, API routing, and frontend delivery. `backend/_http.py` centralizes HTTP-facing support, separating request/response concerns from interview logic. The frontend is a single HTML/CSS/JavaScript client at `frontend/index.html`, responsible for text interaction, microphone capture, browser speech synthesis, and displaying interview progress and results.

#### Interview Orchestration and Session Flow
`backend/interviewer.py` is the core stateful interview engine. It maintains session-level data such as transcript, current question, elapsed time, difficulty progression, follow-up history, and completion state. A typical flow is: client creates/configures an interview, the engine requests an LLM-generated question, user text or transcribed speech is appended to the transcript, and the engine selects follow-ups or advances the plan. The `<END_INTERVIEW>` control token ends the live interview and triggers final evaluation.

Relevant paths:
- `backend/interviewer.py`
- `backend/main.py`
- `backend/prompts.py`

#### LLM and Prompt Boundary
`backend/llm.py` provides the swappable OpenAI-compatible model integration, allowing Groq, OpenAI, or locally hosted Ollama to be selected through environment configuration. `backend/prompts.py` separates interviewer behavior from final evaluator behavior: one prompt drives question/follow-up generation, while another evaluates the complete transcript and produces scoring, strengths, weaknesses, and report content. This boundary keeps provider transport independent from interview policy and output shaping.

Relevant paths:
- `backend/llm.py`
- `backend/prompts.py`
- `backend/config.py`

#### Plans, Topics, and Evaluation
Structured interview plans and topic-oriented progress are represented by `backend/topics.py`. These plans support preset interview packs and job-description-derived interview plans, and provide the structure against which live progress and final evaluation can be aligned. The interview engine consumes this structure to sequence or adapt questions rather than treating every session as an unstructured chat.

Relevant paths:
- `backend/topics.py`
- `backend/interviewer.py`
- `backend/prompts.py`

#### Speech, Persistence, and Execution Integrations
Speech input crosses an external transcription boundary in `backend/stt.py`, configured for Groq Whisper; speech output remains browser-side via the Web Speech/SpeechSynthesis API in `frontend/index.html`. SQLite-backed interview history is encapsulated by `backend/db.py`, separating durable records from active in-memory session flow. Coding-round infrastructure is isolated in `backend/coding.py`, `backend/runner.py`, and `backend/piston.py`, indicating a boundary for code submission, execution orchestration, and likely Piston execution-service integration.

Relevant paths:
- `backend/stt.py`
- `backend/db.py`
- `backend/coding.py`
- `backend/runner.py`
- `backend/piston.py`

#### Runtime and Configuration
The application runs on Python 3.11+ with FastAPI and Uvicorn, using dependencies declared in `requirements.txt`. Runtime configuration, including LLM provider URL/model/key and Whisper settings, is loaded by `backend/config.py` from environment values documented in `.env.example`. External dependencies are OpenAI-compatible LLM APIs, Groq Whisper for transcription, optional local Ollama, browser microphone APIs, browser speech synthesis, SQLite, and potentially Piston for code execution.

Main entry points: [`backend/main.py`](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/main.py) (FastAPI application), [`backend/interviewer.py`](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/interviewer.py) (Interview engine), [`frontend/index.html`](https://github.com/subodhnarayan/ai-interviewer/blob/main/frontend/index.html) (Voice interview UI), [`backend/llm.py`](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/llm.py) (LLM gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_ui["Voice interview UI<br/>HTML/JS client<br/>[index.html]"]
  node_browser_speech["Browser speech APIs<br/>browser APIs"]
end

subgraph group_server["FastAPI backend"]
  node_app["FastAPI application<br/>HTTP server<br/>[main.py]"]
  node_http["HTTP support<br/>request/response layer<br/>[_http.py]"]
  node_engine{{"Interview engine<br/>stateful orchestrator<br/>[interviewer.py]"}}
  node_topics["Interview plans<br/>topic planner<br/>[topics.py]"]
  node_prompts["Interview prompts<br/>LLM policy<br/>[prompts.py]"]
  node_llm["LLM gateway<br/>provider adapter<br/>[llm.py]"]
  node_stt["Speech transcription<br/>STT adapter<br/>[stt.py]"]
  node_history[("Interview history<br/>SQLite persistence<br/>[db.py]")]
  node_coding["Coding rounds<br/>submission flow<br/>[coding.py]"]
  node_runner["Code runner<br/>execution orchestrator<br/>[runner.py]"]
  node_piston["Piston adapter<br/>execution integration<br/>[piston.py]"]
  node_config["Runtime configuration<br/>environment settings<br/>[config.py]"]
end

subgraph group_services["External services"]
  node_llm_provider(("LLM provider<br/>OpenAI-compatible API"))
  node_whisper(("Groq Whisper<br/>transcription API"))
  node_piston_service(("Piston service<br/>code execution API"))
end

node_ui -->|"interview and history API"| node_app
node_app -->|"serves root UI"| node_ui
node_ui -->|"microphone and spoken output"| node_browser_speech
node_app -->|"uses"| node_http
node_app -->|"creates and drives sessions"| node_engine
node_app -->|"transcribes recorded speech"| node_stt
node_app -->|"reads and writes records"| node_history
node_app -->|"coding-round endpoints"| node_coding
node_engine -->|"sequences against plan"| node_topics
node_engine -->|"question and evaluation policy"| node_prompts
node_engine -->|"generates questions and report"| node_llm
node_engine -->|"persists completed interview"| node_history
node_stt -->|"audio transcription"| node_whisper
node_coding -->|"submits code"| node_runner
node_runner -->|"delegates execution"| node_piston
node_piston -->|"execution requests"| node_piston_service
node_llm -->|"model requests"| node_llm_provider
node_config -.->|"provider URL, model, key"| node_llm
node_config -.->|"Whisper settings"| node_stt

click node_ui "https://github.com/subodhnarayan/ai-interviewer/blob/main/frontend/index.html"
click node_app "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/main.py"
click node_http "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/_http.py"
click node_engine "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/interviewer.py"
click node_topics "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/topics.py"
click node_prompts "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/prompts.py"
click node_llm "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/llm.py"
click node_stt "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/stt.py"
click node_history "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/db.py"
click node_coding "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/coding.py"
click node_runner "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/runner.py"
click node_piston "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/piston.py"
click node_config "https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui,node_browser_speech toneBlue
class node_app,node_http,node_engine,node_topics,node_prompts,node_llm,node_stt,node_history,node_coding,node_runner,node_piston,node_config toneAmber
class node_llm_provider,node_whisper,node_piston_service toneMint
```

## Components

### Browser client

- [Voice interview UI](https://github.com/subodhnarayan/ai-interviewer/blob/main/frontend/index.html): HTML/JS client · Captures text and microphone input and renders progress and results. · `frontend/index.html`
- **Browser speech APIs**: browser APIs · Provides microphone access and speech synthesis.

### FastAPI backend

- [FastAPI application](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/main.py): HTTP server · Serves the UI and owns API routes including health. · `backend/main.py`
- [HTTP support](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/_http.py): request/response layer · `backend/_http.py`
- [Interview engine](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/interviewer.py): stateful orchestrator · Manages active session state, adaptive questions, transcript, and completion. · `backend/interviewer.py`
- [Interview plans](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/topics.py): topic planner · Defines preset and job-description-derived topic plans. · `backend/topics.py`
- [Interview prompts](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/prompts.py): LLM policy · Separates question-generation and final-evaluation instructions. · `backend/prompts.py`
- [LLM gateway](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/llm.py): provider adapter · Selects an OpenAI-compatible model provider. · `backend/llm.py`
- [Speech transcription](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/stt.py): STT adapter · `backend/stt.py`
- [Interview history](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/db.py): SQLite persistence · Stores durable interview records separately from active sessions. · `backend/db.py`
- [Coding rounds](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/coding.py): submission flow · `backend/coding.py`
- [Code runner](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/runner.py): execution orchestrator · `backend/runner.py`
- [Piston adapter](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/piston.py): execution integration · `backend/piston.py`
- [Runtime configuration](https://github.com/subodhnarayan/ai-interviewer/blob/main/backend/config.py): environment settings · Loads model-provider and Whisper settings. · `backend/config.py`

### External services

- **LLM provider**: OpenAI-compatible API · Groq, OpenAI, or local Ollama.
- **Groq Whisper**: transcription API
- **Piston service**: code execution API

## Connections

- Voice interview UI → FastAPI application: interview and history API
- FastAPI application → Voice interview UI: serves root UI
- Voice interview UI → Browser speech APIs: microphone and spoken output
- FastAPI application → HTTP support: uses
- FastAPI application → Interview engine: creates and drives sessions
- FastAPI application → Speech transcription: transcribes recorded speech
- FastAPI application → Interview history: reads and writes records
- FastAPI application → Coding rounds: coding-round endpoints
- Interview engine → Interview plans: sequences against plan
- Interview engine → Interview prompts: question and evaluation policy
- Interview engine → LLM gateway: generates questions and report
- Interview engine → Interview history: persists completed interview
- Speech transcription → Groq Whisper: audio transcription
- Coding rounds → Code runner: submits code
- Code runner → Piston adapter: delegates execution
- Piston adapter → Piston service: execution requests
- LLM gateway → LLM provider: model requests
- Runtime configuration → LLM gateway: provider URL, model, key
- Runtime configuration → Speech transcription: Whisper settings
