OctiAI

Categories

Legacy Module Refactor Roadmap Template

Operator-grade, milestone-driven plan that converts legacy code + tech‑debt notes into verifiable, reversible refactor milestones with interface contracts, tests, CI gates, and...

What You'll Get

How to Use

Make each milestone small, testable, and reversible

Limit each milestone to a single responsibility (ex: extract pure transform, split interface, add adapter). Require: (a) a minimal pseudo-diff that compiles, (b) two automated tests for every changed public API (happy + edge/failure), and (c) CI gating with clear thresholds. This minimizes regression risk and keeps rollbacks trivial.

Works Best With

Best used when you can provide code excerpts, CI config, and runtime SLOs

Prompt Template


# Developer Productivity Prompt Blueprint (use EXACT section order)

## Goal
- Produce a prioritized, milestone-based refactor roadmap to break a legacy module into modular components without changing external behavior. Deliver milestones, interface contracts, migration steps, short-term mitigations, success metrics, estimated timelines, rollback strategy, and verification tests.

## Inputs
- Provide the following artifacts when running the prompt:
  - Code excerpts: core files under the legacy module and public callers.
  - Repo context: file paths and build/test commands.
  - Tech-debt notes: current issues, TODOs, known hacks.
  - Runtime constraints: latency, memory, cold-starts, concurrency, GC, deployment model.
  - Desired end-state: target module boundaries, public API surface, deployment units.
  - Constraints & non-goals: e.g., "no behavioral changes", "no major rewrites", "no new infra".
  - Current CI status and test coverage metrics.
- If any of the above are missing, the prompt will request the minimal missing artifacts before proceeding.

## Prompt
You are a senior engineer tasked with producing an operator-grade refactor roadmap for a legacy code module. Work from the repository root {{repo_root}} and focus on the legacy module at {{module_path}}. Use the tech-debt notes below and respect the runtime constraints below. The goal is to reach the desired end-state described below without breaking existing behavior and while minimizing scope creep.

Tech-debt notes:
{{tech_debt_notes}}

Runtime constraints:
{{runtime_constraints}}

Desired end-state:
{{desired_end_state}}

Risk tolerance (choose one): {{risk_tolerance}}

Deliverables required (produce all sections exactly as specified in Output Format). For each milestone, provide:
- Concrete files to change and minimal diffs (pseudo-diff snippets).
- Clear interface contracts (types/signatures/behaviors) for new modules.
- Migration steps with ordering, required build/test commands, and expected CI gating.
- Acceptance criteria (precise checks that confirm no behavioral change).
- Rollback instructions for each milestone.
- Estimated timeline (in days) and required reviewer roles.

Procedure:
1. First, list assumptions and unknowns derived from the inputs. If any critical artifact is missing, stop and list the exact files/snippets required.
2. Produce 5 ranked likely root-cause hypotheses that explain why the module accumulated tech debt; include confidence score (%) and indicators to validate each hypothesis.
3. Create a prioritized set of milestones (3-7), each with: objective, scope, required interface contracts, explicit migration steps (ordered), minimal patch examples (diff-like), verification commands, acceptance criteria, rollback plan, and estimated timeline.
4. For each milestone, list the top 3 risks and at least one short-term mitigation that preserves behavior.
5. Provide a minimal-attack surface strategy: which files/classes/functions must remain untouched until final integration to avoid regressions.
6. Provide an automated test/verification checklist per milestone: unit tests to add, integration tests to run, invariants to assert, smoke tests, and performance regression checks (commands and thresholds).
7. Provide CI gating rules and required metrics to declare a milestone "green" (e.g., test pass, coverage delta ≤ X, latency change ≤ Y%).
8. Produce a rollback plan and “stop criteria” that indicate when to halt the refactor and revert.
9. Provide a final summary roadmap combining milestones into a timeline with estimated total effort and required reviewers.

Formatting and strict requirements:
- Produce structured, ordered outputs only. Use numbered steps and bullet lists; avoid prose paragraphs.
- Output must include code-like pseudo-diff snippets for any suggested changes (5-20 lines) and explicit shell/CI commands to run verification.
- Prioritize minimal diffs and non-invasive changes; mark any suggested change that is invasive with a risk tag HIGH.
- When proposing interface contracts, include example signatures (language-appropriate), expected inputs/outputs, and error behaviors.
- Generate at least two concrete test cases per changed public API: one happy-path and one edge/failure case.
- All placeholders above are required and will be substituted before execution. If a placeholder cannot be filled, the agent must request it as per step 1.

