Skip to content

LovepreetSingh12/ai-debugger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🧠 AI Code Debugger

An intelligent backend service that executes Python code, detects errors, and explains them in plain English using AI. This project goes beyond basic error handling by providing root cause analysis, fixes, and improved code suggestions.


🚀 Features

  • ⚡ Execute Python code safely
  • ❌ Detect runtime & syntax errors
  • 🤖 AI-powered explanation of errors
  • 🛠 Suggested fixes with corrected code
  • 📊 Structured debugging output
  • 🌐 REST API using FastAPI

🏗️ Architecture

User Code
   ↓
Executor (subprocess sandbox)
   ↓
Error Capture
   ↓
AI Explanation Engine
   ↓
Structured Response

🧱 Tech Stack

  • Backend: FastAPI
  • Execution Engine: Python subprocess
  • AI Integration: OpenAI API
  • Language: Python 3.12

📦 Project Structure

ai-debugger/
 ├── main.py           # FastAPI entry point
 ├── executor.py       # Code execution logic
 ├── ai_explainer.py   # AI integration
 ├── requirements.txt  # Dependencies

⚙️ Setup Instructions

1. Clone the repo

git clone <your-repo-url>
cd ai-debugger

2. Create virtual environment

python -m venv venv

Activate:

Windows:

venv\Scripts\activate

Mac/Linux:

source venv/bin/activate

3. Install dependencies

pip install fastapi uvicorn openai

4. Set API key

export OPENAI_API_KEY="your_api_key_here"

5. Run server

python -m uvicorn main:app --reload

🧪 API Usage

Endpoint

POST /debug

Request Body

{
  "code": "print(10/0)"
}

Response (Error Case)

{
  "success": false,
  "error": "ZeroDivisionError: division by zero",
  "ai_explanation": "..."
}

Response (Success Case)

{
  "success": true,
  "output": "10"
}

🧠 Example

Input

print(10/0)

Output

  • Error detected
  • AI explains the issue
  • Suggested fix provided

🔐 Security Considerations

  • Uses subprocess with timeout to prevent infinite loops
  • Avoids direct exec() usage
  • Recommended: Add Docker sandbox for production

🔥 Future Improvements

  • 🧩 AST-based static analysis
  • 🧪 Auto test case generation
  • 🖥️ Frontend UI (React)
  • 🐳 Docker-based sandbox execution
  • 📈 Logging & monitoring
  • ⚡ Multi-language support

💡 Why This Project Matters

This project demonstrates:

  • Real-world problem solving
  • Backend system design
  • AI integration in developer tools
  • Error handling & observability

Perfect for:

  • SDE roles
  • Backend engineering
  • Freelancing projects

🤝 Contributing

Feel free to fork and improve the project.


📜 License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages