Local AI integration / Design study
Privacy-first local AI architecture for interview prep
How I built InterviewForge to run entirely locally with Ollama, sandboxed code execution, and a cover letter system that learns from your successful applications. No cloud, no accounts, no data leaves your machine.
Interview prep tools usually require API keys, store your code on their servers, and charge monthly fees. I wanted something that runs entirely on my machine: local AI inference, sandboxed code execution, and a cover letter generator that actually learns from what worked for me. The challenge: make it fast, secure, and useful without any cloud dependencies.
01 / Local AI
Ollama integration without cloud dependencies
Most AI-powered tools call OpenAI or Anthropic APIs. That's fine if you're building a SaaS product, but I wanted something that works offline and keeps my data private. Ollama runs LLMs locally: you pull a model like Qwen or Llama, and it runs on your machine. No API keys, no billing, no data leaves your computer.
The integration wasn't straightforward. Ollama's API is simple (POST to /api/generate), but handling streaming responses, managing model selection, and dealing with slow inference on large models required careful state management. I built a model service that abstracts the Ollama client, handles connection health checks, and provides a clean interface for the rest of the app.
The tricky part: prompt engineering for different tasks. Question generation needs different prompts than code review. Cover letter generation needs yet another approach. I built a prompt template system where each task type has its own template with placeholders for context (topic, difficulty, user's answer, etc.). Templates are stored as markdown files so I can iterate on them without touching code.
02 / Code execution
Running user code safely in the browser
Interview prep means users write code and want to test it. Running arbitrary JavaScript in the browser is dangerous: it can access your cookies, make network requests, or crash the tab. I needed a way to execute code safely and capture the output.
Solution: browser Workers and sandboxed iframes. For simple JavaScript, I create a Web Worker, post the user's code to it, and let it run. Workers can't access the DOM or cookies, so they're isolated. I add a 3-second timeout: if the code takes longer, I terminate the worker and show a timeout error.
For DOM and React code, I need a real browser environment. I create a hidden iframe with a sandboxed document, inject the user's code, and run it. The iframe has no access to the parent window, so it can't escape the sandbox. After execution, I extract the results and clean up the iframe.
The hidden tests are the interesting part. When I generate a coding question, I also generate hidden test cases. These tests run in the same sandbox, but the user doesn't see the test code. This prevents cheating: you can't just hardcode the answer if you don't know what the tests check.
03 / Learning from success
Cover letters that improve based on your wins
Most cover letter generators are dumb: they take your resume and the job description, call an LLM, and spit out generic text. I wanted something smarter: a system that learns from your successful applications.
Here's how it works: when you apply for a job, you track whether you got an interview. If you did, that cover letter is marked as successful. The system stores the letter, the job description, and the outcome. Next time you apply for a similar role, the generator retrieves your successful letters as examples and uses them as context for the LLM.
The implementation: I built a feedback loop. Each application has a status (applied, interview, rejected). When you mark one as successful, it goes into a 'learned examples' pool. The prompt template for cover letter generation includes a section for 'successful examples from similar roles' where I inject 2-3 past letters that worked. The LLM sees what worked for you and generates something in a similar style.
The privacy angle: all of this data stays in your local SQLite database. No cloud, no tracking. Your successful cover letters are your data, not mine.
04 / CV analysis
Extracting context from resumes for situational questions
Mock interviews can generate technical questions, but situational questions ('Tell me about a time when...') are harder. They need context about your experience. I added a feature where you upload your CV as a PDF, and the system extracts text to generate personalized situational questions.
PDF parsing in the browser is tricky. I use pdfjs-dist to extract text, but PDFs are messy: scanned documents, password-protected files, weird layouts. I built a text extraction pipeline that handles the common cases: extract text page by page, clean up whitespace, detect sections (experience, education, skills), and store the structured data.
The extracted text becomes context for the LLM. When generating a situational question, the prompt includes: 'Here is the candidate's experience: [extracted text]. Generate a behavioral question that asks them to describe a specific situation from their background.' The LLM can now ask things like 'Tell me about a time you led a team through a technical challenge' if your CV mentions leadership experience.
The privacy constraint: the PDF stays in the browser. I extract the text immediately and discard the file. The extracted text is stored in SQLite, but it's your data, on your machine.
05 / Architecture
Why NestJS + React + SQLite
I chose NestJS for the backend because it's TypeScript-first, has good DI, and integrates well with TypeORM. The backend handles: Ollama communication, SQLite queries, PDF parsing, and serving the React frontend. It's a monolith, but it's a clean monolith: clear module boundaries, dependency injection everywhere.
React 19 for the frontend because it's what I know best, and Vite makes the dev experience fast. The frontend is mostly stateless: it calls the backend API, gets results, renders them. State management is simple: React Query for server state, local state for UI.
SQLite via better-sqlite3 because it's fast, reliable, and requires no setup. The database stores: topics, questions, user answers, application tracking, cover letters, and extracted CV text. All in one file (~/.interviewforge/db.sqlite). Backup is just copying the file.
The monorepo structure: pnpm workspaces with backend/, frontend/, and shared/ packages. Shared contains TypeScript interfaces and validation schemas (using Zod) that both frontend and backend use. This prevents type mismatches between API requests and responses.
System flow
Local AI interview prep flow
- 01
User selects topic and difficulty
Frontend sends request to backend with topic ID, subtopics, and difficulty level
- 02
Backend generates question via Ollama
Prompt template fills in context, sends to local Ollama, receives structured JSON response
- 03
Question stored in SQLite
Question, answer, and metadata saved to database for spaced repetition tracking
- 04
User submits answer
Frontend captures user answer, sends to backend for evaluation
- 05
AI evaluates answer
Backend uses rubric prompt template to evaluate answer, returns feedback with score
- 06
Mastery score updated
Spaced repetition algorithm updates review interval based on score
Decision record
Design decisions and tradeoffs
↔ Scroll horizontally to compare approaches and tradeoffs.
| Decision | Approach | Tradeoff |
|---|---|---|
| Local-first architecture | Run everything locally with Ollama, no cloud dependencies | Slower inference on large models, but complete privacy and no API costs |
| Worker-based code execution | Use Web Workers and sandboxed iframes for code execution | Limited to browser JavaScript APIs, but completely isolated from user data |
| Feedback-driven cover letters | Store successful applications and use them as context for future generations | Requires user to track outcomes, but produces better-tailored letters over time |
Failure cases & validation
Failure scenarios to validate
Proposed validation scenarios and expected behavior. These are design checks, not reported production test results.
User runs infinite loop in code practice
Worker timeout triggers after 3 seconds, error shown, no tab crash
Ollama is not running
Connection check fails, UI shows clear error message with instructions to start Ollama
User uploads password-protected PDF
PDF parsing fails gracefully, user sees error message, no data corruption
Cover letter generation with no successful examples
System falls back to generic template, still generates usable letter
Evidence & further reading