# Xpace Design Studio: master plan and status (updated 25 Nov 2026)

Based on "Xpace Design Studio Final Developer Proposal" v1.1. DONE = built and tested here. NOT VERIFIED = written but could not be run here. GATED = needs something only KY / the Xpace team can supply.

## 1. Architecture (as built)
- Engine (shared/engine.ts, pure TypeScript, mm): project JSON -> parts, 3D boxes, plan footprints, rule violations, bill of quantities. One source feeds 2D, 3D, permissions and quotes.
- API (server/, Node 22 + node:sqlite, no npm packages): tenants, projects, immutable revisions, scoped share links, approval state machine, audit, signed-webhook outbox, render queue. server/db.ts is the only storage file; swap it for PostgreSQL in production.
- Sales studio (web/studio.html): 2D plan editor (drag, snap, attach to wall, rotate), rules panel, DXF import, drawing underlay with calibration, live 3D preview, save/publish/share, review/verify/release, integrations.
- Customer viewers: /g/ for generated projects (web/gviewer.html), /v/ for the original hand-built Muji page (web/viewer.html, v15). Both: private link, autosave, undo/redo, A/B/C, Looks, submit, confirm, PDF, embed events.
- Render worker (worker/render_worker.py): Blender Cycles script pulling jobs from the API. NOT VERIFIED (no Blender here).
- Deploy (deploy/): Dockerfile, compose with Caddy for design.buildxpace.com, backup script. Docker image NOT BUILT here (no Docker daemon), file layout checked by running the same steps by hand.

## 2. Gates
| Gate | Status |
|---|---|
| A Viewer independent of Claude, validation, PDF, persistence | DONE |
| B Project schema, reusable builders, 2D editor, second project with no code | DONE for rectangular rooms and five unit types (base, wall, tall, wardrobe, island). Browser test creates a second project through the UI only. |
| C Secure links, responsive UI, approval, measurement check | DONE on the server and in both viewers. Real-phone benchmark and supplier-texture realism NOT DONE. |
| D CRM/Calculator/Chat/SiteOps | Adapter + outbox DONE and tested against a mock receiver. The four real endpoints are GATED: we do not know their contracts. Drawing import: DXF (rectangle room only) and image underlay DONE; PDF drawings and non-rectangular rooms not done. |
| E HD stills | Queue, worker protocol, de-dup and image download DONE and tested with a fake worker. Blender scene builder NOT VERIFIED; reference-scene match NOT DONE. |
| H AI recognition, path tracing, fabrication export | Not started (as the proposal says: later). |

## 3. Approval state machine
draft -> published -> customer_submitted -> sales_reviewed -> customer_confirmed -> production_released. Release needs customer_confirmed AND site_verified. A published revision is the only editable one; any layout change is a new revision (parent link kept). Customer link scope is computed by the server from the engine's part list: existing units are locked unless sales ticks "Let customer change existing units" for that link.

## 4. Integration contract (webhooks, signed)
Events: design.link_created -> CRM, Chat; design.submitted -> CRM, Chat, Calculator; design.reviewed -> CRM, Chat; design.confirmed -> CRM, Calculator, SiteOps; design.released -> CRM, SiteOps, Chat. POST JSON {id,event,at,tenantId,data}; headers X-Xpace-Event, X-Xpace-Signature (sha256 HMAC of the body with the secret shown once), Idempotency-Key (receiver must dedupe). Retries with backoff, dead after 8 tries. No customer names or phone numbers in payloads: ids and design data only. Calculator pulls quantities from GET /api/selections/:id/bom and must apply its own prices (never trust the client). Private/localhost URLs are refused.

## 5. Security
Built: hashed staff keys and link tokens; token in URL fragment, removed from the address bar, no-referrer, no-store; per-link scope enforced server-side on every write; tenant on every query (foreign ids 404); body-size and rate limits (proxy-aware with TRUST_PROXY=1); frame-ancestors from tenant allowlist plus embedOrigin check; postMessage origin and source checks; audit log; DXF parsed as text only; webhook SSRF guard. Still to do before public launch: replace the staff key with the Xpace login, pen test, DB backups running (backup.sh), TLS monitoring, signed asset URLs if private textures are added.

## 6. Known limits
Rooms are rectangles. Units are boxes with doors, shelves and plinths: good for sales, not fabrication. Colours are flat hex plus a simple grain hint, not supplier scans, so screen colour is approximate. Existing Muji dimensions (island, curtain, beams, fridge clearance) are unverified until site checks. Underlay images are not saved with the project. Staff sign-in is a placeholder key.

## 7. Decisions still needed
1. Existing Xpace login and tenant model (replace staff key).
2. The four real integration endpoints and their auth.
3. Supplier texture files (the colour swatch permission is confirmed; scans are a separate ask).
4. GPU provider for Blender and who runs it.
5. Customer approval wording and retention period.
