Technical debt analysis and remediation. Scans codebase for code smells, duplication, complexity, testing gaps, and architecture issues. Generates prioritized reports with ROI estimates...
Analyze the HeadsUp codebase to identify, quantify, and prioritize technical debt. Generate actionable remediation plans with clear ROI.
Target: $ARGUMENTS
Conduct a thorough scan based on the target area. If no area specified, scan the full codebase.
Target Mapping:
| Argument | Scan Scope |
|---|---|
all |
Full codebase |
challenges |
lib/heads_up/challenges*, lib/heads_up_web/live/challenge_live/* |
goals |
lib/heads_up/goals*, lib/heads_up_web/live/goal_live/* |
users |
lib/heads_up/accounts*, lib/heads_up_web/live/users_live/* |
social |
Social features: likes, comments, subscriptions, feed |
admin |
lib/heads_up_web/live/admin_live/* |
tests |
test/**/*_test.exs |
schemas |
lib/heads_up/**/*.ex (Ecto schemas only) |
liveviews |
lib/heads_up_web/live/**/*.ex |
Search for these patterns:
Duplicated Code
Complex Code
case/cond/if blocks (>3 levels)render/1 functions over 200 linesPoor Structure
naive_datetime vs utc_datetime)on_delete specifications@doc@moduledoc on modules@spec) on public functionsFor each debt item found, assess:
Severity Levels:
Impact Scoring:
Impact = Frequency_of_change x Severity x Blast_radius
Where:
Frequency: How often this code is touched (1-5)
Severity: How bad the debt is (1-5)
Blast_radius: How much code is affected (1-5)
Create the report at project/tech-debt/TD-[DATE]-[area].md
# Technical Debt Report: [Area]
**Date:** YYYY-MM-DD
**Scope:** [what was scanned]
**Overall Score:** X/100 (lower = more debt)
## Executive Summary
- Total debt items: X
- Critical: X | High: X | Medium: X | Low: X
- Estimated remediation effort: X hours
- Top 3 priorities: [list]
## Debt Inventory
### Critical Items
| # | Category | File | Description | Impact | Effort |
|---|----------|------|-------------|--------|--------|
| 1 | [type] | path | description | score | hours |
### High Priority Items
[same table format]
### Medium Priority Items
[same table format]
### Low Priority Items
[same table format]
## Metrics
### Code Quality
- Average function length: X lines
- Functions >50 lines: X
- Modules >500 lines: X
- Duplicated patterns: X locations
### Test Coverage
- Context functions tested: X%
- LiveView events tested: X%
- Files without tests: X
### Schema Health
- Missing indexes: X
- Missing validations: X
- Inconsistent patterns: X
## Quick Wins (< 4 hours each)
1. [item] - Effort: Xh, Savings: Xh/month
2. [item] - Effort: Xh, Savings: Xh/month
## Remediation Roadmap
### Week 1-2: Quick Wins
- [ ] [task]
- [ ] [task]
### Month 1: High Priority
- [ ] [task]
- [ ] [task]
### Month 2-3: Medium Priority
- [ ] [task]
- [ ] [task]
## Prevention Recommendations
1. [recommendation]
2. [recommendation]
For each Quick Win and High Priority item, create a task file:
Location: project/tech-debt/tasks/TDT-XXX-[slug].md
# TDT-XXX: [Task Title]
## Source
- Report: TD-[DATE]-[area].md
- Severity: [Critical/High/Medium/Low]
- Impact Score: X/125
## Description
[What needs to change and why]
## Files Affected
- `path/to/file.ex`
## Steps
1. [step]
2. [step]
3. [step]
## Effort Estimate
- Hours: X
- Complexity: [Low/Medium/High]
## Acceptance Criteria
- [ ] [criterion]
- [ ] [criterion]
- [ ] Tests pass: `mix test`
## Status
- [ ] Planned
- [ ] In Progress
- [ ] Done
- [ ] Verified
# BAD: Repo call in LiveView
def handle_event("save", params, socket) do
Repo.insert(changeset) # Should be in context
end
# GOOD: Context function
def handle_event("save", params, socket) do
Goals.create_goal(params)
end
# BAD: Business logic in template
<%= if length(user.goals) >= 2 do %> # Magic number, logic in template
# GOOD: Helper or context function
<%= if Goals.at_limit?(@current_user) do %>
# Check for: missing validates, missing indexes, missing on_delete
schema "goals" do
belongs_to :user, User # Should have on_delete
field :status, Ecto.Enum # Should validate in changeset
end
# BAD: N+1 query
goals |> Enum.map(fn g -> Repo.preload(g, :user) end)
# GOOD: Batch preload
goals |> Repo.preload(:user)
After generating the report, display a summary:
Tech Debt Analysis Complete
============================
Scope: [area]
Report: project/tech-debt/TD-[DATE]-[area].md
Tasks: X created in project/tech-debt/tasks/
Summary:
Critical: X items
High: X items
Medium: X items
Low: X items
Total: X items
Top 3 Quick Wins:
1. [description] (Xh effort, Xh/month savings)
2. [description] (Xh effort, Xh/month savings)
3. [description] (Xh effort, Xh/month savings)
Estimated total remediation: X hours