Overview
Use this refactoring method:
- Map the current modules and the dependencies between them.
- Identify clusters of files that together provide one meaningful capability.
- Define a small interface for that capability.
- Move the related logic behind the interface.
- Create tests around the external behavior of the deeper module.
- Update callers to depend on the interface rather than internal pieces.
- Record the module and interface explicitly in future product and implementation plans.
- Delegate internal implementation only after the interface and test boundary are clear.
For an end-to-end capability, the deep module may span a large flow. A browser-based editor, for example, can be structured so that an action at the interface is traceable through the back end and testable from the outside. Giving the agent a visible full flow and a reliable test boundary can transform its ability to make changes safely.