API Client
Relevant source files
The following files were used as context for generating this wiki page:The API Client is a collection of TypeScript modules within the apps/frontend/lib/api/ directory that serves as the exclusive communication layer between the Next.js frontend and the Python FastAPI backend. It abstracts all HTTP requests into a set of strongly-typed functions, providing a clear and maintainable interface for data fetching and manipulation.
The client is responsible for handling all interactions related to resumes, job descriptions, AI-powered content generation (tailoring, enrichment, cover letters), and application configuration. It centralizes API endpoint definitions, request/response logic, and error handling, ensuring consistency across the frontend application.
Sources: apps/frontend/lib/api/client.ts, apps/frontend/lib/api/index.ts
Core Architecture
The foundation of the API client is built in client.ts. It establishes the base configuration for all API calls and provides low-level utility functions for making HTTP requests.
Sources: apps/frontend/lib/api/client.ts
Configuration
The client's configuration is minimal, consisting of two exported constants that define the connection to the backend server.
API_URL: The base URL of the backend server, sourced from theNEXT_PUBLIC_API_URLenvironment variable. It defaults tohttp://localhost:8000.API_BASE: The full path to the versioned API endpoint, constructed by appending/api/v1toAPI_URL. All subsequent API calls are relative to this path.
// File: apps/frontend/lib/api/client.ts:6-7
export const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000';
export const API_BASE = `${API_URL}/api/v1`;
Sources: apps/frontend/lib/api/client.ts:6-7
Base Fetch Utilities
A set of wrapper functions around the native fetch API standardizes requests. The core function, apiFetch, handles URL construction, while helpers provide syntactic sugar for common HTTP methods.
This diagram illustrates the flow of a typical POST request from a UI component to the backend.
The primary functions in client.ts are:
| Function | Method | Description |
|---|---|---|
apiFetch(endpoint, options) | - | The core fetch wrapper. Prepends API_BASE to the endpoint and executes the request. |
apiPost(endpoint, body) | POST | Sends a POST request with a JSON body. |
apiPatch(endpoint, body) | PATCH | Sends a PATCH request with a JSON body. |
apiPut(endpoint, body) | PUT | Sends a PUT request with a JSON body. |
apiDelete(endpoint) | DELETE | Sends a DELETE request. |
getUploadUrl() | - | Returns the full URL for the file upload endpoint (/resumes/upload). |
Sources: apps/frontend/lib/api/client.ts:13-50
Module Organization
The API client is organized by feature, with specific functionality grouped into separate files. A central index.ts file exports all public functions, providing a single entry point for the rest of the application.
This diagram shows how index.ts acts as a facade, exporting functionality from specialized modules like resume.ts and enrichment.ts, which in turn rely on the base client.ts.
Sources: apps/frontend/lib/api/index.ts, AGENTS.md
Resume Management
All operations related to creating, reading, updating, and deleting resumes are handled by the functions in apps/frontend/lib/api/resume.ts. This module also manages related entities like job descriptions, cover letters, and PDF generation.
Key Functions
| Function | HTTP Method & Endpoint | Description |
|---|---|---|
fetchResumeList() | GET /resumes/list | Retrieves a list of all resumes. |
fetchResume(resumeId) | GET /resumes?resume_id={id} | Fetches the full data for a single resume. |
updateResume(resumeId, data) | PATCH /resumes/{id} | Updates the processed data of a resume. |
deleteResume(resumeId) | DELETE /resumes/{id} | Deletes a resume from the database. |
uploadJobDescriptions(desc, resumeId) | POST /jobs/upload | Uploads a job description associated with a resume. |
improveResume(resumeId, jobId) | POST /resumes/improve | Triggers the AI to tailor a resume for a specific job. |
downloadResumePdf(resumeId, settings) | GET /resumes/{id}/pdf | Generates and downloads a resume as a PDF file with specified template settings. |
generateCoverLetter(resumeId) | POST /resumes/{id}/generate-cover-letter | Generates a cover letter for a tailored resume. |
fetchJobDescription(resumeId) | GET /resumes/{id}/job-description | Fetches the job description associated with a tailored resume. |
Sources: apps/frontend/lib/api/resume.ts, AGENTS.md
Resume Tailoring Flow
The "Tailor Resume" feature involves a sequence of API calls to first upload a job description and then request an AI-improved version of the resume.
This sequence diagram shows the interaction between the user, the frontend API client, and the backend.
Resume Enrichment
The AI-powered resume enrichment feature is a multi-step process managed by functions in apps/frontend/lib/api/enrichment.ts. This workflow helps users enhance their master resume by answering targeted questions generated by an AI.
Sources: apps/frontend/lib/api/enrichment.ts, AGENTS.md
Data Structures
The enrichment process relies on specific data structures for communication between the frontend and backend.
AnalysisResponse: The result of the initial analysis, containing items to enrich, questions for the user, and a summary.// File: apps/frontend/lib/api/enrichment.ts:10-22 export interface AnalysisResponse { items_to_enrich: EnrichmentItem[]; questions: EnrichmentQuestion[]; analysis_summary?: string; }EnhancementPreview: The result after the user answers questions, containing the newly generated bullet points.
Sources: apps/frontend/lib/api/enrichment.ts:10-38
Enrichment Workflow
The wizard-like flow consists of three distinct API calls: analyzing the resume, generating enhancements based on user answers, and applying the changes.
This diagram shows the three-stage process of resume enrichment, from analysis to application.
Sources: apps/frontend/lib/api/enrichment.ts:44-93, AGENTS.md