Prompt Engineering Refactoring Architecture

Architecture Cleanup Prompt — Boundaries Without a Redesign

Dependency cycles, leaky modules, misplaced responsibilities — cleaned up within the existing design. Explicitly not an invitation to invent a new architecture.

Overview

Architecture refactors attract scope explosions: asked to break one dependency cycle, the model proposes a hexagonal rewrite. This prompt uses the architecture cleanup goal with its built-in fence — straighten boundaries and dependencies within the existing design; do not invent a new architecture, introduce new layers, or redesign the system. The priorities are practical: modules expose purpose not internals, high-level policy stops depending on low-level detail, cycles get broken, misplaced responsibilities move to the module that owns the concept. An aggressive risk profile allows real restructuring — staged, verifiable, and traceable to the goal.

How to use this resource

  1. Fence the scope

    Cleanup within the existing design — the contract names the redesign temptation and forbids it.

  2. Fix direction and ownership

    Dependencies point from policy to detail, cycles break, responsibilities move to their owning module.

  3. Verify at the seams

    Module moves change visibility and initialization order — every consumer must still get the same contract.

Why This Works

  • The explicit no-redesign fence prevents the scope explosion these refactors are famous for
  • Dependency direction is checkable — vibes-based "cleaner architecture" is not
  • Integration-level validation catches what unit-level checks miss in module moves

Best for

  • Codebases where module boundaries eroded gradually
  • Restructuring that must stay shippable at every stage
  • Teams that want cleanup, not an architecture pitch

Not for

  • Designing a new system architecture from requirements — out of scope by the contract's own rules
  • Documenting the existing architecture — that's the Markdown Output Builder's space

Use cases

  • Breaking a dependency cycle between two packages
  • Moving misplaced responsibilities to the module that owns them
  • Narrowing a module interface that leaks internals

FAQ

Will this prompt propose a rewrite when I ask it to break one dependency cycle?

That's exactly what the built-in fence prevents. The TRANSFORMATION GUIDANCE states this is "cleanup within the existing architecture — do not invent a new architecture, introduce new layers, or redesign the system." So a request to break the reporting-package cycle stays scoped to boundaries and dependency direction, not the hexagonal rewrite these refactors usually attract.

The risk level is set to Aggressive — does that mean it can change behavior?

Aggressive applies only to the SIZE of the change, never its safety: no behavioral assumptions, no feature invention, no guessed requirements. The BEHAVIOR PRESERVATION requirements keep outputs, business rules, side-effect ordering, and public contracts identical, and if the goal and preserving behavior ever conflict, behavior wins and the model stops to explain.

How does it check that moving a module didn't quietly break a consumer?

The VALIDATION STRATEGY validates at the integration level, because "a module move preserves behavior only if every consumer still gets the same contract." It asks for a before/after verification plan, a behavior comparison per changed unit, and integration checks on every external touchpoint — since moving code across boundaries shifts visibility and initialization order.

More resources from Refactor Prompt Builder

Resources that pair well

Related tools

Tip: Save time by exploring related resources and tools that integrate with this resource.