# Frontend integration contract (v3)

23 October 2026 · Adapter contract between these templates and Yahya’s WordPress/BuddyBoss implementation. Names below are frontend interfaces, not mandated database fields, REST routes or WordPress hook names.

**v3 compatibility:** `MasteryClubState`, `MasteryClubConfig`, every `MasteryClubUI` method, every `mc:*` event and every integration `data-mc-*` hook from v2 are unchanged. v3 **adds** the items marked *new*. One presentation-only hook was replaced: `data-mc-agenda` (the v2 agenda tabs) is gone because Danny’s five-day scroll-stack is restored as `data-mc-stack`; it has no integration role. On welcome, the VIP/free variants now use `data-mc-for="vip"` / `"free"` (both existed in v2).

## Page mapping

| Template | Production role | Integration hooks |
|---|---|---|
| `templates/index.html` | Challenge landing (`challenge.masteryclub.ai`) | Two `form[data-mc-form="register"]` with `name="first_name"` + `name="email"`; `[data-mc-video="signup"]` media slot; *new* `[data-mc-expert-rail]` filled from `MasteryClubConfig.decemberGuests`; *new* `[data-mc-slot="proof"]` (hidden until approved proof); *new* `[data-mc-portrait="ron"|"danny"]` |
| `templates/vip.html` | Optional Challenge VIP | `[data-mc-action="checkout"]`, `[data-mc-action="skip-vip"]`, `[data-mc-checkout]` status, `[data-mc-video="vip"]`, `[data-mc-for="vip-pending"|"vip-ready"|"registered"]`, `[data-mc-name]` |
| `templates/welcome.html` | Thank-you + getting ready | `[data-mc-action="create-account"|"sign-in"|"copy-referral"|"calendar"|"workbook"|"enter-lobby"|"checkout"]`, `[data-mc-referral]`, `[data-mc-referral-help]`, five `[data-mc-step]` (`account`, `share`, `calendar`, `workbook`, `interviews`) with `[data-mc-step-status]`, `[data-mc-progress]`, `[data-mc-vip-label]`, `[data-mc-video="welcome"]` |
| `templates/lobby.html` | One customised BuddyBoss newsfeed page | `[role=tab][data-mc-room="free"|"vip"]`, `[data-mc-room-panel="free"|"vip"]`, `[data-mc-for="free"|"vip"|"offer"]`, `[data-mc-action="checkout"|"calendar"|"workbook"|"membership"]`, sample `form[data-mc-form="comment"][data-post]` + `[data-mc-comments]` (reference only), *new* `[data-mc-feed="free"|"vip"]` marks where each native activity loop renders |

All pages: `[data-mc-legal="privacy"|"terms"|"contact"]` footer links are placeholders (*new* marker) — point them at the approved legal routes. `[data-mc-fragment]` (*new*) marks the blocks exported to `wordpress/fragments/`; it has no behaviour.

Registration submit buttons are `disabled` in the HTML and enabled by `ui.js`. There is no GET fallback; nothing personal ever goes in a URL.

## One Lobby route, two rooms

`data-mc-room="free"` / `"vip"` are the tabs; `data-mc-room-panel` the matching panels. `MasteryClubUI.showRoom("free" | "vip")` changes presentation only. Hashes `#community` / `#challenge-vip` are view hints on the **same** route, never entitlement evidence.

- Tabs follow the ARIA tabs pattern: `aria-selected`, roving `tabindex`, `aria-controls`, Arrow/Home/End keys.
- *new:* any non-tab element with `data-mc-room` (e.g. “See the VIP room” in the banner, VIP shortcuts in the sidebar) switches the room **and** moves focus to the selected tab, scrolling the reader to the top of the room. Behaviour lives in `ui.js`; no extra hook needed.
- Free member + VIP room → `[data-mc-for="free"]` locked preview with the offer. Its unlock button is the normal `data-mc-action="checkout"`.
- VIP owner + VIP room → `[data-mc-for="vip"]` owned room: Q&A, replays, extended workbook, VIP group feed. Acquisition upsells (`.lb-upgrade`, `.lb-keycard`) are `data-mc-for="free"` and disappear; useful VIP shortcuts appear instead.
- Distinct BuddyBoss groups may power the two queries. Render each room’s feed and resources only for entitled users. Don’t send VIP content to free members and hide it with CSS.

