Backend Project Structure
Relevant source files
The following files were used as context for generating this wiki page:The Resume Matcher backend is a lean FastAPI application designed for AI-powered resume processing, data management, and serving API endpoints for the Next.js frontend. Its architecture emphasizes modularity, with a clear separation of concerns between API routing, business logic, data storage, and AI integration. The backend supports multiple AI providers through a unified interface and uses a simple JSON-based database for data persistence.
This structure allows for easy maintenance and extension. For more detailed information on the API contracts and architecture, refer to the project's internal documentation, such as backend-guide.md and backend-architecture.md.
Sources: AGENTS.md:27-35, SETUP.md:213-233
Directory and Module Overview
The backend code is located in the apps/backend/ directory. The structure is organized to separate different functionalities into distinct modules, following common practices for FastAPI applications.
Sources: AGENTS.md:27, SETUP.md:214
This diagram shows the high-level directory structure of the backend application.
Sources: SETUP.md:213-233, AGENTS.md:27-35
The table below describes the purpose of each key file and directory.
| Path | Description |
|---|---|
app/main.py | The main FastAPI application entry point. It handles application startup, CORS configuration, and includes the API routers. |
app/config.py | Manages application configuration using Pydantic settings, loading values from environment variables. |
app/database.py | A wrapper for the TinyDB library, providing a simple interface for JSON-based data storage. |
app/llm.py | A wrapper around LiteLLM that provides a unified interface for interacting with various AI providers (OpenAI, Ollama, etc.). It includes features like JSON mode, retry logic, and robust JSON extraction. |
app/routers/ | Contains API endpoint definitions, with each file corresponding to a specific resource (e.g., resumes, jobs, config). |
app/services/ | Holds the core business logic, such as resume parsing (parser.py) and content improvement (improver.py). |
app/schemas/ | Defines Pydantic models for data validation, serialization, and ensuring API contracts with the frontend. |
app/prompts/ | Stores and manages the prompt templates used for communicating with the LLMs. |
data/ | The directory where the TinyDB JSON database files are automatically created and stored. |
pyproject.toml | Defines project metadata and Python dependencies, managed by uv. |
.env.example | A template for the environment variables file (.env) required to run the backend. |
Sources: AGENTS.md:29-35, SETUP.md:217-229, INSTALL.md:103-111
Core Components
Application Entry Point
The app/main.py file initializes the FastAPI application. It sets up CORS (Cross-Origin Resource Sharing) middleware to allow requests from the frontend and includes all the API routers defined in the app/routers/ directory. It also defines shutdown logic to gracefully close resources like the database and PDF renderer.
Sources: AGENTS.md:29, REPORT.md:73-74
LLM Integration
The app/llm.py module is central to the backend's AI capabilities. It uses the litellm library to create a provider-agnostic interface for making calls to various Large Language Models.
Key features include:
- Multi-Provider Support: Can connect to OpenAI, Anthropic, Gemini, OpenRouter, DeepSeek, and local Ollama instances.
- JSON Mode: Automatically enables JSON output format for supported models to ensure structured data responses.
- Retry Logic: Implements automatic retries with a lower temperature for JSON completion calls to improve reliability.
- Robust JSON Extraction: Contains a custom parser (
_extract_json()) to handle malformed LLM responses, including those wrapped in markdown code blocks. - Asynchronous Safety: Passes API keys directly to
litellm.acompletion()calls to avoid race conditions with global environment variables in an async context.
Sources: AGENTS.md:113-125, REPORT.md:67-69
Prompt Management
All LLM prompts are centralized in the app/prompts/ directory, primarily within templates.py and enrichment.py. This separation makes it easy to manage and update the instructions given to the AI.
templates.py: Contains prompts for core tasks like parsing a resume (PARSE_RESUME_PROMPT), improving a resume (IMPROVE_RESUME_PROMPT), and generating cover letters (COVER_LETTER_PROMPT).enrichment.py: Holds prompts specific to the resume enrichment feature, such as analyzing a resume for weaknesses (ANALYZE_RESUME_PROMPT) and enhancing descriptions (ENHANCE_DESCRIPTION_PROMPT).
The prompts use f-string style placeholders (e.g., {resume_text}) for dynamic value substitution.
Sources: AGENTS.md:35, apps/backend/app/prompts/templates.py, apps/backend/app/prompts/enrichment.py
An example of a prompt template for parsing a resume:
# apps/backend/app/prompts/templates.py:90-109
PARSE_RESUME_PROMPT = """Parse this resume into JSON. Output ONLY the JSON object, no other text.
Map content to standard sections when possible. For non-standard sections (like Publications, Volunteer Work, Research, Hobbies), add them to customSections with an appropriate type.
Example output format:
{schema}
Custom section types:
- "text": Single text block (e.g., objective, statement)
- "itemList": List of items with title, subtitle, years, description (e.g., publications, research)
- "stringList": Simple list of strings (e.g., hobbies, interests)
Rules:
- Use "" for missing text fields, [] for missing arrays, null for optional fields
- Number IDs starting from 1
- Format years as "YYYY - YYYY" or "YYYY - Present"
- Use snake_case for custom section keys (e.g., "volunteer_work", "publications")
- Preserve the original section name as a descriptive key
- Normalize dates: "Jan 2020" → "2020", "2020-2021" → "2020 - 2021", "Current"/"Ongoing" → "Present"
- For ambiguous dates like "3 years experience", infer approximate years from context or use "~YYYY"
- Flag overlapping dates (concurrent roles) by preserving both, don't merge
Resume to parse:
{resume_text}"""
Sources: apps/backend/app/prompts/templates.py:90-109
Database
The application uses TinyDB, a lightweight, document-oriented database that stores data in a JSON file. The app/database.py module acts as a wrapper around TinyDB, providing specific methods for resume and job-related CRUD operations. All data is stored in the apps/backend/data/ directory.
Sources: AGENTS.md:31, SETUP.md:205-211
Request Flow
The following diagram illustrates a typical request flow, for example, when a user uploads a resume to be parsed.
Dependencies
The backend relies on a minimal set of powerful libraries, managed by uv and defined in pyproject.toml.
| Package | Purpose |
|---|---|
fastapi | The main web framework for building APIs. |
uvicorn | An ASGI server to run the FastAPI application. |
python-multipart | Handles file uploads (e.g., resumes). |
pydantic & pydantic-settings | Used for data validation, serialization, and managing environment configurations. |
tinydb | A lightweight, document-oriented database that stores data in JSON files. |
litellm | A unified interface to call various LLM providers like OpenAI, Ollama, and Anthropic. |
markitdown | Converts PDF and DOCX files to Markdown for processing. |
python-dotenv | Loads environment variables from a .env file. |
Sources: install.txt:8-20, SETUP.md:229
Conclusion
The backend of Resume Matcher is architected as a modular and scalable FastAPI application. It effectively separates concerns into distinct layers for API routing, business logic (services), data modeling (schemas), AI interaction (LLM), and persistence (database). This clean structure, combined with its provider-agnostic AI integration and simple file-based database, makes the backend both powerful and easy to maintain for developers.
Sources: AGENTS.md:27-35