phx-techdebt

$npx mdskill add oliver-kriska/claude-elixir-phoenix/phx-techdebt

Analyze Elixir/Phoenix code for duplication and refactoring opportunities.

  • Detects duplicate code patterns and anti-patterns in Elixir/Phoenix projects.
  • Uses Credo for automated analysis and Grep for pattern searching.
  • Applies three strikes rule and prefers composition over inheritance.
  • Outputs prioritized list of refactoring opportunities with test coverage requirements.

SKILL.md

.github/skills/phx-techdebtView on GitHub ↗
---
name: phx-techdebt
description: Analyze Elixir/Phoenix technical debt — duplicates, refactoring opportunities,
  credo issues. Use when asked about code quality, cleanup, or what to improve.
---

# Technical Debt Detection

Find and eliminate duplicate code patterns, anti-patterns, and refactoring opportunities in Elixir/Phoenix projects.

## Iron Laws - Never Violate These

1. **Search before refactoring** - Understand full scope of duplication before extracting
2. **Three strikes rule** - Extract shared code only after 3+ duplications
3. **Prefer composition** - Use behaviours and protocols over inheritance-style abstractions
4. **Test coverage first** - Ensure tests exist before refactoring duplicated code

## Analysis Checklist

### 1. Run Credo for Automated Detection

Run `mix credo --strict`.

Focus on:

- Design issues (duplication, complexity)
- Consistency issues (naming, patterns)
- Refactoring opportunities

### 2. Find Duplicate Ecto Query Patterns

Use Grep to search for repeated Repo calls (`Repo.get!`, `Repo.get`, `Repo.one`) in `lib/**/*.ex`.
Use Grep to find duplicate query patterns (`from.*in.*where`) in `lib/**/*.ex`.

### 3. Find Duplicate Validation Logic

Use Grep with `output_mode: "count"` to count `def changeset` occurrences in `lib/**/*.ex`.
Use Grep to find repeated validations (`validate_required`, `validate_format`) in `lib/**/*.ex`.

### 4. Find Copy-Pasted Controller Actions

Use Grep to find similar action patterns (`def create`, `def update`, `def delete`) in `lib/*_web/**/*.ex`.

## Common Duplication Patterns

| Pattern | Symptom | Solution |
|---------|---------|----------|
| Repeated queries | Same `Repo.get` in multiple contexts | Create shared query module |
| Duplicate validations | Same `validate_*` calls | Extract to shared changeset |
| Similar controllers | Copy-pasted CRUD actions | Use Phoenix generators consistently |
| Repeated transforms | Same `Enum.map` patterns | Extract to domain module |

## Reporting Format

For each duplication found, report:

1. **Location**: File paths and line numbers
2. **Pattern**: What code is duplicated
3. **Extraction**: Suggested shared function/module
4. **Effort**: Low/Medium/High to fix

## Usage

Run `phx-techdebt` to analyze the codebase and generate a prioritized report of technical debt with specific remediation steps.

More from oliver-kriska/claude-elixir-phoenix

SkillDescription
ash-frameworkAsh Framework — resources, actions, policies, aggregates, calculations, AshPhoenix.Form, LiveView, migrations. Use when generating resources via mix ash.codegen, editing changes, checks, types, validations, or domain code interfaces.
catchupSummarize and review what changed while you were away. Use after a weekend, vacation, or flight to check missed PRs, git commits, Linear tickets, and meetings — one prioritized brief, not a firehose.
cc-changelog|
codex-abRun an A/B codex review experiment — holistic codex review vs 3 focused dimension passes (security, ecto, liveview) on the branch diff, classify findings, report a panel-value verdict. Use when the branch is fresh, before any codex review runs.
compound-docsSearchable Elixir/Phoenix/Ecto solution documentation system with YAML frontmatter. Builds institutional knowledge from solved problems. Use when consulting past solutions before investigating new issues.
docs-check|
ecto-n1-checkDetect N+1 query anti-patterns specifically — Repo calls inside Enum/for
ecto-patternsEcto patterns — schemas, changesets, queries, migrations, Multi, associations, preloads, upserts. Use when editing Repo calls, Ecto.Query, or schema fields. Skip for Ash.
ecto:constraint-debugDebug Ecto constraint violations - trace triggers, check migrations, find duplicate data. Use when seeing unique_constraint, foreign_key_constraint, or check_constraint errors.
ecto:n1-checkDetect N+1 query anti-patterns specifically — Repo calls inside Enum/for loops, missing preloads on associations. Use when N+1 is explicitly suspected, NOT for unrelated Ecto questions or wider database performance.