moicle 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ args: "[MODULE] [DOMAIN]"
6
6
 
7
7
  # DDD Refactor Workflow
8
8
 
9
- Refactor existing code into DDD architecture, or improve existing DDD structure. Execute phases sequentially, run rule checks after each phase.
9
+ Restructure existing code into DDD layers, or fix drift in an existing DDD module. **Preserves behavior** refactor structure, never change logic.
10
10
 
11
11
  **ARGUMENTS:** `<module> <domain>` — e.g., `marketing notification`, `users identity`, `products catalog`
12
12
 
@@ -16,316 +16,235 @@ Refactor existing code into DDD architecture, or improve existing DDD structure.
16
16
  - ✅ Existing DDD module has drifted (fat controller, anemic entity, mixed concerns)
17
17
  - ✅ Splitting one domain into multiple bounded contexts
18
18
  - ❌ Building a brand-new feature → use `/feature:new`
19
- - ❌ Just renaming files / variables → just do it, no skill needed
19
+ - ❌ Just renaming files / variables → just do it
20
20
  - ❌ Fixing a bug → use `/fix:hotfix` or `/fix:root-cause`
21
21
 
22
22
  ## Read Architecture First
23
23
 
24
- Read `ddd-architecture.md` + stack-specific doc.
25
-
26
- ### Stack Detection
27
- | File | Stack Doc |
28
- |------|-----------|
29
- | `go.mod` | `go-backend.md` |
30
- | `package.json` + NestJS dep | `nodejs-nestjs.md` |
31
- | `package.json` + `vite.config.*` | `react-frontend.md` |
32
- | `pubspec.yaml` | `flutter-mobile.md` |
33
- | `composer.json` | `laravel-backend.md` |
34
- | `remix.config.*` | `remix-fullstack.md` |
35
-
36
- Architecture files: `.claude/architecture/{name}.md` (project) → `~/.claude/architecture/{name}.md` (global).
24
+ Detect stack via `~/.claude/architecture/_shared/stack-detection.md`. Load `ddd-architecture.md` + stack doc.
37
25
 
38
26
  ---
39
27
 
40
28
  ## Workflow
41
29
 
42
30
  ```
43
- PHASE 0: Foundation Check
44
- → PHASE 1: Analyze Current Module
45
- → PHASE 2: Build Domain Layer
46
- → PHASE 3: Build Infrastructure Layer
47
- → PHASE 4: Build Application Layer
48
- → PHASE 5: Domain Tests
49
- → PHASE 6: Integration & Cleanup
50
- → REVIEW LOOP (run /review:architect, fix, repeat until clean)
31
+ 0 FOUNDATION → 1 ANALYZE → 2 DOMAIN → 3 INFRA → 4 APP → 5 TESTS → 6 CLEANUP → REVIEW LOOP
51
32
  ```
52
33
 
53
- Each phase has a Rule Check. DO NOT skip any phase.
34
+ Each phase has a Rule Check. Do not skip any phase.
54
35
 
55
36
  ---
56
37
 
57
- ## PHASE 0: Foundation Check
38
+ ## Phase 0: FOUNDATION
58
39
 
59
- Verify DDD foundation exists in the project.
40
+ **New project (no `domain/` yet):** create
41
+ - `domain/shared/` — base event types, event collector, dispatcher interface
42
+ - Event bus infrastructure
43
+ - App bootstrap/config struct
60
44
 
61
- ### For new DDD projects (no domain/ dir yet)
62
- Create shared foundation:
63
- - `domain/shared/` — base event types, event collector, event dispatcher interface
64
- - Event bus / dispatcher infrastructure
65
- - Bootstrap/app config struct
66
-
67
- ### For existing DDD projects
68
- Verify foundation is intact:
45
+ **Existing project:** verify
69
46
  ```bash
70
- # Check shared domain types exist
71
- ls {domain_root}/shared/ 2>/dev/null && echo "PASS" || echo "NEED SETUP"
72
-
73
- # Check event infrastructure exists (if applicable)
74
- ls {eventbus_path}/ 2>/dev/null && echo "PASS" || echo "NEED SETUP"
47
+ ls {domain_root}/shared/ 2>/dev/null && echo PASS || echo NEED SETUP
48
+ ls {eventbus_path}/ 2>/dev/null && echo PASS || echo NEED SETUP
75
49
  ```
76
50
 
