{
  "name": "Job Application Review With Local AI",
  "nodes": [
    {
      "id": "a7f2ce3c-a8ab-4fca-8513-fd00cdd2c336",
      "name": "Job Application Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.6,
      "position": [0, 0],
      "parameters": {
        "authentication": "basicAuth",
        "formTitle": "Review a job application",
        "formDescription": "Paste the job description and upload the resume you are sending. The workflow scores the match and drafts a follow-up for you to review. Nothing is sent automatically.",
        "formFields": {
          "values": [
            { "fieldLabel": "Job Title", "fieldType": "text", "requiredField": true },
            { "fieldLabel": "Company", "fieldType": "text", "requiredField": true },
            { "fieldLabel": "Job Description", "fieldType": "textarea", "requiredField": true, "placeholder": "Paste the full job posting" },
            { "fieldLabel": "Resume", "fieldType": "file", "requiredField": true, "multipleFiles": false, "acceptFileTypes": ".pdf,.docx,.doc,.txt" }
          ]
        },
        "responseMode": "onReceived",
        "options": {
          "path": "job-application-review",
          "appendAttribution": false,
          "respondWithOptions": {
            "values": {
              "respondWith": "text",
              "formSubmittedText": "Got it. The score lands in your Job Application Reviews sheet and the follow-up draft in Google Docs."
            }
          }
        }
      }
    },
    {
      "id": "eb2affa5-e313-45a0-b1ea-c4b466ff6825",
      "name": "Prepare Form Submission",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [260, 0],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first();\nconst j = item.json;\nconst bin = item.binary || {};\nconst key = Object.keys(bin)[0];\nif (!key) throw new Error('No resume file was uploaded.');\nreturn [{\n  json: {\n    source: 'form',\n    jobTitle: String(j['Job Title'] || '').trim(),\n    company: String(j['Company'] || '').trim(),\n    jobDescription: String(j['Job Description'] || '').trim(),\n    resumeFileName: bin[key].fileName || 'resume'\n  },\n  binary: { resume: bin[key] }\n}];"
      }
    },
    {
      "id": "b2dc2b71-be52-4a7f-b923-20959fe678cf",
      "name": "Extract Resume Text (Tika)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [1240, 100],
      "parameters": {
        "method": "PUT",
        "url": "http://tika:9998/tika",
        "sendHeaders": true,
        "headerParameters": { "parameters": [ { "name": "Accept", "value": "text/plain" } ] },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "resume",
        "options": { "timeout": 60000, "response": { "response": { "responseFormat": "text" } } }
      }
    },
    {
      "id": "cc581e80-b9f3-4374-8f90-f246f250990e",
      "name": "Watch Job Folder",
      "type": "n8n-nodes-base.localFileTrigger",
      "typeVersion": 1,
      "position": [0, 300],
      "parameters": {
        "triggerOn": "folder",
        "path": "/data/job-applications-inbox",
        "events": ["add"],
        "options": {
          "awaitWriteFinish": true,
          "ignoreInitial": true,
          "depth": 0,
          "usePolling": true,
          "ignored": "**/README.md"
        }
      }
    },
    {
      "id": "3156d007-382e-4aa3-b4c4-3034484c5202",
      "name": "Read Job File",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [260, 300],
      "parameters": {
        "operation": "read",
        "fileSelector": "={{ $json.path }}",
        "options": { "dataPropertyName": "jobFile" }
      }
    },
    {
      "id": "2776e07a-6c41-4280-a167-dbd4437bfabc",
      "name": "Extract Job Text (Tika)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [500, 300],
      "parameters": {
        "method": "PUT",
        "url": "http://tika:9998/tika",
        "sendHeaders": true,
        "headerParameters": { "parameters": [ { "name": "Accept", "value": "text/plain" } ] },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "jobFile",
        "options": { "timeout": 60000, "response": { "response": { "responseFormat": "text" } } }
      }
    },
    {
      "id": "501ea125-d047-48dc-bd02-dd04bb66b872",
      "name": "Read Master Resume",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [740, 300],
      "parameters": {
        "operation": "read",
        "fileSelector": "/data/job-applications/resume.pdf",
        "options": { "dataPropertyName": "resume" }
      }
    },
    {
      "id": "6f47c68e-4ff5-48c6-ad1a-6f9fb91e2f67",
      "name": "Prepare Folder Submission",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [980, 300],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const raw = String($('Extract Job Text (Tika)').first().json.data || '');\nconst text = raw.replace(/\\\\([<>|*_#\\-\\[\\]()])/g, '$1').replace(/\\r/g, '').trim();\n// The job file starts with 'Title: ...' and 'Company: ...'. Tika may join lines, so match patterns instead of lines.\nconst titleMatch = text.match(/title\\s*:\\s*(.+?)(?=\\s*company\\s*:|\\n|\\s{2,}|$)/i);\nconst companyMatch = text.match(/company\\s*:\\s*(.+?)(?=\\n|\\s{2,}|$)/i);\nlet description = text;\nif (companyMatch) description = text.slice(companyMatch.index + companyMatch[0].length);\nelse if (titleMatch) description = text.slice(titleMatch.index + titleMatch[0].length);\nconst filePath = String($('Watch Job Folder').first().json.path || '');\nconst fileName = filePath.split('/').pop();\nconst item = $input.first();\nreturn [{\n  json: {\n    source: 'watched folder',\n    jobTitle: titleMatch ? titleMatch[1].trim() : fileName.replace(/\\.[^.]+$/, ''),\n    company: companyMatch ? companyMatch[1].trim() : 'Unknown company',\n    jobDescription: description.replace(/\\n{3,}/g, '\\n\\n').trim(),\n    resumeFileName: 'resume.pdf',\n    jobFile: filePath\n  },\n  binary: { resume: item.binary.resume }\n}];"
      }
    },
    {
      "id": "01c1300e-21b4-4526-a446-422ca9e47550",
      "name": "Combine Application Text",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1480, 100],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const src = $('Prepare Form Submission').isExecuted\n  ? $('Prepare Form Submission').first().json\n  : $('Prepare Folder Submission').first().json;\nconst resumeText = String($input.first().json.data || '')\n  .replace(/\\\\([<>|*_#\\-\\[\\]()])/g, '$1')\n  .replace(/\\n{3,}/g, '\\n\\n')\n  .trim();\nif (resumeText.length < 50) {\n  throw new Error('Tika returned almost no text from the resume. It may be a scanned image.');\n}\nif (src.jobDescription.length < 50) {\n  throw new Error('The job description is empty or too short to review.');\n}\nreturn [{ json: { ...src, resumeText } }];"
      }
    },
    {
      "id": "1846f6f8-f9cf-4a51-92e9-3eae91392f44",
      "name": "Analyze Requirements",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [1720, 100],
      "parameters": {
        "promptType": "define",
        "text": "=You are screening a job application. Compare the RESUME against the JOB DESCRIPTION.\n\nList every qualification the job asks for. For each one, classify it:\n- type: \"required\" (must have, required, minimum), \"preferred\" (nice to have, preferred, bonus) or \"implied\" (not stated as a requirement but clearly expected from the duties)\n- status: \"met\" (the resume clearly shows it), \"partial\" (related or weaker evidence) or \"missing\" (no evidence)\n- evidence: a short quote or paraphrase from the resume, or \"\" when missing\n\nOnly use what the resume actually says. Do not assume skills that are not written down.\n\nReturn ONLY JSON in this exact shape:\n{\"requirements\":[{\"requirement\":\"...\",\"type\":\"required\",\"status\":\"met\",\"evidence\":\"...\"}],\"summary\":\"one sentence on overall fit\"}\n\nJOB TITLE: {{ $json.jobTitle }}\nCOMPANY: {{ $json.company }}\n\nJOB DESCRIPTION:\n{{ $json.jobDescription }}\n\nRESUME:\n{{ $json.resumeText }}"
      }
    },
    {
      "id": "a80ce952-39b9-446b-8ed1-f748556924ac",
      "name": "qwen2.5 14B (analysis)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [1720, 320],
      "parameters": {
        "model": "qwen2.5:14b-instruct-q5_K_M",
        "options": { "temperature": 0.1, "numCtx": 4096, "format": "json", "keepAlive": "10m" }
      }
    },
    {
      "id": "18164b47-f188-49da-80ea-2f96c1e9cdba",
      "name": "Score Coverage",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [2000, 100],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "// Weights: required = 3, preferred = 2, implied = 1\n// Credit: met = 1, partial = 0.5, missing = 0\nconst WEIGHTS = { required: 3, preferred: 2, implied: 1 };\nconst CREDIT = { met: 1, partial: 0.5, missing: 0 };\nconst app = $('Combine Application Text').first().json;\nconst out = $input.first().json || {};\nlet parsed = null;\nlet parseError = '';\nif (Array.isArray(out.requirements)) {\n  // The chain already parsed the model's JSON\n  parsed = out;\n} else {\n  try {\n    const raw = String(out.text || '');\n    parsed = JSON.parse(raw.slice(raw.indexOf('{'), raw.lastIndexOf('}') + 1));\n  } catch (err) {\n    parseError = 'The model did not return valid JSON: ' + err.message;\n  }\n}\nconst reqs = (parsed && Array.isArray(parsed.requirements) ? parsed.requirements : [])\n  .map(r => ({\n    requirement: String(r.requirement || '').trim(),\n    type: WEIGHTS[String(r.type || '').toLowerCase()] ? String(r.type).toLowerCase() : 'implied',\n    status: CREDIT[String(r.status || '').toLowerCase()] !== undefined ? String(r.status).toLowerCase() : 'missing',\n    evidence: String(r.evidence || '').trim()\n  }))\n  .filter(r => r.requirement);\nif (!parseError && reqs.length === 0) parseError = 'The model returned no requirements.';\nlet earned = 0;\nlet possible = 0;\nfor (const r of reqs) {\n  possible += WEIGHTS[r.type];\n  earned += WEIGHTS[r.type] * CREDIT[r.status];\n}\nconst score = possible > 0 ? Math.round((earned / possible) * 100) : 0;\nconst missing = reqs.filter(r => r.status === 'missing' && r.type !== 'implied').map(r => r.requirement + ' (' + r.type + ')');\nconst partial = reqs.filter(r => r.status === 'partial').map(r => r.requirement + ' (' + r.type + ')');\nconst matched = reqs.filter(r => r.status !== 'missing' && r.evidence).map(r => r.requirement + ': ' + r.evidence);\nreturn [{\n  json: {\n    ...app,\n    score,\n    requirementCount: reqs.length,\n    requiredMissing: reqs.filter(r => r.type === 'required' && r.status === 'missing').length,\n    missingQualifications: missing.join('; ') || 'none',\n    partialQualifications: partial.join('; ') || 'none',\n    matchedEvidence: matched.join('\\n') || 'none found',\n    fitSummary: parsed && parsed.summary ? String(parsed.summary) : '',\n    parseError,\n    requirements: reqs\n  }\n}];"
      }
    },
    {
      "id": "ff7e5da0-0f6d-4c13-93e5-29e2790d8ef8",
      "name": "Draft Follow-Up",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [2240, 100],
      "parameters": {
        "promptType": "define",
        "text": "=Write a short follow-up email the applicant can send after applying for this job.\n\nRules:\n- Use ONLY the strengths listed under MATCHED EVIDENCE. Never claim a skill or experience that is not listed there.\n- Do not mention missing qualifications.\n- Under 170 words. Friendly and professional. No buzzwords.\n- Start with a line \"Subject: ...\" then a blank line, then the email body.\n- Address it to \"Hello [Hiring Manager],\" and sign off with \"[Your Name]\".\n\nJOB TITLE: {{ $json.jobTitle }}\nCOMPANY: {{ $json.company }}\n\nMATCHED EVIDENCE:\n{{ $json.matchedEvidence }}"
      }
    },
    {
      "id": "6d701339-0164-4b69-8e94-83620ced4eae",
      "name": "qwen2.5 14B (drafting)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [2240, 320],
      "parameters": {
        "model": "qwen2.5:14b-instruct-q5_K_M",
        "options": { "temperature": 0.4, "numCtx": 4096, "keepAlive": "10m" }
      }
    },
    {
      "id": "2e0af33e-6a31-4675-a52e-2aa773da24a2",
      "name": "Score Below 70?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [2520, 100],
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose" },
          "conditions": [
            {
              "leftValue": "={{ $('Score Coverage').first().json.score }}",
              "operator": { "type": "number", "operation": "lt" },
              "rightValue": 70
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "89c0820a-a793-49a7-9a06-3c4b20c6c065",
      "name": "Mark Manual Review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [2760, 0],
      "parameters": {
        "mode": "manual",
        "includeOtherFields": false,
        "assignments": {
          "assignments": [
            {
              "id": "rs",
              "name": "reviewStatus",
              "type": "string",
              "value": "={{ 'Manual review: score ' + $('Score Coverage').first().json.score + ' is below 70' + ($('Score Coverage').first().json.parseError ? ' (' + $('Score Coverage').first().json.parseError + ')' : '') }}"
            }
          ]
        }
      }
    },
    {
      "id": "d39a5fba-1c81-4fe1-b94a-2b7bd13221a3",
      "name": "Mark Ready For Review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [2760, 200],
      "parameters": {
        "mode": "manual",
        "includeOtherFields": false,
        "assignments": {
          "assignments": [
            {
              "id": "rs",
              "name": "reviewStatus",
              "type": "string",
              "value": "Strong match: review the draft, then send it yourself"
            }
          ]
        }
      }
    },
    {
      "id": "ef6a4847-a422-47a2-a0fe-bd47ea3d850e",
      "name": "Create Follow-Up Doc",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [3000, 100],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "file",
        "operation": "createFromText",
        "content": "={{ 'Follow-up draft: ' + $('Score Coverage').first().json.jobTitle + ' at ' + $('Score Coverage').first().json.company + '\\n\\n' + 'Coverage score: ' + $('Score Coverage').first().json.score + ' / 100\\n' + 'Status: ' + $json.reviewStatus + '\\n' + 'Missing: ' + $('Score Coverage').first().json.missingQualifications + '\\n' + 'Partial: ' + $('Score Coverage').first().json.partialQualifications + '\\n\\n' + '--- DRAFT: review and edit before sending ---\\n\\n' + $('Draft Follow-Up').first().json.text.trim() + '\\n' }}",
        "name": "={{ 'Follow-up - ' + $('Score Coverage').first().json.company + ' - ' + $('Score Coverage').first().json.jobTitle + ' - ' + $now.setZone('America/New_York').toFormat('yyyy-MM-dd') }}",
        "driveId": { "__rl": true, "mode": "list", "value": "My Drive" },
        "folderId": { "__rl": true, "mode": "list", "value": "root", "cachedResultName": "/ (Root folder)" },
        "options": { "convertToGoogleDocument": true }
      }
    },
    {
      "id": "30e7da39-3aae-4ab8-a1fe-1efb6d424bb4",
      "name": "Log To Review Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [3480, 100],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "authentication": "oAuth2",
        "documentId": { "__rl": true, "mode": "id", "value": "YOUR_GOOGLE_SHEET_ID" },
        "sheetName": { "__rl": true, "mode": "name", "value": "Applications" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Date": "={{ $now.setZone('America/New_York').toFormat('yyyy-MM-dd HH:mm') }}",
            "Job Title": "={{ $('Score Coverage').first().json.jobTitle }}",
            "Company": "={{ $('Score Coverage').first().json.company }}",
            "Source": "={{ $('Score Coverage').first().json.source }}",
            "Score": "={{ $('Score Coverage').first().json.score }}",
            "Missing Qualifications": "={{ $('Score Coverage').first().json.missingQualifications }}",
            "Partial Qualifications": "={{ $('Score Coverage').first().json.partialQualifications }}",
            "Review Status": "={{ $('Mark Manual Review').isExecuted ? $('Mark Manual Review').first().json.reviewStatus : $('Mark Ready For Review').first().json.reviewStatus }}",
            "Follow-Up Doc": "={{ 'https://docs.google.com/document/d/' + $('Create Follow-Up Doc').first().json.id + '/edit' }}"
          },
          "schema": [
            { "id": "Date", "displayName": "Date", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Job Title", "displayName": "Job Title", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Company", "displayName": "Company", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Source", "displayName": "Source", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Score", "displayName": "Score", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Missing Qualifications", "displayName": "Missing Qualifications", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Partial Qualifications", "displayName": "Partial Qualifications", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Review Status", "displayName": "Review Status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true },
            { "id": "Follow-Up Doc", "displayName": "Follow-Up Doc", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Job Application Form": { "main": [[{ "node": "Prepare Form Submission", "type": "main", "index": 0 }]] },
    "Prepare Form Submission": { "main": [[{ "node": "Extract Resume Text (Tika)", "type": "main", "index": 0 }]] },
    "Extract Resume Text (Tika)": { "main": [[{ "node": "Combine Application Text", "type": "main", "index": 0 }]] },
    "Watch Job Folder": { "main": [[{ "node": "Read Job File", "type": "main", "index": 0 }]] },
    "Read Job File": { "main": [[{ "node": "Extract Job Text (Tika)", "type": "main", "index": 0 }]] },
    "Extract Job Text (Tika)": { "main": [[{ "node": "Read Master Resume", "type": "main", "index": 0 }]] },
    "Read Master Resume": { "main": [[{ "node": "Prepare Folder Submission", "type": "main", "index": 0 }]] },
    "Prepare Folder Submission": { "main": [[{ "node": "Extract Resume Text (Tika)", "type": "main", "index": 0 }]] },
    "Combine Application Text": { "main": [[{ "node": "Analyze Requirements", "type": "main", "index": 0 }]] },
    "Analyze Requirements": { "main": [[{ "node": "Score Coverage", "type": "main", "index": 0 }]] },
    "qwen2.5 14B (analysis)": { "ai_languageModel": [[{ "node": "Analyze Requirements", "type": "ai_languageModel", "index": 0 }]] },
    "Score Coverage": { "main": [[{ "node": "Draft Follow-Up", "type": "main", "index": 0 }]] },
    "Draft Follow-Up": { "main": [[{ "node": "Score Below 70?", "type": "main", "index": 0 }]] },
    "qwen2.5 14B (drafting)": { "ai_languageModel": [[{ "node": "Draft Follow-Up", "type": "ai_languageModel", "index": 0 }]] },
    "Score Below 70?": {
      "main": [
        [{ "node": "Mark Manual Review", "type": "main", "index": 0 }],
        [{ "node": "Mark Ready For Review", "type": "main", "index": 0 }]
      ]
    },
    "Mark Manual Review": { "main": [[{ "node": "Create Follow-Up Doc", "type": "main", "index": 0 }]] },
    "Mark Ready For Review": { "main": [[{ "node": "Create Follow-Up Doc", "type": "main", "index": 0 }]] },
    "Create Follow-Up Doc": { "main": [[{ "node": "Log To Review Sheet", "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "nodeGroups": [
    { "id": "7bf1b17a-c51c-456b-90ef-b78b4ca89f8a", "name": "Form intake", "nodeNames": ["Prepare Form Submission"], "description": "Takes the pasted job description and the uploaded resume from the form" },
    { "id": "8955de7e-9106-4585-a7f1-77e035d5f638", "name": "Watched folder intake", "nodeNames": ["Read Job File", "Extract Job Text (Tika)", "Read Master Resume", "Prepare Folder Submission"], "description": "Reads a job .txt dropped in the inbox folder, extracts it with Tika and pairs it with the master resume" },
    { "id": "3ea34e12-b183-47d2-912d-01ca81c2806e", "name": "Extract with Tika", "nodeNames": ["Extract Resume Text (Tika)", "Combine Application Text"], "description": "Apache Tika pulls plain text out of the resume (PDF, Word or text)" },
    { "id": "95ba2565-fc59-426d-b06e-520f0441d94d", "name": "Analyze and score", "nodeNames": ["Analyze Requirements", "qwen2.5 14B (analysis)", "Score Coverage"], "description": "Local qwen2.5 lists each requirement as met, partial or missing; a Code node turns that into a 0-100 score" },
    { "id": "4236beca-8f42-442e-b998-a64fc0a0b0e2", "name": "Draft follow-up", "nodeNames": ["Draft Follow-Up", "qwen2.5 14B (drafting)"], "description": "Local qwen2.5 writes a follow-up email using only the matched evidence" },
    { "id": "52248e10-1ed1-4f8f-aeca-837433c6a1c3", "name": "Review and save", "nodeNames": ["Score Below 70?", "Mark Manual Review", "Mark Ready For Review", "Create Follow-Up Doc", "Log To Review Sheet"], "description": "Scores under 70 are flagged for manual review; every draft becomes its own Google Doc and a row in the sheet" }
  ]
}
