# Business Analysis - Module Loop Protocol (_module-loop.md)

> **Loaded by:** step-03a1-setup, step-03b-ui, step-03c-compile, step-03d-validate
> **Purpose:** State management and iteration logic for multi-module specification loop

---

## State Management

```json
{
  "metadata": {
    "workflow": {
      "mode": "application",
      "moduleOrder": ["Customers", "Products", "Orders", "Invoices"],
      "currentModuleIndex": 2,
      "completedModules": ["Customers", "Products"],
      "currentModule": "Orders"
    }
  }
}
```

## Loop Logic (end of each step-03 iteration)

```
1. Mark current module as "validated" in master feature.json
2. Add to completedModules[]
3. IF currentModuleIndex + 1 < moduleOrder.length:
     currentModuleIndex++
     currentModule = moduleOrder[currentModuleIndex]
     Write master feature.json
     Display: "Module {name} complete. Next: {next_name} ({N}/{total})"
     RE-LOAD: steps/step-03a1-setup.md
4. ELSE:
     master.status = "specified"
     Load: steps/step-04a-collect.md
```

## Context Management During Loop

To prevent context explosion as modules accumulate:
- **Current module:** Load full module feature.json
- **Completed modules:** Only load compact summary via `ba-reader.getCompletedModulesSummary()` (max 100 lines)
- **Master feature.json:** Only read workflow state + application roles

## Resume After Interruption

```
1. ba-reader.findApplicationFeature() -> locate master feature.json
2. Read metadata.workflow.currentModuleIndex
3. IF currentModule has a feature.json with status != "validated":
     Resume step-03a1-setup for that module
4. ELSE:
     Start step-03a1-setup for next module
```
