Best for
- Use when refactoring legacy code or reducing technical debt safely.
modu-ai/moai-adk/.claude/skills/moai-workflow-ddd/SKILL.md
Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation. Use when refactoring legacy code or reducing technical debt safely.
Decision brief
Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Declared | Source record | Install path and trigger |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/modu-ai/moai-adk --skill ".claude/skills/moai-workflow-ddd"Inspect the Agent Skill "moai-workflow-ddd" from https://github.com/modu-ai/moai-adk/blob/48239c7dc7428c8751a04f6321887c2d36123884/.claude/skills/moai-workflow-ddd/SKILL.md at commit 48239c7dc7428c8751a04f6321887c2d36123884. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
The analyze phase focuses on understanding the current codebase structure and identifying refactoring opportunities.
The analyze phase focuses on understanding the current codebase structure and identifying refactoring opportunities.
The preserve phase establishes safety nets before making any changes.
Before proceeding to improvement phase, verify:
The improve phase makes structural changes while continuously validating behavior preservation.
Permission review
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 91/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 1,191 | Source | Repository attention, not individual Skill quality |
| Compatibility | 1 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
[NOTE] This workflow is selected based on .moai/config/sections/quality.yaml:
constitution:
development_mode: ddd # or tdd
When to use this workflow:
development_mode: ddd → Use DDD (this workflow)development_mode: tdd → Use TDD instead (moai-workflow-tdd)Key distinction:
Domain-Driven Development provides a systematic approach for refactoring existing codebases where behavior preservation is paramount. Unlike TDD which creates new functionality, DDD improves structure without changing behavior.
Core Cycle - ANALYZE-PRESERVE-IMPROVE:
When to Use DDD:
When NOT to Use DDD:
Greenfield Project Adaptation:
For new projects without existing code, DDD adapts its cycle:
This makes DDD a superset of TDD - it includes TDD's test-first approach while also supporting refactoring scenarios.
TDD Approach (for new features):
DDD Approach (for refactoring):
The golden rule of DDD is that observable behavior must remain identical before and after refactoring. This means:
The analyze phase focuses on understanding the current codebase structure and identifying refactoring opportunities.
Identify logical boundaries in the codebase by examining:
Use AST-grep to analyze structural patterns. For Python, search for import patterns to understand module dependencies. For class hierarchies, analyze inheritance relationships and method distributions.
Evaluate code quality metrics:
Low cohesion and high coupling indicate refactoring candidates.
Use AST-grep to identify problematic patterns:
Create analysis reports documenting:
The preserve phase establishes safety nets before making any changes.
Characterization tests capture existing behavior without assumptions about correctness. The goal is to document what the code actually does, not what it should do.
Steps for creating characterization tests:
Characterization test naming convention: testcharacterize[component]_[scenario]
For complex outputs, use snapshot testing to capture current behavior:
Snapshot files serve as behavior contracts during refactoring.
Before proceeding to improvement phase, verify:
Run mutation testing if available to verify test effectiveness.
The improve phase makes structural changes while continuously validating behavior preservation.
Never make large changes at once. Follow this pattern:
Extract Method: When a code block can be named and isolated. Use AST-grep to identify candidates by searching for repeated code blocks or long methods.
Extract Class: When a class has multiple responsibilities. Move related methods and fields to a new class while maintaining the original API through delegation.
Move Method: When a method uses data from another class more than its own. Relocate while preserving all call sites.
Inline Refactoring: When indirection adds complexity without benefit. Replace delegation with direct implementation.
Rename Refactoring: When names do not reflect current understanding. Update all references atomically using AST-grep rewrite.
Use AST-grep for safe, semantic-aware transformations:
For method extraction, create a rule that identifies the code pattern and rewrites to the extracted form.
For API migration, create a rule that matches old API calls and rewrites to new API format.
For deprecation handling, create rules that identify deprecated patterns and suggest modern alternatives.
After each transformation:
When executing DDD through moai:2-run in DDD mode:
Step 1 - Initial Assessment:
Step 2 - Analyze Phase Execution:
Step 3 - Preserve Phase Execution:
Step 4 - Improve Phase Execution:
Step 5 - Validation and Completion:
For complex refactoring requiring multiple iterations:
Behavior Preservation (Required):
Structure Improvement (Goals):
Apply TRUST 5 framework with DDD focus:
DDD relies heavily on AST-grep for:
Rules live in .moai/config/astgrep-rules/; scan with moai ast-grep and apply rewrites with moai ast-edit.
DDD complements testing workflow:
DDD outputs feed into quality assessment:
Tests Fail After Transformation:
Characterization Tests Are Flaky:
Performance Degradation:
When DDD session encounters issues:
Version: 1.0.0 Status: Active
| Rationalization | Reality |
|---|---|
| "This legacy code is obviously broken, I will just rewrite it" | The broken-looking code may encode production behavior callers depend on. ANALYZE first, rewrite with tests. |
| "Characterization tests are just busywork" | They are the safety net that lets you refactor without fear. Without them, refactor equals rewrite. |
| "I understand this module well enough to skip ANALYZE" | Understanding is not verification. ANALYZE forces you to name assumptions and confront callers. |
| "This function has no tests because it has no behavior worth testing" | If it has callers, it has contract. The contract is the thing to characterize. |
| "I will preserve behavior by being careful" | Carefulness is not a mechanism. Tests are the only mechanism that catches regressions. |
| "This refactor is too small to need DDD" | Small refactors cause silent regressions exactly because people skip the safety net. |
Chesterton's Fence: Do not remove or replace code whose purpose you cannot explain. ANALYZE phase exists specifically to uncover the reasoning behind code that looks wrong.
Frequently asked questions
Domain-Driven Development workflow specialist using ANALYZE-PRESERVE-IMPROVE cycle for behavior-preserving code transformation.
The source record exposes this install command: npx skills add https://github.com/modu-ai/moai-adk --skill ".claude/skills/moai-workflow-ddd". Inspect the command and pinned source before running it.
The pinned source record declares support for: claude code.
Alternatives
yonatangross/orchestkit
Grade work that already exists and decide whether it can merge. Runs the project's current unit, integration, and E2E suites plus security scanning and type checking, scores every dimension 0-10, and returns a merge verdict with a VERIFIED-vs-CLAIMED evidence manifest. Writes no test files and edits no source. Use when verifying changes are ready to merge. Use /ork:cover instead when the tests still have to be written.
PramodDutta/qaskills
Gate RAG pipelines in CI with versioned golden eval sets, per-metric thresholds, baseline drift detection, and a build that fails when retrieval or answer quality regresses.
brucesongs/kali-claw
CAN/CAN-FD bus analysis, UDS diagnostics, IVI pentest, OBD-II exploitation, key fob replay/relay attacks, GNSS spoofing, EV charging station (ISO 15118), and connected vehicle red team operations.
upex-galaxy/agentic-qa-boilerplate
Execute regression test suites via CI/CD, analyze results, classify failures, and produce GO/NO-GO release decisions. Use when running regression, smoke, or sanity suites through GitHub Actions, monitoring workflow runs, downloading Allure or Playwright artifacts, classifying failures (REGRESSION vs FLAKY vs KNOWN vs ENVIRONMENT vs NEW TEST), computing pass-rate and trend metrics, deciding release readiness, generating executive quality reports, or creating regression issues. Triggers on: run re