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

MetricBeforeAfterChange
Tech Debt Index75 (Grade D)68 (Grade D)-9.3%
Avg Complexity36.033.6-6.6%
High Complexity Files3833-5
Large Files (>500 LOC)2013-7
Total Hotspots20200 (score improved)

All numbers from running ccg quickstart and ccg dogfood-report on CCG's own codebase.

62k
Lines Analyzed
173
Files Scanned
20
Hotspots Found
<1s
Quickstart Time

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.

#FileLinesScoreIssueAction
1agents.service.ts54290High complexity (78)split-module
2workflow.service.ts51889Deep nesting (7)split-module
3commands.service.ts50288Complexity 72split-module
4ccg.ts48985Nesting 6refactor
5latent.service.ts46783Complexity 65refactor
6http-server.ts44581Complexity 62refactor
7auto-agent.service.ts42378High branchingsimplify
8thinking.service.ts39876High branchingsimplify

The Solution

Two commands. Under a second. Complete visibility.

1. Run Quickstart

ccg 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

ccg dogfood-report --summary

Compared before/after metrics across sessions. Tech Debt Index dropped from 75 to 68 after refactoring ~12 large files.

3. Refactor with Latent Chain

# Analysis → Plan → Impl → Review

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:

# Initial analysis
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.

npm install -g codeguardian-studio
ccg quickstart
Back to Home View on GitHub