AI-Assisted Full-Scale Refactoring in Practice: A Methodology for Clearing All Technical Debt in 1 Day

How to leverage AI sub-agents and parallel building to completely refactor a project and clear all technical debt in just one day.
This article shares a real-world case of using AI to fully refactor a debt-ridden project in just one day. It covers the three-phase methodology — information gathering, critical decision-making (choosing full rewrite over incremental fixes), and parallel implementation using AI sub-agents — along with key insights on treating automated tests as acceptance criteria and adopting a project-manager style of AI collaboration.
Introduction: In the Age of AI Programming, Technical Debt Accumulation Is Nearly Inevitable
When you've been using AI-assisted programming for a while, the accumulation of technical debt is almost unavoidable. The concept of Technical Debt was first introduced by Ward Cunningham in 1992 to describe compromises made in software design for the sake of short-term delivery speed. In traditional development, technical debt is usually a conscious trade-off decision. But in AI-assisted programming scenarios, technical debt accumulation takes on entirely new characteristics — it's often unconscious and accelerated. AI-generated code tends to solve the immediate problem rather than pursue global optimization. The limited context window of each conversation makes it difficult for AI to maintain overall architectural consistency. After multiple iterations, inconsistencies in code style and design patterns quickly compound, resulting in debt accumulation that's even faster than manual coding.
When a project enters the vicious cycle of "fix A, break B; fix B, break C and D," incremental patches can no longer solve the problem. A Chinese Bilibili creator known as "Grape" shared a bold decision in episode 109 of his AI programming series — to completely refactor his multi-character voice dubbing project, rebuilding it from scratch, and the entire process took just 1 day.
This case offers an important insight: in the era of AI-assisted development, the cost of refactoring has dropped dramatically. The key lies in methodology and collaboration strategy with AI.
Why Choose Full-Scale Refactoring Over Incremental Fixes
After multiple rounds of AI-assisted development, the project had accumulated significant technical debt:
- Fragmented entry points: Multiple entry points mapped to different ports, creating a chaotic structure
- Scattered configuration: Configuration information spread across multiple locations
- Dead module buildup: Numerous useless dependencies introduced during exploration
- Oversized files: Individual files reaching 2,000+, 1,700+, and 1,500+ lines
- Dangling calls: Inconsistencies between registration methods and usage patterns
- Bloated installation packages: An audio synthesis project with a staggering 1.9GB of dependencies

The dependency bloat issue deserves special attention. 1.9GB of dependencies is indeed abnormally bloated for an audio synthesis project. This phenomenon is known as "Dependency Hell" in modern software development. Its root cause lies in the transitive dependency mechanism of package managers — installing one library may automatically pull in dozens or even hundreds of indirect dependencies. In AI-assisted programming, this problem is particularly severe: AI suggests installing various libraries while exploring solutions, and even when the final solution only uses a small fraction of them, the abandoned libraries and their dependencies remain in the project. The author's mention of "a single full suite taking up 600-700MB" likely refers to a complete installation of a machine learning framework, which contains massive GPU computing libraries and precompiled binaries with staggering file sizes.
The author's judgment was clear: this wasn't a matter of poorly written code, but rather a project that had never undergone a "clean refactoring" after multiple iterations. Since it was a self-maintained project with no need to consider other users, a bold and thorough rebuild was the way to go.
Refactoring Methodology: Three Phases of AI Collaboration
Phase 1: Information Gathering and Solution Design (~1.5 hours)
The author first had the AI dispatch Sub-agents to comprehensively understand the current project's planning and design intent. Sub-agents are a task decomposition mechanism in modern AI programming tools (such as Claude Code, Cursor, etc.). When the main agent receives a complex task, it can break it down into multiple subtasks and dispatch independent sub-agents to handle them in parallel. Each Sub-agent has its own execution context and can simultaneously read different files, analyze different modules, and execute different code modifications. This mechanism is similar to the "divide and conquer" strategy in software engineering. Its advantage is that parallel processing dramatically reduces total time, while each sub-agent focuses on a local task, reducing context window pressure.
Key instructions included:
- Gather information and propose a rough framework — review before deciding
- Document the plan in Markdown format — ensure traceability
- Create a separate Git branch — to prevent uncontrollable issues

In the solution design, the author made several core decisions:
- Completely remove all Alibaba Cloud-related modules, keeping only DeepSeek and Doubao
- Reuse the existing AI invocation framework (scaffolding) from the main project
- Prepare for eventually merging the multi-character dubbing feature as a module of the main project
- Keep the two projects independent, since the current project was clearly not mature enough
Phase 2: The Critical Decision — Don't Build on Ruins
This was the most important decision point in the entire refactoring process. When the AI leaned toward "replacing one module at a time," the author explicitly rejected this incremental approach:
"Throw away all the previous code completely and re-architect from scratch in the most appropriate and rational way."
This decision touches on a classic debate in software engineering. The "small-step refactoring" advocated by Martin Fowler in Refactoring: Improving the Design of Existing Code is the mainstream industry methodology — make only tiny changes at a time, paired with continuous testing, ensuring the system remains runnable at all times. It's low-risk, rollback-friendly, and the preferred approach for enterprise projects. On the other hand, the "Big Bang Rewrite" is something Joel Spolsky and others have strongly opposed — he once called Netscape's full rewrite "the single worst strategic mistake that any software company can make." However, AI-assisted development is changing this equation: AI's parallel building capabilities and rapid code generation compress the time cost of a full rewrite from weeks to hours, while the problem of AI getting "lost in legacy code" during incremental refactoring actually becomes a new risk factor.
The author explained why he didn't adopt the traditional "small steps with rollback" refactoring strategy: when AI processes things bit by bit, it tends to get "confused" and ends up re-introducing the historical baggage that was supposed to be discarded. Since someone (the author himself) was watching the whole time, it was better to do it all at once.

