framework-migration-legacy-modernize

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Legacy Code Modernization Workflow

遗留代码现代化工作流

Orchestrate a comprehensive legacy system modernization using the strangler fig pattern, enabling gradual replacement of outdated components while maintaining continuous business operations through expert agent coordination.
[Extended thinking: The strangler fig pattern, named after the tropical fig tree that gradually envelops and replaces its host, represents the gold standard for risk-managed legacy modernization. This workflow implements a systematic approach where new functionality gradually replaces legacy components, allowing both systems to coexist during transition. By orchestrating specialized agents for assessment, testing, security, and implementation, we ensure each migration phase is validated before proceeding, minimizing disruption while maximizing modernization velocity.]
采用Strangler Fig Pattern(绞杀者模式)编排全面的遗留系统现代化工作,通过专业Agent协调,在逐步替换过时组件的同时保持业务持续运行。
[扩展思考:Strangler Fig Pattern得名于一种会逐渐包裹并取代宿主的热带无花果树,是管控风险的遗留系统现代化的黄金标准。本工作流采用系统化方法,让新功能逐步替换遗留组件,允许新旧系统在过渡期间共存。通过协调负责评估、测试、安全和实施的专业Agent,我们确保每个迁移阶段在推进前都经过验证,在最大程度提升现代化速度的同时将业务中断降至最低。]

Use this skill when

适用场景

  • Working on legacy code modernization workflow tasks or workflows
  • Needing guidance, best practices, or checklists for legacy code modernization workflow
  • 处理遗留代码现代化工作流相关任务或流程
  • 需要遗留代码现代化工作流的指导、最佳实践或检查清单

Do not use this skill when

不适用场景

  • The task is unrelated to legacy code modernization workflow
  • You need a different domain or tool outside this scope
  • 任务与遗留代码现代化工作流无关
  • 需要此范围之外的其他领域或工具

Instructions

操作指引

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.
  • If detailed examples are required, open
    resources/implementation-playbook.md
    .
  • 明确目标、约束条件和所需输入。
  • 应用相关最佳实践并验证结果。
  • 提供可执行步骤和验证方法。
  • 如需详细示例,请打开
    resources/implementation-playbook.md

Phase 1: Legacy Assessment and Risk Analysis

阶段1:遗留系统评估与风险分析

1. Comprehensive Legacy System Analysis

1. 全面遗留系统分析

  • Use Task tool with subagent_type="legacy-modernizer"
  • Prompt: "Analyze the legacy codebase at $ARGUMENTS. Document technical debt inventory including: outdated dependencies, deprecated APIs, security vulnerabilities, performance bottlenecks, and architectural anti-patterns. Generate a modernization readiness report with component complexity scores (1-10), dependency mapping, and database coupling analysis. Identify quick wins vs complex refactoring targets."
  • Expected output: Detailed assessment report with risk matrix and modernization priorities
  • 使用Task工具,设置subagent_type="legacy-modernizer"
  • 提示词:"分析位于$ARGUMENTS的遗留代码库。记录技术债务清单,包括:过时依赖项、已弃用API、安全漏洞、性能瓶颈和架构反模式。生成包含组件复杂度评分(1-10)、依赖映射和数据库耦合分析的现代化就绪报告。识别快速优化项与复杂重构目标。"
  • 预期输出:包含风险矩阵和现代化优先级的详细评估报告

2. Dependency and Integration Mapping

2. 依赖与集成映射

  • Use Task tool with subagent_type="architect-review"
  • Prompt: "Based on the legacy assessment report, create a comprehensive dependency graph showing: internal module dependencies, external service integrations, shared database schemas, and cross-system data flows. Identify integration points that will require facade patterns or adapter layers during migration. Highlight circular dependencies and tight coupling that need resolution."
  • Context from previous: Legacy assessment report, component complexity scores
  • Expected output: Visual dependency map and integration point catalog
  • 使用Task工具,设置subagent_type="architect-review"
  • 提示词:"基于遗留系统评估报告,创建全面的依赖关系图,包括:内部模块依赖、外部服务集成、共享数据库架构和跨系统数据流。识别迁移期间需要使用facade patterns或adapter layers的集成点。突出显示需要解决的循环依赖和紧耦合问题。"
  • 前置上下文:遗留系统评估报告、组件复杂度评分
  • 预期输出:可视化依赖关系图和集成点目录

3. Business Impact and Risk Assessment

