# Context Isolation Architecture

## Pattern Overview

```
Main conversation (orchestrator):
  ├─ Determine topological order
  ├─ FOR each module:
  │   └─ Agent(ba-writer) ──► reads 5 files, writes 7 files, returns 1-line JSON
  │                           (isolated context: ~500-1000 lines per module)
  └─ Collect 1-line results only, display summary
```

## Why Context Isolation is CRITICAL

A 10-module project has ~10K lines of JSON data. Loading all at once exceeds Sonnet's effective context. Processing one module per Agent keeps each invocation under ~2K lines.

## Orchestration Pattern (ba-009 fix)

The orchestrator does NOT read detailed agent results.

Each Agent returns a single compact JSON confirmation:

```json
{
  "moduleCode": "Employees",
  "filesCreated": 7,
  "errors": [],
  "complexity": "simple"
}
```

The orchestrator stores ONLY this summary (1 line per module).

**Orchestrator context budget:** ~200 lines max (12 modules × ~15 lines each).

## Execution Flow

1. **Determine topological order** from step-00 data
2. **For EACH module in topological order:**
   - Call Agent(ba-writer) with isolated context
   - Receive 1-line JSON confirmation
   - Store only the confirmation
3. **Collect all confirmations** and display summary
4. **Never load detailed agent results** back into main conversation

This pattern prevents context accumulation across modules and enables processing of large multi-module projects.
