CodeMentorAI is an AI-powered static code analysis and adaptive learning platform. By parsing Abstract Syntax Trees (AST), evaluating complexity metrics, detecting code smells, and using machine learning to cluster user coding weaknesses, CodeMentorAI generates personalized coding tasks to help developers systematically improve their programming skills.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Source Code │ ────> │ AST Parser │ ────> │ Smell Detector │
│ (User Input) │ │ (ast_parser.py) │ │(smell_detector) │
└─────────────────┘ └─────────────────┘ └────────┬────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Custom Coding │ <──── │ Task Generator │ <──── │ ML Weakness │
│ Exercises Output│ │(task_generator) │ │ Clustering │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- AST Parsing (
ast_parser.py): Evaluates the lexical structure of Python code, extracting class declarations, function signatures, loop depths, and control flow nodes. - Metrics Computation (
code_metrics.py): Measures cyclomatic complexity, logical lines of code, and inheritance nesting depth. - Code Smell Detection (
smell_detector.py): Scans codebases for common architectural anti-patterns, including:- Long Method (excessive statement count)
- God Class (too many fields and methods)
- Deep Nesting (excessive conditional branch layering)
- Unsupervised Weakness Clustering (
weakness_clustering.py): Utilizes K-Means clustering (fromscikit-learn) on historical user telemetry to identify distinct categories of coding mistakes or conceptual gaps. - Adaptive Task Generator (
task_generator.py): Programmatically creates targeted programming challenges to address specific weak clusters identified by the ML engine. - Skill Tracking (
skill_tracker.py): Records a history of analyzed metrics and dynamically updates the developer's proficiency logs.
- Python 3.10+
- AST - Native Python Abstract Syntax Trees library.
- Scikit-learn - K-Means clustering for categorizing coding errors.
- Pandas & NumPy - Parsing and formatting user code metrics.
- FastAPI / Flask - API server framework.
Clone the repository:
git clone https://github.com/Parshav2304/CodeMentorAI.git
cd CodeMentorAICreate a virtual environment and install requirements:
python -m venv venv
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate
pip install -r requirements.txtAnalyze a script directly from the command line:
python main.py --file path/to/your_code.pyDistributed under the MIT License. See LICENSE for more information.