Skip to content

Corpse-dead/AI-powered-Python-code-analyzer

Repository files navigation

πŸ€– Smart Code Review Assistant

An AI-powered Python code analyzer that uses machine learning to evaluate code quality, detect code smells, and provide actionable improvement suggestions.

Python FastAPI ML License

🌐 Live Demo

Coming Soon! Deploy to Railway, Render, or Heroku - see DEPLOYMENT.md

🌟 Features

  • πŸ“Š Static Code Analysis: Comprehensive metrics including cyclomatic complexity, maintainability index, and Halstead metrics
  • πŸ€– ML-Powered Quality Prediction: Machine learning model trained to predict code quality scores
  • πŸ” Code Smell Detection: Automatically detects common anti-patterns and code smells
  • πŸ’‘ Smart Suggestions: Provides actionable recommendations for code improvement
  • 🎨 Beautiful Web Interface: Modern, responsive UI for easy code submission and result visualization
  • πŸ“ˆ Detailed Metrics: Lines of code, complexity, documentation ratio, and more

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository:
git clone https://github.com/Corpse-dead/AI-powered-Python-code-analyzer.git
cd AI-powered-Python-code-analyzer
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
python app.py
  1. Open your browser and navigate to:
http://localhost:8000

πŸ“– Usage

Web Interface

  1. Upload a File: Click "Choose File" and select a Python (.py) file
  2. Paste Code: Copy and paste your Python code directly into the text area
  3. View Results: Get instant feedback with quality scores, metrics, and suggestions

API Endpoints

Analyze Uploaded File

curl -X POST "http://localhost:8000/api/analyze" \
  -F "file=@your_code.py"

Analyze Code Text

curl -X POST "http://localhost:8000/api/analyze-text" \
  -H "Content-Type: application/json" \
  -d '{"code": "def hello(): print(\"Hello, World!\")"}'

Health Check

curl "http://localhost:8000/api/health"

πŸ—οΈ Project Structure

smart-code-review/
β”œβ”€β”€ app.py                 # FastAPI application entry point
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ code_analyzer.py   # Static code analysis module
β”‚   └── ml_models.py       # ML-based quality prediction
β”œβ”€β”€ static/
β”‚   β”œβ”€β”€ index.html         # Web interface
β”‚   β”œβ”€β”€ styles.css         # Styling
β”‚   └── script.js          # Frontend logic
β”œβ”€β”€ requirements.txt       # Python dependencies
└── README.md             # This file

🎯 Metrics Explained

Code Metrics

  • Lines of Code (LOC): Total lines including comments and blanks
  • Logical Lines: Actual code lines (excluding comments/blanks)
  • Comment Ratio: Percentage of comments in code
  • Cyclomatic Complexity: Measure of code complexity
  • Maintainability Index: Overall code maintainability (0-100)

Quality Score

The ML model assigns a quality score (0-100) based on:

  • Code structure and organization
  • Naming conventions
  • Documentation quality
  • Complexity metrics
  • Best practices adherence

Letter Grades

  • A (85-100): Excellent code quality
  • B (70-84): Good code with minor improvements needed
  • C (55-69): Acceptable code, some refactoring recommended
  • D (40-54): Poor code, significant improvements needed
  • F (0-39): Very poor code, major refactoring required

πŸ”§ Technology Stack

  • Backend: FastAPI (Python web framework)
  • ML/AI: scikit-learn, RandomForest classifier
  • Code Analysis: Radon, AST, Pylint
  • Frontend: HTML5, CSS3, Vanilla JavaScript
  • API: RESTful API with JSON responses

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ Future Enhancements

  • Support for additional programming languages (JavaScript, Java, etc.)
  • Integration with GitHub for automatic PR reviews
  • Custom rule configuration
  • Historical analysis and trend tracking
  • VS Code extension
  • Docker containerization
  • Advanced NLP models (CodeBERT, GraphCodeBERT)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Created by a CS student passionate about AI/ML and code quality!

πŸ™ Acknowledgments

  • FastAPI for the excellent web framework
  • scikit-learn for ML capabilities
  • Radon for code metrics
  • The Python community for amazing tools and libraries

πŸ“§ Contact

Questions or suggestions? Feel free to open an issue or reach out!


⭐ If you find this project useful, please consider giving it a star on GitHub!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published