<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Amit Tiwari</title>
    <description>The latest articles on Forem by Amit Tiwari (@amit_tiwari_a6de91f35a773).</description>
    <link>https://forem.com/amit_tiwari_a6de91f35a773</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1933700%2F5866db18-9441-4010-a881-5f64766f3a18.jpg</url>
      <title>Forem: Amit Tiwari</title>
      <link>https://forem.com/amit_tiwari_a6de91f35a773</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/amit_tiwari_a6de91f35a773"/>
    <language>en</language>
    <item>
      <title>I Built a Python CLI That Scores Your Codebase Health (and Fails Your CI If It's Bad)</title>
      <dc:creator>Amit Tiwari</dc:creator>
      <pubDate>Sun, 15 Feb 2026 21:19:01 +0000</pubDate>
      <link>https://forem.com/amit_tiwari_a6de91f35a773/i-built-a-python-cli-that-scores-your-codebase-health-and-fails-your-ci-if-its-bad-2cbn</link>
      <guid>https://forem.com/amit_tiwari_a6de91f35a773/i-built-a-python-cli-that-scores-your-codebase-health-and-fails-your-ci-if-its-bad-2cbn</guid>
      <description>&lt;h2&gt;
  
  
  🧠 CodeSurgeon – A CLI Tool That Analyzes Your Python Architecture &amp;amp; Fails Your CI If It’s Unhealthy
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/github-2026-01-21"&gt;GitHub Copilot CLI Challenge&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 What I Built
&lt;/h2&gt;

&lt;p&gt;I built &lt;strong&gt;CodeSurgeon&lt;/strong&gt; — a Python CLI tool that performs deep architectural analysis of Python projects and generates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📊 Cyclomatic complexity metrics
&lt;/li&gt;
&lt;li&gt;🔁 Circular dependency detection
&lt;/li&gt;
&lt;li&gt;♻️ Duplicate function detection
&lt;/li&gt;
&lt;li&gt;📁 Large file detection
&lt;/li&gt;
&lt;li&gt;🧠 Architecture health score (0–100)
&lt;/li&gt;
&lt;li&gt;🚨 CI mode that fails pipelines when quality drops
&lt;/li&gt;
&lt;li&gt;📦 Full structured JSON output
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Built using only Python standard libraries (&lt;code&gt;ast&lt;/code&gt;, &lt;code&gt;os&lt;/code&gt;, &lt;code&gt;hashlib&lt;/code&gt;, &lt;code&gt;json&lt;/code&gt;, etc.).&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 Why CodeSurgeon?
&lt;/h2&gt;

&lt;p&gt;Most static analysis tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Require heavy dependencies
&lt;/li&gt;
&lt;li&gt;Focus only on linting
&lt;/li&gt;
&lt;li&gt;Don’t give architecture health scoring
&lt;/li&gt;
&lt;li&gt;Don’t integrate cleanly into CI
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CodeSurgeon acts like a &lt;strong&gt;doctor for your codebase&lt;/strong&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It scans.&lt;br&gt;&lt;br&gt;
It diagnoses.&lt;br&gt;&lt;br&gt;
It scores.&lt;br&gt;&lt;br&gt;
It recommends.&lt;br&gt;&lt;br&gt;
It enforces quality in CI.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧪 Demo
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🎥 Video Walkthrough
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://youtu.be/SHOAeKBbcPU" rel="noopener noreferrer"&gt;https://youtu.be/SHOAeKBbcPU&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the demo, I show:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running full analysis
&lt;/li&gt;
&lt;li&gt;Generating formatted terminal output
&lt;/li&gt;
&lt;li&gt;Producing JSON output
&lt;/li&gt;
&lt;li&gt;Running CI mode
&lt;/li&gt;
&lt;li&gt;Triggering a CI failure
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 GitHub Repository
&lt;/h2&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/codyamit/codesurgeon" rel="noopener noreferrer"&gt;https://github.com/codyamit/codesurgeon&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🔎 Core Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ Scanner Engine
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Counts total lines of code
&lt;/li&gt;
&lt;li&gt;Detects files &amp;gt; 600 LOC
&lt;/li&gt;
&lt;li&gt;Structured results
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2️⃣ Dependency Analyzer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Parses Python files using &lt;code&gt;ast&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Extracts import statements
&lt;/li&gt;
&lt;li&gt;Builds dependency graph
&lt;/li&gt;
&lt;li&gt;Detects circular dependencies using DFS
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3️⃣ Duplicate Function Detector
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Extracts functions via AST
&lt;/li&gt;
&lt;li&gt;Normalizes bodies
&lt;/li&gt;
&lt;li&gt;Hashes with &lt;code&gt;hashlib.md5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Groups identical implementations
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4️⃣ Metrics Calculator
&lt;/h3&gt;

&lt;p&gt;Cyclomatic Complexity:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Complexity = 1 + number_of_branching_nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Branching nodes counted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if&lt;/li&gt;
&lt;li&gt;for&lt;/li&gt;
&lt;li&gt;while&lt;/li&gt;
&lt;li&gt;try&lt;/li&gt;
&lt;li&gt;with&lt;/li&gt;
&lt;li&gt;boolean operators (and/or)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tracks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;total functions
&lt;/li&gt;
&lt;li&gt;average complexity
&lt;/li&gt;
&lt;li&gt;max complexity
&lt;/li&gt;
&lt;li&gt;functions over threshold
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Architecture Health Score
&lt;/h2&gt;

&lt;p&gt;Scoring:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start at 100
&lt;/li&gt;
&lt;li&gt;−5 per circular dependency
&lt;/li&gt;
&lt;li&gt;−3 per large file (&amp;gt;600 LOC)
&lt;/li&gt;
&lt;li&gt;−2 per duplicate group
&lt;/li&gt;
&lt;li&gt;−1 per high-complexity function (&amp;gt;10)
&lt;/li&gt;
&lt;li&gt;Clamped 0–100
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Risk Levels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;80–100 → Low
&lt;/li&gt;
&lt;li&gt;60–79 → Moderate
&lt;/li&gt;
&lt;li&gt;40–59 → High
&lt;/li&gt;
&lt;li&gt;0–39 → Critical
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 JSON Output Mode
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 main.py . --json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Outputs structured JSON:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "path": ".",
  "scanner": {...},
  "dependencies": {...},
  "metrics": {...},
  "duplicates": {...},
  "health_score": {...},
  "recommendations": {...}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Perfect for dashboards and automation.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚨 CI/CD Mode
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 main.py . --ci --threshold 85
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Behavior:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs full analysis&lt;/li&gt;
&lt;li&gt;Compares score with threshold&lt;/li&gt;
&lt;li&gt;Exit code 0 → PASS&lt;/li&gt;
&lt;li&gt;Exit code 1 → FAIL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Health Score: 91
CI Threshold: 95
FAILED
Exit code: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Pipeline-ready.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠 CLI Usage
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 main.py . --all
python3 main.py . --scan
python3 main.py . --metrics
python3 main.py . --json
python3 main.py . --ci --threshold 90
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  💻 My Experience Using GitHub Copilot CLI
&lt;/h2&gt;

&lt;p&gt;This entire project was built with &lt;strong&gt;GitHub Copilot CLI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Copilot helped me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate project structure
&lt;/li&gt;
&lt;li&gt;Implement AST parsing logic
&lt;/li&gt;
&lt;li&gt;Write DFS cycle detection
&lt;/li&gt;
&lt;li&gt;Refactor scoring logic
&lt;/li&gt;
&lt;li&gt;Improve CLI formatting
&lt;/li&gt;
&lt;li&gt;Implement CI mode
&lt;/li&gt;
&lt;li&gt;Optimize structured JSON output
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The biggest advantage?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I focused on architecture and product thinking while Copilot handled structure and boilerplate.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It genuinely felt like pair programming inside the terminal.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What I Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AST is extremely powerful
&lt;/li&gt;
&lt;li&gt;You can build serious tools using only standard library
&lt;/li&gt;
&lt;li&gt;Architecture scoring can be automated
&lt;/li&gt;
&lt;li&gt;CLI tools are still highly relevant
&lt;/li&gt;
&lt;li&gt;Copilot CLI accelerates system-level development dramatically
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 Why This Is Different
&lt;/h2&gt;

&lt;p&gt;This isn’t just:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A linter
&lt;/li&gt;
&lt;li&gt;A metrics tool
&lt;/li&gt;
&lt;li&gt;A dependency analyzer
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a unified &lt;strong&gt;architecture health platform&lt;/strong&gt; for Python projects.&lt;/p&gt;

&lt;p&gt;Works in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Local development
&lt;/li&gt;
&lt;li&gt;CI/CD pipelines
&lt;/li&gt;
&lt;li&gt;JSON automation workflows
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Future Improvements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-language support
&lt;/li&gt;
&lt;li&gt;Graph visualization export
&lt;/li&gt;
&lt;li&gt;HTML reports
&lt;/li&gt;
&lt;li&gt;GitHub Action template
&lt;/li&gt;
&lt;li&gt;Trend tracking
&lt;/li&gt;
&lt;li&gt;PR comment integration
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;CodeSurgeon was built from scratch in one focused sprint using GitHub Copilot CLI.&lt;/p&gt;

&lt;p&gt;And honestly?&lt;/p&gt;

&lt;p&gt;This is one of the cleanest CLI tools I’ve ever built.&lt;/p&gt;




&lt;p&gt;If you like the idea, give it a ⭐ on GitHub:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/codyamit/codesurgeon" rel="noopener noreferrer"&gt;https://github.com/codyamit/codesurgeon&lt;/a&gt;&lt;/p&gt;




</description>
      <category>devchallenge</category>
      <category>githubchallenge</category>
      <category>cli</category>
      <category>githubcopilot</category>
    </item>
  </channel>
</rss>
