|
| 1 | +# Agentic Flow — Swimlane Diagram |
| 2 | + |
| 3 | +End-to-end flow of the Angular UI generator agent. Rendered as a Mermaid sequence diagram (swimlane-equivalent: each participant is a lane, arrows are handoffs). |
| 4 | + |
| 5 | +## Lanes |
| 6 | + |
| 7 | +| Lane | Role | |
| 8 | +|------|------| |
| 9 | +| **User** | Supplies PRD, selects Stitch design | |
| 10 | +| **Orchestrator** | `src/orchestrator/pipeline.mts` — coordinates all phases | |
| 11 | +| **Dribbble** | Design inspiration source (API → scraper → cache) | |
| 12 | +| **Stitch** | Google Stitch design generator (live → cache) | |
| 13 | +| **LLM** | Claude — Opus (planning/design) + Sonnet (codegen/fixes) | |
| 14 | +| **KB** | Knowledge base — `docs/knowledge-bases/*` fidelity corrections | |
| 15 | +| **Playwright** | `scripts/verify.mts` — Stage A/B/C pixel-diff validator | |
| 16 | +| **FS** | File system — generated Angular workspace + reports | |
| 17 | + |
| 18 | +## Diagram |
| 19 | + |
| 20 | +```mermaid |
| 21 | +sequenceDiagram |
| 22 | + autonumber |
| 23 | + participant U as User |
| 24 | + participant O as Orchestrator |
| 25 | + participant D as Dribbble |
| 26 | + participant S as Stitch |
| 27 | + participant L as LLM (Opus/Sonnet) |
| 28 | + participant KB as Knowledge Base |
| 29 | + participant P as Playwright |
| 30 | + participant FS as File System |
| 31 | +
|
| 32 | + Note over U,FS: Phase 0 — Preflight & Workspace Init |
| 33 | + U->>O: PRD + config |
| 34 | + O->>FS: init workspace, validate deps |
| 35 | + O->>KB: preflight load fidelity-corrections.md |
| 36 | + KB-->>O: applicable Prevention entries |
| 37 | +
|
| 38 | + Note over U,FS: Phase 1 — Design Inspiration (Hard Gate) |
| 39 | + O->>D: search(PRD-derived queries) |
| 40 | + alt API ok |
| 41 | + D-->>O: results |
| 42 | + else API fails |
| 43 | + O->>D: scraper fallback |
| 44 | + alt scraper ok |
| 45 | + D-->>O: results |
| 46 | + else scraper fails |
| 47 | + O->>D: cache fallback |
| 48 | + alt cache hit |
| 49 | + D-->>O: results |
| 50 | + else cache miss |
| 51 | + O-->>U: ABORT (hard gate) |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + O->>L: design-selection(results) |
| 56 | + L-->>O: selected inspiration |
| 57 | +
|
| 58 | + Note over U,FS: Phase 2 — Stitch Design (Hard Gate) |
| 59 | + O->>S: generate(PRD + inspiration) |
| 60 | + alt live ok |
| 61 | + S-->>O: designs |
| 62 | + else live fails |
| 63 | + O->>S: cache fallback |
| 64 | + alt cache hit |
| 65 | + S-->>O: designs |
| 66 | + else cache miss |
| 67 | + O-->>U: ABORT (hard gate) |
| 68 | + end |
| 69 | + end |
| 70 | + O->>U: open previews |
| 71 | + U-->>O: selected design |
| 72 | + O->>L: extract style guide |
| 73 | + L-->>O: tokens, palette, spacing |
| 74 | +
|
| 75 | + Note over U,FS: Phase 3 — Component Library |
| 76 | + O->>L: component-library-agent(tokens) |
| 77 | + L-->>O: design tokens + atom specs |
| 78 | + O->>FS: write design-tokens.scss, specs |
| 79 | +
|
| 80 | + Note over U,FS: Phase 4 — Planning & Per-Element Build (Bottom-Up) |
| 81 | + O->>L: planning-agent (task graph) |
| 82 | + L-->>O: ordered atoms → panels → layout |
| 83 | + loop For each element (atoms → panels → layout) |
| 84 | + O->>KB: load entries for this element |
| 85 | + KB-->>O: Prevention hints |
| 86 | + O->>L: codegen (with KB hints) |
| 87 | + L-->>FS: .ts / .html / .scss |
| 88 | +
|
| 89 | + loop Fix Loop — max 10 iter (lint/TS) |
| 90 | + O->>L: validate + lint |
| 91 | + L-->>O: errors? |
| 92 | + alt errors |
| 93 | + O->>L: fix |
| 94 | + L-->>FS: patched code |
| 95 | + else clean |
| 96 | + end |
| 97 | + end |
| 98 | +
|
| 99 | + Note over O,P: Phase 5 — Stage C Verify (per element) |
| 100 | + O->>P: verify.mts <element-id> |
| 101 | + P->>FS: Stage A baseline |
| 102 | + P->>FS: Stage B live capture |
| 103 | + P->>P: Stage C pixel-diff (10% threshold) |
| 104 | + P-->>O: summary.json (pass/fail per region) |
| 105 | +
|
| 106 | + loop Fidelity Fix Loop — max 30 iter (KB budget §5) |
| 107 | + alt Stage C fail |
| 108 | + O->>KB: consult matching motifs |
| 109 | + KB-->>O: correction guidance |
| 110 | + O->>L: fix with KB hints (prefer Sonnet) |
| 111 | + L-->>FS: patched code |
| 112 | + O->>P: re-verify |
| 113 | + P-->>O: summary.json |
| 114 | + else Stage C pass |
| 115 | + end |
| 116 | + end |
| 117 | +
|
| 118 | + alt budget exhausted |
| 119 | + O->>FS: document drift category, escalate |
| 120 | + end |
| 121 | + end |
| 122 | +
|
| 123 | + Note over U,FS: Phase 6 — Build & Whole-Page Verify |
| 124 | + O->>FS: bun run build |
| 125 | + alt build fails |
| 126 | + O->>L: fix build errors |
| 127 | + L-->>FS: patched code |
| 128 | + end |
| 129 | + O->>P: whole-page Stage C (all regions.json) |
| 130 | + P-->>O: final report |
| 131 | + O->>L: visual-fidelity-agent (LLM review) |
| 132 | + L-->>O: fidelity score |
| 133 | +
|
| 134 | + Note over U,FS: Phase 7 — Summary & Reporting |
| 135 | + O->>FS: decisions.md, cost report, fidelity scores |
| 136 | + O-->>U: run complete |
| 137 | +``` |
| 138 | + |
| 139 | +## Decision & Loop Points |
| 140 | + |
| 141 | +| # | Point | Branch | Cap | |
| 142 | +|---|-------|--------|-----| |
| 143 | +| 1 | Dribbble source | API → scraper → cache → **abort** | 3 strategies, hard gate | |
| 144 | +| 2 | Stitch generation | live → cache → **abort** | 2 strategies, hard gate | |
| 145 | +| 3 | Fix Loop (lint/TS) | errors → LLM fix → re-lint | **10 iter/task** | |
| 146 | +| 4 | Fidelity Fix Loop (Stage C) | pixel miss > 10% → KB → LLM fix → re-verify | **30 iter/element** (KB §5) | |
| 147 | +| 5 | Budget exhausted | categorize drift, document, move on | hard stop | |
| 148 | +| 6 | Build failure | LLM fixes, retry compile | implicit fix-loop | |
| 149 | + |
| 150 | +## Key File Pointers |
| 151 | + |
| 152 | +- `src/index.mts:64` — entry point, CLI + login |
| 153 | +- `src/orchestrator/pipeline.mts:104` — 6-phase orchestrator |
| 154 | +- `src/orchestrator/fix-loop.mts:41` — 10-iter lint/TS loop |
| 155 | +- `scripts/verify.mts:43` — Stage A/B/C Playwright validator (10% threshold at line 16) |
| 156 | +- `docs/ui-plan/04-per-element-workflow.md:66` — universal per-element workflow |
| 157 | +- `docs/prompts/codegen.md:1` — mandatory KB preflight for codegen |
| 158 | +- `docs/prompts/visual-fidelity.md:1` — visual reviewer prompt |
| 159 | +- `docs/knowledge-bases/panel-model-fidelity-corrections.md:1` — KB source |
0 commit comments