Open-source competitive programming problem analyzer
Paste a URL β Get a step-by-step solution with complexity analysis, code, and interview tips.
- What It Does
- Supported Platforms
- Choose Your LLM
- Quick Start
- Configuration
- Project Structure
- How the Analysis Pipeline Works
- API Reference
- Tech Stack
- Contributing
- Troubleshooting
- License
SolveTrace takes a competitive programming problem (via URL or pasted text) and generates a comprehensive analysis:
- Auto-scrapes the problem statement, examples, input/output constraints
- Queries a RAG knowledge base of 30+ algorithm patterns for relevant techniques
- Sends everything to your chosen LLM with a carefully crafted prompt
- Returns a structured breakdown:
- π’ Step-by-step approach with reasoning
- β±οΈ Time & space complexity with explanations
- π» Clean, well-commented code solution
- π‘ Key insights & common pitfalls
- π Related problems from other platforms
- π Interview tips
| Platform | Scraping | Example URL |
|---|---|---|
| Codeforces | β Full support | codeforces.com/problemset/problem/1/A |
| LeetCode | β Full support | leetcode.com/problems/two-sum |
| AtCoder | β Full support | atcoder.jp/contests/abc001/tasks/abc001_1 |
| HackerRank | β Full support | hackerrank.com/challenges/solve-me-first |
You can also paste problem text directly if your platform isn't supported.
SolveTrace supports 3 LLM providers β pick the one that fits your needs:
| Provider | Type | Cost | Setup | Best For |
|---|---|---|---|---|
| Ollama | Local | Free | Install Ollama + pull a model | Privacy, offline use, no API costs |
| Google Gemini | Cloud API | Free tier available | Get API key from Google AI Studio | Fast, generous free tier |
| OpenAI | Cloud API | Paid | Get API key from OpenAI | GPT-4o quality |
Ollama lets you run AI models locally on your machine β completely free, no API key needed.
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh # Linux/macOS
# Windows: download from https://ollama.com/download
# Pull a coding-optimized model (recommended)
ollama pull qwen2.5-coder:7b
# Or use a larger model for better quality
ollama pull qwen2.5-coder:14b
ollama pull llama3.1:8b
ollama pull codellama:13b- Go to Google AI Studio
- Create an API key (free tier: 15 requests/minute)
- Set
GEMINI_API_KEY=your_key_hereinbackend/.env - Set
LLM_PROVIDER=geminiinbackend/.env
- Go to OpenAI API Keys
- Create an API key (requires billing setup)
- Set
OPENAI_API_KEY=your_key_hereinbackend/.env - Set
LLM_PROVIDER=openaiinbackend/.env
| Software | Version | Download |
|---|---|---|
| Python | 3.11+ | python.org |
| Node.js | 18+ | nodejs.org |
| Git | Any | git-scm.com |
| Ollama (or API key) | Latest | ollama.com |
# 1. Clone the repository
git clone https://github.com/rafaelcapeloo/SolveTrace.git
cd SolveTrace
# 2. Setup Backend
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# 3. Configure your LLM provider
cp .env.example .env
nano .env # or use your preferred editor
# β Set LLM_PROVIDER to "ollama", "gemini", or "openai"
# β Set the corresponding API key if using a cloud provider
# 4. Start the backend server
uvicorn app.main:app --reload --port 8000
# 5. Open a new terminal tab, setup Frontend
cd ../frontend
npm install
npm run devOpen http://localhost:3000 and start analyzing! π
# 1. Clone the repository
git clone https://github.com/rafaelcapeloo/SolveTrace.git
cd SolveTrace
# 2. Setup Backend
cd backend
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
# 3. Configure your LLM provider
copy .env.example .env
notepad .env
# β Set LLM_PROVIDER to "ollama", "gemini", or "openai"
# β Set the corresponding API key if using a cloud provider
# 4. Start the backend server
uvicorn app.main:app --reload --port 8000
# 5. Open a new terminal window, setup Frontend
cd ..\frontend
npm install
npm run devOpen http://localhost:3000 and start analyzing! π
Note for Windows users: If
uvicornis not recognized, trypython -m uvicorn app.main:app --reload --port 8000
All configuration is done through the backend/.env file. Here's a complete reference:
# ===========================
# LLM Provider Configuration
# ===========================
# Which LLM to use: "ollama" (local), "gemini" (Google), or "openai"
LLM_PROVIDER=ollama
# --- Ollama (Local) ---
# Make sure Ollama is running: ollama serve
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=qwen2.5-coder:7b
# --- Google Gemini ---
# Get your key: https://aistudio.google.com/apikey
GEMINI_API_KEY=
GEMINI_MODEL=gemini-2.0-flash
# --- OpenAI ---
# Get your key: https://platform.openai.com/api-keys
OPENAI_API_KEY=
OPENAI_MODEL=gpt-4o-mini
# ===========================
# Server Configuration
# ===========================
# SQLite database for caching scraped problems and analyses
DATABASE_URL=sqlite+aiosqlite:///./solvetrace.db
# Frontend URL (for CORS)
CORS_ORIGINS=http://localhost:3000,http://localhost:5173
# Set to true for verbose SQL and debug logging
DEBUG=falseYou can switch providers at any time by changing the LLM_PROVIDER value and restarting the backend. You can also switch providers from the UI using the LLM Provider dropdown on the Solve page β providers with a β are configured and ready, while providers with β need their API key set in .env.
SolveTrace/
βββ backend/ # FastAPI Python backend
β βββ app/
β β βββ api/
β β β βββ analysis.py # POST /api/analyze β main analysis endpoint
β β β βββ problems.py # GET /api/problems β browse cached problems
β β βββ models/
β β β βββ analysis.py # Analysis SQLAlchemy model (stores LLM results)
β β β βββ problem.py # Problem model (caches scraped data)
β β βββ schemas/
β β β βββ analysis.py # Pydantic request/response schemas
β β βββ services/
β β β βββ analyzer.py # π§ Core pipeline: Scrape β RAG β LLM β Store
β β β βββ llm/
β β β β βββ gemini.py # Google Gemini API client
β β β β βββ ollama.py # Local Ollama client
β β β β βββ openai_client.py # OpenAI GPT client
β β β β βββ parser.py # JSON response parser + validator
β β β β βββ prompts.py # LLM prompt templates
β β β βββ rag/
β β β β βββ knowledge.py # 30+ algorithm pattern definitions
β β β β βββ vectorstore.py # Lightweight vector store (Gemini embeddings / keyword fallback)
β β β βββ scraper/
β β β βββ base.py # Base scraper interface
β β β βββ codeforces.py # Codeforces scraper
β β β βββ leetcode.py # LeetCode scraper
β β β βββ atcoder.py # AtCoder scraper
β β β βββ hackerrank.py # HackerRank scraper
β β βββ utils/
β β β βββ helpers.py # URL parsing, language validation
β β βββ config.py # Settings from environment variables
β β βββ database.py # Async SQLAlchemy + SQLite setup
β β βββ main.py # FastAPI app entry point
β βββ .env.example # Configuration template
β βββ requirements.txt # Python dependencies
β
βββ frontend/ # Next.js React frontend
β βββ src/
β βββ app/
β β βββ page.tsx # Landing page
β β βββ page.module.css # Landing styles
β β βββ solve/
β β βββ page.tsx # π― Main solve page (URL input, results, code)
β β βββ page.module.css # Solve page styles
β βββ components/
β β βββ layout/
β β βββ Navbar.tsx # Navigation bar
β β βββ Navbar.module.css # Navbar styles
β βββ services/
β β βββ api.ts # API client (fetch wrapper)
β βββ types/
β βββ index.ts # TypeScript interfaces
β
βββ README.md # This file
User Input (URL or text)
β
βΌ
βββββββββββββββββββ
β 1. SCRAPE β Auto-detect platform β scrape title, statement,
β or PARSE β examples, constraints, tags, difficulty
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β 2. CACHE CHECK β Check SQLite DB β if this problem was already
β β analyzed in the same language, return cached result
ββββββββββ¬βββββββββ
β (cache miss)
βΌ
βββββββββββββββββββ
β 3. RAG QUERY β Query 30+ algorithm patterns (DP, graphs, greedy...)
β β using embeddings or keyword matching
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β 4. LLM CALL β Build structured prompt with problem + RAG context
β β β Send to Ollama / Gemini / OpenAI
β β β Parse JSON response
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β 5. STORE & RETURNβ Save analysis to SQLite β return structured result
β β with approach, complexity, code, insights, tips
βββββββββββββββββββ
Analyze a competitive programming problem.
Request Body:
{
"url": "https://codeforces.com/problemset/problem/1/A",
"problem_text": null,
"language": "python",
"provider": "ollama",
"model": null
}| Field | Type | Required | Description |
|---|---|---|---|
url |
string | One of url/problem_text | Problem URL |
problem_text |
string | One of url/problem_text | Raw problem text |
language |
string | No (default: python) | Solution language |
provider |
string | No | Override LLM provider |
model |
string | No | Override model name |
Response: Full analysis with approach steps, complexity, code, insights, tips.
Retrieve a previously generated analysis by ID.
Get available LLM providers and their configuration status.
List cached scraped problems. Optional ?platform= filter.
Health check β returns status and current LLM provider.
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 14+, TypeScript | UI, routing, SSR |
| Styling | CSS Modules | Scoped component styles |
| Syntax Highlighting | highlight.js | Code block rendering |
| Backend | FastAPI, Python 3.11+ | API, analysis pipeline |
| Database | SQLAlchemy (async) + SQLite | Cache & persistence |
| Scraping | httpx + BeautifulSoup4 | Platform-specific scrapers |
| RAG | Custom vector store | Algorithm pattern matching |
| LLM (Local) | Ollama | Run models locally |
| LLM (Cloud) | Google Gemini / OpenAI | Cloud API models |
Contributions are welcome! Here are some ideas:
- Add more algorithm patterns to
backend/app/services/rag/knowledge.py - Improve LLM prompts in
backend/app/services/llm/prompts.py - Add more supported languages
- Add scrapers for more platforms (SPOJ, UVa, DMOJ, Kattis)
- Add localStorage-based history in the frontend
- Add problem comparison (side-by-side analysis)
- Add export to PDF/Markdown
- Add more LLM providers (Anthropic Claude, Mistral, Groq)
- Add WebSocket streaming for real-time analysis progress
- Add a VS Code extension
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Test locally (both frontend and backend)
- Submit a pull request
ModuleNotFoundError: No module named 'app'
Fix: Make sure you're running from the backend/ directory and your virtual environment is activated.
httpx.ConnectError: [Errno 111] Connection refused
Fix: Make sure Ollama is running. Start it with:
ollama serve # Start the Ollama server
ollama pull qwen2.5-coder:7b # Pull a model if not done yetValueError: LLM analysis failed (Gemini): 403 ...
Fix: Check that your API key is correct in backend/.env and that you have sufficient quota/credits.
TypeError: Failed to fetch
Fix: Make sure the backend is running on port 8000 and that CORS_ORIGINS in .env includes your frontend URL (http://localhost:3000).
LeetCode uses client-side rendering, which makes scraping harder. If scraping fails, try pasting the problem text directly using the "Paste Problem" mode.
MIT β use it however you want.
Built with β by @rafaelcapeloo