moai-workflow-ddd

Refactors legacy code through an ANALYZE-PRESERVE-IMPROVE cycle with characterization tests and AST-grep transformations.

2|Updated May 27, 2026
One-click install
npx skills add https://github.com/yekinya/moai-novel --skill moai-workflow-ddd-yekinya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: moai-workflow-ddd
Source: https://github.com/yekinya/moai-novel/tree/main/moai-novel/.claude/skills/moai-workflow-ddd
Command: npx skills add https://github.com/yekinya/moai-novel --skill moai-workflow-ddd-yekinya

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Refactoring legacy code without breaking existing behavior is risky when test coverage is thin. This Skill provides a structured Domain-Driven Development workflow that captures current behavior with characterization tests before making any structural changes, so refactoring never silently alters functionality. ## Core Features & Use Cases - ANALYZE Phase: Identifies domain boundaries, coupling and cohesion metrics, and problematic patterns like god classes and feature envy using AST-grep structural analysis. - PRESERVE Phase: Creates characterization tests and behavior snapshots that document what the code actually does, building a verified safety net before changes begin. - IMPROVE Phase: Executes incremental refactorings (extract method, extract class, move method, rename) with continuous test validation after every step. - Use Case: When modernizing a production module with minimal tests, run the DDD cycle to capture current behavior as tests, then restructure the code incrementally while the test suite confirms identical behavior at each commit. ## Quick Start Ask the AI to refactor a legacy module using the DDD workflow, starting with characterization tests to preserve its current behavior.

Frequently Asked Questions about moai-workflow-ddd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor legacy code without breaking existing behavior?

Use the ANALYZE-PRESERVE-IMPROVE cycle: first analyze structure and coupling, then write characterization tests that capture current behavior, then make small incremental changes running the full test suite after each step. Revert immediately if any test fails.

What is the difference between DDD and TDD workflows?

TDD uses a RED-GREEN-REFACTOR cycle to create new functionality with specification tests. DDD uses ANALYZE-PRESERVE-IMPROVE to restructure existing code with characterization tests that capture current behavior, keeping observable behavior identical before and after.

What are characterization tests and when should I write them?

Characterization tests document what code actually does rather than what it should do. Write them before refactoring any code with insufficient coverage: exercise critical paths, let tests fail to discover actual output, then update expectations to match.

When should I not use the DDD refactoring workflow?

Do not use DDD when behavior changes are required; modify the SPEC first instead. DDD is strictly for structural improvements where observable behavior, API contracts, and side effects must remain identical.

What should I do when tests fail after a refactoring transformation?

Revert immediately to the last known good state, analyze which tests failed and why, and check whether the transformation unintentionally changed behavior. Then retry with smaller transformation steps and commit each successful change.