The Three-Step Workflow for Legacy Systems
Legacy codebases are often defined by poor documentation, complex data flows, and a lack of tests. Rather than attempting a massive refactor, adopt a change-request-driven approach: learn the codebase organically by only modifying what is necessary. This is executed through three distinct phases:
- Plan: Prepare a sandbox (ideally using Docker) and document local build, linter, and testing tools in a
README. This allows the AI to self-correct by running tests and catching syntax errors in a disposable environment. Before writing code, use 'planning mode' to map the 'blast radius' of changes, identifying which APIs or database tables will be affected. - Execute: Treat the AI as a human coworker rather than a typewriter. Use a 'model split' strategy: employ high-reasoning models to draft acceptance criteria and tests (BDD/TDD), then hand off the implementation to faster, cheaper models. To prevent context drift, break large tasks into small subtasks and maintain a markdown checklist to track progress.
- Verify: Implement a three-layer filter to prevent bugs from reaching production: (1) Human code review, (2) automated CI/CD AI review where a second model critiques the PR, and (3) automated smoke tests in a staging environment.
Establishing Guardrails and Rules
To maintain quality and consistency, define 'Agent Rules' that dictate how the AI behaves. These rules act as automatic guardrails, enforcing standards such as 'always write tests first,' 'check that the app builds,' and 'never commit without permission.' By forcing the agent to generate multiple architectural options and critique its own plans, you can smoke out hidden requirements and ensure the AI remains aligned with your team's engineering standards.