π§ CodeSurgeon β A CLI Tool That Analyzes Your Python Architecture & Fails Your CI If Itβs Unhealthy
This is a submission for the GitHub Copilot CLI Challenge.
π What I Built
I built CodeSurgeon β a Python CLI tool that performs deep architectural analysis of Python projects and generates:
- π Cyclomatic complexity metrics
- π Circular dependency detection
- β»οΈ Duplicate function detection
- π Large file detection
- π§ Architecture health score (0β100)
- π¨ CI mode that fails pipelines when quality drops
- π¦ Full structured JSON output
Built using only Python standard libraries (ast, os, hashlib, json, etc.).
π― Why CodeSurgeon?
Most static analysis tools:
- Require heavy dependencies
- Focus only on linting
- Donβt give architecture health scoring
- Donβt integrate cleanly into CI
CodeSurgeon acts like a doctor for your codebase:
It scans.
It diagnoses.
It scores.
It recommends.
It enforces quality in CI.
π§ͺ Demo
π₯ Video Walkthrough
In the demo, I show:
- Running full analysis
- Generating formatted terminal output
- Producing JSON output
- Running CI mode
- Triggering a CI failure
π¦ GitHub Repository
π https://github.com/codyamit/codesurgeon
π Core Features
1οΈβ£ Scanner Engine
- Counts total lines of code
- Detects files > 600 LOC
- Structured results
2οΈβ£ Dependency Analyzer
- Parses Python files using
ast - Extracts import statements
- Builds dependency graph
- Detects circular dependencies using DFS
3οΈβ£ Duplicate Function Detector
- Extracts functions via AST
- Normalizes bodies
- Hashes with
hashlib.md5 - Groups identical implementations
4οΈβ£ Metrics Calculator
Cyclomatic Complexity:
Complexity = 1 + number_of_branching_nodes
Branching nodes counted:
- if
- for
- while
- try
- with
- boolean operators (and/or)
Tracks:
- total functions
- average complexity
- max complexity
- functions over threshold
π§ Architecture Health Score
Scoring:
- Start at 100
- β5 per circular dependency
- β3 per large file (>600 LOC)
- β2 per duplicate group
- β1 per high-complexity function (>10)
- Clamped 0β100
Risk Levels:
- 80β100 β Low
- 60β79 β Moderate
- 40β59 β High
- 0β39 β Critical
π¦ JSON Output Mode
python3 main.py . --json
Outputs structured JSON:
{
"path": ".",
"scanner": {...},
"dependencies": {...},
"metrics": {...},
"duplicates": {...},
"health_score": {...},
"recommendations": {...}
}
Perfect for dashboards and automation.
π¨ CI/CD Mode
python3 main.py . --ci --threshold 85
Behavior:
- Runs full analysis
- Compares score with threshold
- Exit code 0 β PASS
- Exit code 1 β FAIL
Example:
Health Score: 91
CI Threshold: 95
FAILED
Exit code: 1
Pipeline-ready.
π CLI Usage
python3 main.py . --all
python3 main.py . --scan
python3 main.py . --metrics
python3 main.py . --json
python3 main.py . --ci --threshold 90
π» My Experience Using GitHub Copilot CLI
This entire project was built with GitHub Copilot CLI.
Copilot helped me:
- Generate project structure
- Implement AST parsing logic
- Write DFS cycle detection
- Refactor scoring logic
- Improve CLI formatting
- Implement CI mode
- Optimize structured JSON output
The biggest advantage?
I focused on architecture and product thinking while Copilot handled structure and boilerplate.
It genuinely felt like pair programming inside the terminal.
π§ What I Learned
- AST is extremely powerful
- You can build serious tools using only standard library
- Architecture scoring can be automated
- CLI tools are still highly relevant
- Copilot CLI accelerates system-level development dramatically
π₯ Why This Is Different
This isnβt just:
- A linter
- A metrics tool
- A dependency analyzer
Itβs a unified architecture health platform for Python projects.
Works in:
- Local development
- CI/CD pipelines
- JSON automation workflows
π Future Improvements
- Multi-language support
- Graph visualization export
- HTML reports
- GitHub Action template
- Trend tracking
- PR comment integration
π― Final Thoughts
CodeSurgeon was built from scratch in one focused sprint using GitHub Copilot CLI.
And honestly?
This is one of the cleanest CLI tools Iβve ever built.
If you like the idea, give it a β on GitHub:
π https://github.com/codyamit/codesurgeon
Top comments (0)