Code Quality Scan
Systematic codebase scan that identifies duplication, redundancy, architectural issues, and improvement opportunities. Produces a prioritized action plan.
Workflow
Step 1: Scope Definition
Determine the scan scope:
- Full repo: Scan everything (default)
- Directory: Scan a specific package/module
- Post-change: Scan only files changed since last commit or compared to a branch
Step 2: Structural Analysis
- Project layout: Map the directory structure and identify the architecture pattern (flat, layered, hexagonal, etc.)
- Dependency graph: Trace imports between packages to identify:
- Circular dependencies
- Unexpected cross-layer dependencies
- Packages that import too many others (high fan-out)
- Packages imported by too many others (high fan-in, potential God package)
- File size distribution: Flag unusually large files (likely candidates for splitting)
Step 3: Duplication Detection
Search for code duplication across the codebase:
- Structural duplication: Similar function signatures, similar struct/type definitions
- Logic duplication: Repeated patterns (error handling, validation, formatting)
- Cross-package duplication: Same utility reimplemented in multiple packages
For each duplication found, report:
- Location (files and line ranges)
- Nature of duplication (exact copy, similar pattern, same concept)
- Suggested refactoring (extract function, create shared package, use interface)
Step 4: Redundancy Check
- Dead code: Functions, types, or constants that are never referenced
- Unused imports/dependencies: Check go.mod, package.json for unused entries
- Overlapping abstractions: Multiple types or interfaces serving the same purpose
- Unnecessary complexity: Over-abstracted code, premature generalization
Step 5: Architecture Assessment
Evaluate the overall design:
- Separation of concerns: Are layers (CLI, domain, storage, etc.) cleanly separated?
- API surface: Are internal details leaking through public interfaces?
- Error handling: Is error handling consistent? Are errors wrapped with context?
- Naming consistency: Are naming conventions consistent across the codebase?
Step 6: Report & Prioritize
Present findings as a prioritized list:
Code Quality Scan Results:
High Priority:
1. [Issue] — [Location] — [Impact] — [Suggested fix]
2. ...
Medium Priority:
3. [Issue] — [Location] — [Impact] — [Suggested fix]
4. ...
Low Priority (nice to have):
5. ...
Prioritization criteria:
- High: Bugs, security issues, significant duplication, architectural violations
- Medium: Code quality improvements, moderate duplication, naming inconsistencies
- Low: Style preferences, minor optimizations, cosmetic improvements
Ask the user which items to address, then work through them.
What NOT to Flag
- Minor style differences that don't affect readability
- Test file duplication (test fixtures often intentionally repeat setup)
- Generated code
- Vendor/third-party code
Common Findings
- Formatter/display code duplicated across CLI commands: Extract to shared
output or formatter package
- Similar validation logic in multiple handlers: Create a validation middleware or shared validator
- Multiple config parsing approaches: Consolidate into a single config package
- Type overlap between layers: Domain types leaked into CLI or storage layers
- N+1 patterns: Loop with individual API/DB calls instead of batch operations
Examples
Example 1: Full repo scan
User: "scan the repo and suggest improvements"
Action:
1. Map project structure
2. Trace dependencies between packages
3. Search for duplicated patterns
4. Check for dead code
5. Assess architecture
6. Present prioritized report
Example 2: Post-refactor validation
User: "find code duplications and refactoring plan"
Action:
1. Focus on structural and logic duplication
2. Identify extraction candidates
3. Propose concrete refactoring steps with file references
4. Estimate scope of each refactoring
1---2name: dev-code-quality3description: Systematic codebase quality scan for identifying duplication, redundancy, and improvement opportunities. Use when reviewing a repo's architecture, finding refactoring targets, or assessing code health. Triggers: "scan the repo", "find code duplication", "suggest improvements", "code quality review", "is there redundant code", "refactoring plan", "architecture review".4license: MIT5---67# Code Quality Scan89Systematic codebase scan that identifies duplication, redundancy, architectural issues, and improvement opportunities. Produces a prioritized action plan.1011## Workflow1213### Step 1: Scope Definition1415Determine the scan scope:1617- **Full repo**: Scan everything (default)18- **Directory**: Scan a specific package/module19- **Post-change**: Scan only files changed since last commit or compared to a branch2021### Step 2: Structural Analysis22231. **Project layout**: Map the directory structure and identify the architecture pattern (flat, layered, hexagonal, etc.)242. **Dependency graph**: Trace imports between packages to identify:25 - Circular dependencies26 - Unexpected cross-layer dependencies27 - Packages that import too many others (high fan-out)28 - Packages imported by too many others (high fan-in, potential God package)293. **File size distribution**: Flag unusually large files (likely candidates for splitting)3031### Step 3: Duplication Detection3233Search for code duplication across the codebase:34351. **Structural duplication**: Similar function signatures, similar struct/type definitions362. **Logic duplication**: Repeated patterns (error handling, validation, formatting)373. **Cross-package duplication**: Same utility reimplemented in multiple packages3839For each duplication found, report:4041- Location (files and line ranges)42- Nature of duplication (exact copy, similar pattern, same concept)43- Suggested refactoring (extract function, create shared package, use interface)4445### Step 4: Redundancy Check46471. **Dead code**: Functions, types, or constants that are never referenced482. **Unused imports/dependencies**: Check go.mod, package.json for unused entries493. **Overlapping abstractions**: Multiple types or interfaces serving the same purpose504. **Unnecessary complexity**: Over-abstracted code, premature generalization5152### Step 5: Architecture Assessment5354Evaluate the overall design:55561. **Separation of concerns**: Are layers (CLI, domain, storage, etc.) cleanly separated?572. **API surface**: Are internal details leaking through public interfaces?583. **Error handling**: Is error handling consistent? Are errors wrapped with context?594. **Naming consistency**: Are naming conventions consistent across the codebase?6061### Step 6: Report & Prioritize6263Present findings as a prioritized list:6465```66Code Quality Scan Results:6768High Priority:691. [Issue] — [Location] — [Impact] — [Suggested fix]702. ...7172Medium Priority:733. [Issue] — [Location] — [Impact] — [Suggested fix]744. ...7576Low Priority (nice to have):775. ...78```7980**Prioritization criteria**:8182- **High**: Bugs, security issues, significant duplication, architectural violations83- **Medium**: Code quality improvements, moderate duplication, naming inconsistencies84- **Low**: Style preferences, minor optimizations, cosmetic improvements8586Ask the user which items to address, then work through them.8788## What NOT to Flag8990- Minor style differences that don't affect readability91- Test file duplication (test fixtures often intentionally repeat setup)92- Generated code93- Vendor/third-party code9495## Common Findings9697- **Formatter/display code duplicated across CLI commands**: Extract to shared `output` or `formatter` package98- **Similar validation logic in multiple handlers**: Create a validation middleware or shared validator99- **Multiple config parsing approaches**: Consolidate into a single config package100- **Type overlap between layers**: Domain types leaked into CLI or storage layers101- **N+1 patterns**: Loop with individual API/DB calls instead of batch operations102103## Examples104105**Example 1: Full repo scan**106107```108User: "scan the repo and suggest improvements"109Action:1101. Map project structure1112. Trace dependencies between packages1123. Search for duplicated patterns1134. Check for dead code1145. Assess architecture1156. Present prioritized report116```117118**Example 2: Post-refactor validation**119120```121User: "find code duplications and refactoring plan"122Action:1231. Focus on structural and logic duplication1242. Identify extraction candidates1253. Propose concrete refactoring steps with file references1264. Estimate scope of each refactoring127```