For each missing UC (iteratively, user confirms each):
a. Classify sync vs async by PRD signals. Look for keywords in PRD §4 acceptance criteria for this US: webhook, cron, biweekly, scheduled, daily, external service, queue, event → async. Otherwise → sync.
b. Identify actors from SAD §5 (Container view). Parse Mermaid C4Container block. If async flow needs Scheduler / Worker / External Service and §5 has no such Container → flag "new actor" in the report; still draw the actor in sequence (don't block on §5 update).
c. Generate Mermaid sequenceDiagram block. Template:
sequenceDiagram
autonumber
participant U as User (Methodist)
participant API as content-api
participant DB as Postgres
Note over U, API: Precondition: <state from PRD>
U->>API: <action>
API->>DB: <query>
DB-->>API: <result>
API-->>U: <response>
Note over API, DB: writes <table.column> (see §6.4 ER)
alt <error condition 1>
API-->>U: 4xx <error code>
else <error condition 2>
DB-->>API: timeout
API-->>U: 5xx <error code>
end
Note over U, API: Postcondition: <state from PRD>
d. Add async patterns to webhook + retry flows. When async:
- First step in handler:
check idempotency key.
- Retry budget in a
Note over Worker, External: retry up to N with exponential backoff.
- DLQ as an
alt branch after N failed attempts.
e. Fold cache layer into a Note for performance-critical reads. If PRD §5 lists a latency budget for this US (e.g., p95 < 120ms), do NOT draw a separate cache diagram. Add Note over API, DB: dashboard hits Redis first; cache TTL 60s inline.
f. Flag ADR potential. If the flow involves a non-trivial architectural decision (SAGA vs 2PC, idempotency strategy choice, retry budget shape, polling vs push), do NOT auto-generate an ADR. Add to the final report under "ADR potential": US-N: consider ADR for <topic>.
g. Validate Mermaid syntax with mmdc --parse-only (mandatory). Write the block to a temp file and run mmdc -i <tmp> --parse-only (or equivalent). If parse fails → fix one-shot or surface to user.
h. Show to user, ask confirm. Render the diagram block (mention the mmdc validation passed). User responds ok / redo / skip. On redo, accept the user's note and regenerate.