77
- If any FAIL → create foundation first before proceeding.
51
+ If FAIL → set up foundation before continuing.
52
+
53
+ ### Gate
54
+ - [ ] Shared domain types exist
55
+ - [ ] Event infrastructure exists (if domain raises events)
78
56
 
79
57
  ---
80
58
 
81
- ## PHASE 1: Analyze Current Module
59
+ ## Phase 1: ANALYZE
82
60
 
83
- Read ALL source files before making any changes.
61
+ **Goal:** read ALL source files in the old module before touching anything.
84
62
 
85
- ### Actions
86
- 1. Read all files in the current module/feature directory
87
- 2. Read related models/types
88
- 3. Read related enums/constants
89
- 4. Read current routes/screens/providers for this module
63
+ ### Read
64
+ - All files in the module dir
65
+ - Related models / types / enums
66
+ - Routes / providers / screens for this module
67
+ - Existing tests (CRITICAL used in Phase 5)
90
68
 
91
- ### Output (report to user)
92
- - All entities/models and their fields
93
- - All usecases (functions/methods) and their logic
94
- - All DTOs (request/response structs)
95
- - All validators (if any)
96
- - All cross-module calls
97
- - All events/side-effects (notifications, SSE, analytics)
98
- - All external dependencies (DB, cache, messaging, etc.)
99
- - All endpoints/screens/UI elements
69
+ ### Output to user
70
+ ```markdown
71
+ ## Refactor Plan: {module} {domain}
72
+
73
+ ### Current state
74
+ - Entities/models: {list with fields}
75
+ - Usecases (functions): {list with 1-line logic summary}
76
+ - DTOs: {list}
77
+ - Cross-module calls: {list}
78
+ - Side-effects: {notifications / SSE / analytics / async jobs}
79
+ - External deps: {DB, cache, messaging}
80
+ - Endpoints/screens: {list with method + path}
81
+ - Test files: {list with case counts}
82
+
83
+ ### Proposed DDD structure
84
+ - Value objects to extract: {list}
85
+ - Entities: {list}
86
+ - Events: {list}
87
+ - Ports: {list}
88
+ - Usecases: {list}
89
+ - Listeners: {list}
90
+ ```
100
91
 
101
- ### Rule Check Phase 1
102
- - [ ] All module files read and understood
103
- - [ ] All entities, usecases, dependencies, endpoints listed
104
- - [ ] Report presented to user and **CONFIRM received** before continuing
92
+ ### Gate
93
+ - [ ] All module files read
94
+ - [ ] Plan presented to user
95
+ - [ ] **User CONFIRMED** before continuing
105
96
 
106
97
  ---
107
98
 
