Logo Nw Legacy Refactoring Ddd

Nw Legacy Refactoring Ddd

Tổ chức
nWave-ai
nw-legacy-refactoring-ddd

DDD-guided legacy refactoring patterns -- strangler fig, bubble context, ACL migration, 14 tactical/strategic/infrastructure patterns, and incremental monolith-to-microservices methodology

Tổng quan

Nhà phát hànhnWave-ai
Kho mãnWave
Tên kỹ năngnw-legacy-refactoring-ddd
Sao
616
Bản fork
65
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được nWave-ai công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Nw Legacy Refactoring Ddd trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/nWave-ai/nWave/tree/main/nWave/skills/nw-legacy-refactoring-ddd
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nWave-ai/nWave.git /tmp/nWave
mkdir -p .claude/skills
cp -r /tmp/nWave/nWave/skills/nw-legacy-refactoring-ddd .claude/skills/nw-legacy-refactoring-ddd
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Nw Legacy Refactoring Ddd trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Nw Legacy Refactoring Ddd ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Nw Legacy Refactoring Ddd với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Legacy Refactoring with DDD

Refactoring legacy systems using Domain-Driven Design as the strategic compass. DDD tells you WHERE and WHY to refactor; traditional techniques (progressive-refactoring, mikado-method) tell you HOW.

Principle: "Start simple, grow big" -- incremental steps tested at each stage.

Decision Framework: Before Refactoring

Ask three questions before any DDD refactoring:

  1. Business value: what business outcome does refactoring this area enable?
  2. Risk: what breaks if we refactor vs. if we do not?
  3. Cost: time, effort, disruption -- is it justified?

When NOT to Refactor

  • System scheduled for replacement
  • Stable system with no new development
  • Cost exceeds benefit
  • Team lacks DDD experience with no learning budget
  • Domain is genuinely simple (CRUD-dominated)

Cynefin-Refactoring Mapping

Cynefin DomainRefactoring Approach
ClearApply established patterns directly; standard refactoring catalogs
ComplicatedAnalyze with experts, then apply patterns; multiple valid solutions
ComplexProbe with safe-to-fail experiments; EventStorming to discover patterns
ChaoticAct first to stabilize, then refactor; emergency patches acceptable
ConfusionGather information before deciding; avoid premature refactoring

Migration Methodology (4 Phases)

Phase 1: Understand and Stabilize

  1. Run EventStorming to map current system (Big Picture)
  2. Assess complexity using Cynefin framework
  3. Write characterization tests for critical paths (Feathers technique)
  4. Identify bounded contexts in existing codebase via language divergence

Phase 2: Modularize the Monolith

  1. Introduce module structure aligned with bounded contexts
  2. Use mediator pattern for initial decoupling between modules
  3. Apply fitness functions to measure progress (coupling, cohesion, dependency direction)
  4. Refactor database schemas toward context alignment

Phase 3: Introduce Events and CQRS

  1. Replace mediator with event-driven communication
  2. Implement CQRS for contexts benefiting from read/write separation
  3. Split databases per bounded context using expand/contract pattern
  4. Use event-based data synchronization for cross-context data needs

Phase 4: Extract Services (if justified)

  1. Evaluate microservices readiness (6 signals below)
  2. Start with most independent bounded context
  3. Use strangler fig pattern -- incrementally extract while legacy still runs
  4. Apply appropriate saga pattern for distributed transactions

Microservices Readiness Signals

  1. Clear domain boundaries already established
  2. Scaling pressure on specific areas (not uniform)
  3. Independent development needs across teams
  4. Operational maturity (CI/CD, monitoring, automated testing in place)
  5. Technical expertise in distributed systems
  6. Business justification (not trend-following)

Strategic Refactoring Patterns

Strangler Fig

Build new DDD-modeled functionality alongside legacy. Route requests to new code as features complete. Legacy gradually shrinks until fully replaced. Changes are incremental, monitored, low risk of unexpected breakage.

Mikado integration: use Mikado exploration to discover dependencies between legacy components before extracting. Each Mikado leaf becomes an atomic refactoring step.

Bubble Context

Create a small bounded context (the "bubble") where DDD principles apply. The bubble communicates with legacy through an Anti-Corruption Layer. Progressively expand the bubble to encompass more legacy functionality.

Steps:

  1. Identify the most valuable bounded context (core domain) for initial DDD investment
  2. Create an ACL between the new context and legacy
  3. Apply tactical DDD within the bubble (aggregates, value objects, domain events)
  4. Gradually expand, moving more logic behind the ACL
  5. Retire legacy components as new context absorbs their functionality

Evolve Context Map

Integration patterns change as refactoring progresses. Map current relationships, identify mismatches, propose new patterns. Typical evolution: Conformist -> Customer-Supplier with ACL -> Partnership.

Split Bounded Context

