Cover Letter Generation
Relevant source files
The following files were used as context for generating this wiki page:- apps/backend/app/services/cover_letter.py
- apps/backend/app/prompts/templates.py
- apps/backend/app/routers/resumes.py
- apps/frontend/components/builder/resume-builder.tsx
- apps/frontend/components/builder/cover-letter-editor.tsx
- apps/frontend/lib/api/resume.ts
- apps/frontend/app/print/cover-letter/[id]/page.tsx
- apps/frontend/app/(default)/settings/page.tsx
The Cover Letter Generation feature provides users with an AI-powered tool to create brief, tailored cover letters based on their resume and a specific job description. This functionality is integrated into the resume tailoring workflow and the main resume builder interface, allowing for both automatic and on-demand generation.
The system is designed to produce concise, professional cover letters that highlight the most relevant qualifications from the candidate's resume. Users can enable or disable this feature, edit the generated content, and download the final cover letter as a PDF.
Sources: README.md:80-82, apps/frontend/app/(default)/settings/page.tsx:288-295
Feature Configuration
Users can enable or disable automatic cover letter generation from the application's settings page. A toggle switch controls this feature.
- Enable Cover Letter: When checked, a cover letter is automatically generated alongside a tailored resume during the
/resumes/improveprocess.
This setting is managed via the updateFeatureConfig API call, which persists the user's choice on the backend.
Sources: apps/frontend/app/(default)/settings/page.tsx:288-295, apps/backend/app/routers/resumes.py:220-221
The diagram below shows the simple configuration flow.
Backend Architecture
The backend, built with FastAPI, manages the core logic for generating, storing, and retrieving cover letters.
Sources: apps/backend/app/routers/resumes.py, apps/backend/app/services/cover_letter.py
API Endpoints
Several API endpoints in resumes.py are dedicated to cover letter functionality.
| Method | Endpoint | Description |
|---|---|---|
POST | /resumes/improve | If enabled, generates a cover letter in parallel with resume tailoring and stores it. |
POST | /resumes/{resume_id}/generate-cover-letter | Generates a cover letter on-demand for an existing tailored resume. |
PATCH | /resumes/{resume_id}/cover-letter | Updates the cover letter content for a specific resume. |
GET | /resumes/{resume_id}/cover-letter/pdf | Generates and returns a PDF of the cover letter. |
Sources: apps/backend/app/routers/resumes.py:207-302, 492-501, 574-633, 731-759
Service Layer & LLM Prompting
The generation logic resides in apps/backend/app/services/cover_letter.py. The generate_cover_letter function orchestrates the call to the LLM.
It uses the COVER_LETTER_PROMPT from apps/backend/app/prompts/templates.py. This prompt provides strict instructions to the LLM to ensure the output is high-quality and meets specific requirements.
# apps/backend/app/prompts/templates.py:117-142
COVER_LETTER_PROMPT = """Write a brief cover letter for this job application.
IMPORTANT: Write in {output_language}.
Job Description:
{job_description}
Candidate Resume (JSON):
{resume_data}
Requirements:
- 100-150 words maximum
- 3-4 short paragraphs
- Opening: Reference ONE specific thing from the job description (product, tech stack, or problem they're solving) - not generic excitement about "the role"
- Middle: Pick 1-2 qualifications from resume that DIRECTLY match stated requirements - prioritize relevance over impressiveness
- Closing: Simple availability to discuss, no desperate enthusiasm
- If resume shows career transition, frame the pivot as intentional and relevant
- Extract company name from job description - do not use placeholders
- DO NOT invent information not in the resume
- Tone: Confident peer, not eager applicant
- Do NOT use em dash ("—") anywhere in the writing/output, even if it exists, remove it
Output plain text only. No JSON, no markdown formatting."""
Sources: apps/backend/app/prompts/templates.py:117-142
On-Demand Generation Flow
The on-demand generation allows a user to create a cover letter for an already-tailored resume.
The following sequence diagram illustrates the on-demand generation process initiated from the frontend.
Frontend Architecture
The frontend provides the user interface for interacting with the cover letter feature, including editing, previewing, and triggering generation.
Key UI Components
The functionality is primarily managed within the ResumeBuilder component and its children.
| Component | File | Description |
|---|---|---|
ResumeBuilder | resume-builder.tsx | Main component that manages state for tabs, content, and actions like generating, saving, and downloading. |
CoverLetterEditor | cover-letter-editor.tsx | A textarea-based editor for modifying the generated cover letter content. It includes word/character counts. |
CoverLetterPreview | cover-letter-preview.tsx | Renders a preview of the cover letter with the user's personal information in the header. |
GeneratePrompt | generate-prompt.tsx | A placeholder component shown when no cover letter exists, prompting the user to generate one. |
ConfirmDialog | confirm-dialog.tsx | Used to confirm with the user before regenerating a cover letter, preventing accidental loss of edits. |
Sources: apps/frontend/components/builder/resume-builder.tsx, apps/frontend/components/builder/cover-letter-editor.tsx, apps/frontend/components/builder/cover-letter-preview.tsx
State Management
In resume-builder.tsx, several useState hooks manage the cover letter's lifecycle:
coverLetter: Stores the string content of the cover letter.isCoverLetterSaving: Tracks the saving state for the editor.isGeneratingCoverLetter: Tracks the loading state during on-demand generation.showRegenerateDialog: Manages the visibility of the confirmation dialog before overwriting existing content.
When a user edits the content, the onChange callback in CoverLetterEditor updates the coverLetter state in the parent ResumeBuilder.
Sources: apps/frontend/components/builder/resume-builder.tsx:68-69, 75-79, 336-344
PDF Generation
The application can export the final cover letter as a PDF. This process involves both the backend and frontend.
PDF Generation Flow
When a user clicks the "Download" button for a cover letter, the backend uses a headless browser (Playwright) to render a special, print-only frontend page and save it as a PDF.
This diagram shows the PDF generation sequence.
The print page at apps/frontend/app/print/cover-letter/[id]/page.tsx is a minimal React component that fetches the cover letter data and renders it with basic styling suitable for a formal document. It includes the user's name and contact details in the header, the current date, and the formatted paragraphs of the letter.
Sources: apps/frontend/app/print/cover-letter/[id]/page.tsx:55-179