skills/controller-refactor-plan/SKILL.md
Analyze one controller file, determine which handlers are no longer wired from routes, and assess whether controller responsibilities have grown beyond validation/response orchestration. Produce analysis only (no implementation plan). Use this when the user says 'analyze this controller', 'is this controller still used', 'find dead controller handlers', or 'does this controller do too much'.
npx skillsauth add ryan-mahoney/ryan-llm-skills controller-refactor-planInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill to audit a single controller in firstwho-app and produce an analysis document. The analysis answers three questions: which controller handlers are still reachable from routes, where controller code exceeds controller scope, and what context boundaries are implicated. This skill is analysis-only and does not propose implementation sequencing.
$1 - Required. Path to a controller file, usually under app/controllers/ (example: app/controllers/orders/orders-controller.js).$2 - Optional. Output path for the markdown analysis. If omitted, write to docs/<controller-name>-analysis.md.AGENTS.md exists.$1 exists and is a file.controller_path="$1"
controller_name="$(basename "$controller_path" .js)"
output_path="${2:-docs/${controller_name}-analysis.md}"
mkdir -p "$(dirname "$output_path")"
controller_rel="${controller_path#app/controllers/}"
controller_no_ext="${controller_rel%.js}"
Find where this controller is imported and where its handlers are used in routing.
rg -n "controllers/${controller_no_ext}(\\.js)?" app/routes
Then read each matching route file (always include app/routes/backend-routes.js) and build a table:
default import, named import, alias import)controller.method or direct function)Pattern reference: Route wiring style is defined in app/routes/backend-routes.js with both default-object handlers (for example calibrate.updateProfile) and named imports (for example createPaymentIntent as ordersCreatePaymentIntent from app/controllers/orders/orders-controller.js).
Extract all handlers this controller makes externally reachable.
rg -n "export const [A-Za-z0-9_]+\s*=|export default\s*\{" "$controller_path"
Also inspect inline handler definitions in default exports:
rg -n "^[[:space:]]*[A-Za-z0-9_]+:\s*async\s*\(|^[[:space:]]*[A-Za-z0-9_]+:\s*\(" "$controller_path"
Create a handler inventory table:
named or default object)active, possibly-unused, indirect/unknown)Treat handlers with no route references as possibly-unused until a repo-wide search confirms no non-router callers:
handler_name="<handler>"
rg -n "\\b${handler_name}\\b" app
Audit whether handlers are mainly orchestration or contain domain logic that belongs in contexts.
Use fast signals:
rg -n "from \"\.\./\.\./models|from \"\.\./models|from \"\.\./\.\./libraries/nodejs-manager/src/libraries/db-conn|from \"\.\./libraries/nodejs-manager/src/libraries/db-conn|\.transaction\(|await db\." "$controller_path"
rg -n "from \"\.\./\.\./contexts|from \"\.\./contexts" "$controller_path"
rg -n "new Stripe|new OpenAI|S3Client|axios|fetch\(" "$controller_path"
For each handler, classify responsibilities:
controller-appropriate: request/session validation, auth gate, selecting status code, renderPage/jsonResponse.should-live-in-context: model queries, transactions, business rule branching, third-party orchestration, heavy data shaping.Pattern reference (healthy split): app/controllers/community/calibrate-controller.js keeps route handlers thin and delegates business logic to app/contexts/calibrate.js.
Pattern reference (scope creep example): app/controllers/community/community-resources-controller.js and large managers such as app/controllers/opportunities/opportunities-job-manager.js include substantial model/data logic directly in controllers.
Prefer reusing existing contexts where themes already exist.
app/contexts/.move to existing context (name the exact file)create new context (propose exact path and thematic scope)Guideline for new context creation: only add a new file when responsibilities do not fit existing context boundaries.
Write the plan to $output_path using this structure:
# Controller Analysis: <controller path>
## 1. Route Reachability
| Handler | Export | Route(s) | Status |
| --- | --- | --- | --- |
## 2. Findings: Controller Scope
- <finding with file/line references>
## 3. Dead or Orphaned Handlers
- <handler> - <evidence>
## 4. Context Boundary Analysis
- Existing contexts related to controller concerns
- Responsibilities currently in controller that align with those contexts
- Responsibilities with no clear existing context home
## 5. Risk + Test Surface
- Behavior risks
- Regression checks
- Existing tests and apparent gaps in `app/test/controllers/` and `app/test/contexts/`
Do not include:
You may include observations such as:
but keep them evidence-based and non-prescriptive.
app/routes/backend-routes.js; there is no auto-registration.app/contexts/calibrate.js and app/contexts/orders.js).app/test/ (not adjacent to implementation).indirect/unknown and show search evidence instead of guessing.testing
This skill should be used when the user asks to "run the spec", "implement the spec", or "execute the spec". Implements every step in a SpecOps implementation spec by delegating each step (or logical group of adjacent steps) to a sequential subagent, conventional-committing each one independently, and — when `roborev` is on the path — running `roborev check` on every commit and `roborev fix` (with spec context, so the fix cannot silently drift the implementation away from the spec) on any commit that fails.
development
Exhaustively audit a top-level UI implementation component against an HTML prototype and produce a grouped markdown checklist of corrections. Use when a user asks for UI parity review, visual QA, design implementation audit, pixel-level drift detection, or behavior/style mismatch analysis between prototype HTML and shipped component code.
development
Audit a SpecOps implementation spec against its source analysis spec to find requirements, policies, contracts, edge cases, error modes, invariants, defaults, side effects, or implementation steps that the implementation has dropped, weakened, contradicted, or silently changed — then patch the implementation spec to restore them. Use this skill whenever the user mentions auditing, comparing, conforming, reconciling, or checking an implementation spec against an analysis spec, finding gaps between two specs, ensuring an implementation spec preserves analysis behavior, or verifying spec derivation or traceability. Also trigger when the user describes "did the implementation spec lose anything from the analysis," "does the implementation match the analysis," "verify the implementation spec covers everything," or asks to confirm one spec is faithful to another. Run this before generating code from an implementation spec and after either spec is edited.
development
Audit a set of SpecOps analysis specs for cross-spec coherence — establish a dependency-ordered implementation sequence, then verify pairwise integration contracts at module boundaries plus three cross-cutting consistency dimensions (shared data models, side-effect ownership, terminology) — and patch the affected specs to resolve gaps. Use this skill whenever the user mentions cross-spec consistency, integration gaps between specs, conflicts between specs, duplicate work across specs, implementation order, dependency order for migration, building an implementation-order checklist, ensuring specs interoperate, terminology drift across specs, or shared data model conflicts. Also trigger when the user describes "do my specs agree with each other," "what order should I implement these in," "find inconsistencies across all my specs," or asks to audit a folder of analysis specs as a set rather than individually. Run this once after generating a full set of analysis specs, before deriving implementation specs.