108
- ## PHASE 2: Create Domain Layer
109
-
110
- Create `domain/{domain}/` (if first module in this domain) or add to existing.
111
-
112
- ### 2.1 Value Objects (`valueobjects/`)
113
- - Extract typed values from existing code (status strings, rates, amounts)
114
- - Immutable with behavior methods
115
- - **Only stdlib imports** — check Forbidden Imports from architecture doc
116
-
117
- ### 2.2 Entities (`entities/`)
118
- - Convert existing model fields to domain entity
119
- - Add constructor function/method
120
- - Add behavior methods (state transitions, calculations)
121
- - Add event collection (collect events on state changes)
122
- - Add mappers to/from persistence models (if applicable)
123
- - **No framework imports**
124
-
125
- ### 2.3 Events (`events/`)
126
- - One file per domain event
127
- - Extend/embed base event type
128
- - Carry data needed by listeners
129
- - Extract from existing direct side-effect calls (SSE, notifications, etc.)
130
-
131
- ### 2.4 Ports (`ports/`)
132
- - One file per port interface
133
- - Store ports: persistence interface from existing repository/DB calls
134
- - Adapter ports: external service interfaces
135
- - Platform-agnostic naming
136
- - **No infrastructure imports**
137
-
138
- ### 2.5 UseCases (`usecases/`)
139
- - Extract business logic from existing controllers/handlers/services
140
- - Import port interfaces from `ports/`
141
- - Split by concern: one file per action group
142
- - Business logic lives HERE
143
- - **No infrastructure imports**
144
-
145
- ### Rule Check Phase 2
146
- Run check scripts from architecture doc:
147
- ```bash
148
- # Build domain layer
149
- {stack_build_command_for_domain}
99
+ ## Phase 2: DOMAIN LAYER
100
+
101
+ Create `domain/{domain}/` (or add to existing).
150
102
 
151
- # Check domain purity
152
- {grep_forbidden_imports_in_domain} && echo "FAIL" || echo "PASS"
103
+ ### Order: VO → entities → events → ports → usecases
153
104
 
154
- # Check no cross-domain imports
155
- {check_cross_domain_imports}
105
+ - **Value Objects** (`valueobjects/`) — extract typed values (status strings, rates, amounts). Immutable + behavior methods. Stdlib imports only.
106
+ - **Entities** (`entities/`) — convert old models. Constructor + behavior methods + event collection. Add mappers to/from persistence. No framework imports.
107
+ - **Events** (`events/`) — one file per event. Extract from existing direct side-effect calls.
108
+ - **Ports** (`ports/`) — one file per interface. Store ports (persistence), adapter ports (external services). Platform-agnostic naming (`URLParser` not `ShopeeURLParser`). No infra imports.
109
+ - **UseCases** (`usecases/`) — extract business logic from old controllers/handlers/services. Import from `ports/`. Split by concern, ≤200 lines/file. No infra imports.
110
+
111
+ ### Gate
112
+ ```bash
113
+ {build_domain} && echo PASS || echo FAIL
114
+ {grep_forbidden in domain/} && echo FAIL || echo PASS
115
+ {cross_domain_check} && echo FAIL || echo PASS
156
116
  ```
157
117
 
158
118
  ---
159
119
 
160
- ## PHASE 3: Create Infrastructure Layer
120
+ ## Phase 3: INFRASTRUCTURE LAYER
161
121
 
162
- ### 3.1 Store/API Implementation
163
- - Implement interfaces from `domain/{domain}/ports/`
164
- - Use mapper functions (domain entity ↔ persistence model)
165
- - Compile-time interface check (where possible)
166
- - NO business logic pure persistence
167
- - Keep existing persistence models where they are
122
+ - Implement port interfaces from `domain/{domain}/ports/`
123
+ - Mapper functions: domain entity ↔ persistence model
124
+ - Compile-time interface check (where supported)
125
+ - NO business logic
126
+ - Keep existing persistence models in place
168
127
 
169
- ### Rule Check Phase 3
170
- ```bash
171
- # Build infrastructure
172
- {stack_build_command_for_infra}
173
- ```
128
+ ### Gate
129
+ - [ ] Infra build passes
130
+ - [ ] All port interfaces implemented
174
131
 
175
132
  ---
176
133
 
177
- ## PHASE 4: Create Application Layer
134
+ ## Phase 4: APPLICATION LAYER
135
+
136
+ ### 4.1 Listeners (extract side-effects)
137
+ **CRITICAL:** Side-effects (notifications, SSE, analytics, jobs) **MUST NOT** be called directly in usecases or infra. Flow must be: entity collects event → usecase dispatches → listener handles.
178
138
 
179
- ### 4.1 Listeners (extract from existing side-effects)
180
- - **CRITICAL:** Side-effects (notifications, SSE, analytics, async jobs) MUST NOT be called directly in usecases or infrastructure
181
- - They MUST flow through: entity collects events → usecase dispatches → listener handles
182
139
  - One file per event listener
183
- - Register in event bus/registry
140
+ - Register in event bus
184
141
 
185
142
  ### 4.2 Service
186
- - Thin wrapper delegating to domain usecases
187
- - NO business logic
143
+ - Thin wrapper, delegates to usecases. No business logic.
188
144
 
189
- ### 4.3 Handler/Controller/Screen
190
- - Registration/wiring function
191
- - Thin: parse input call service → return output
145
+ ### 4.3 Handler / Controller / Screen
146
+ - Registration / wiring function
147
+ - Thin: parse → service → return
192
148
  - DTOs in separate file
193
- - All endpoints/routes must match the old ones (same path + method)
149
+ - **All endpoints must match the old paths + methods**
194
150
 
195
- ### Rule Check Phase 4
196
- ```bash
197
- # Build application layer
198
- {stack_build_command_for_application}
199
- ```
151
+ ### Gate
152
+ - [ ] App build passes
153
+ - [ ] Every old endpoint has a new handler at the same path
200
154
 
201
155
  ---
202
156
 
203
- ## PHASE 5: Domain Tests
157
+ ## Phase 5: TESTS
204
158
 
205
- **CRITICAL:** MUST read old tests before writing new ones. Copy all test cases and business scenarios to domain tests. Do not lose any test coverage.
159
+ **CRITICAL:** read old tests first, copy every scenario. Do not lose coverage.
206
160
 
207
- ### 5.1 Process
208
- 1. Read ALL test files in old module
209
- 2. List all test cases and business scenarios
210
- 3. Write domain tests covering all those scenarios
211
- 4. Focus on business logic (pure unit tests, no integration needed yet)
161
+ 1. Read all old test files
162
+ 2. List all test cases + business scenarios
163
+ 3. Write domain tests covering all of them
212
164
 
213
- ### 5.2 Entity Tests
214
- - Behavior methods (state transitions, validations, calculations)
215
- - Edge cases (zero values, boundary conditions)
216
- - Business rules
217
- - NO mocking needed — pure tests
165
+ ### What to test
166
+ - **Entities** — behavior methods, edge cases, business rules (pure, no mocks)
167
+ - **UseCases** happy + error paths, validation, event collection (mock ports)
168
+ - **Value Objects** — transitions, calculations, edge cases (pure)
218
169
 
219
- ### 5.3 UseCase Tests
220
- - Mock port interfaces
221
- - All business flows (happy path + error cases)
222
- - Input validation
223
- - Domain event collection (if applicable)
224
-
225
- ### Rule Check Phase 5
226
- ```bash
227
- # Run domain tests
228
- {stack_test_command_for_domain}
229
- ```
170
+ ### Gate
171
+ - [ ] Old test count ≤ new test count
172
+ - [ ] Every old scenario covered
173
+ - [ ] `{test_command}` passes
230
174
 
231
175
  ---
232
176
 
233
- ## PHASE 6: Integration & Cleanup
177
+ ## Phase 6: INTEGRATION & CLEANUP
234
178
 
235
- ### 6.1 Update Router/Provider/Registry
236
- - Add new registration calls
237
- - Remove old module routes/registrations
238
- - All endpoints/screens must match the old ones
179
+ ### 6.1 Wire up the new module
180
+ - Add registration calls in router / provider / registry
181
+ - Remove old module registrations
182
+ - Endpoints/screens match old paths
239
183
 
240
- ### 6.2 Remove Old Module
241
- - Delete old module directory ONLY AFTER verifying build + test pass
242
- - DO NOT delete shared models/types that other modules still use
184
+ ### 6.2 Remove old module
185
+ - Delete old directory **only after** build + tests pass
186
+ - Do NOT delete shared models/types other modules still use
243
187
 
244
- ### Rule Check Phase 6
188
+ ### Gate
245
189
  ```bash
