moai-workflow-ddd
Skill1.2k starsChanged 3 months agoApache-2.0View on GitHub
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.
1 other project uses a version of this, 1 of them edited.
Trending
Quiet since September.thin dataabout the whole repository
Most recently taken up by
- modu-ai/cc-pluginsedited, first seen Feb 11, 2026
Who's talking about modu-ai/moai-adk
- Ven0m0/claude-config“Add a structured external integration plan to the root TODO backlog”GitHub · Mar 18, 2026 · 4 reactions
- Ven0m0/claude-config“TODO list”GitHub · Jan 31, 2026 · 1 reactions
- sudosubin/agents.nix“agent-skills.github.modu-ai.moai-adk: init at 3.1.2”GitHub · Sep 30, 2026
- anthropics/claude-code“Worktree-isolation Bash check folds command substitutions in quoted-delimiter heredoc bodies but refuses …”GitHub · Sep 7, 2026
- bjw202/minidiscord“docs(t41): moai gate 종료 코드 합류 — upstream 이슈 문안 (제출 안 함)”GitHub · Sep 6, 2026
The biggest 5 of 13 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 13
Talked about on GitHub (13 times).
On GitHub · 13
- Mar 18, 2026Add a structured external integration plan to the root TODO backlog — Ven0m0/claude-config4 reactions · 4 comments
- Jan 31, 2026TODO list — Ven0m0/claude-config1 reaction · 18 comments
- Sep 30, 2026agent-skills.github.modu-ai.moai-adk: init at 3.1.2 — sudosubin/agents.nix0 reactions
- Sep 7, 2026Worktree-isolation Bash check folds command substitutions in quoted-delimiter heredoc bodies but refuses braces there, though such bodies cannot expand — anthropics/claude-code0 reactions
- Sep 6, 2026docs(t41): moai gate 종료 코드 합류 — upstream 이슈 문안 (제출 안 함) — bjw202/minidiscord0 reactions
8 more on GitHub
- Jul 23, 2026Hands-on eval: promote MoAI-ADK to core tier — cameronsjo/spec-compare0 reactions
- Apr 22, 2026Add MoAI-ADK to Collections & Libraries — travisvn/awesome-claude-skills0 reactions
- Apr 22, 2026Add MoAI-ADK to Meta & Orchestration category — VoltAgent/awesome-claude-code-subagents0 reactions
- Apr 22, 2026Add MoAI-ADK — SPEC-first Agentic Development Kit — jqueryscript/awesome-claude-code0 reactions
- Apr 22, 2026Add MoAI-ADK — SPEC-first AI-assisted coding framework — wsxiaoys/awesome-ai-coding0 reactions
- Apr 22, 2026Add MoAI-ADK — SPEC-first Agentic Development Kit for Claude Code — e2b-dev/awesome-ai-agents0 reactions
- Nov 19, 2025Issue #1: Estructura base del proyecto .NET 9 — mjcuadrado/mjcuadrado-net-sdk0 reactions
- Nov 13, 2025fix: resolve conflitos Git + remove hooks SYNC bloqueantes (Windows f… — PedroGiudice/lex-vector0 reactions
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- modu-ai/cc-plugins★ 6889% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository45 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hns-lsel-applierSkill
- hns-lsel-curatorSkill
- hns-moaiadk-best-practicesSkill
- hns-moaiadk-dev-referenceSkill
- hns-moaiadk-patternsSkill
- hns-oss-docs-i18n-rulesSkill
- hns-oss-docs-readme-syncSkill
- hns-oss-docs-structure-mapSkill
- hns-oss-docs-verifySkill
- hns-workflow-ci-loopSkill
- moai-domain-backendSkill
- moai-domain-databaseSkill
- moai-domain-design-dnaSkill
- moai-domain-frontendSkill
- moai-domain-html-reportSkill
- moai-domain-humanizeSkill
- moai-domain-svg-infographicSkill
- moai-foundation-ccSkill
- moai-foundation-coreSkill
- moai-foundation-qualitySkill
- moai-foundation-thinkingSkill
- moai-harness-learnerSkill
- moai-kanban-foremanSkill
- moai-meta-harnessSkill
- moai-ref-api-patternsSkill
- moai-ref-cross-model-auditSkill
- moai-ref-git-workflowSkill
- moai-ref-llm-securitySkill
- moai-ref-owasp-checklistSkill
- moai-ref-react-patternsSkill
- moai-ref-secopsSkill
- moai-ref-seoSkill
- moai-ref-supply-chainSkill
- moai-ref-testing-pyramidSkill
- moai-ref-ui-polishSkill
- moaiSkill
- moai-workflow-docs-claim-checkSkill
- moai-workflow-loopSkill
- moai-workflow-projectSkill
- moai-workflow-specSkill
- moai-workflow-tddSkill
- moai-workflow-testingSkill
- moai-workflow-worktreeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
44 rules. About 0 are common, 44 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈44
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
When to Use DDD:
- Distinctive: line 60
When NOT to Use DDD:
- Distinctive: line 62
When behavior changes are required (modify SPEC first)
- Distinctive: line 63
When the code already exists and the goal is behavior change rather than behavior-preserving refactoring (DDD preserves behavior.
- Distinctive: line 86
Test Type: Specification tests that define expected behavior
- Distinctive: line 94
Test Type: Characterization tests that capture current behavior
- Distinctive: line 101
All existing tests must pass unchanged
- Distinctive: line 123
Use AST-grep to analyze structural patterns.
- Distinctive: line 139
Use AST-grep to identify problematic patterns:
- Distinctive: line 146
Create analysis reports documenting:
- Distinctive: line 184
Before proceeding to improvement phase, verify:
- Distinctive: line 186
All existing tests pass (100% green)
- Distinctive: line 189
No flaky tests exist in the safety net
- Distinctive: line 191
Run mutation testing if available to verify test effectiveness.
- Distinctive: line 199
Never make large changes at once.
- Distinctive: line 202
Run full test suite
- Distinctive: line 203
If tests fail, revert immediately
- Distinctive: line 204
If tests pass, commit the change
- Distinctive: line 221
Use AST-grep for safe, semantic-aware transformations:
- Distinctive: line 233
Run unit tests (fast feedback)
- Distinctive: line 234
Run integration tests (behavior validation)
- Distinctive: line 235
Run characterization tests (snapshot comparison)
- Distinctive: line 236
Verify no new warnings or errors introduced
- Distinctive: line 237
Check performance benchmarks if applicable
- Distinctive: line 245
When executing DDD through moai:2-run in DDD mode:
- Distinctive: line 249
Read SPEC document for refactoring scope
- Distinctive: line 255
Run AST-grep analysis on target code
- Distinctive: line 257
Create domain boundary map
- Distinctive: line 262
Verify all existing tests pass
- Distinctive: line 263
Create characterization tests for uncovered paths
- Distinctive: line 270
Run tests after each change
- Distinctive: line 271
Commit successful changes immediately
- Distinctive: line 272
Document any discovered issues
- Distinctive: line 278
Verify all behavior snapshots match
- Distinctive: line 298
All pre-existing tests pass
- Distinctive: line 299
All characterization tests pass
- Distinctive: line 300
No API contract changes
- Distinctive: line 347
Before/after metrics comparison
- Distinctive: line 361
Check if transformation changed behavior unintentionally
- Distinctive: line 362
Consider smaller transformation steps
- Distinctive: line 369
Consider snapshot tolerance settings
- Distinctive: line 375
Consider caching or optimization
- Distinctive: line 380
When DDD session encounters issues:
- Distinctive: line 405
Chesterton's Fence: Do not remove or replace code whose purpose you cannot explain.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Domain-Driven Development (DDD) Workflow
Development Mode Configuration (CRITICAL)
[NOTE] This workflow is selected based on .moai/config/sections/quality.yaml:
constitution:
development_mode: ddd # or tddWhen to use this workflow:
development_mode: ddd→ Use DDD (this workflow)development_mode: tdd→ Use TDD instead (moai-workflow-tdd)
Key distinction:
- DDD: Characterization-test-first for existing codebases with minimal test coverage
- TDD (default): Test-first development for all work, including brownfield projects with pre-RED analysis
Quick Reference
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:
- ANALYZE: Domain boundary identification, coupling metrics, AST structural analysis
- PRESERVE: Characterization tests, behavior snapshots, test safety net verification
- IMPROVE: Incremental structural changes with continuous behavior validation
When to Use DDD:
- Refactoring legacy code with existing tests
- Improving code structure without functional changes
- Technical debt reduction in production systems
- API migration and deprecation handling
- Code modernization projects
- Greenfield projects (with adapted cycle - see below)
When NOT to Use DDD:
- When behavior changes are required (modify SPEC first)
- When the code already exists and the goal is behavior change rather than behavior-preserving refactoring (DDD preserves behavior; for new behavior, modify the SPEC first, or use TDD)
Greenfield Project Adaptation:
For new projects without existing code, DDD adapts its cycle:
- ANALYZE: Requirements analysis instead of code analysis
- PRESERVE: Define intended behavior through specification tests (test-first)
- IMPROVE: Implement code to satisfy the defined tests
This makes DDD a superset of TDD - it includes TDD's test-first approach while also supporting refactoring scenarios.
Core Philosophy
DDD vs TDD Comparison
TDD Approach (for new features):
- Cycle: RED-GREEN-REFACTOR
- Goal: Create new functionality through tests
- Starting Point: No code exists
- Test Type: Specification tests that define expected behavior
- Outcome: New working code with test coverage
DDD Approach (for refactoring):
- Cycle: ANALYZE-PRESERVE-IMPROVE
- Goal: Improve structure without behavior change
- Starting Point: Existing code with defined behavior
- Test Type: Characterization tests that capture current behavior
- Outcome: Better structured code with identical behavior
Behavior Preservation Principle
The golden rule of DDD is that observable behavior must remain identical before and after refactoring. This means:
- All existing tests must pass unchanged
- API contracts remain identical
- Side effects remain identical
- Performance characteristics remain within acceptable bounds
Implementation Guide
Phase 1: ANALYZE
The analyze phase focuses on understanding the current codebase structure and identifying refactoring opportunities.
Domain Boundary Identification
Identify logical boundaries in the codebase by examining:
- Module dependencies and import patterns
- Data flow between components
- Shared state and coupling points
- Public API surfaces
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.
Coupling and Cohesion Metrics
Evaluate code quality metrics:
- Afferent Coupling (Ca): Number of classes depending on this module
- Efferent Coupling (Ce): Number of classes this module depends on
- Instability (I): Ce / (Ca + Ce) - higher means less stable
- Abstractness (A): Abstract classes / Total classes
- Distance from Main Sequence: |A + I - 1|
Low cohesion and high coupling indicate refactoring candidates.
Structural Analysis Patterns
Use AST-grep to identify problematic patterns:
- God classes with too many methods or responsibilities
- Feature envy where methods use other class data excessively
- Long parameter lists indicating missing abstractions
- Duplicate code patterns across modules
Create analysis reports documenting:
- Current architecture overview
- Identified problem areas with severity ratings
- Proposed refactoring targets with risk assessment
- Dependency graphs showing coupling relationships
Phase 2: PRESERVE
The preserve phase establishes safety nets before making any changes.
Characterization Tests
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:
- Step 1: Identify critical code paths through execution
- Step 2: Create tests that exercise these paths
- Step 3: Let tests fail initially to discover actual output
- Step 4: Update tests to expect actual output
- Step 5: Document any surprising behavior discovered
Characterization test naming convention: testcharacterize[component]_[scenario]
Behavior Snapshots
For complex outputs, use snapshot testing to capture current behavior:
- API response snapshots
- Serialization output snapshots
- State transformation snapshots
- Error message snapshots
Snapshot files serve as behavior contracts during refactoring.
Test Safety Net Verification
Before proceeding to improvement phase, verify:
- All existing tests pass (100% green)
- New characterization tests cover refactoring targets
- Code coverage meets threshold for affected areas
- No flaky tests exist in the safety net
Run mutation testing if available to verify test effectiveness.
Phase 3: IMPROVE
The improve phase makes structural changes while continuously validating behavior preservation.
Incremental Transformation Strategy
Never make large changes at once. Follow this pattern:
- Make smallest possible structural change
- Run full test suite
- If tests fail, revert immediately
- If tests pass, commit the change
- Repeat until refactoring goal achieved
Safe Refactoring Patterns
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.
AST-Grep Assisted Transformations
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.
Continuous Validation Loop
After each transformation:
- Run unit tests (fast feedback)
- Run integration tests (behavior validation)
- Run characterization tests (snapshot comparison)
- Verify no new warnings or errors introduced
- Check performance benchmarks if applicable
DDD Workflow Execution
Standard DDD Session
When executing DDD through moai:2-run in DDD mode:
Step 1 - Initial Assessment:
- Read SPEC document for refactoring scope
- Identify affected files and components
- Assess current test coverage
Step 2 - Analyze Phase Execution:
- Run AST-grep analysis on target code
- Generate coupling and cohesion metrics
- Create domain boundary map
- Document refactoring opportunities
Step 3 - Preserve Phase Execution:
- Verify all existing tests pass
- Create characterization tests for uncovered paths
- Generate behavior snapshots
- Confirm safety net adequacy
Step 4 - Improve Phase Execution:
- Execute transformations incrementally
- Run tests after each change
- Commit successful changes immediately
- Document any discovered issues
Step 5 - Validation and Completion:
- Run full test suite
- Compare before/after metrics
- Verify all behavior snapshots match
- Generate refactoring report
DDD Loop Pattern
For complex refactoring requiring multiple iterations:
- Set maximum loop iterations based on scope
- Each loop focuses on one refactoring target
- Exit conditions: all targets adddessed or iteration limit reached
- Progress tracking through TODO list updates
Quality Metrics
DDD Success Criteria
Behavior Preservation (Required):
- All pre-existing tests pass
- All characterization tests pass
- No API contract changes
- Performance within bounds
Structure Improvement (Goals):
- Reduced coupling metrics
- Improved cohesion scores
- Reduced code complexity
- Better separation of concerns
DDD-Specific TRUST Validation
Apply TRUST 5 framework with DDD focus:
- Testability: Characterization test coverage adequate
- Readability: Naming and structure improvements verified
- Understandability: Domain boundaries clearer
- Security: No new vulnerabilities introduced
- Transparency: All changes documented and traceable
Integration Points
With AST-Grep Skill
DDD relies heavily on AST-grep for:
- Structural code analysis
- Pattern identification
- Safe code transformations
- Multi-file refactoring
Rules live in .moai/config/astgrep-rules/; scan with moai ast-grep and apply rewrites with moai ast-edit.
With Testing Workflow
DDD complements testing workflow:
- Uses characterization tests from testing patterns
- Integrates with mutation testing for safety net validation
- Leverages snapshot testing infrastructure
With Quality Framework
DDD outputs feed into quality assessment:
- Before/after metrics comparison
- TRUST 5 validation for changes
- Technical debt tracking
Troubleshooting
Common Issues
Tests Fail After Transformation:
- Revert immediately to last known good state
- Analyze which tests failed and why
- Check if transformation changed behavior unintentionally
- Consider smaller transformation steps
Characterization Tests Are Flaky:
- Identify sources of non-determinism
- Mock external dependencies
- Fix time-dependent or order-dependent behavior
- Consider snapshot tolerance settings
Performance Degradation:
- Profile before and after
- Identify hot paths affected by changes
- Consider caching or optimization
- Document acceptable trade-offs
Recovery Procedures
When DDD session encounters issues:
- Save current state with git stash
- Reset to last successful commit
- Review transformation that caused failure
- Plan alternative approach
- Resume from preserved state
Version: 1.0.0 Status: Active
<!-- moai:evolvable-start id="rationalizations" -->Common Rationalizations
| 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.
<!-- moai:evolvable-end --><!-- moai:evolvable-start id="red-flags" -->Red Flags
- Refactor commit with zero new tests and zero existing test changes
- ANALYZE artifact absent or reduced to a one-line summary
- Characterization tests that only assert on return values, ignoring side effects and state changes
- IMPROVE phase introduces new public API without test coverage
- Behavior-preserving claim made without before/after test evidence
- Legacy tests deleted during IMPROVE rather than updated
<!-- moai:evolvable-end --><!-- moai:evolvable-start id="verification" -->Verification
- ANALYZE artifact exists and names every caller of the modified code
- Characterization tests exist for every public entry point before IMPROVE begins
- Characterization tests pass on the pre-refactor commit (baseline verified)
- Characterization tests still pass after every IMPROVE step
- No existing test was deleted without an equivalent replacement
- Coverage for the modified package is equal to or higher than before the change
- Side effects (I/O, global state) are captured in at least one test assertion
<!-- moai:evolvable-end -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