When a context grows too large or serves conflicting purposes:

  1. Domain decomposition to break responsibilities into subdomains
  2. Context mapping to plan the split and redefine integration patterns
  3. Isolate related aggregates
  4. Introduce domain events for communication
  5. Gradually refactor dependent code

Validation: bounded context splits are driven by business evolution, not technical convenience. Validate with domain experts.

Merge Bounded Contexts

When separation causes more friction than value:

  1. Identify redundancies (overlapping models, duplicate logic, tight coupling)
  2. Establish unified ubiquitous language
  3. Consolidate aggregates and deprecate redundant events
  4. Revisit context map

Tactical Refactoring Patterns

These patterns apply tactical DDD concepts (aggregates, value objects, domain events, domain services, CQRS) to refactoring. For foundational definitions and design rules, load domain-driven-design from solution-architect/.

PatternWhat It FixesKey Step
Replace primitives with VOsPrimitive obsessionCreate self-validating type, replace in aggregate, update mapping
Enrich anemic modelLogic in services, data in entitiesMove business rules from service "if" statements into owning entity
Introduce domain eventsDirect coupling between aggregatesReplace method calls with immutable past-tense events + handlers
Extract domain serviceCross-aggregate operations in application layerCreate stateless domain-typed service; guard against overuse
Introduce CQRSRead/write contention on same modelSeparate read DTOs from write aggregates; CQRS != event sourcing

Infrastructure Refactoring Patterns

Split Database by Bounded Context

Most challenging aspect of DDD refactoring. Use expand/contract pattern for safe migration.

  1. Identify table ownership by bounded context
  2. Expand: add new schema/tables aligned with target context
  3. Migrate: copy data, set up synchronization
  4. Contract: remove old schema after validation
  5. Test integrity at each step

Event-Based Data Synchronization

When contexts need data owned by another context:

  1. Owning context publishes integration events on state changes
  2. Consuming context maintains read-only local copy, updated via event handlers
  3. ACL translates between event format and local model
  4. Accept eventual consistency (design for it, test for it)

Replace Mediator with Events

Prepare for microservice extraction. Mediator is a stepping stone, not a destination.

  1. Identify all mediator interactions between modules
  2. Define domain/integration events for each interaction
  3. Implement event bus (in-process initially, message broker for distribution)
  4. Remove mediator dependencies
  5. Test behavioral equivalence (async vs. sync differences)

Extract Microservice

Only when module is stable, independently deployable, and business-justified.

  1. Verify bounded context independence (no shared database, no synchronous coupling)
  2. Extract module to independent service with own persistence
  3. Define API contract and integration events
  4. Deploy independently with monitoring
  5. Apply saga pattern for any cross-service transactions

Fitness Functions for Progress

Measure refactoring progress with automated fitness functions in CI:

MetricWhat It MeasuresTool Examples
Afferent couplingIncoming dependencies to moduleNDepend, SonarQube, jdepend
Efferent couplingOutgoing dependencies from moduleSame
Dependency directionDependencies flow correctly (inward)ArchUnit, NetArchTest
Test coverageSafety net for refactoringCoverage tools
CohesionRelatedness of components within moduleLCOM metrics

Define fitness function thresholds as acceptance criteria for refactoring stories.

Testing Strategy for Legacy Refactoring

Test TypeWhenPurpose
Characterization testsBefore touching legacy codeDocument current behavior as safety net
Contract testsWhen splitting contextsVerify interservice communication
Eventual consistency testsAfter introducing eventsSimulate network failures, verify convergence
Schema integrity testsDuring database refactoringVerify constraints and data integrity

Characterization tests (Feathers): run legacy code, observe output, write tests that assert current behavior -- even if behavior seems wrong. These tests protect against unintended changes during refactoring.

Integration with Existing Skills

  • mikado-method: use Mikado exploration to discover dependencies before strangler fig extraction. Each Mikado leaf = one atomic DDD refactoring step
  • progressive-refactoring: apply L1-L4 refactoring within each bounded context after DDD restructuring. DDD operates at architecture level; RPP operates at code level
  • hexagonal-testing: each bounded context is a hexagon. Test domain logic through driving ports; mock driven ports for isolation

Câu hỏi thường gặp

Kỹ năng AI Nw Legacy Refactoring Ddd làm được gì?

DDD-guided legacy refactoring patterns -- strangler fig, bubble context, ACL migration, 14 tactical/strategic/infrastructure patterns, and incremental monolith-to-microservices methodology

Vì sao nên dùng Nw Legacy Refactoring Ddd trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Nw Legacy Refactoring Ddd là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Nw Legacy Refactoring Ddd trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/nWave-ai/nWave/tree/main/nWave/skills/nw-legacy-refactoring-ddd. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Nw Legacy Refactoring Ddd?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Nw Legacy Refactoring Ddd với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Nw Legacy Refactoring Ddd với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Nw Legacy Refactoring Ddd có miễn phí không?

Có. Kỹ năng này được nWave-ai phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