# Refactoring Existing Project This tutorial guides through analyzing, documenting, and refactoring an existing codebase. ## 4.05 **🧑‍💻 Developers**: User Input ### Define Goals Create in `_docs/00_problem`: - `problem_description.md`: What system currently does + what you want to change/improve - `acceptance_criteria.md`: Success criteria for the refactoring - `security_approach.md`: Security requirements (if applicable) ## 4.10 **🤖📋AI plan**: Build Documentation from Code ### Execute `/4.refactoring/4.10_documentation` ### Revise - Review generated component docs - Verify accuracy against actual code behavior ## 4.20 **🤖📋AI plan**: Form Solution with Flows ### Execute `/4.refactoring/4.20_form_solution_flows` ### Revise - Review solution description - Verify flow diagrams match actual system behavior - Store to `_docs/01_solution/solution.md` ## 4.30 **🤖✨AI Research**: Deep Research of Approaches ### Execute `/4.refactoring/4.30_deep_research` ### Revise - Review suggested improvements - Prioritize changes based on impact vs effort ## 4.35 **🤖✨AI Research**: Solution Assessment with Codebase ### Execute `/4.refactoring/4.35_solution_assessment` ### Revise - Review weak points identified in current implementation - Decide which to address ## 4.40 **🤖📋AI plan**: Integration Tests Description ### Execute `/4.refactoring/4.40_tests_description` ### Revise - Ensure tests cover critical functionality - Add edge cases ## 4.50 **🤖📋AI plan**: Implement Tests ### Execute `/4.refactoring/4.50_implement_tests` ### Verify - All tests pass on current codebase - Tests serve as safety net for refactoring ## 4.60 **🤖📋AI plan**: Analyze Coupling ### Execute `/4.refactoring/4.60_analyze_coupling` ### Revise - Review coupling analysis - Prioritize decoupling strategy ## 4.70 **🤖📋AI plan**: Execute Decoupling ### Execute `/4.refactoring/4.70_execute_decoupling` ### Verify - Run integration tests after each change - All tests must pass before proceeding ## 4.80 **🤖📋AI plan**: Technical Debt ### Execute `/4.refactoring/4.80_technical_debt` ### Revise - Review debt items - Prioritize by impact ## 4.90 **🤖📋AI plan**: Performance Optimization ### Execute `/4.refactoring/4.90_performance` ### Verify - Benchmark before/after - Run tests to ensure no regressions ## 4.95 **🤖📋AI plan**: Security Review ### Execute `/4.refactoring/4.95_security` ### Verify - Address identified vulnerabilities - Run security tests if applicable