A Docker-based tool for analyzing code complexity across projects. This tool scans codebases and generates comprehensive complexity metrics including cyclomatic complexity, maintainability index, and code structure analysis.
The Complexity Analyzer is a containerized Python application that helps developers and teams understand the structural complexity of their codebases. It produces detailed reports on code metrics that can inform refactoring decisions and code quality improvements.
Pull the latest image from Docker Hub:
docker pull kartdev03/complexity-analyzer:latest
Run the analyzer and output results to your current directory:
docker run -v $(pwd)/output:/app/output kartdev03/complexity-analyzer python analyze_projects.py
This command:
output directory to the container's /app/output directory./output/ on your host machineThe analyzer generates multiple output files in the output directory:
output/
├── analysis_flask.json
├── analysis_requests.json
├── analysis_rich.json
├── comparison.json
└── analysis_report.txt
This tool has been successfully used to analyze three major Python projects:
| Project | Files | SLOC | Avg Complexity | Max Complexity | Effort (person-months) |
|---|---|---|---|---|---|
| Flask | 23 | 3,065 | 2.53 | 21 | 10.52 |
| Requests | 18 | 2,005 | 3.36 | 23 | 4.98 |
| Rich | 78 | 14,936 | 3.23 | 59 | 41.04 |
Measures the number of linearly independent paths through code. Higher values indicate more complex logic:
Real-world insight: Flask's maximum complexity of 21 in a single function represents a complex piece of logic that could benefit from refactoring.
Advanced software metrics that measure program complexity and code quality:
Example from Flask:
Provides effort estimation and project planning metrics:
Flask Example:
Rich Example (larger project):
Real Data: Flask has 3,065 SLOC across 23 files, averaging 133 SLOC per file.
Calculates how maintainable code is on a scale of 0-100:
| Host Path | Container Path | Purpose |
|---|---|---|
$(pwd)/output | /app/output | Output directory for results |
For more information, visit the Docker Hub repository: https://hub.docker.com/r/kartdev03/complexity-analyzer
The JSON report includes:
{
"project_name": "requests",
"files_analyzed": 18,
"total_sloc": 2005,
"total_loc": 5641,
"total_blank": 1099,
"total_comments": 2537,
"cyclomatic_complexity": [
{
"file": "auth.py",
"function": "build_digest_header",
"complexity": 23
}
],
"halstead": {
"volume": 78594.93,
"difficulty": 57.64,
"effort": 4529910.15,
"estimated_bugs": 26.20
},
"cocomo": {
"model_type": "organic",
"effort": 4.98,
"time": 4.60,
"team_size": 1.08,
"cost": 49823.17
},
"file_details": [...],
"class_metrics": [...],
"module_metrics": [...],
"avg_cyclomatic": 3.36,
"max_cyclomatic": 23,
"min_cyclomatic": 1,
"maintainability_index": {...}
}
The comparison.json file provides side-by-side metrics:
[
{
"project": "Flask",
"files": 23,
"sloc": 3065,
"avg_cyclomatic": 2.527,
"max_cyclomatic": 21,
"halstead_volume": 107102.22,
"halstead_difficulty": 70.04,
"estimated_bugs": 35.70,
"cocomo_effort": 10.52,
"cocomo_time": 5.70,
"cocomo_cost": 105177.63
}
]
The analysis_report.txt provides executive insights:
EXECUTIVE SUMMARY
Total Projects Analyzed: 3
Combined SLOC: 20,006
Combined Files: 119
FLASK
Files Analyzed: 23
Total SLOC: 3,065
Average Cyclomatic Complexity: 2.53 (Low - well-structured)
Halstead Estimated Bugs: 35.70
COCOMO Effort: 10.52 person-months
| Metric | Usefulness | Best Use Case |
|---|---|---|
| SLOC | High | Quick size comparison between projects |
| Cyclomatic Complexity | Very High | Identifying functions needing refactoring |
| Halstead Metrics | Moderate-High | Estimating bugs and effort |
| Data-flow Complexity | Moderate | Finding high-coupling functions |
| COCOMO Model | High for Planning | Budgeting and timeline estimation |
Low Complexity Projects: All three projects (Flask, Requests, Rich) maintain average cyclomatic complexity below 3.5, indicating well-structured code.
Outlier Functions: Rich has a maximum complexity of 59, suggesting some complex algorithms. Flask and Requests have max complexities of 21 and 23 respectively.
Scalability: Rich's 78 files show that even larger projects can maintain low average complexity through good code organization.
Effort Estimation: Despite Rich being 5x larger than Flask, the effort estimate is only 4x higher, showing economies of scale in larger projects.
Bug Density: Using Halstead metrics, Rich is estimated to have 219 bugs, which scales appropriately with its size.
For issues, questions, or feature requests, visit:
Latest: kartdev03/complexity-analyzer:latest
Pull the specific version or check Docker Hub for available tags.
Last Updated: November 2025
Content type
Image
Digest
sha256:ede7a89a6…
Size
76.9 MB
Last updated
about 1 year ago
docker pull kartdev03/complexity-analyzer