{
  "name": "Build a Free Local n8n Job Interview Coach",
  "nodes": [
    {
      "id": "fb9fe5bd-8447-4887-8393-2fa90959bfaa",
      "name": "Interview Practice Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [0, 300],
      "parameters": {
        "formTitle": "Free Local Interview Coach",
        "formDescription": "Paste the job you are applying for. A local AI model on this server will write 5 interview questions for it, then coach you on your answers. Nothing leaves this machine.",
        "formFields": {
          "values": [
            { "fieldLabel": "Job title", "fieldName": "job_title", "fieldType": "text", "placeholder": "e.g. Junior Python Backend Developer", "requiredField": true },
            { "fieldLabel": "Job description", "fieldName": "job_description", "fieldType": "textarea", "placeholder": "Paste the job posting here", "requiredField": true },
            { "fieldLabel": "Your experience for this role", "fieldName": "experience", "fieldType": "textarea", "placeholder": "A few sentences about your background, skills and projects", "requiredField": true },
            {
              "fieldLabel": "Interview language",
              "fieldName": "language",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  { "option": "English" },
                  { "option": "Spanish" },
                  { "option": "French" },
                  { "option": "German" },
                  { "option": "Portuguese" },
                  { "option": "Italian" }
                ]
              },
              "requiredField": true
            }
          ]
        },
        "options": { "path": "interview-coach", "buttonLabel": "Generate my questions", "appendAttribution": false }
      }
    },
    {
      "id": "85a85bde-31f1-49fa-95f1-554f694329b0",
      "name": "Prepare Interview Request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 300],
      "parameters": {
        "jsCode": "// Clean up the form submission so the model always gets the same shape of request.\nconst f = $input.first().json;\n\nfunction clean(value, maxChars) {\n  const text = String(value || '').split('\\r').join('').trim();\n  return text.length > maxChars ? text.slice(0, maxChars) + ' ...' : text;\n}\n\nreturn [{\n  json: {\n    sessionId: 'interview-' + $execution.id,\n    jobTitle: clean(f.job_title || f['Job title'], 150),\n    // Long job posts are trimmed so they fit the local model's context window.\n    jobDescription: clean(f.job_description || f['Job description'], 4000),\n    experience: clean(f.experience || f['Your experience for this role'], 2000),\n    language: clean(f.language || f['Interview language'], 40) || 'English',\n    submittedAt: f.submittedAt\n  }\n}];"
      }
    },
    {
      "id": "2a5c6702-5fef-414a-9c85-14b44c267c18",
      "name": "Generate 5 Interview Questions",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [460, 300],
      "parameters": {
        "promptType": "define",
        "text": "=You are an experienced hiring manager preparing a realistic job interview.\n\nJob title: {{ $json.jobTitle }}\n\nJob description:\n{{ $json.jobDescription }}\n\nCandidate experience:\n{{ $json.experience }}\n\nWrite exactly 5 interview questions for this role in {{ $json.language }}. Mix behavioral, technical and situational questions, tie each one to the job description, and make each one answerable in one to two minutes.\n\nReply with JSON only, in this shape:\n{\"questions\": [\"question 1\", \"question 2\", \"question 3\", \"question 4\", \"question 5\"]}"
      }
    },
    {
      "id": "2e5abfb0-ca81-4901-b13c-1cf11871b0f8",
      "name": "Ollama gemma4 (questions)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [460, 520],
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": { "temperature": 0.6, "numCtx": 8192, "format": "json", "keepAlive": "10m" }
      }
    },
    {
      "id": "681ce280-b3bb-42d0-8f72-9914809e6bd9",
      "name": "Parse Questions",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [700, 300],
      "parameters": {
        "jsCode": "// Pull the 5 questions out of the model's reply.\n// With JSON mode on, the chain usually returns the parsed object already.\nconst ctx = $('Prepare Interview Request').first().json;\nconst out = $input.first().json;\nlet questions = Array.isArray(out.questions) ? out.questions : [];\n\nif (questions.length === 0) {\n  // Fallback: the reply came back as text, so parse it ourselves.\n  let raw = String(out.text || '');\n  const thinkEnd = raw.lastIndexOf('</think>');\n  if (thinkEnd !== -1) raw = raw.slice(thinkEnd + 8);\n  try {\n    questions = JSON.parse(raw.slice(raw.indexOf('{'), raw.lastIndexOf('}') + 1)).questions || [];\n  } catch (error) {\n    questions = raw.split('\\n').map(line => line.trim()).filter(line => line.endsWith('?'));\n  }\n}\n\nquestions = questions.map(q => String(q).trim()).filter(Boolean).slice(0, 5);\nif (questions.length < 5) {\n  throw new Error('The model returned ' + questions.length + ' usable questions instead of 5: ' + JSON.stringify(out).slice(0, 400));\n}\n\nreturn [{ json: { ...ctx, questions } }];"
      }
    },
    {
      "id": "c21b91e5-8592-44af-9f43-3d5cf1ac5040",
      "name": "Answer the Questions",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [940, 300],
      "parameters": {
        "operation": "page",
        "formFields": {
          "values": [
            { "fieldLabel": "=1. {{ $json.questions[0] }}", "fieldName": "answer_1", "fieldType": "textarea", "placeholder": "Type your answer here, or attach a recording below" },
            { "fieldLabel": "Recorded answer to question 1 (optional)", "fieldName": "audio_1", "fieldType": "file", "multipleFiles": false, "acceptFileTypes": ".wav,.mp3,.m4a,.webm,.ogg,.flac" },
            { "fieldLabel": "=2. {{ $json.questions[1] }}", "fieldName": "answer_2", "fieldType": "textarea", "placeholder": "Type your answer here, or attach a recording below" },
            { "fieldLabel": "Recorded answer to question 2 (optional)", "fieldName": "audio_2", "fieldType": "file", "multipleFiles": false, "acceptFileTypes": ".wav,.mp3,.m4a,.webm,.ogg,.flac" },
            { "fieldLabel": "=3. {{ $json.questions[2] }}", "fieldName": "answer_3", "fieldType": "textarea", "placeholder": "Type your answer here, or attach a recording below" },
            { "fieldLabel": "Recorded answer to question 3 (optional)", "fieldName": "audio_3", "fieldType": "file", "multipleFiles": false, "acceptFileTypes": ".wav,.mp3,.m4a,.webm,.ogg,.flac" },
            { "fieldLabel": "=4. {{ $json.questions[3] }}", "fieldName": "answer_4", "fieldType": "textarea", "placeholder": "Type your answer here, or attach a recording below" },
            { "fieldLabel": "Recorded answer to question 4 (optional)", "fieldName": "audio_4", "fieldType": "file", "multipleFiles": false, "acceptFileTypes": ".wav,.mp3,.m4a,.webm,.ogg,.flac" },
            { "fieldLabel": "=5. {{ $json.questions[4] }}", "fieldName": "answer_5", "fieldType": "textarea", "placeholder": "Type your answer here, or attach a recording below" },
            { "fieldLabel": "Recorded answer to question 5 (optional)", "fieldName": "audio_5", "fieldType": "file", "multipleFiles": false, "acceptFileTypes": ".wav,.mp3,.m4a,.webm,.ogg,.flac" }
          ]
        },
        "options": {
          "formTitle": "=Your {{ $json.jobTitle }} interview",
          "formDescription": "Answer each question once: type it, or attach a recording of yourself answering out loud. A recording is used instead of the typed answer for that question.",
          "buttonLabel": "Get my feedback",
          "appendAttribution": false
        }
      }
    },
    {
      "id": "aee9c04a-5be5-45c8-9986-8e3784a93f21",
      "name": "Split Answers Per Question",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1180, 300],
      "parameters": {
        "jsCode": "// Turn the answer page into one item per question, keeping any recording as binary data.\nconst page = $input.first();\nconst ctx = $('Parse Questions').first().json;\nconst answers = page.json || {};\nconst files = page.binary || {};\nconst fileKeys = Object.keys(files);\n\nreturn ctx.questions.map((question, i) => {\n  const n = i + 1;\n  const typed = String(answers['answer_' + n] || '').trim();\n  const fileKey = fileKeys.find(k => k === 'audio_' + n || k.startsWith('audio_' + n + '_'));\n  const item = {\n    json: { sessionId: ctx.sessionId, questionNumber: n, question, typedAnswer: typed, hasRecording: Boolean(fileKey) }\n  };\n  if (fileKey) item.binary = { audio: files[fileKey] };\n  return item;\n});"
      }
    },
    {
      "id": "4e839314-3554-4763-a31c-4e78877656ac",
      "name": "Recorded Answer?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [1420, 300],
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose" },
          "conditions": [
            { "leftValue": "={{ $json.hasRecording }}", "operator": { "type": "boolean", "operation": "true", "singleValue": true } }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "fd597a7e-a6a4-45cd-8101-67e9f2e94782",
      "name": "Transcribe with Speaches",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [1660, 200],
      "parameters": {
        "method": "POST",
        "url": "http://speaches:8000/v1/audio/transcriptions",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            { "parameterType": "formBinaryData", "name": "file", "inputDataFieldName": "audio" },
            { "parameterType": "formData", "name": "model", "value": "Systran/faster-distil-whisper-large-v3" }
          ]
        },
        "options": { "timeout": 300000 }
      }
    },
    {
      "id": "2ef4e43c-09f4-44ec-aed5-c167c6b971b9",
      "name": "Use Transcript",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1900, 200],
      "parameters": {
        "mode": "manual",
        "includeOtherFields": false,
        "assignments": {
          "assignments": [
            { "id": "t1", "name": "questionNumber", "value": "={{ $(\"Recorded Answer?\").item.json.questionNumber }}", "type": "number" },
            { "id": "t2", "name": "question", "value": "={{ $(\"Recorded Answer?\").item.json.question }}", "type": "string" },
            { "id": "t3", "name": "answerText", "value": "={{ ($json.text || \"\").trim() }}", "type": "string" },
            { "id": "t4", "name": "answerSource", "value": "recording (transcribed by Speaches)", "type": "string" }
          ]
        }
      }
    },
    {
      "id": "32187d0b-6a28-4ad4-879a-4cde40b8385f",
      "name": "Combine Answers",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [2140, 300],
      "parameters": { "mode": "append" }
    },
    {
      "id": "a19c9012-83bf-4d7c-913e-6f97e04d1476",
      "name": "Use Typed Answer",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1900, 420],
      "parameters": {
        "mode": "manual",
        "includeOtherFields": false,
        "assignments": {
          "assignments": [
            { "id": "y1", "name": "questionNumber", "value": "={{ $json.questionNumber }}", "type": "number" },
            { "id": "y2", "name": "question", "value": "={{ $json.question }}", "type": "string" },
            { "id": "y3", "name": "answerText", "value": "={{ $json.typedAnswer || \"(no answer given)\" }}", "type": "string" },
            { "id": "y4", "name": "answerSource", "value": "typed", "type": "string" }
          ]
        }
      }
    },
    {
      "id": "b375cc48-f9a8-4740-b70d-ead8ca449d3f",
      "name": "Evaluate Each Answer",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [2380, 300],
      "parameters": {
        "promptType": "define",
        "text": "=You are a supportive but honest interview coach.\n\nRole: {{ $(\"Prepare Interview Request\").first().json.jobTitle }}\n\nJob description:\n{{ $(\"Prepare Interview Request\").first().json.jobDescription }}\n\nInterview question {{ $json.questionNumber }}: {{ $json.question }}\n\nCandidate answer ({{ $json.answerSource }}):\n{{ $json.answerText }}\n\nJudge how well this answer would land with a hiring manager for this role. Be specific to what the candidate actually said. Write the feedback in {{ $(\"Prepare Interview Request\").first().json.language }}.\n\nReply with JSON only, in this shape:\n{\"score\": 7, \"strengths\": \"1-2 sentences on what worked\", \"improvements\": \"1-2 sentences on what was missing or weak\", \"actionTip\": \"one concrete thing to say or do differently next time\"}\n\nThe score is a whole number from 1 to 10. If the answer is empty or says no answer was given, score it 1 and explain what a strong answer would cover."
      }
    },
    {
      "id": "1aeb3845-16df-4290-8f0d-84cb6e4c38a7",
      "name": "Ollama gemma4 (feedback)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [2380, 520],
      "parameters": {
        "model": "gemma4:12b-it-qat",
        "options": { "temperature": 0.3, "numCtx": 8192, "format": "json", "keepAlive": "10m" }
      }
    },
    {
      "id": "b4d4186c-8744-4412-b97a-bb42c6b69cc9",
      "name": "Build Session Report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2620, 300],
      "parameters": {
        "jsCode": "// Pair each evaluation with its answer, then build the session record and the results page.\nconst ctx = $('Parse Questions').first().json;\nconst answers = $('Combine Answers').all().map(item => item.json);\n\nfunction readEvaluation(json) {\n  // With JSON mode on, the chain usually returns the parsed object already.\n  if (json.score !== undefined) return json;\n  let raw = String(json.text || '');\n  const thinkEnd = raw.lastIndexOf('</think>');\n  if (thinkEnd !== -1) raw = raw.slice(thinkEnd + 8);\n  try {\n    return JSON.parse(raw.slice(raw.indexOf('{'), raw.lastIndexOf('}') + 1));\n  } catch (error) {\n    return { score: null, strengths: '', improvements: raw.trim(), actionTip: '' };\n  }\n}\n\nfunction esc(value) {\n  return String(value == null ? '' : value)\n    .split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;');\n}\n\nconst results = $input.all().map((item, i) => {\n  const evaluation = readEvaluation(item.json);\n  const score = Number.parseInt(evaluation.score, 10);\n  return {\n    ...answers[i],\n    score: Number.isNaN(score) ? null : Math.min(10, Math.max(1, score)),\n    strengths: evaluation.strengths || '',\n    improvements: evaluation.improvements || '',\n    actionTip: evaluation.actionTip || ''\n  };\n}).sort((a, b) => a.questionNumber - b.questionNumber);\n\nconst scored = results.filter(r => r.score !== null);\nconst averageScore = scored.length ? Math.round((scored.reduce((sum, r) => sum + r.score, 0) / scored.length) * 10) / 10 : null;\n\nconst cards = results.map(r =>\n  '<div style=\"border:1px solid #ddd;border-radius:8px;padding:14px 16px;margin:14px 0;text-align:left\">' +\n  '<p style=\"margin:0 0 6px\"><b>' + r.questionNumber + '. ' + esc(r.question) + '</b></p>' +\n  '<p style=\"margin:0 0 8px;color:#555\"><i>Your answer (' + esc(r.answerSource) + '):</i> ' + esc(r.answerText) + '</p>' +\n  '<p style=\"margin:0 0 6px\"><b>Score:</b> ' + (r.score === null ? 'n/a' : r.score + ' / 10') + '</p>' +\n  '<p style=\"margin:0 0 6px\"><b>What worked:</b> ' + esc(r.strengths) + '</p>' +\n  '<p style=\"margin:0 0 6px\"><b>What to improve:</b> ' + esc(r.improvements) + '</p>' +\n  '<p style=\"margin:0\"><b>Try this next time:</b> ' + esc(r.actionTip) + '</p>' +\n  '</div>'\n).join('');\n\nconst reportHtml =\n  '<div style=\"max-width:720px;margin:24px auto;font-family:system-ui,sans-serif;line-height:1.45\">' +\n  '<h2 style=\"margin-bottom:4px\">Your interview feedback</h2>' +\n  '<p style=\"margin-top:0;color:#555\">' + esc(ctx.jobTitle) + ' &middot; ' + esc(ctx.language) +\n  ' &middot; Average score: <b>' + (averageScore === null ? 'n/a' : averageScore + ' / 10') + '</b></p>' +\n  cards +\n  '<p style=\"color:#777;font-size:13px\">Generated on this server by gemma4 with Ollama. Saved as session ' + esc(ctx.sessionId) + '.</p>' +\n  '</div>';\n\nreturn [{\n  json: {\n    sessionId: ctx.sessionId,\n    jobTitle: ctx.jobTitle,\n    jobDescription: ctx.jobDescription,\n    experience: ctx.experience,\n    language: ctx.language,\n    model: 'gemma4:12b-it-qat',\n    questions: ctx.questions,\n    answers: results.map(r => ({ questionNumber: r.questionNumber, question: r.question, answerSource: r.answerSource, answerText: r.answerText })),\n    evaluations: results.map(r => ({ questionNumber: r.questionNumber, score: r.score, strengths: r.strengths, improvements: r.improvements, actionTip: r.actionTip })),\n    averageScore,\n    reportHtml\n  }\n}];"
      }
    },
    {
      "id": "762cebea-95bb-4f4e-8b35-b0250ab30ff5",
      "name": "Create Sessions Table",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.7,
      "position": [2860, 300],
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS interview_sessions (\n  id serial PRIMARY KEY,\n  session_id text NOT NULL,\n  job_title text,\n  job_description text,\n  experience text,\n  interview_language text,\n  model text,\n  questions jsonb,\n  answers jsonb,\n  evaluations jsonb,\n  average_score numeric(4,1),\n  created_at timestamptz DEFAULT now()\n);"
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "be76f10f-7e10-46a1-bd50-3e516f6737d5",
      "name": "Save Session to Postgres",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.7,
      "position": [3100, 300],
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO interview_sessions\n  (session_id, job_title, job_description, experience, interview_language, model, questions, answers, evaluations, average_score)\nVALUES ($1, $2, $3, $4, $5, $6, $7::jsonb, $8::jsonb, $9::jsonb, $10)\nRETURNING id, session_id, average_score, created_at;",
        "options": {
          "queryReplacement": "={{ [ $(\"Build Session Report\").first().json.sessionId, $(\"Build Session Report\").first().json.jobTitle, $(\"Build Session Report\").first().json.jobDescription, $(\"Build Session Report\").first().json.experience, $(\"Build Session Report\").first().json.language, $(\"Build Session Report\").first().json.model, JSON.stringify($(\"Build Session Report\").first().json.questions), JSON.stringify($(\"Build Session Report\").first().json.answers), JSON.stringify($(\"Build Session Report\").first().json.evaluations), $(\"Build Session Report\").first().json.averageScore ] }}"
        }
      },
      "executeOnce": true
    },
    {
      "id": "98f96f97-46e1-4976-b992-45846cb7dcf0",
      "name": "Show Coaching Feedback",
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.5,
      "position": [3340, 300],
      "parameters": {
        "operation": "completion",
        "respondWith": "showText",
        "responseText": "={{ $(\"Build Session Report\").first().json.reportHtml }}"
      }
    }
  ],
  "connections": {
    "Interview Practice Form": { "main": [[{ "node": "Prepare Interview Request", "type": "main", "index": 0 }]] },
    "Prepare Interview Request": { "main": [[{ "node": "Generate 5 Interview Questions", "type": "main", "index": 0 }]] },
    "Generate 5 Interview Questions": { "main": [[{ "node": "Parse Questions", "type": "main", "index": 0 }]] },
    "Ollama gemma4 (questions)": { "ai_languageModel": [[{ "node": "Generate 5 Interview Questions", "type": "ai_languageModel", "index": 0 }]] },
    "Parse Questions": { "main": [[{ "node": "Answer the Questions", "type": "main", "index": 0 }]] },
    "Answer the Questions": { "main": [[{ "node": "Split Answers Per Question", "type": "main", "index": 0 }]] },
    "Split Answers Per Question": { "main": [[{ "node": "Recorded Answer?", "type": "main", "index": 0 }]] },
    "Recorded Answer?": {
      "main": [
        [{ "node": "Transcribe with Speaches", "type": "main", "index": 0 }],
        [{ "node": "Use Typed Answer", "type": "main", "index": 0 }]
      ]
    },
    "Transcribe with Speaches": { "main": [[{ "node": "Use Transcript", "type": "main", "index": 0 }]] },
    "Use Transcript": { "main": [[{ "node": "Combine Answers", "type": "main", "index": 0 }]] },
    "Combine Answers": { "main": [[{ "node": "Evaluate Each Answer", "type": "main", "index": 0 }]] },
    "Use Typed Answer": { "main": [[{ "node": "Combine Answers", "type": "main", "index": 1 }]] },
    "Evaluate Each Answer": { "main": [[{ "node": "Build Session Report", "type": "main", "index": 0 }]] },
    "Ollama gemma4 (feedback)": { "ai_languageModel": [[{ "node": "Evaluate Each Answer", "type": "ai_languageModel", "index": 0 }]] },
    "Build Session Report": { "main": [[{ "node": "Create Sessions Table", "type": "main", "index": 0 }]] },
    "Create Sessions Table": { "main": [[{ "node": "Save Session to Postgres", "type": "main", "index": 0 }]] },
    "Save Session to Postgres": { "main": [[{ "node": "Show Coaching Feedback", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
