docs/NEXT-PHASE.md

Next Phase — Studio restructure + Portal Builder

Reference doc for the next build phase. Supersedes the studio view list in §4.3 of BUILD-PLAN.md; extends §10 (self-serve). Written 2026-07-07.


1. Two products, one foundation

Surface Package Audience Purpose
Design Studio studio/ (exists, restructure) Internal (design + dev) Living docs + QA for @departmnt/ui
Portal Builder app/ = @departmnt/portal-builder (new workspace) Clients (self-serve) Part of Core — the brand dashboard

Foundations (@departmnt/ui: tokens, primitives, components, modules) stay untouched and are the single render source for both. Anything both surfaces need (module registry, field schemas, editors, portal preview) moves to a shared layer — see §5 Refactors.


2. Design Studio — target IA (5 views)

Replace the current 6 phase-based views (Foundations / Theme Lab / Lookbook / Flow Map / Module Preview / Builder) with product-shaped views:

2.1 Docs

Single reading destination. Content:

  • Full token layout (three tiers, generated scales, --module-* / --page-fg semantic slots).
  • Semantic colour options mapped to colour profiles (default / panels / minimal / background) — which var lands where, per profile, with live swatches.
  • Component tiers explained (Tier 1 Radix / Tier 2 composed / Tier 3 modules).
  • Tech stack + build pipeline (pnpm workspace, tsup, mark-client, tokens codegen).
  • Radix Themes usage rules (variants we use, no classic, arrows/radius canon).
  • Module + component documentation (render /docs/*.md — today they're repo-only).
  • NEW: Design-patterns doc (see §6) rendered here.

Source: absorb Foundations page content + docs/*.md. Markdown-rendered in-app so docs stop drifting from the repo.

2.2 Themes

Per brand: logo, seed colours (accent + gray), the generated 12-step scales (light/dark), colour profile assignment. Absorbs: Foundations scales + Theme Lab profile/radius/scaling controls. Theme Lab's custom-profile builder stays here (it becomes the model for Portal Builder → Theme).

2.3 Components

The Lookbook, evolved: colour-profile switcher + variant selector tabs (done) + colour breakdown (done). Add: per-component doc link into Docs.

2.4 Modules

Module Preview, evolved:

  • Consistent tokens audit surfaced per module (which --module-* slots it consumes).
  • Full Radix usage listing (which Radix components compose it — extend layers.ts).
  • Design patterns adhered to (pattern badges linking to the patterns doc).
  • Full clickthrough + functionality preview — interactive states, expanded views (GalleryExpanded, ProfileModule expanded), simulated data flows.

2.5 Builder

Unchanged for now. It is the prototype for Portal Builder → Portal; freeze features here and pour new effort into the Portal Builder app.

Retired: Flow Map as a top view (fold the flow graph into Docs), phase-numbered nav (P1–P6), views.ts phase/status fields.


3. Portal Builder (app/) — Core brand dashboard

Product name: Portal Builder, a section of Core (the brand dashboard). Dashboard IA (⭐ = build first):

Builder

  • ⭐ Portal — full experience preview + full module editor. Screens have designated slots; each slot accepts only slot-valid modules (extend flows/slots model). Tabs: a screen can enable tabs bound to a module list (e.g. Music → all music modules collected/posted). Mobile version = limited module editor (see §3.1).
  • ⭐ Theme — revise the theme: logo, seed colour, colour profile, radius. (Port of Studio Themes/Theme Lab with guardrails.)
  • ⭐ Modules — full index with clickthrough preview, fields, docs, and an "Add to portal" button (routes into Portal with the module staged).
  • Logic — user-built gamification logic from tag taps + digital actions (trigger → condition → reward graph). Later: needs backend events.

Other dashboard sections

  • ⭐ Products — create products to sell; connect Shopify or Stripe (backend not scoped yet — build UI against mock adapters).
  • ⭐ Events — create event links that onboard new users into the portal and are served to existing users.
  • Tags — select + buy NFC tags, configure claim page, set artefact unlocks.
  • ⭐ Audience — all users; segments from NFC claims or hand-built with filters + tags.
  • Analytics — tap-based analytics etc. (dev feeds data in; build shell + chart primitives).

Build order: Portal → Theme → Modules → Products → Events → Audience → (Tags, Logic, Analytics).

3.1 Mobile Portal Builder

A first-class mobile view — as easy as posting to Instagram:

  • Single-column portal preview, tap a slot → bottom-sheet module picker → simplified fields (photo/text first), post.
  • Limited module editor: text, images, toggles; no slot restructuring or logic.
  • Reuses the same PortalConfig + field schemas; the editor surface is what shrinks.

3.2 Persistence

Per BUILD-PLAN §10: mock/localStorage first, Supabase in P1. Config model = PortalConfig (already JSON-serialisable).


4. New modules to build (Studio + Portal Builder)

Module Notes
User directory + DMs Member list, profiles, 1:1 threads. Needs realtime backend later; build presentational modules + mock store now.
Community chat Global chat room. Same chat primitives as DMs.
Group chats + channels Membership gated by NFC claim or audience segment — ties into Audience segments.
File download Gated file delivery (artefact unlock target).
Page lock & Drop Lock external pages/content (e.g. Shopify product or collection page); access only through this module. Needs a redirect/token mechanism — document as a backend contract, mock in UI.

Chat family shares primitives: MessageList, MessageInput, ThreadRow, PresenceDot — build once in modules/shared/, compose three modules from them.


5. Codebase audit — limitations + refactors

Audited: studio/lib/*, studio/components/*, studio/app/*, modules/*, docs/*.

5.1 Blocking the Portal Builder split

  1. Studio-locked shared logic. renderers.tsx (module registry + SAMPLE_PROPS), fields.ts (field schemas), builder.ts (PortalConfig), portal-preview.tsx, content-editor.tsx, social-editor.tsx, fields-editor.tsx all live in studio/. Portal Builder needs every one. → Refactor: extract to a shared workspace package (e.g. builder-kit/ = @departmnt/builder-kit) consumed by both apps. Do this before app/ scaffolding.
  2. builder/page.tsx is a 712-line monolith — screen nav, slot editing, module picker, fields rail, preview all in one file. → Split into components as part of the extraction; Portal Builder must not import a page.
  3. PreviewChrome lives in studio but is portal UI (used it for --page-fg work). → Move to modules/shared/ or builder-kit so the public runtime renders the same chrome.

5.2 Model gaps for the new IA

  1. Slots are flow-node data (flows.ts couples screen graph + slot defs + toggles). Tabs, slot-valid module types, and mobile editing need a screen schema: slots[] { id, accepts[], max }, tabs[] { id, source: moduleQuery }. → Version PortalConfig (add version: 2) when this lands; write a v1→v2 migration for localStorage configs.
  2. No module capability metadata. modules.ts has tier/category/blurb but nothing machine- readable for "slot-valid", "tab source", "artefact-unlockable", "mobile-editable". → Extend the registry entry: capabilities: string[], slotTypes: string[], mobileFields?: string[].
  3. Field schemas can't express chat/directory/logic editors. FieldType is text/toggle/select/aspect-ratio; content/social needed bespoke editors. → Add 'list' (typed item arrays — generalise ContentEditor/SocialEditor's drag-reorder pattern) and 'media' (upload slot, data-URL now / storage later) before building the new modules.
  4. layers.ts is hand-maintained (390 lines) and will drift as modules grow — it's also the source for "full Radix usage" in Studio Modules. → Acceptable short-term; note as debt. Long-term: generate from module source (ts-morph pass in scripts/).

5.3 Docs + content

  1. docs/*.md aren't rendered anywhere — the Docs view needs an in-app markdown renderer (next-mdx-remote or a build step). Keep files as the source of truth.
  2. views.ts is phase-based — rewrite for the 5-view IA; home page cards read from it.
  3. Foundations/Theme Lab/Lookbook overlap (three places render scales/tokens) — the restructure removes the duplication (Docs = reading, Themes = per-brand identity, Components = component QA).

5.4 Known debt (carry, don't fix now)

  • color="gray" text sitting directly on the accent page bg under the background profile stays muted-dark (needs literal per-appearance restores).
  • generate-scale.ts is a v1 perceptual generator — revisit contrast guarantees when Theme editing goes client-facing (clients will pick arbitrary seeds; validate contrast in the Theme UI).
  • Radix Select/Tabs interactions in headless tests need synthetic pointer events (harness quirk).
  • icon.svg has a pre-existing lint error (empty <title>).

6. Design-patterns doc (Studio only)

New docs/PATTERNS.md, rendered in Studio → Docs. Sections:

  • Modules — ModuleShell anatomy, semantic slots, radius canon, arrows, CTA rules.
  • Module collections — how modules group on a screen (stacks, tabs, linked modules).
  • Artefacts — an unlocked group of modules: definition, unlock sources (NFC tap, action), locked/unlocked states.
  • Forms — field variants (soft default), validation, submission states.
  • Claim screen — NFC tap → claim flow.
  • Artefact unlock screen — reveal moment, transition into the portal.
  • Welcome screen — first-run after claim/signup.
  • Plus: empty states, loading, error surfaces as they stabilise.

7. Sequence

  1. Extract builder-kit (registry, fields, config model, editors, portal preview + chrome). (§5.1)
  2. Studio restructure to Docs / Themes / Components / Modules / Builder; markdown rendering; write docs/PATTERNS.md. (§2, §6)
  3. Screen schema v2 — slots with accepts, tabs, module capabilities. (§5.2)
  4. Scaffold app/ Portal Builder — dashboard shell + ⭐ Portal / Theme / Modules on mock data.
  5. ⭐ Products, Events, Audience shells (mock adapters; Shopify/Stripe unscoped).
  6. Mobile builder view. (§3.1)
  7. New modules — chat primitives → directory/DMs/community/groups; file download; page lock & drop. (§4)
  8. Persistence (Supabase) per BUILD-PLAN §10 P1 — then Tags, Logic, Analytics as backend lands.