Codebase Health Analysis
When analyzing codebase health, drift auto-detects the language from manifest files and applies the appropriate analysis strategy.
Language Detection
Check for manifest files in this order:
go.mod → Go (full AST analysis)
package.json → TypeScript/JavaScript (heuristic regex)
pyproject.toml or requirements.txt → Python (indentation-aware heuristic)
Cargo.toml → Rust (heuristic regex)
pom.xml or build.gradle → Java (heuristic regex)
Gemfile → Ruby (def/end tracking heuristic)
composer.json → PHP (heuristic regex)
*.csproj → C# (heuristic regex)
1. Cyclomatic Complexity Analysis
Calculate cyclomatic complexity for each function by counting decision points:
Base complexity: 1 per function, then +1 for each decision point.
Go (AST-based)
- +1 for each:
if, for, range, select, switch (type switch)
- +1 for each
case clause (except default)
- +1 for each
&& or || binary operator
- Do NOT recurse into function literals
TypeScript/JavaScript (regex-based)
- +1 for:
if(, else if, for(, while(, do{, case X:, catch(
- +1 for:
&&, ||, ??, ?.
Python (indentation-aware)
- +1 for:
if, elif, for, while, except, with
- +1 for:
and, or, inline if...else
- Function boundaries determined by indentation level
Rust
- +1 for:
if, else if, for, while, loop, match, => {
- +1 for:
&&, ||, ?
Java
- +1 for:
if(, else if, for(, while(, do{, case X:, catch(
- +1 for:
&&, ||, ternary ? :
Ruby (def/end tracking)
- +1 for:
if, elsif, unless, for, while, until, when, rescue
- +1 for:
&&, ||
- Function boundaries determined by
def/end keyword depth
PHP
- +1 for:
if(, elseif(, for(, foreach(, while(, do{, case X:, catch(
- +1 for:
&&, ||, ternary ? :
C#
- +1 for:
if(, else if, for(, foreach(, while(, do{, case X:, catch(, switch(
- +1 for:
&&, ||, ??, ternary ? :
Severity thresholds:
- 1-10: Good (green) — easy to understand and test
- 11-20: Warning (yellow) — consider refactoring
- 21+: Critical (red) — should be refactored immediately
2. Dependency Freshness
Check the language-specific manifest against its registry:
| Language |
Manifest |
Registry |
| Go |
go.mod |
https://proxy.golang.org/{mod}/@latest |
| TypeScript/JS |
package.json |
https://registry.npmjs.org/{pkg}/latest |
| Python |
requirements.txt / pyproject.toml |
https://pypi.org/pypi/{pkg}/json |
| Rust |
Cargo.toml |
https://crates.io/api/v1/crates/{crate} |
| Java |
pom.xml / build.gradle |
https://search.maven.org/solrsearch/select |
| Ruby |
Gemfile |
https://rubygems.org/api/v1/gems/{name}.json |
| PHP |
composer.json |
https://repo.packagist.org/p2/{vendor}/{package}.json |
| C# |
*.csproj |
https://api.nuget.org/v3-flatcontainer/{name}/index.json |
Staleness classification:
- Current: version matches latest
- Stale (30-90 days): behind latest
- Outdated (90+ days): significantly behind, may have security patches
3. Architectural Boundary Violations
Define import rules that enforce module boundaries. A boundary rule like pkg/api -> internal/db means code in pkg/api/ should NOT import packages containing internal/db.
Import detection patterns per language:
- Go: Full AST import parsing
- TypeScript/JS:
import...from, require(), dynamic import()
- Python:
import X, from X import
- Rust:
use, pub use, extern crate
- Java:
import (including static)
- Ruby:
require, require_relative
- PHP:
use, require_once, include
- C#:
using, using static
4. Dead Code Detection
Find exported/public functions that have zero callers within the project:
- Go: Full AST — tracks all
CallExpr and SelectorExpr nodes
- Other languages: Scans for export patterns and cross-references with all call sites
5. Health Score Calculation
Combine metrics into an overall health score (0-100):
total = complexity_score * 0.30
+ deps_score * 0.20
+ boundaries_score * 0.20
+ dead_code_score * 0.15
+ coverage_score * 0.15
Example Usage
# Install drift
go install github.com/greatnessinabox/drift/cmd/drift@latest
# Run in any supported project
cd /path/to/project
drift report # Terminal-formatted report
drift snapshot # JSON output for CI (includes "language" field)
drift check --fail-under 70 # CI health gate
drift # Full interactive TUI dashboard
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: codebase-health-analysis3description: Analyze codebase health across Go, TypeScript/JS, Python, Rust, Java, Ruby, PHP, and C# — including cyclomatic complexity, dependency freshness, dead code detection, and architectural boundary violations. Use this skill when asked about code quality, tech debt, code health, complexity analysis, or dependency management. Use when this capability is needed.4---56# Codebase Health Analysis78When analyzing codebase health, drift auto-detects the language from manifest files and applies the appropriate analysis strategy.910## Language Detection1112Check for manifest files in this order:131. `go.mod` → Go (full AST analysis)142. `package.json` → TypeScript/JavaScript (heuristic regex)153. `pyproject.toml` or `requirements.txt` → Python (indentation-aware heuristic)164. `Cargo.toml` → Rust (heuristic regex)175. `pom.xml` or `build.gradle` → Java (heuristic regex)186. `Gemfile` → Ruby (def/end tracking heuristic)197. `composer.json` → PHP (heuristic regex)208. `*.csproj` → C# (heuristic regex)2122## 1. Cyclomatic Complexity Analysis2324Calculate cyclomatic complexity for each function by counting decision points:2526**Base complexity:** 1 per function, then +1 for each decision point.2728### Go (AST-based)29- +1 for each: `if`, `for`, `range`, `select`, `switch` (type switch)30- +1 for each `case` clause (except default)31- +1 for each `&&` or `||` binary operator32- Do NOT recurse into function literals3334### TypeScript/JavaScript (regex-based)35- +1 for: `if(`, `else if`, `for(`, `while(`, `do{`, `case X:`, `catch(`36- +1 for: `&&`, `||`, `??`, `?.`3738### Python (indentation-aware)39- +1 for: `if`, `elif`, `for`, `while`, `except`, `with`40- +1 for: `and`, `or`, inline `if...else`41- Function boundaries determined by indentation level4243### Rust44- +1 for: `if`, `else if`, `for`, `while`, `loop`, `match`, `=> {`45- +1 for: `&&`, `||`, `?`4647### Java48- +1 for: `if(`, `else if`, `for(`, `while(`, `do{`, `case X:`, `catch(`49- +1 for: `&&`, `||`, ternary `? :`5051### Ruby (def/end tracking)52- +1 for: `if`, `elsif`, `unless`, `for`, `while`, `until`, `when`, `rescue`53- +1 for: `&&`, `||`54- Function boundaries determined by `def`/`end` keyword depth5556### PHP57- +1 for: `if(`, `elseif(`, `for(`, `foreach(`, `while(`, `do{`, `case X:`, `catch(`58- +1 for: `&&`, `||`, ternary `? :`5960### C#61- +1 for: `if(`, `else if`, `for(`, `foreach(`, `while(`, `do{`, `case X:`, `catch(`, `switch(`62- +1 for: `&&`, `||`, `??`, ternary `? :`6364**Severity thresholds:**65- 1-10: Good (green) — easy to understand and test66- 11-20: Warning (yellow) — consider refactoring67- 21+: Critical (red) — should be refactored immediately6869## 2. Dependency Freshness7071Check the language-specific manifest against its registry:7273| Language | Manifest | Registry |74|----------|----------|----------|75| Go | `go.mod` | `https://proxy.golang.org/{mod}/@latest` |76| TypeScript/JS | `package.json` | `https://registry.npmjs.org/{pkg}/latest` |77| Python | `requirements.txt` / `pyproject.toml` | `https://pypi.org/pypi/{pkg}/json` |78| Rust | `Cargo.toml` | `https://crates.io/api/v1/crates/{crate}` |79| Java | `pom.xml` / `build.gradle` | `https://search.maven.org/solrsearch/select` |80| Ruby | `Gemfile` | `https://rubygems.org/api/v1/gems/{name}.json` |81| PHP | `composer.json` | `https://repo.packagist.org/p2/{vendor}/{package}.json` |82| C# | `*.csproj` | `https://api.nuget.org/v3-flatcontainer/{name}/index.json` |8384**Staleness classification:**85- Current: version matches latest86- Stale (30-90 days): behind latest87- Outdated (90+ days): significantly behind, may have security patches8889## 3. Architectural Boundary Violations9091Define import rules that enforce module boundaries. A boundary rule like `pkg/api -> internal/db` means code in `pkg/api/` should NOT import packages containing `internal/db`.9293Import detection patterns per language:94- **Go**: Full AST import parsing95- **TypeScript/JS**: `import...from`, `require()`, dynamic `import()`96- **Python**: `import X`, `from X import`97- **Rust**: `use`, `pub use`, `extern crate`98- **Java**: `import` (including static)99- **Ruby**: `require`, `require_relative`100- **PHP**: `use`, `require_once`, `include`101- **C#**: `using`, `using static`102103## 4. Dead Code Detection104105Find exported/public functions that have zero callers within the project:106107- **Go**: Full AST — tracks all `CallExpr` and `SelectorExpr` nodes108- **Other languages**: Scans for export patterns and cross-references with all call sites109110## 5. Health Score Calculation111112Combine metrics into an overall health score (0-100):113114```115total = complexity_score * 0.30116 + deps_score * 0.20117 + boundaries_score * 0.20118 + dead_code_score * 0.15119 + coverage_score * 0.15120```121122## Example Usage123124```bash125# Install drift126go install github.com/greatnessinabox/drift/cmd/drift@latest127128# Run in any supported project129cd /path/to/project130drift report # Terminal-formatted report131drift snapshot # JSON output for CI (includes "language" field)132drift check --fail-under 70 # CI health gate133drift # Full interactive TUI dashboard134```135136---137> Converted and distributed by [TomeVault](https://tomevault.io/claim/greatnessinabox) — claim your Tome and manage your conversions.138<!-- tomevault:4.0:skill_md:2026-04-13 -->