CodeGuard is a Python and FastAPI-based code analysis system designed to improve code quality by analyzing Python files every time a wit push
is executed. The system performs code quality checks using structural analysis (AST), detects common issues, and returns visual graphs for in-depth analysis.
- Python 3.8 or higher
- Required Python packages (listed in
requirements.txt
)
Install dependencies: pip install -r requirements.txt
Run the FastAPI server: uvicorn main:app --reload
Folder Structure
Python-Final_Project/
├── CodeGuard-Backend/
│ ├── api/
│ │ └── endpoints.py # Defining API endpoints (routes)
│ ├── db/
│ │ └── mongo.py # MongoDB connection
│ ├── services/
│ │ ├── analizer.py
│ │ └── graphs.py
│ ├── main.py # FastAPI server definition
│ │
│ └── requirement.txt # Project dependencies
│
├── WitProject-Frontend/
│ ├── CLI.py
│ ├── commit.py
│ ├── files.py
│ └── repository.py
└── README.md
API Endpoints /analyze - POST Accepts Python files for analysis
Returns visual graphs for code analysis
Performs code quality checks: function length, file length, unused variables,Variables in Hebrew,missing documentation
/alerts - POST Accepts Python files
Returns a list of warnings and issues
Code Quality Checks: Functions longer than 20 lines
Files longer than 200 lines
Variables assigned but never used
Variables in Hebrew
Functions missing docstrings
Visual Graphs (Matplotlib) Histogram of function lengths Pie chart of issue types Bar chart of issues per file Line chart showing issue counts over time
Usage Running wit push will send files to the server, which will perform the analysis and return results including links to graphs and warnings.