Refactoring
- Establish a behavior baseline with tests or reproducible commands.
- Identify the ownership boundary and dependency direction the code should follow.
- Move in small compilable steps; avoid simultaneous semantic changes unless explicitly required.
- Preserve public APIs or provide an intentional migration path.
- Delete replaced code and update imports, docs, tests, and generated artifacts.
- Compare behavior and performance before and after.