Case Study: Dogfooding CCG
How Code Guardian Studio reduced its Tech Debt Index from 75 to 68 (-9.3%) by running CCG on its own ~62,000 line codebase.
Before vs After
| Metric | Before | After | Change |
|---|---|---|---|
| Tech Debt Index | 75 (Grade D) | 68 (Grade D) | -9.3% |
| Avg Complexity | 36.0 | 33.6 | -6.6% |
| High Complexity Files | 38 | 33 | -5 |
| Large Files (>500 LOC) | 20 | 13 | -7 |
| Total Hotspots | 20 | 20 | 0 (score improved) |
All numbers from running ccg quickstart and ccg dogfood-report on CCG's own codebase.
The Challenge
CCG grew from a simple MCP server to a full enterprise toolkit with 70+ tools. We needed to find and fix the most problematic files before shipping v4.0.
Rapid Growth
8 major modules added in weeks: Memory, Guard, Workflow, Testing, Documents, Agents, Latent Chain, and Code Optimizer.
Technical Debt
Some service files exceeded 700 lines with deep nesting and high cyclomatic complexity. Manual review would take days.
Time Pressure
We needed actionable insights fast — which files to split, which patterns to refactor, and in what order.
Top Hotspots Identified
CCG's Code Optimizer ranked every file by complexity, nesting depth, and size.
| # | File | Lines | Score | Issue | Action |
|---|---|---|---|---|---|
| 1 | agents.service.ts | 542 | 90 | High complexity (78) | split-module |
| 2 | workflow.service.ts | 518 | 89 | Deep nesting (7) | split-module |
| 3 | commands.service.ts | 502 | 88 | Complexity 72 | split-module |
| 4 | ccg.ts | 489 | 85 | Nesting 6 | refactor |
| 5 | latent.service.ts | 467 | 83 | Complexity 65 | refactor |
| 6 | http-server.ts | 445 | 81 | Complexity 62 | refactor |
| 7 | auto-agent.service.ts | 423 | 78 | High branching | simplify |
| 8 | thinking.service.ts | 398 | 76 | High branching | simplify |
The Solution
Two commands. Under a second. Complete visibility.
1. Run Quickstart
Scanned 173 files, calculated metrics for each, and ranked them by composite score in under 1 second. Report written to docs/reports/.
2. Track Progress
Compared before/after metrics across sessions. Tech Debt Index dropped from 75 to 68 after refactoring ~12 large files.
3. Refactor with Latent Chain
Used CCG's Latent Chain mode with Claude Code to safely split oversized services into focused modules.
What We Refactored
First optimization pass focused on the biggest files.
Split Large Services
Files over 700 lines (agents, commands, workflow) were extracted into smaller, focused modules. Each 800+ line file became 2-3 services.
Reduced Nesting
Deep callback chains and nested conditionals were flattened using early returns and guard clauses. Max nesting dropped from 7 to 5.
Extracted Helpers
Common patterns across modules (parsing, validation, formatting) became shared utilities. Reduced duplication by ~15%.
All refactoring was guided by CCG's hotspot rankings and validated by re-running ccg dogfood-report after each change.
Results
Measurable improvement in code health.
TDI: 75 → 68
Tech Debt Index improved by 9.3%. Still Grade D, but trending toward Grade C (<60) with continued refactoring.
7 Fewer Large Files
Files over 500 lines dropped from 20 to 13. The worst offenders (700-1300 lines) were split into manageable modules.
Complexity: 36 → 33.6
Average complexity score decreased by 6.6%. More files now fall in the "healthy" range (<30 complexity).
How We Measured This
All metrics come from CCG's built-in analysis tools.
Tech Debt Index (TDI)
Composite metric (0-100) combining:
- Cyclomatic complexity per file
- Max nesting depth
- File size (lines of code)
- Branch score (if/switch/ternary density)
- TODO/FIXME count
Grade scale: A (0-20), B (21-40), C (41-60), D (61-80), F (81-100)
Commands used:
ccg quickstart
# Track progress over time
ccg dogfood-report --summary
Try it on your codebase
Get the same analysis in under a second. Free for all developers.
ccg quickstart