246
- # Full build
247
- {stack_full_build_command}
248
-
249
- # Verify old module removed
250
- test -d {old_module_path} && echo "FAIL: old module exists" || echo "PASS"
251
-
252
- # Verify no old imports remain
253
- grep -r "{old_module_import}" --include="*.{ext}" . && echo "FAIL: old imports" || echo "PASS"
190
+ {full_build} && echo PASS || echo FAIL
191
+ test -d {old_module_path} && echo "FAIL: still there" || echo PASS
192
+ grep -r "{old_import_path}" --include="*.{ext}" . && echo "FAIL: stale imports" || echo PASS
254
193
  ```
255
194
 
256
195
  ---
257
196
 
258
- ## REVIEW LOOP
197
+ ## Review Loop
259
198
 
260
- After all phases complete, run the full architecture review. **Keep looping until ALL checks pass.**
199
+ After Phase 6, call `/review:architect {stack} {domain}`. Loop until score B.
261
200
 
262
201
  ```
263
202
  LOOP:
264
- 1. Run /review:architect {stack} {domain}
265
- 2. Collect violations
266
- 3. IF violations with severity >= MEDIUM:
267
- a. Fix all violations
268
- b. Run full build to verify
269
- c. Run all tests to verify
270
- d. GOTO 1
271
- 4. IF score >= B:
272
- BREAK → Final Report
203
+ 1. /review:architect {stack} {domain}
204
+ 2. IF violations severity ≥ MEDIUM:
205
+ fix all full build all tests → GOTO 1
206
+ 3. IF score ≥ B → BREAK
273
207
  ```
274
208
 
275
209
  ---
276
210
 
277
211
  ## Final Report
278
212
 
279
- When review loop passes with score >= B:
280
-
281
213
  ```markdown
