ADR-017: Shareable Demo Results
Context
The AI demos produce artifacts worth keeping — a generated architecture diagram or drafted ADR is exactly what a visitor wants to send to a colleague. But the platform state model works against that: all session state is client-side (ADR-006), so closing the tab destroys the result; the backend is stateless; a share feature cannot justify standby infrastructure; and letting anonymous visitors persist data is an abuse vector that must be bounded.
Decision
Persist shared results as documents in the existing Firestore layer (ADR-007) — a third consumer of the persistence layer already chosen for caching, adding zero new infrastructure.
POST /api/share validates the demo type against an allowlist (diagram, adr, cost, arb; the client offers Share on Diagram, ADR, and ARB), enforces a 200 KB payload cap, and stores the result under a cryptographically random ID; the client copies /?share=<id> to the clipboard. GET /api/share/:id is an ID-validated lookup backed by an in-memory L1 cache; the SPA reads ?share= on load, routes to the matching demo tab, and hydrates the result. The endpoints sit behind their own per-IP rate limit (60 req / 15 min, ADR-019), so hostile traffic is rejected before any Firestore write.
Amended 2026-10-16: App Check now also guards /api/share when enforcement is on.
Consequences
Benefits:
* Durable links at zero standby cost — an unused share feature costs exactly nothing.
* Privacy stays opt-in: persistence happens only on an explicit Share click, and documents live in the same Madrid-regional database, preserving the EU data boundary (ADR-013).
* No new moving parts: reuses the Firestore client, IAM bindings, and crypto utilities already in place.
Trade-offs:
* Links expire — each document carries an expiresAt 90 days out, enforced on read and by a Firestore TTL policy (the same mechanism bounds every collection the server writes, including contact messages at 90 days).
* Public-by-ID reads — mitigated by unguessable IDs and no enumeration surface; only demo outputs (never uploads) are shareable.
Alternatives considered
1. Encoding the whole result in the URL: Rejected — diagram and ADR payloads routinely exceed practical URL limits and links become unreadable or truncated by chat clients.
2. Cloud Storage objects + signed URLs: Rejected — object lifecycle and CORS management add operational surface with no benefit over a keyed document read.
3. Expanding server-side session state: Rejected — it would reverse ADR-006 for a feature that needs exactly one immutable document.