3. 业务影响与风险评估

  • Use Task tool with subagent_type="business-analytics::business-analyst"
  • Prompt: "Evaluate business impact of modernizing each component identified. Create risk assessment matrix considering: business criticality (revenue impact), user traffic patterns, data sensitivity, regulatory requirements, and fallback complexity. Prioritize components using a weighted scoring system: (Business Value × 0.4) + (Technical Risk × 0.3) + (Quick Win Potential × 0.3). Define rollback strategies for each component."
  • Context from previous: Component inventory, dependency mapping
  • Expected output: Prioritized migration roadmap with risk mitigation strategies
  • 使用Task工具,设置subagent_type="business-analytics::business-analyst"
  • 提示词:"评估每个已识别组件现代化后的业务影响。创建风险评估矩阵,考虑:业务关键性(收入影响)、用户流量模式、数据敏感性、监管要求和回退复杂度。采用加权评分系统对组件进行优先级排序:(业务价值 × 0.4) + (技术风险 × 0.3) + (快速优化潜力 × 0.3)。为每个组件定义回滚策略。"
  • 前置上下文:组件清单、依赖映射
  • 预期输出:带有风险缓解策略的优先级迁移路线图

Phase 2: Test Coverage Establishment

阶段2:测试覆盖率建立

1. Legacy Code Test Coverage Analysis

1. 遗留代码测试覆盖率分析

  • Use Task tool with subagent_type="unit-testing::test-automator"
  • Prompt: "Analyze existing test coverage for legacy components at $ARGUMENTS. Use coverage tools to identify untested code paths, missing integration tests, and absent end-to-end scenarios. For components with <40% coverage, generate characterization tests that capture current behavior without modifying functionality. Create test harness for safe refactoring."
  • Expected output: Test coverage report and characterization test suite
  • 使用Task工具,设置subagent_type="unit-testing::test-automator"
  • 提示词:"分析位于$ARGUMENTS的遗留组件的现有测试覆盖率。使用覆盖率工具识别未测试的代码路径、缺失的集成测试和未覆盖的端到端场景。对于覆盖率<40%的组件,生成可捕获当前行为而不修改功能的特征测试。创建用于安全重构的测试工具集。"
  • 预期输出:测试覆盖率报告和特征测试套件

2. Contract Testing Implementation

2. 契约测试实施

  • Use Task tool with subagent_type="unit-testing::test-automator"
  • Prompt: "Implement contract tests for all integration points identified in dependency mapping. Create consumer-driven contracts for APIs, message queue interactions, and database schemas. Set up contract verification in CI/CD pipeline. Generate performance baselines for response times and throughput to validate modernized components maintain SLAs."
  • Context from previous: Integration point catalog, existing test coverage
  • Expected output: Contract test suite with performance baselines
  • 使用Task工具,设置subagent_type="unit-testing::test-automator"
  • 提示词:"为依赖映射中识别的所有集成点实施契约测试。为API、消息队列交互和数据库架构创建消费者驱动契约。在CI/CD流水线中设置契约验证。生成响应时间和吞吐量的性能基准,以验证现代化组件是否符合SLA要求。"
  • 前置上下文:集成点目录、现有测试覆盖率
  • 预期输出:带有性能基准的契约测试套件

3. Test Data Management Strategy

3. 测试数据管理策略

  • Use Task tool with subagent_type="data-engineering::data-engineer"
  • Prompt: "Design test data management strategy for parallel system operation. Create data generation scripts for edge cases, implement data masking for sensitive information, and establish test database refresh procedures. Set up monitoring for data consistency between legacy and modernized components during migration."
  • Context from previous: Database schemas, test requirements
  • Expected output: Test data pipeline and consistency monitoring
  • 使用Task工具,设置subagent_type="data-engineering::data-engineer"
  • 提示词:"设计用于并行系统运行的测试数据管理策略。创建边缘场景的数据生成脚本,为敏感信息实现数据掩码,并建立测试数据库刷新流程。设置迁移期间遗留组件与现代化组件之间的数据一致性监控。"
  • 前置上下文:数据库架构、测试要求
  • 预期输出:测试数据管道和一致性监控方案

Phase 3: Incremental Migration Implementation

阶段3:增量迁移实施

1. Strangler Fig Infrastructure Setup

