Welcome to the Code Reviewer project! This is the backend service that powers an AI-driven code analysis and simulated execution platform, leveraging Google's Generative AI (Gemini 2.5 Flash).
A Node.js/Express server that acts as a proxy and orchestrator for Google's Generative AI models. It exposes endpoints to:
- Analyze Code: Generate senior-level code reviews based on strict guidelines.
- Simulate Execution: Mimic a sandboxed online compiler (like Node.js, Python 3, GCC) and return structured runtime logs and errors.
The technical challenge lies in coercing a Large Language Model (LLM) to act as deterministic infrastructure. Rather than conversational output, the AI is constrained to act as a compiler that outputs strict JSON schemas, allowing the frontend to render dynamic terminal logs without requiring an actual Dockerized code execution environment.
- Backend: Node.js + Express, utilizing
@google/generative-aiSDK. Hosted on Render. - Frontend: React application, hosted on Netlify.
The AI's behavior is shaped by two distinct system instructions:
- Code Reviewer: Instructed to assume the role of a Senior Developer (7+ years experience) focusing on 6 pillars: Code Quality, Best Practices, Efficiency, Error Detection, Scalability, and Readability. The prompt enforces a strict output format containing categories:
Bad Code,Issues,Recommended Fix, andImprovements. - Compiler Simulation: Instructed to behave as a sandboxed execution engine. It analyzes the language, simulates execution line-by-line, and is strictly ordered to return a raw JSON object (without markdown).
Since LLMs can sometimes ignore formatting instructions, the backend implements robust parsing and fallback strategies in the executeCode controller:
- Sanitization: The
simulateExecutionservice strips unwanted Markdown artifacts (like ```json) from the raw AI response using Regex. - Validation: The controller attempts to
JSON.parse()the sanitized response expecting a specific schema:{ logs: [...], result: String, error: String }. - Graceful Fallback: If the AI's response is malformed and fails JSON parsing, the server does not retry (to save latency/cost). Instead, the
catchblock intercepts the failure and bundles the raw text into a safe fallback schema:{ "logs": [{ "type": "log", "text": "Raw LLM string output..." }], "result": null, "error": null }
This guarantees the API always returns a predictable schema, preventing frontend crashes.
- Node.js (version 16+ recommended)
- A Google Gemini API Key
git clone https://github.com/dineshkumar-mb/code-ReviewBackend
cd code-ReviewBackend
npm installCreate a .env file in the root directory:
GOOGLE_GEMINI_KEY=your_gemini_api_key
npm startContributions are welcome! Please fork the repo, create a feature branch, and submit a PR.
This project is licensed under the MIT License.