Analyze Python source code safely using the Abstract Syntax Tree (AST) without executing it.
CodeInsight is a lightweight command-line static code analysis tool for Python. It analyzes Python source code without executing it, providing structural insights, syntax validation, code metrics, and code quality warnings using Python's built-in Abstract Syntax Tree (AST) module.
The project was built with a strong emphasis on clean architecture, modularity, maintainability, automated testing, and software engineering best practices.
- β‘ AST-based static analysis
- π Recursive folder analysis
- π Code metrics and reporting
- β Static syntax validation
- π§ͺ Unit tested
- π GitHub Actions CI
- π Modular architecture
- Overview
- Project Motivation
- Why AST?
- Features
- Design Principles
- Project Architecture
- Analysis Workflow
- Project Structure
- Technologies Used
- Installation
- Usage
- Running Unit Tests
- Project Roadmap
- Key Engineering Concepts Demonstrated
Understanding source code without executing it is an important capability in modern software development. Static analysis helps developers detect issues early, understand project structure, and improve maintainability before runtime.
CodeInsight demonstrates how Python's built-in AST module can be used to safely inspect source code while applying professional software engineering practices such as modular architecture, separation of concerns, automated testing, and continuous integration.
Unlike regular expressions or string-based parsing, Python's Abstract Syntax Tree (AST) provides a structured representation of source code.
Using the built-in ast module allows CodeInsight to accurately
identify functions, classes, imports, and other language constructs
without executing the program, making the analysis both safe and
reliable.
- Count total lines
- Count blank lines
- Count comment lines
- Count functions
- Count classes
- Count imports
- Extract function names
- Extract class names
- Extract imported modules
- Detect Python syntax errors
- Display syntax error line number
- Display syntax error message
- Detect TODO comments
- Detect large functions
- Warn about low comment coverage
- Generate code health summary
- Generate recommendations
- Analyze a single Python file
- Recursively analyze an entire directory
- Generate individual reports for each Python file
- Display project summary
- Console report
- Text report
- Separate report for each analyzed file
- Modular architecture
- Separation of concerns
- Configuration management
- Unit testing
- GitHub Actions CI
- Clean project organization
- Single Responsibility Principle (SRP)
- Separation of Concerns
- Modular Architecture
- Configuration over hard-coded values
- Maintainability
- Testability
User Input
β
βΌ
Select File / Folder
β
βΌ
Validate Source Code
β
βΌ
Parse with AST
β
βΌ
Calculate Metrics
β
βΌ
Detect Warnings
β
βΌ
Generate Reports
CodeInsight/
β
βββ analyzer.py
βββ config.py
βββ file_utils.py
βββ main.py
βββ metrics.py
βββ parser.py
βββ report.py
βββ utils.py
βββ validator.py
βββ sample_code/
βββ reports/
βββ tests/
βββ docs/
βββ .github/
βββ README.md
βββ requirements.txt
βββ .gitignore
- Python 3.13
- Python Standard Library
- ast
- pathlib
- unittest
- Git
- GitHub
- GitHub Actions
Clone the repository:
git clone https://github.com/Jatin048/CodeInsight.git
cd CodeInsightCreate a virtual environment:
python -m venv .venvActivate it:
Windows
.venv\Scripts\activateLinux / macOS
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun:
python main.pyExample input:
sample_code
or
sample_code/sample1.py
Generated reports are automatically saved inside the reports/
directory.
python -m unittest discover testsThe test suite also runs automatically on every push and pull request using GitHub Actions.
============================================================
PROJECT SUMMARY
============================================================
Files Found : 4
Successful : 3
Failed : 1
Reports Generated : 3
- Cyclomatic Complexity
- Dead Code Detection
- Duplicate Code Detection
- PEP 8 Naming Checks
- HTML reports
- JSON reports
- PDF export
- Command-line arguments (
argparse) - Plugin architecture
- Docker support
- Static code analysis using Python AST
- Abstract Syntax Tree traversal
- Modular software architecture
- Separation of concerns
- Recursive file system traversal
- Static syntax validation
- Configuration management
- Automated unit testing
- Continuous Integration with GitHub Actions
- Report generation
This project leverages Python's built-in AST module and other standard library components to perform safe and efficient static code analysis.
This project is licensed under the MIT License.
- β Feature Complete
- β Unit Tested
- β GitHub Actions Enabled
- π Stable Release: v1.1.0
Jatin Arora
Feel free to open an issue for bug reports, feature requests, or general feedback. Contributions and discussions are always welcome.