Phase 3: Parallel Build Implementation (~5 hours)
Construction began at 7 PM and was fully completed by 11 PM, including call testing. The core acceleration technique during the implementation phase was: having AI dispatch Sub-agents to build in parallel. Multiple sub-agents simultaneously handled different modules — one responsible for backend API rebuilding, one for frontend interface migration, one for configuration system unification — this parallel capability is the greatest advantage of AI refactoring over manual refactoring.

Several key safeguards during implementation:
- Automated tests as acceptance criteria: Previously accumulated test cases served as a safety net for the refactoring. The role automated tests play in refactoring is essentially a "behavioral contract" — they define what output the system should produce for various inputs. When code is completely rewritten, as long as all test cases still pass, you can be largely confident that the new system maintains the functional integrity of the old one. This is known as "Regression Testing" in software engineering. Notably, the test cases the author accumulated during AI-assisted development proved unexpectedly valuable in this refactoring — they transformed from "development aids" into "refactoring acceptance criteria." This also reminds us that even during rapid AI programming iterations, the investment in writing test cases may only truly pay off during refactoring.
- Side-by-side comparison of old and new versions: Ensuring the new version possessed all capabilities of the old one
- Implementation in 10 slices: Each slice could be independently verified
Concrete Results of the Refactoring
After this full-scale refactoring, the project saw significant improvements:
- Consolidated configuration entry: Unified management, no longer scattered everywhere
- Separation of code and build artifacts: Code is code, compiled files are compiled files
- Clear directory architecture: Both frontend and backend have well-organized directory structures
- Dramatically slimmed dependencies: Removed various useless packages introduced during exploration (a single full suite alone was 600-700MB)
- Historical materials archived: Historical materials organized into categorized directories
- Port conflict resolution: Avoided port conflicts with other projects
Three Insights for AI Programming Practice
Don't Fear Refactoring — AI Has Dramatically Reduced Its Cost
In the era of AI-assisted development, the cost of refactoring has dropped from "weeks" to "1 day." The key prerequisites are:
- Clear ability to describe requirements
- Automated tests as acceptance criteria
- Well-defined architectural goals
This means a developer's core competitive advantage is shifting from "the ability to write code" to "the ability to describe problems and define standards." You don't need to be able to write every line of code, but you need to clearly tell the AI what you want, what you don't want, and how to verify whether the results are correct.
Master the "Project Manager" Style of AI Collaboration
The author demonstrated an efficient hierarchical approach to AI collaboration:
- Not scrutinizing the architecture plan AI rebuilt in detail ("I couldn't fully understand it even if I looked")
- But intervening at critical decision points (such as rejecting incremental refactoring)
- Validating results through test cases and old-vs-new comparisons
The core of this model is: focus your energy on decisions and acceptance, and delegate execution to AI. This closely mirrors the role of a "project manager" in traditional software project management — a project manager doesn't need to personally write every line of code but needs to control direction, make key decisions, and ensure delivery quality. In the AI programming era, every developer has to some extent become a "project manager of an AI team," managing not human engineers but a group of AI agents.
Be Decisive About When to Address Technical Debt
When a project shows symptoms of "whack-a-mole" — fix one thing, another pops up — rather than struggling in an ocean of bugs, it's better to decisively choose full-scale refactoring. This is especially true for personal projects, where there's no burden of backward compatibility, and the benefits of refactoring are immediate — all historical baggage cleared in one shot.
To determine whether a full-scale refactoring is needed, watch for these signals: fixing one bug on average introduces more than one new bug; AI's success rate when modifying existing code is consistently declining; you spend more time explaining the existing code structure to AI than describing the requirements themselves. When these signals appear simultaneously, it usually means the cost of incremental fixes has exceeded the cost of a complete rebuild.
Conclusion
The core value of this case isn't in the technical details, but in the shift in mindset: refactoring strategies in the AI era can be far more aggressive. When you have clear goals, comprehensive tests, and AI's parallel building capabilities, "starting from scratch" is no longer a frightening choice — it's an efficient one. One day of investment yields a clean, clear, and sustainably evolvable codebase.
From a broader perspective, this also signals a change in the software development lifecycle model. Traditional software engineering emphasizes "design once, maintain continuously," but the AI-assisted development era may give rise to a new paradigm — "rapid prototyping, periodic rebuilding." When refactoring costs are low enough, maintaining long-term code cleanliness is no longer the only strategy. Periodic "tear it down and start over" may actually be the more economical choice.
Related articles

AI Full-Stack Development Architecture: A Three-Layer Progressive Path from Prototype to Production
A detailed guide to AI full-stack development architecture covering Node.js+TypeScript+Monorepo engineering, Docker CI/CD deployment, and AI engine design with interview tips.

The AI Industry's Psychological Warfare: Narrative Manipulation, Ecosystem Lock-In, and the Endgame
Behind the AI industry's relentless product launches and narrative building lie deeper battles over data monopolies, ecosystem lock-in, and expectation management. A deep dive into the psyop phenomenon.

ByteDance Codex Chinese Manual: An In-Depth Guide to AI-Powered Programming
In-depth analysis of the ByteDance Codex Chinese Manual covering multi-language support, prompt standards, context management, and practical templates for AI programming.