moicle 1.3.0 → 1.4.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.
@@ -0,0 +1,575 @@
1
+ ---
2
+ name: sync-docs
3
+ description: Sync documentation workflow - reads codebase and docs folder to generate structured output docs with architecture, use cases, diagrams, and README index. Includes automated review loop. Use when user says "sync docs", "sync documentation", "generate docs", "update docs sync", "doc sync".
4
+ ---
5
+
6
+ # Sync Docs Workflow
7
+
8
+ Automated workflow that reads codebase and existing docs to generate a complete, structured documentation output with architecture overview, use case diagrams, and a README index linking all sub-files.
9
+
10
+ ## Workflow Overview
11
+
12
+ ```
13
+ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
14
+ │ 1. SCAN │──▶│1.5 CONFIRM──▶│2. GENERATE──▶│ 3. REVIEW │──▶│4. COMPLETE│
15
+ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘
16
+ ▲ │
17
+ │ Feedback │
18
+ └──────────────┘
19
+ (loop until pass)
20
+ ```
21
+
22
+ **Key**: Phase 1.5 CONFIRM asks user to choose between REFACTOR (full restructure) or UPDATE (keep structure, update & link only). Phase 3 REVIEW automatically loops back to Phase 2 GENERATE if issues are found.
23
+
24
+ ---
25
+
26
+ ## Phase 1: SCAN
27
+
28
+ **Goal**: Read and understand the entire codebase and existing docs
29
+
30
+ ### Actions
31
+
32
+ 1. **Identify project stack**:
33
+ - Check `package.json`, `go.mod`, `pubspec.yaml`, `composer.json`, etc.
34
+ - Determine primary language and framework
35
+
36
+ 2. **Read existing documentation**:
37
+ ```bash
38
+ # Find all doc files
39
+ find . -name "*.md" -not -path "*/node_modules/*" -not -path "*/vendor/*" -not -path "*/.dart_tool/*" | sort
40
+
41
+ # Find existing docs folder
42
+ ls -la docs/ 2>/dev/null
43
+ ```
44
+
45
+ 3. **Map codebase structure**:
46
+ ```bash
47
+ # Get directory tree (exclude build artifacts)
48
+ tree -L 4 -I 'node_modules|vendor|dist|build|.dart_tool|.git' --dirsfirst
49
+ ```
50
+
51
+ 4. **Identify key components**:
52
+ - Entry points (main files, routes, controllers)
53
+ - Domain/business logic (services, use cases, models)
54
+ - Data layer (repositories, database, APIs)
55
+ - Configuration files
56
+ - Test files
57
+
58
+ 5. **Extract use cases** from the codebase:
59
+ - Read route definitions, controller methods, service methods
60
+ - Identify distinct user-facing features/flows
61
+ - Group related functionality into use cases
62
+
63
+ 6. **Read architecture files** (if exist):
64
+ ```bash
65
+ ls .claude/architecture/*.md 2>/dev/null
66
+ ls ~/.claude/architecture/*.md 2>/dev/null
67
+ ```
68
+
69
+ ### Output
70
+ ```markdown
71
+ ## Scan Results
72
+
73
+ ### Stack: [identified stack]
74
+ ### Architecture: [identified pattern]
75
+
76
+ ### Existing Docs
77
+ - [list of existing .md files and their status]
78
+
79
+ ### Identified Use Cases
80
+ 1. [Use Case 1] - [brief description]
81
+ 2. [Use Case 2] - [brief description]
82
+ 3. [Use Case N] - [brief description]
83
+
84
+ ### Key Components
85
+ - Entry Points: [list]
86
+ - Business Logic: [list]
87
+ - Data Layer: [list]
88
+ - Config: [list]
89
+
90
+ ### Docs Output Plan
91
+ - docs/README.md (index)
92
+ - docs/business.md (business overview - non-technical, business language only)
93
+ - docs/architecture.md
94
+ - docs/use-cases/[usecase-name].md (per use case)
95
+ - docs/diagrams/ (embedded in use case files via mermaid)
96
+ ```
97
+
98
+ ### Gate
99
+ - [ ] Codebase fully scanned
100
+ - [ ] Use cases identified
101
+ - [ ] Existing docs read
102
+ - [ ] Output plan defined
103
+
104
+ ---
105
+
106
+ ## Phase 1.5: CONFIRM
107
+
108
+ **Goal**: Ask the user how they want to handle docs before generating.
109
+
110
+ ### Actions
111
+
112
+ 1. **Present scan results** from Phase 1 to the user (current structure, identified use cases, docs plan)
113
+
114
+ 2. **Ask the user**:
115
+ ```
116
+ How would you like to proceed with the docs?
117
+
118
+ 1. Refactor - Restructure docs into the standard template (docs/README.md, business.md, architecture.md, use-cases/) and relink everything
119
+ 2. Update & Link only - Keep the current docs structure as-is, only update content and fix linking
120
+
121
+ (Choose 1 or 2)
122
+ ```
123
+
124
+ 3. **Based on the choice, set the mode for Phase 2**:
125
+ - **REFACTOR mode (choice 1)**: Run Phase 2 GENERATE in full - create new structure, migrate useful content from old docs into the new template, remove/replace old doc files that are no longer needed
126
+ - **UPDATE mode (choice 2)**: Run Phase 2 in update-only mode - preserve existing file/folder structure, only update content inside existing files to match current code, add/fix links between files, add mermaid diagrams where missing, DO NOT move/rename/delete existing files
127
+
128
+ ### Gate
129
+ - [ ] User has chosen a mode (REFACTOR or UPDATE)
130
+ - [ ] Mode is recorded for Phase 2 to handle accordingly
131
+
132
+ ---
133
+
134
+ ## Phase 2: GENERATE
135
+
136
+ **Goal**: Generate all documentation files based on the selected mode from Phase 1.5
137
+
138
+ ### Mode Selection
139
+
140
+ - **REFACTOR mode**: Create an entirely new docs structure following the template below. If old docs exist, migrate useful content into the new structure. May remove/replace old files.
141
+ - **UPDATE mode**: Preserve the existing file/folder structure. Only perform:
142
+ - Update content in existing doc files to match current code
143
+ - Add/fix links between files (relative links)
144
+ - Add mermaid diagrams to existing files where missing
145
+ - Add new files ONLY when there are undocumented use cases/features
146
+ - DO NOT move, rename, or delete existing files
147
+ - Ensure there is 1 index file (README.md or existing index) linking to all docs
148
+
149
+ > **The templates below apply fully to REFACTOR mode. For UPDATE mode, use them as content/format reference only — do NOT force the structure.**
150
+
151
+ ### Output Structure
152
+
153
+ ```
154
+ docs/
155
+ ├── README.md # Index - links to all sub-files
156
+ ├── business.md # Business overview - non-technical, business language only
157
+ ├── architecture.md # Architecture overview + system diagram
158
+ └── use-cases/
159
+ ├── [use-case-1].md # Use case doc + sequence diagram
160
+ ├── [use-case-2].md # Use case doc + sequence diagram
161
+ └── [use-case-N].md # Use case doc + sequence diagram
162
+ ```
163
+
164
+ ### 2.1 Generate `docs/README.md` (Index)
165
+
166
+ ```markdown
167
+ # [Project Name] Documentation
168
+
169
+ > Auto-generated documentation synced from codebase.
170
+
171
+ ## Overview
172
+
173
+ [1-2 paragraph project description derived from codebase]
174
+
175
+ ## Table of Contents
176
+
177
+ ### Business
178
+ - [Business Overview](./business.md) - Business overview, goals, target users
179
+
180
+ ### Architecture
181
+ - [Architecture Overview](./architecture.md) - System architecture, layers, and patterns
182
+
183
+ ### Use Cases
184
+ - [Use Case 1](./use-cases/use-case-1.md) - [brief description]
185
+ - [Use Case 2](./use-cases/use-case-2.md) - [brief description]
186
+ - [Use Case N](./use-cases/use-case-n.md) - [brief description]
187
+
188
+ ## Tech Stack
189
+
190
+ | Component | Technology |
191
+ |-----------|-----------|
192
+ | Language | [language] |
193
+ | Framework | [framework] |
194
+ | Database | [database] |
195
+ | Other | [key deps] |
196
+
197
+ ## Quick Links
198
+
199
+ - [Business Overview](./business.md)
200
+ - [Architecture Diagram](./architecture.md#system-diagram)
201
+ - [Use Case Diagrams](./use-cases/)
202
+ ```
203
+
204
+ ### 2.2 Generate `docs/business.md` (Business Overview)
205
+
206
+ This file is written entirely in business language. NO code, NO class/function names, NO technical jargon. Target audience: stakeholders, product owners, business analysts - people who don't need to know the code.
207
+
208
+ ```markdown
209
+ # [Project Name] - Business Overview
210
+
211
+ ## What is this product?
212
+
213
+ [2-3 paragraphs describing the product in everyday language. Explain what problem it solves, for whom, and why it's needed.]
214
+
215
+ ## Target Users
216
+
217
+ ### [Role 1] - e.g., End User
218
+ - **Who**: [description]
219
+ - **Needs**: [what they need from the product]
220
+ - **What they do**: [key actions on the system]
221
+
222
+ ### [Role 2] - e.g., Administrator
223
+ - **Who**: [description]
224
+ - **Needs**: [what they need]
225
+ - **What they do**: [key actions on the system]
226
+
227
+ ## Core Business Processes
228
+
229
+ ### [Process 1] - e.g., Registration and first-time use
230
+ [Describe each step from the user's perspective. No mention of API, database, or any technical details.]
231
+
232
+ 1. [Step 1 - what the user does]
233
+ 2. [Step 2 - how the system responds]
234
+ 3. [Step N]
235
+
236
+ ### [Process 2] - e.g., Placing an order
237
+ [Same approach - describe from a business perspective]
238
+
239
+ ## Key Features
240
+
241
+ | Feature | Description | Used by |
242
+ |---------|-------------|---------|
243
+ | [Feature 1] | [explain in business language] | [role] |
244
+ | [Feature 2] | [explain] | [role] |
245
+
246
+ ## Business Rules
247
+
248
+ Key rules the system follows:
249
+
250
+ 1. **[Rule 1]**: [explain - e.g., "Every order must contain at least 1 product"]
251
+ 2. **[Rule 2]**: [explain - e.g., "Users can only request a refund within 7 days"]
252
+ 3. **[Rule N]**: [explain]
253
+
254
+ ## Business Entity Relationships
255
+
256
+ [Describe key relationships in plain text, e.g.:]
257
+ - A **customer** can create multiple **orders**
258
+ - An **order** contains multiple **products**
259
+ - A **product** belongs to a **category**
260
+
261
+ ## Value Flow
262
+
263
+ [Describe how the product creates value for each stakeholder:]
264
+
265
+ - **For [role 1]**: [value they receive]
266
+ - **For [role 2]**: [value they receive]
267
+ - **For the business**: [value the business receives]
268
+
269
+ ## Business Glossary
270
+
271
+ | Term | Definition |
272
+ |------|-----------|
273
+ | [Term 1] | [explain in the product's context] |
274
+ | [Term 2] | [explain] |
275
+ ```
276
+
277
+ **IMPORTANT rules for business.md**:
278
+ - DO NOT use words like: API, endpoint, database, repository, controller, service, model, schema, query, migration, route, middleware, component, module, class, function, method, interface, type
279
+ - NO code blocks whatsoever
280
+ - NO file path references or code file names
281
+ - Write as if explaining to someone who doesn't know programming
282
+ - Use the project's business domain language (e.g., "order" instead of "Order entity", "user" instead of "User model")
283
+ - Extract business rules from code logic (validation, conditions, constraints) and express them in business language
284
+
285
+ ### 2.3 Generate `docs/architecture.md` (Technical)
286
+
287
+ ```markdown
288
+ # Architecture Overview
289
+
290
+ ## System Diagram
291
+
292
+ \`\`\`mermaid
293
+ graph TB
294
+ [Generate actual system architecture diagram based on codebase layers]
295
+ \`\`\`
296
+
297
+ ## Layers
298
+
299
+ ### [Layer 1 Name]
300
+ - **Location**: `[directory path]`
301
+ - **Responsibility**: [what this layer does]
302
+ - **Key Files**: [list important files]
303
+
304
+ ### [Layer 2 Name]
305
+ [same structure]
306
+
307
+ ## Directory Structure
308
+
309
+ \`\`\`
310
+ [actual project directory tree with annotations]
311
+ \`\`\`
312
+
313
+ ## Dependencies Between Layers
314
+
315
+ \`\`\`mermaid
316
+ graph LR
317
+ [Show dependency direction between layers]
318
+ \`\`\`
319
+
320
+ ## Design Patterns Used
321
+ - [Pattern 1]: [where and why]
322
+ - [Pattern 2]: [where and why]
323
+
324
+ ## Data Flow
325
+
326
+ \`\`\`mermaid
327
+ flowchart LR
328
+ [Show how data flows through the system]
329
+ \`\`\`
330
+ ```
331
+
332
+ ### 2.4 Generate Use Case Files (`docs/use-cases/[name].md`)
333
+
334
+ Generate ONE file per use case:
335
+
336
+ ```markdown
337
+ # [Use Case Name]
338
+
339
+ ## Overview
340
+
341
+ [Description of what this use case does from user perspective]
342
+
343
+ ## Actors
344
+ - [Actor 1]: [role]
345
+ - [Actor 2]: [role]
346
+
347
+ ## Flow
348
+
349
+ ### Main Flow
350
+
351
+ 1. [Step 1]
352
+ 2. [Step 2]
353
+ 3. [Step N]
354
+
355
+ ### Sequence Diagram
356
+
357
+ \`\`\`mermaid
358
+ sequenceDiagram
359
+ participant [Actor]
360
+ participant [Component1]
361
+ participant [Component2]
362
+ participant [DataStore]
363
+
364
+ [Actor]->>[Component1]: [action]
365
+ [Component1]->>[Component2]: [action]
366
+ [Component2]->>[DataStore]: [action]
367
+ [DataStore]-->>[Component2]: [response]
368
+ [Component2]-->>[Component1]: [response]
369
+ [Component1]-->>[Actor]: [response]
370
+ \`\`\`
371
+
372
+ ## Related Files
373
+
374
+ | File | Purpose |
375
+ |------|---------|
376
+ | `[path/to/file]` | [what it does in this use case] |
377
+ | `[path/to/file]` | [what it does in this use case] |
378
+
379
+ ## Error Cases
380
+
381
+ | Error | Cause | Handling |
382
+ |-------|-------|----------|
383
+ | [Error 1] | [cause] | [how handled] |
384
+
385
+ ## Notes
386
+
387
+ - [Any important implementation details]
388
+ ```
389
+
390
+ ### Generation Rules
391
+
392
+ 1. **Diagrams MUST be mermaid** - embedded in markdown, not external files
393
+ 2. **Every use case MUST have a sequence diagram** showing the actual flow through code
394
+ 3. **Architecture MUST have a system diagram** showing layers/components
395
+ 4. **README MUST link to every sub-file** with working relative links
396
+ 5. **Use actual file paths** from codebase, not placeholders
397
+ 6. **Use actual class/function names** from codebase
398
+ 7. **If existing docs/ folder has content**, merge/update rather than overwrite useful information
399
+
400
+ ### Gate
401
+ - [ ] docs/README.md generated with all links
402
+ - [ ] docs/business.md generated with pure business language (no technical terms)
403
+ - [ ] docs/architecture.md generated with system diagram
404
+ - [ ] All use case files generated with sequence diagrams
405
+ - [ ] All links are relative and correct
406
+ - [ ] All diagrams use mermaid syntax
407
+
408
+ ---
409
+
410
+ ## Phase 3: REVIEW (Automated Loop)
411
+
412
+ **Goal**: Verify generated docs are complete and accurate. Loop back to GENERATE if issues found.
413
+
414
+ ### Review Checklist
415
+
416
+ Run through ALL checks below. If ANY check fails, fix and re-check.
417
+
418
+ #### 3.1 Structure Check
419
+ - [ ] `docs/README.md` exists and has all links
420
+ - [ ] `docs/business.md` exists
421
+ - [ ] `docs/architecture.md` exists with system diagram
422
+ - [ ] Each identified use case has its own file in `docs/use-cases/`
423
+ - [ ] All relative links in README.md point to existing files
424
+
425
+ #### 3.2 Business Check
426
+ - [ ] `docs/business.md` contains NO technical jargon (API, endpoint, database, repository, controller, service, model, schema, query, migration, route, middleware, component, module, class, function, method, interface, type)
427
+ - [ ] `docs/business.md` has NO code blocks
428
+ - [ ] `docs/business.md` does NOT reference file paths
429
+ - [ ] Business processes are fully described from the user's perspective
430
+ - [ ] Business rules are correctly extracted from code logic
431
+ - [ ] Glossary contains all domain-specific terms
432
+
433
+ #### 3.3 Content Check
434
+ - [ ] Architecture diagram reflects actual codebase layers
435
+ - [ ] Each use case sequence diagram matches actual code flow
436
+ - [ ] File paths referenced in docs actually exist in codebase
437
+ - [ ] Class/function names in diagrams match actual code
438
+ - [ ] No placeholder text like `[TODO]`, `[TBD]`, `[placeholder]`
439
+ - [ ] No template markers like `{name}`, `[name]` left unfilled
440
+
441
+ #### 3.4 Completeness Check
442
+ - [ ] Every major feature/flow has a use case doc
443
+ - [ ] Architecture doc covers all layers found in codebase
444
+ - [ ] README links to ALL generated sub-files
445
+ - [ ] Diagrams are syntactically valid mermaid
446
+
447
+ #### 3.5 Consistency Check
448
+ - [ ] Naming is consistent across all docs
449
+ - [ ] Same component uses same name everywhere
450
+ - [ ] File naming convention is consistent (kebab-case)
451
+
452
+ ### Review Process
453
+
454
+ ```
455
+ FOR each check in checklist:
456
+ IF check FAILS:
457
+ 1. Note the issue
458
+ 2. Fix it (go back to relevant GENERATE sub-step)
459
+ 3. Re-run ALL checks from the beginning
460
+ IF all checks PASS:
461
+ Proceed to Phase 4
462
+ ```
463
+
464
+ ### Review Output
465
+ ```markdown
466
+ ## Review Results - Iteration [N]
467
+
468
+ ### Checks Passed: [X/total]
469
+ ### Checks Failed: [Y/total]
470
+
471
+ ### Issues Found
472
+ 1. [issue] → [fix applied]
473
+ 2. [issue] → [fix applied]
474
+
475
+ ### Status: [PASS - proceed to Phase 4 / FAIL - re-running Phase 2]
476
+ ```
477
+
478
+ **IMPORTANT**: Do NOT proceed to Phase 4 until ALL checks pass. Maximum 3 iterations - if still failing after 3 loops, report remaining issues and proceed.
479
+
480
+ ---
481
+
482
+ ## Phase 4: COMPLETE
483
+
484
+ **Goal**: Final output and summary
485
+
486
+ ### Actions
487
+
488
+ 1. **List all generated files**:
489
+ ```bash
490
+ find docs/ -name "*.md" | sort
491
+ ```
492
+
493
+ 2. **Print summary**:
494
+ ```markdown
495
+ ## Sync Docs Complete
496
+
497
+ ### Generated Files
498
+ - docs/README.md (index)
499
+ - docs/business.md (business overview)
500
+ - docs/architecture.md
501
+ - docs/use-cases/[list all]
502
+
503
+ ### Use Cases Documented: [count]
504
+ ### Diagrams Generated: [count]
505
+ ### Review Iterations: [count]
506
+
507
+ ### How to Use
508
+ Start at `docs/README.md` - it links to everything.
509
+ ```
510
+
511
+ 3. **Read the docs/ folder one final time** to confirm everything is in order
512
+
513
+ ### Gate
514
+ - [ ] All files verified
515
+ - [ ] Summary provided
516
+ - [ ] User informed of output location
517
+
518
+ ---
519
+
520
+ ## Recommended Agents
521
+
522
+ | Phase | Agent | Purpose |
523
+ |-------|-------|---------|
524
+ | SCAN | `@clean-architect` | Identify architecture patterns |
525
+ | SCAN | `@code-reviewer` | Understand code structure |
526
+ | GENERATE | `@docs-writer` | Write documentation |
527
+ | REVIEW | `@code-reviewer` | Verify accuracy |
528
+
529
+ ---
530
+
531
+ ## Quick Reference
532
+
533
+ ### Trigger Phrases
534
+ - "sync docs"
535
+ - "sync documentation"
536
+ - "generate structured docs"
537
+ - "update docs sync"
538
+ - "create docs from codebase"
539
+ - "doc sync"
540
+
541
+ ### Output Structure
542
+ ```
543
+ docs/
544
+ ├── README.md # Index with links
545
+ ├── business.md # Business overview (non-technical)
546
+ ├── architecture.md # System overview + diagram
547
+ └── use-cases/
548
+ └── *.md # One per use case + sequence diagram
549
+ ```
550
+
551
+ ### Diagram Types Used
552
+ | Where | Diagram Type | Purpose |
553
+ |-------|-------------|---------|
554
+ | architecture.md | `graph TB` | System architecture |
555
+ | architecture.md | `graph LR` | Layer dependencies |
556
+ | architecture.md | `flowchart LR` | Data flow |
557
+ | use-cases/*.md | `sequenceDiagram` | Use case flow |
558
+
559
+ ### Review Loop
560
+ ```
561
+ Scan → Confirm (Refactor/Update?) → Generate → Review → Pass? → Complete
562
+ → Fail? → Fix → Review again (max 3x)
563
+ ```
564
+
565
+ ## Success Criteria
566
+
567
+ Documentation sync is complete when:
568
+ 1. Business overview written entirely in business language, no technical jargon
569
+ 2. All codebase features are documented as use cases
570
+ 3. Architecture accurately reflects codebase
571
+ 4. Every use case has a sequence diagram
572
+ 5. README.md links to all sub-files
573
+ 6. All file paths and names match actual codebase
574
+ 7. All mermaid diagrams are valid
575
+ 8. Review loop passed all checks