1. 绞杀者模式基础设施搭建

  • Use Task tool with subagent_type="backend-development::backend-architect"
  • Prompt: "Implement strangler fig infrastructure with API gateway for traffic routing. Configure feature flags for gradual rollout using environment variables or feature management service. Set up proxy layer with request routing rules based on: URL patterns, headers, or user segments. Implement circuit breakers and fallback mechanisms for resilience. Create observability dashboard for dual-system monitoring."
  • Expected output: API gateway configuration, feature flag system, monitoring dashboard
  • 使用Task工具,设置subagent_type="backend-development::backend-architect"
  • 提示词:"搭建带有API网关的Strangler Fig基础设施以实现流量路由。使用环境变量或特性管理服务配置特性标志,用于逐步发布。设置代理层,基于以下规则实现请求路由:URL模式、请求头或用户分段。实现断路器和回退机制以提升弹性。创建用于双系统监控的可观测性仪表板。"
  • 预期输出:API网关配置、特性标志系统、监控仪表板

2. Component Modernization - First Wave

2. 组件现代化 - 第一阶段

  • Use Task tool with subagent_type="python-development::python-pro" or "golang-pro" (based on target stack)
  • Prompt: "Modernize first-wave components (quick wins identified in assessment). For each component: extract business logic from legacy code, implement using modern patterns (dependency injection, SOLID principles), ensure backward compatibility through adapter patterns, maintain data consistency with event sourcing or dual writes. Follow 12-factor app principles. Components to modernize: [list from prioritized roadmap]"
  • Context from previous: Characterization tests, contract tests, infrastructure setup
  • Expected output: Modernized components with adapters
  • 使用Task工具,设置subagent_type="python-development::python-pro"或"golang-pro"(基于目标技术栈)
  • 提示词:"对评估中识别的第一阶段组件(快速优化项)进行现代化改造。针对每个组件:从遗留代码中提取业务逻辑,使用现代模式(依赖注入、SOLID原则)实现,通过适配器模式确保向后兼容性,使用事件溯源或双写机制保持数据一致性。遵循12-factor app原则。需现代化的组件:[来自优先级迁移路线图的列表]"
  • 前置上下文:特征测试、契约测试、基础设施搭建
  • 预期输出:带有适配器的现代化组件

3. Security Hardening

3. 安全加固

  • Use Task tool with subagent_type="security-scanning::security-auditor"
  • Prompt: "Audit modernized components for security vulnerabilities. Implement security improvements including: OAuth 2.0/JWT authentication, role-based access control, input validation and sanitization, SQL injection prevention, XSS protection, and secrets management. Verify OWASP top 10 compliance. Configure security headers and implement rate limiting."
  • Context from previous: Modernized component code
  • Expected output: Security audit report and hardened components
  • 使用Task工具,设置subagent_type="security-scanning::security-auditor"
  • 提示词:"审计现代化组件的安全漏洞。实施安全改进措施,包括:OAuth 2.0/JWT认证、基于角色的访问控制、输入验证与清理、SQL注入防护、XSS防护和密钥管理。验证是否符合OWASP Top 10标准。配置安全头并实现速率限制。"
  • 前置上下文:现代化组件代码
  • 预期输出:安全审计报告和加固后的组件

Phase 4: Performance Validation and Optimization

阶段4:性能验证与优化

1. Performance Testing and Optimization

1. 性能测试与优化

  • Use Task tool with subagent_type="application-performance::performance-engineer"
  • Prompt: "Conduct performance testing comparing legacy vs modernized components. Run load tests simulating production traffic patterns, measure response times, throughput, and resource utilization. Identify performance regressions and optimize: database queries with indexing, caching strategies (Redis/Memcached), connection pooling, and async processing where applicable. Validate against SLA requirements."
  • Context from previous: Performance baselines, modernized components
  • Expected output: Performance test results and optimization recommendations
  • 使用Task工具,设置subagent_type="application-performance::performance-engineer"
  • 提示词:"开展遗留组件与现代化组件的性能对比测试。运行模拟生产流量模式的负载测试,测量响应时间、吞吐量和资源利用率。识别性能退化问题并进行优化:数据库查询索引优化、缓存策略(Redis/Memcached)、连接池和异步处理(如适用)。验证是否符合SLA要求。"
  • 前置上下文:性能基准、现代化组件
  • 预期输出:性能测试结果和优化建议

2. Progressive Rollout and Monitoring

