---
name: step-04b-doc-sync
description: Documentation sync - detect affected modules and update documentation
prev_step: steps/step-04-validate.md
next_step: steps/step-05-examine.md
---

# Step 4b: Documentation Sync

## MANDATORY EXECUTION RULES:

- NEVER skip this step when {doc_mode} = true
- NEVER create documentation from scratch (that is BA skill's job)
- ALWAYS update existing documentation only
- ALWAYS update docs-manifest.json after changes
- IF docs-manifest.json is absent → skip with note "No documentation manifest found"

## YOUR TASK:

Detect which documented modules are affected by the code changes and update their documentation data files.

---

<available_state>
From previous steps:

| Variable | Description |
|----------|-------------|
| `{task_description}` | What was implemented |
| `{task_id}` | Full task identifier |
| `{doc_mode}` | Documentation sync enabled (should be true) |
| `{economy_mode}` | No subagents if true |
| `{save_mode}` | Save outputs to disk |
| `{output_dir}` | Output directory path |
</available_state>

---

## EXECUTION SEQUENCE:

### 1. Check Documentation Manifest

Read `docs-manifest.json` from project root.

**If absent:**
```
Display: "No docs-manifest.json found. Skipping documentation sync."
Display: "TIP: Run /business-analyse to create documentation for your modules."
→ Load next step
```

**If present:** Continue.

### 2. Identify Affected Modules

Get files modified during step-03 (from TodoList or git diff):

```bash
git diff --name-only HEAD~1
```

Match modified files against `codeFiles` in each manifest module entry.

**Build affected modules list:**

| Module | Changed Files | Impact |
|--------|---------------|--------|
| business/{app}/{module} | [list] | [sections] |

### 3. Map Code Changes to Documentation Sections

For each affected module, classify changes:

| Code Change Pattern | Documentation Section |
|--------------------|-----------------------|
| `**/Entities/**` modified | businessRules, features |
| `**/Controllers/**` modified | apiEndpoints, technicalRef |
| `**/Permissions*` modified | permissions |
| `**/Validators/**` modified | businessRules |
| `**/i18n/**` modified | useCases (labels), faq |
| `**/Migrations/**` created | technicalRef |
| `**/DTOs/**` modified | apiEndpoints |
| `**/Commands/**` modified | useCases, features |
| `**/Queries/**` modified | useCases, features |

### 4. Read Current Documentation

For each affected module:

**If {economy_mode} = false:**
- Launch `docs-context-reader` agent for the module
- Agent returns structured summary of current doc state

**If {economy_mode} = true:**
- Read `doc-data.ts` directly
- Read i18n FR file directly

### 5. Update Documentation Data

For each affected module and impacted section:

1. Read current `doc-data.ts`
2. Compare with actual code state
3. Update affected fields:
   - **apiEndpoints**: Scan controller for `[Http*]` attributes
   - **permissions**: Scan PermissionConfiguration.cs for module
   - **businessRules**: Scan validators and entity methods
   - **useCases**: Update if commands/queries changed
   - **features**: Update if new functionality added
4. Write updated `doc-data.ts`
5. Update i18n FR file if label keys changed

### 6. Update Documentation Manifest

For each updated module:

```json
{
  "lastDocUpdate": "{current_timestamp}",
  "gitCommitDoc": "{current_commit_sha}",
  "status": "synced"
}
```

Update `docs-manifest.json` root `lastUpdated`.

### 7. Save Output (if save_mode)

Write `{output_dir}/04b-doc-sync.md` with:
- Modules checked
- Modules updated
- Sections modified
- Files changed

---

## SUCCESS METRICS:

- All affected modules identified
- Documentation data files updated for impacted sections
- docs-manifest.json timestamps updated
- No new documentation created (only updates)

## FAILURE MODES:

- docs-manifest.json absent → skip gracefully (not a failure)
- doc-data.ts has unexpected format → report warning, skip module
- No modules affected → display "No documented modules affected by changes"

---

## NEXT STEP:

```
IF {test_mode} = true AND step-07 not yet done:
    → Load steps/step-07-tests.md
ELSE IF {examine_mode} = true:
    → Load steps/step-05-examine.md
ELSE:
    → Display completion summary
    → IF {pr_mode} = true: Load steps/step-09-finish.md
```