## Server-rendered config and state

Print both **before** `scripts/ui.js`. JSON-encode safely; no secrets.

```js
window.MasteryClubConfig = {
  lobbyUrl: "https://masteryclub.ai/APPROVED-LOBBY-ROUTE/",
  allowedRedirectOrigins: [ /* exact checkout/account origins chosen by Yahya */ ],
  resources: {
    calendar: "", // approved .ics / calendar URL once times are confirmed
    workbook: ""  // approved free workbook URL
  },
  // new (optional): approved December guests, in reveal order. Empty or absent = mystery cards stay.
  decemberGuests: [
    // { name: "Guest Name", topic: "AI & systems", date: "Dec 3", image: "https://…/headshot.jpg" }
  ]
};
window.MasteryClubState = {
  authenticated: false, registered: false, vip: false, member: false,
  offerVisible: false, firstName: "", referralUrl: "", completed: {}
};
```

`authenticated`, `vip`, `member` come from the logged-in session and verified ownership. `registered` is the registration result; `offerVisible` is the admin Day 4 release flag. `referralUrl` is account-issued and points back to the challenge landing page. Paid Club membership does not imply Challenge VIP unless a bundle is approved.

`decemberGuests` is read by `funnel.js` (presentation). Text is inserted with `textContent` and image URLs must be http(s); still only publish approved names, photos and dates.

`window.MasteryClubUI` exposes `apply(patch)`, `showRoom(room)`, `request(name, payload)`, `notify(message)`, `state()`. `apply()` and `showRoom()` are presentation only.

The redirect guard accepts the current origin, `https://challenge.masteryclub.ai`, `https://masteryclub.ai` and exact origins in `allowedRedirectOrigins`.

## Events

`ui.js` dispatches cancelable `CustomEvent`s on `window`. A handler must call `event.preventDefault()` synchronously, then `event.detail.respond(result)` **exactly once** (also on error/timeout). Unclaimed events show an honest “unavailable / coming soon” message. `result = { ok, message, state, redirect }`; `redirect` must pass the guard; `ok: true` alone moves nobody.

| Event | Detail | Adapter responsibility |
|---|---|---|
| `mc:register` | `firstName`, `email`, `form` | Validate server-side, create/update one registration, keep attribution, queue the confirmation email; respond with the VIP route (or welcome for an existing VIP owner). |
| `mc:checkout` | `trigger`, `returnTo` | From VIP page/welcome `returnTo = welcome.html`; from the Lobby `returnTo = lobby.html#challenge-vip`. Use the server-configured **$47 one-time** product. Grant VIP only on a verified payment; restore the return context. Respond with a message for pending/failed/cancelled so the UI resolves. |
| `mc:skip-vip` | `trigger` | Optional analytics. UI continues to welcome. Never changes ownership. |
| `mc:account` | `mode: "create"|"sign-in"`, `returnTo?`, `trigger` | Open the existing secure account route with a validated return to welcome/Lobby. Link registration + purchases to the verified person. |
| `mc:comment` | `text`, `postId`, `form` | Reference only. In production keep BuddyBoss’s native reply form; don’t attach two submit handlers. |
| `mc:resource` | `resource: "calendar"|"workbook"`, `trigger` | Only when no configured URL exists: respond with an honest pending message or a controlled URL. |
| `mc:membership` | `trigger` | Re-check the release flag and membership; open the later offer only when released. |
| `mc:lobby-entered` | — | Optional analytics; UI then navigates to `lobbyUrl`. |

Notifications: `mc:invitation-copied { url }`, `mc:state-applied { state }`. A copy is not a referral conversion; a download click is not proof of use.

## Required backend outcomes

- Signup survives refresh/retry without duplicates or repeated confirmation emails.
- Checkout callbacks are verified and processed once; support success, pending, cancel/failure and existing-account recovery. `?vip=1`, storage or visiting a return page is never proof of purchase.
- Pre-account purchases link to the right account via signed server context.
- “Continue free” and re-registration never downgrade an owner.
- Referral links open the challenge; attribution counts qualifying registrations under an approved rule. No commission enrollment in this step.
- Gate Lobby login, team publishing, free replies, VIP feed queries and VIP files on the server.
- Release the Club offer from a server/admin flag at Danny’s Day 4 presentation.

These templates deliberately simulate none of these. Run `acceptance-checks.md` on staging.