2. 渐进式发布与监控

  • Use Task tool with subagent_type="deployment-strategies::deployment-engineer"
  • Prompt: "Implement progressive rollout strategy using feature flags. Start with 5% traffic to modernized components, monitor error rates, latency, and business metrics. Define automatic rollback triggers: error rate >1%, latency >2x baseline, or business metric degradation. Create runbook for traffic shifting: 5% → 25% → 50% → 100% with 24-hour observation periods."
  • Context from previous: Feature flag configuration, monitoring dashboard
  • Expected output: Rollout plan with automated safeguards
  • 使用Task工具,设置subagent_type="deployment-strategies::deployment-engineer"
  • 提示词:"使用特性标志实施渐进式发布策略。先将5%的流量导向现代化组件,监控错误率、延迟和业务指标。定义自动回滚触发条件:错误率>1%、延迟>基准值2倍或业务指标下降。创建流量切换运行手册:5% → 25% → 50% → 100%,每个阶段观察24小时。"
  • 前置上下文:特性标志配置、监控仪表板
  • 预期输出:带有自动防护措施的发布计划

Phase 5: Migration Completion and Documentation

阶段5:迁移完成与文档编制

1. Legacy Component Decommissioning

1. 遗留组件退役

  • Use Task tool with subagent_type="legacy-modernizer"
  • Prompt: "Plan safe decommissioning of replaced legacy components. Verify no remaining dependencies through traffic analysis (minimum 30 days at 0% traffic). Archive legacy code with documentation of original functionality. Update CI/CD pipelines to remove legacy builds. Clean up unused database tables and remove deprecated API endpoints. Document any retained legacy components with sunset timeline."
  • Context from previous: Traffic routing data, modernization status
  • Expected output: Decommissioning checklist and timeline
  • 使用Task工具,设置subagent_type="legacy-modernizer"
  • 提示词:"规划已替换遗留组件的安全退役流程。通过流量分析验证无剩余依赖(至少30天流量占比为0%)。归档遗留代码并记录原始功能文档。更新CI/CD流水线以移除遗留构建任务。清理未使用的数据库表并删除已弃用的API端点。记录任何保留的遗留组件及其淘汰时间表。"
  • 前置上下文:流量路由数据、现代化状态
  • 预期输出:退役检查清单和时间表

2. Documentation and Knowledge Transfer

2. 文档编制与知识转移

  • Use Task tool with subagent_type="documentation-generation::docs-architect"
  • Prompt: "Create comprehensive modernization documentation including: architectural diagrams (before/after), API documentation with migration guides, runbooks for dual-system operation, troubleshooting guides for common issues, and lessons learned report. Generate developer onboarding guide for modernized system. Document technical decisions and trade-offs made during migration."
  • Context from previous: All migration artifacts and decisions
  • Expected output: Complete modernization documentation package
  • 使用Task工具,设置subagent_type="documentation-generation::docs-architect"
  • 提示词:"创建全面的现代化文档,包括:架构图(迁移前后)、带有迁移指南的API文档、双系统运行手册、常见问题故障排除指南和经验教训报告。生成现代化系统的开发者入门指南。记录迁移过程中做出的技术决策与权衡。"
  • 前置上下文:所有迁移工件和决策
  • 预期输出:完整的现代化文档包

Configuration Options

配置选项

  • --parallel-systems: Keep both systems running indefinitely (for gradual migration)
  • --big-bang: Full cutover after validation (higher risk, faster completion)
  • --by-feature: Migrate complete features rather than technical components
  • --database-first: Prioritize database modernization before application layer
  • --api-first: Modernize API layer while maintaining legacy backend
  • --parallel-systems:长期保持双系统运行(适用于渐进式迁移)
  • --big-bang:验证完成后全面切换(风险较高,完成速度更快)
  • --by-feature:按完整功能而非技术组件进行迁移
  • --database-first:优先现代化数据库层,再处理应用层
  • --api-first:现代化API层,同时保留遗留后端

Success Criteria

成功标准

  • All high-priority components modernized with >80% test coverage
  • Zero unplanned downtime during migration
  • Performance metrics maintained or improved (P95 latency within 110% of baseline)
  • Security vulnerabilities reduced by >90%
  • Technical debt score improved by >60%
  • Successful operation for 30 days post-migration without rollbacks
  • Complete documentation enabling new developer onboarding in <1 week
Target: $ARGUMENTS
  • 所有高优先级组件完成现代化,测试覆盖率>80%
  • 迁移期间无计划外停机
  • 性能指标保持或提升(P95延迟不超过基准值的110%)
  • 安全漏洞减少>90%
  • 技术债务评分改善>60%
  • 迁移后成功运行30天无回滚
  • 文档完整,新开发者可在1周内完成入职
目标:$ARGUMENTS