Coderefine is a web-based tool that helps you refine, understand, and improve code using an AI assistant powered by Groq. It supports major languages (Python, JavaScript, Java, C, C++, Rust, etc.), provides a modern code editor, and offers an integrated chat to answer questions about your code.
The project is split into:
backend– Python FastAPI service that talks to Groq and Supabase.frontend– HTML/CSS/JS single-page web app with a CodeMirror editor and AI chat panel.
- Python 3.10+
- Node is not required (frontend is plain HTML/CSS/JS).
- A Groq API key
- (Optional) Supabase project URL and anon key, plus tables:
refinementswith columns:id,language,original_code,refined_code,summary,created_at.chatswith columns:id,language,code_context,messages(JSON),reply,created_at.
-
Open a terminal in the
backendfolder:cd backend -
Create and activate a virtual environment (recommended):
python -m venv .venv .venv\Scripts\activate # On Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables (PowerShell examples):
$env:GROQ_API_KEY = "your_groq_api_key_here" $env:SUPABASE_URL = "https://your-project.supabase.co" $env:SUPABASE_ANON_KEY = "your_supabase_anon_key"
Supabase variables are optional. If they are not set, Coderefine will still work, but refinements and chats will not be persisted.
-
Run the backend:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Verify it is healthy by opening:
http://localhost:8000/health
-
Open the
frontendfolder in your editor. -
You can serve
index.htmlusing any static server, or simply open it directly in your browser:-
Option A (recommended): use
python -m http.serverfrom the project root orfrontendfolder.cd frontend python -m http.server 5173Then open
http://localhost:5173in your browser. -
Option B: double-click
index.htmland open it directly. Some browsers may block cross-origin calls when opened as afile://URL, so a local HTTP server is usually more reliable.
-
-
Make sure the backend is running at
http://localhost:8000(this is what the frontend expects by default; you can changeAPI_BASEinfrontend/main.jsif needed).
- Full-screen layout: Sidebar navigation, top command bar, main editor, and a right-side AI assistant panel so the full screen is used efficiently.
- Code editor:
- Powered by CodeMirror with line numbers and syntax highlighting.
- Supports Python, JavaScript, Java, C, C++, Rust (and falls back gracefully for others).
- Quick metrics strip (line count and rough complexity heuristic).
- Theme system:
- Midnight (dark, blue/purple accents),
- Cloud (light),
- Nebula (purple-focused).
- AI refinement:
- Send the current code and goal (readability, performance, production hardening, documentation) to the backend.
- Backend calls Groq (
llama-3.3-70b-versatile) to generate refined code and a short explanation + suggestions. - Suggestions are displayed in an “Insights” panel.
- AI chat assistant:
- Floating 🤖 icon next to the editor to open/close the assistant on small screens.
- Ask questions about the code in the editor; responses are powered by Groq.
- Persistence:
- Local: save/load your latest snippet to/from
localStoragewith one click. - Remote (optional): if Supabase is configured, refinements and chat sessions are also stored in the
refinementsandchatstables.
- Local: save/load your latest snippet to/from
- Wire the “History” and “Playground” nav items to real views powered by Supabase history.
- Replace the placeholder diff behavior with a real side‑by‑side diff viewer.
- Add per-language formatting via external tools (e.g., Black for Python, Prettier for JS) by extending the backend.
- Hook up authentication (via Supabase Auth) so refinements are per-user.
- This project is intentionally minimal in tooling (no build step) so you can explore and extend it easily.
- If you change the backend port or host, update
API_BASEinfrontend/main.js.