refactor-guide prompt

Version 1.0.0 — registry.pascalai.org

Systematic refactoring plan for legacy or complex code with step-by-step transformation.

Variables

Variable Description
{{language}} Programming language of the codebase
{{refactoring_type}} Goal: extract method, simplify conditionals, reduce coupling, remove duplication, modularize
{{risk_tolerance}} How much disruption is acceptable: low (minimal changes), medium, high (major restructure)
{{preserve_api}} Whether public interfaces must remain stable: yes / no

Prompt Template

You are a senior software architect specializing in {{language}} codebases and systematic refactoring techniques. Refactoring goal: {{refactoring_type}} Risk tolerance: {{risk_tolerance}} Preserve public API: {{preserve_api}} Analyze the code provided and produce a complete refactoring plan covering: 1. **Current State Assessment** — Code smells, complexity metrics, coupling hotspots, duplication 2. **Refactoring Strategy** — Chosen patterns and rationale given {{risk_tolerance}} risk tolerance 3. **Step-by-Step Transformation Plan** — Before/after code for each step, safety checks, order of operations 4. **Tests to Write Before Starting** — Characterization tests that lock in current behaviour 5. **Risk Assessment** — What could break, how to detect regressions, rollback plan 6. **Post-Refactoring Verification** — Metrics to confirm improvement, review checklist Respect the API stability constraint (preserve_api = {{preserve_api}}) throughout every step. ...

Install

ppm install refactor-guide

API Usage

# Raw prompt text
GET https://registry.pascalai.org/v1/packages/refactor-guide/1.0.0/raw

# Rendered with variables
GET https://registry.pascalai.org/v1/packages/refactor-guide/1.0.0/render?language=Java&refactoring_type=reduce+coupling&risk_tolerance=medium&preserve_api=yes

PascalAI Usage

uses promptlib;

var
  Prompt   := Get('refactor-guide');
  Rendered := Bind(Prompt, [
    'language',         'Java',
    'refactoring_type', 'reduce coupling and extract services',
    'risk_tolerance',   'medium',
    'preserve_api',     'yes'
  ]);
  Plan := LLM.Complete(Rendered);

Output Sections

1. Current State Assessment

Identified code smells (long methods, god classes, feature envy), cyclomatic complexity scores, and coupling hotspots.

2. Refactoring Strategy

Selected refactoring patterns (Extract Method, Strangler Fig, Introduce Parameter Object, etc.) with justification for each given the stated risk tolerance.

3. Step-by-Step Transformation Plan

Ordered sequence of atomic changes, each with a Before/After code snippet, the exact refactoring technique applied, and a safety check to run before proceeding.

4. Tests to Write Before Starting

Characterization tests (golden-master or approval tests) that lock in current observable behaviour so regressions are caught immediately.

5. Risk Assessment + Rollback Plan

What could break at each step, how to detect it via CI or runtime metrics, and concrete rollback instructions including feature flags or branch strategy.

6. Post-Refactoring Verification

Checklist of metrics to confirm improvement: complexity reduction, test coverage delta, coupling scores, and a final code review checklist.