282
214
  ## Refactor Complete: {module} → {domain}
283
215
 
284
- ### Files Created
285
- - List all new files
286
-
287
- ### Files Modified
288
- - List all modified files
289
-
290
- ### Files Deleted
291
- - List old module files removed
292
-
293
- ### Endpoints/Screens Preserved
294
- | Before | After | Status |
295
- |--------|-------|--------|
296
- | All old routes | Same routes, new handlers | Verified |
297
-
298
- ### Domain Events
299
- | Event | Listeners |
300
- |-------|-----------|
301
-
302
- ### Test Coverage
303
- - X test files, Y test functions
304
- - All old test cases migrated: YES
305
- - Areas covered: value objects, entities, usecases
306
-
307
- ### Review Status: ALL CHECKS PASS
308
- - Build: PASS
309
- - Lint: PASS
310
- - Domain purity: PASS
311
- - Old module removed: PASS
312
- - No old imports: PASS
313
- - Tests: PASS (X/X)
314
- - Architecture score: {A/B}
216
+ ### Changes
217
+ - Files created: {N}
218
+ - Files modified: {N}
219
+ - Files deleted: {N}
220
+
221
+ ### Endpoints preserved
222
+ | Old path | New handler | Status |
223
+ |----------|-------------|--------|
224
+
225
+ ### Domain events introduced
226
+ | Event | Listener(s) |
227
+ |-------|-------------|
228
+
229
+ ### Tests
230
+ - Files: {N}, cases: {M}
231
+ - All old scenarios migrated: YES
232
+
233
+ ### Review score: {A/B}
234
+ - Build / Lint / Domain purity / Old module removed / No stale imports / Tests: all PASS
315
235
  ```
316
236
 
317
237
  ---
318
238
 
319
- ## Interaction Rules
239
+ ## Hard Rules
320
240
 
321
- 1. After each phase, report Rule Check results to user
322
- 2. If a rule fails auto-fix if you know how, otherwise ask user
323
- 3. **DO NOT skip any phase** — all rules must pass before moving to next
324
- 4. If unsure about business logic → **READ the old code carefully, DO NOT invent new logic**
325
- 5. Preserve behaviorrefactor structure only, DO NOT change logic
326
- 6. **MUST read old test files** before writing new tests
327
- 7. When multiple modules map to same domain first module creates domain dir, subsequent add to it
328
- 8. After completing a module, ask user if they want to refactor the next module
241
+ - **Preserve behavior** never change business logic during refactor
242
+ - **MUST read old tests** before writing new ones (no scenario lost)
243
+ - **MUST read old code** carefully don't invent logic from variable names
244
+ - **All endpoints keep their paths** refactor is invisible to clients
245
+ - **Don't skip phases** Rule Checks gate the next phase
246
+ - **Multiple modules same domain:** first module creates the domain dir, others add to it
247
+ - **One module at a time** finish one before starting the next
329
248
 
330
249
  ---
331
250
 
@@ -334,17 +253,17 @@ When review loop passes with score >= B:
334
253
  | When | Use |
335
254
  |------|-----|
336
255
  | Building from scratch (no existing code) | `/feature:new` |
337
- | Just adding tests to existing untested code | `/review:tdd` |
256
+ | Just adding tests to untested code | `/review:tdd` |
338
257
  | Reviewing the refactor before merging | `/review:branch` |
339
- | Final architecture compliance check (called in review loop) | `/review:architect` |
258
+ | Final architecture check (called automatically in review loop) | `/review:architect` |
340
259
 
341
260
  ## Recommended Agents
342
261
 
343
262
  | Phase | Agent | Purpose |
344
263
  |-------|-------|---------|
345
- | ANALYZE | `@refactor` | Identify refactoring opportunities |
346
- | ANALYZE | `@code-reviewer` | Code smell detection |
264
+ | ANALYZE | `@refactor` | Identify refactor scope |
265
+ | ANALYZE | `@code-reviewer` | Smell detection |
347
266
  | PLAN | `@clean-architect` | Architecture alignment |
348
- | REFACTOR | Stack-specific dev agent | Code per architecture |
349
- | TEST | `@test-writer` | Write domain tests |
267
+ | BUILD | Stack-specific dev agent | Implementation |
268
+ | TESTS | `@test-writer` | Domain tests |
350
269
  | REVIEW | `@code-reviewer` | Final quality check |