Tone: decisive, engineering-first, risk-aware. Do not propose full rewrites. Keep each milestone atomic and reversible.

## Output Format
Output:
1) Assumptions/Unknowns
2) Likely root causes (ranked)
3) Fix plan (stepwise milestones with timelines)
4) Patch suggestions (minimal diffs / interface contracts)
5) Test/verification checklist (per milestone, with commands and thresholds)

Be exact and machine-parseable: use ordered lists, nested bullets, and code-like snippets where needed.

## Guardrails
- Do not assume files or behaviors not provided in {{repo_root}} and {{module_path}}.
- Prefer minimal, local changes; avoid touching unrelated modules.
- Do not introduce breaking changes to public APIs unless explicitly approved in {{desired_end_state}}.
- Every milestone must be independently verifiable and revertible.
- Mark any speculative recommendation (due to missing data) with "SPECULATIVE" and the missing evidence required.

## Examples
- Mini root-cause + fix excerpt:
  1) Root cause: Single god-class holding state and side-effects (confidence 85%). Indicator: many unrelated methods in one file and wide use of mutable singletons.
  2) Minimal fix excerpt (pseudo-diff):
     - src/legacy/service.js
       - remove: function processAll(items) { /* huge function with DB + metrics + formatting */ }
       + add: export function processItems(items) { return Worker.process(items) }
       + add: // new module src/legacy/worker.js with pure transform + injected DB client
  3) Quick verification: run npm run test:unit src/legacy/worker.test.js; expected: all tests pass and coverage delta ≤ 1%

Variables

Usage Notes

Not for

Do not include

Legacy Module Refactor Roadmap Template

Convert a legacy module, tech‑debt notes, and runtime constraints into a prioritized, milestone-based refactor roadmap that preserves external behavior and provides minimal diffs, interface contracts, migration steps, per-milestone tests, CI gating, rollback plans, and an integrated timeline.

Turn this into a working asset in minutes.

Import into Workspace to auto-fill variables, adapt output style, and iterate with OctiAI's prompt editor.

What you'll get

Output format

Markdown

Best used when

Avoid when

Sign in to save, like, or rate this prompt.

Made for

What to fill in

Use the guidance below to complete each placeholder with the right level of detail.

Repo Root

Provide the key details needed for this variable.

Module Path

Provide the key details needed for this variable.

Tech Debt Notes

Provide the key details needed for this variable.

Runtime Constraints

Provide the key details needed for this variable.

Desired End State

Provide the key details needed for this variable.

Risk Tolerance

Provide the key details needed for this variable.

Rules

Canonical Examples

Input: Refactor legacy payment processor module at /repo/services/payment-processor to split core business logic, DB access, and third-party gateway integration. Provided: core files (processor.js, db.js, gateway.js), public callers list, repo build/test commands (npm ci; npm test), tech-debt notes, runtime constraints (latency < 300ms P95, memory 256MB), desired end-state (separate modules: core, store, gateway; same public API), risk_tolerance: medium.

Loading result...

Failed to load output.


1) Assumptions/Unknowns
2) Root causes (ranked)
3) Fix plan (4 milestones)
4) Patch suggestions (pseudo-diffs + interfaces)
5) Test/verification checklist (per milestone, commands, thresholds)

Why it works: Focuses on minimal, reversible changes that extract pure logic into a new core module with clear interfaces; each milestone is atomic, test-gated, and includes rollback instructions and verification commands so SREs and reviewers can validate behavior and performance before progressing.

Input: Refactor legacy auth module at monorepo/packages/auth to separate session management from credential verification. Provided: auth/index.ts, auth/session.ts, docs listing public API, tech-debt notes (mixed sync IO + crypto, missing typed interfaces), runtime constraints (cold start critical), desired end-state: separate packages auth-core and auth-session with same external API, risk_tolerance: low.

Loading result...

Failed to load output.


Structured roadmap: assumptions, ranked root causes, 3-5 milestones with pseudo-diffs, interface contracts, test cases, CI gating and rollback rules.

Why it works: Breaks module into core verification and session management with explicit TypeScript interfaces and small non-invasive patches; emphasizes preserving initialization/cold-start characteristics and adding unit coverage to prevent regressions. Includes precise interface signatures and test cases to catch crypto and sync-I/O regressions.

Works Best With

Best used when you can provide code excerpts, CI config, and runtime SLOs