Renue Research Portal — System Architecture

Page map, data flow, deploy pipeline, and reference tables

Shopify Store
Cloudflare Workers
D1 Database
External APIs
Deploy Pipeline
1. Page Map — Where Everything Lives
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#0f766e', 'primaryTextColor': '#e2e8f0', 'lineColor': '#475569', 'secondaryColor': '#1e293b' }}}%%
flowchart LR
  subgraph SHOPIFY["Shopify Store — renuebyscience.com"]
    direction TB
    S_LANDING["/pages/research\nLanding Page"]
    S_NAD["/pages/...-sleep-study\nNAD+ Study"]
    S_SERUM["/pages/...-serum-study\nRenue Blue Study"]
    S_APIGENIN["/pages/...-apigenin-study\nApigenin Study"]
    S_WAITLIST["/pages/...-join-waitlist\nWaitlist Form"]
    S_PRIVACY["/pages/research-privacy\nPrivacy Policy"]
    S_CONSENT["/pages/research-consent\nConsent"]
  end

  subgraph WORKERS["Cloudflare Workers — renue-research.rod-1b4.workers.dev"]
    direction TB
    W_LOGIN["/login\nMagic Link"]
    W_DASH["/dashboard\nParticipant Home"]
    W_ADMIN["/admin\nStaff Panel"]
    W_DOCS["/docs/*\n6 resource pages"]
    W_OTHER["/profile, /support\n/onboarding, /survey/*"]
  end

  S_LANDING --> S_NAD
  S_LANDING --> S_SERUM
  S_LANDING --> S_APIGENIN
  S_LANDING --> S_WAITLIST
  S_NAD --> S_WAITLIST
  S_NAD --> S_PRIVACY
  S_NAD --> S_CONSENT
  S_PRIVACY --> S_LANDING
  S_CONSENT --> S_LANDING

  S_LANDING -.->|"href"| W_LOGIN
  S_WAITLIST -.->|"POST /api/waitlist"| WORKERS
  W_DASH -.->|"Back to Research"| S_LANDING

  style SHOPIFY fill:#1e3a5f,stroke:#60a5fa,stroke-width:2px,color:#e2e8f0
  style WORKERS fill:#0f3b35,stroke:#5eead4,stroke-width:2px,color:#e2e8f0
2. Data Flow — APIs, Database, External Services
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#0f766e', 'primaryTextColor': '#e2e8f0', 'lineColor': '#475569' }}}%%
flowchart TB
  subgraph API["Workers API — 21 endpoints"]
    A_AUTH["Auth API\nsend-link, verify,\nlogout, me"]
    A_PART["Participant API\ndashboard, daily-notes,\nsurvey, support"]
    A_ADMIN["Admin API\nparticipants, approve,\noverride-phase, stats"]
    A_WAITLIST["Waitlist API\nPOST /api/waitlist\n(CORS: public)"]
    A_OURA["Oura OAuth\nconnect, callback"]
    A_CRON["Cron\ncheckPhases\ndaily 19:00 UTC"]
  end

  subgraph D1["D1 Database — 12 tables"]
    DB_CORE["participants\nstudy_enrollments\nstudies"]
    DB_DATA["daily_notes\nsurvey_responses\nsupport_messages"]
    DB_AUTH["sessions\nmagic_links\nauth_log"]
    DB_OURA["oura_data\noura_tokens"]
    DB_WL["waitlist"]
  end

  subgraph EXT["External Services"]
    RESEND["Resend API\nMagic link emails"]
    OURA["Oura Cloud\nOAuth2 + sleep data"]
  end

  A_AUTH --> DB_AUTH
  A_AUTH -->|"Send email"| RESEND
  A_PART --> DB_DATA
  A_PART --> DB_CORE
  A_ADMIN --> DB_CORE
  A_WAITLIST --> DB_WL
  A_OURA --> DB_OURA
  A_OURA -->|"OAuth2"| OURA
  A_CRON --> DB_CORE

  style API fill:#0f3b35,stroke:#5eead4,stroke-width:2px,color:#e2e8f0
  style D1 fill:#2e1065,stroke:#a78bfa,stroke-width:2px,color:#e2e8f0
  style EXT fill:#3b2408,stroke:#fb923c,stroke-width:2px,color:#e2e8f0
3. Deploy Pipeline — How Changes Reach Users
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#f472b6', 'primaryTextColor': '#e2e8f0', 'lineColor': '#94a3b8' }}}%%
flowchart LR
  SRC["static/*.html\nSource mockups"]
  EXTRACT["extract_styles()\nCSS scoped to\n.research-portal-content"]
  STRIP["strip_elements()\nRemove nav, footer,\nscripts, mockup badges"]
  TRANSFORM["transform_links()\n/ → /pages/research\n/login → Workers URL"]
  REINJECT["Re-inject JS\nwaitlist handler\ncard click handler\nsubscribe form"]
  API["Shopify Admin API\nPUT page body_html"]
  CDN["Shopify CDN\n15-30 min cache\n?preview_theme_id\nbypasses cache"]
  LIVE["Live on\nrenuebyscience.com"]

  SYNC["sync-assets.sh\nCopy to assets-built/"]
  WRANGLER["wrangler deploy\nWorkers + D1"]
  WORKERS_LIVE["Live on\nWorkers .dev"]

  SRC --> EXTRACT --> STRIP --> TRANSFORM --> REINJECT --> API --> CDN --> LIVE
  SRC --> SYNC --> WRANGLER --> WORKERS_LIVE

  style SRC fill:#1e293b,stroke:#f472b6,stroke-width:2px,color:#e2e8f0
  style CDN fill:#1e293b,stroke:#fbbf24,stroke-width:2px,color:#fbbf24
  style LIVE fill:#1e3a5f,stroke:#60a5fa,stroke-width:2px,color:#e2e8f0
  style WORKERS_LIVE fill:#0f3b35,stroke:#5eead4,stroke-width:2px,color:#e2e8f0
4. User Journey — Full Lifecycle
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#0f766e', 'primaryTextColor': '#e2e8f0', 'lineColor': '#475569' }}}%%
sequenceDiagram
  participant V as Visitor
  participant S as Shopify Pages
  participant W as Workers API
  participant D as D1 Database
  participant R as Resend Email
  participant O as Oura API

  Note over V,S: Discovery (Public)
  V->>S: Browse /pages/research
  V->>S: Read study details
  V->>S: Fill waitlist form
  S->>W: POST /api/waitlist (cross-origin)
  W->>D: INSERT into waitlist
  W-->>S: 200 OK
  S-->>V: Success animation

  Note over V,W: Enrollment (Staff approves)
  W->>D: Admin approves waitlist entry
  W->>D: INSERT participant + enrollment

  Note over V,W: Authentication
  V->>W: POST /api/auth/send-link
  W->>D: Check participant exists
  W->>D: INSERT magic_link (15min TTL)
  W->>R: Send email with link
  R-->>V: Email with magic link
  V->>W: GET /auth/verify?token=...
  W->>D: Consume token, CREATE session
  W-->>V: Set cookie, redirect /dashboard

  Note over V,W: Study Participation
  V->>W: GET /api/dashboard
  W->>D: SELECT enrollment + phase
  W-->>V: Dashboard with study phase
  V->>W: POST /api/daily-notes
  W->>D: INSERT daily_notes
  V->>W: POST /api/survey/submit
  W->>D: INSERT survey_responses

  Note over W,O: Oura Integration (Phase 8)
  V->>W: GET /oura/connect
  W->>O: OAuth2 authorize redirect
  O-->>V: Auth code callback
  V->>W: GET /oura/callback
  W->>O: Exchange code for tokens
  W->>D: STORE oura_tokens

  Note over W,D: Automated Phase Transitions
  W->>W: Cron: checkPhases (daily 19:00 UTC)
  W->>D: SELECT active enrollments
  W->>D: UPDATE phase if days elapsed
Detailed Reference
Shopify Pages (7 pages on renuebyscience.com)
HandleTitleSource FilePage ID
researchResearch Landingmockup-research-landing.html131477340418
research-nad-complete-sleep-studyNAD+ Sleep Studyrenue-research-study.html131505946882
research-renue-blue-serum-28-day-studyRenue Blue Serum Studyrenue-research-face-serum-study.html132213899522
research-liposomal-apigenin-deep-sleep-studyApigenin Deep Sleep Studyrenue-research-apigenin-sleep-study.html132213932290
research-join-waitlistJoin Waitlistrenue-research-waitlist.html131503685890
research-privacyPrivacy Policyrenue-research-doc-privacy.html131503456514
research-consentInformed Consentrenue-research-doc-consent.html131503489282

Deployed via python3 create_shopify_pages.py --update. CSS scoped to .research-portal-content. Theme template: page.research-portal.json. Staging theme: 159834898690.

Workers Portal Pages (22 routes)
RouteFileAuth
/renue-research.htmlPublic
/loginlogin.htmlPublic
/studyrenue-research-study.htmlPublic
/waitlistrenue-research-waitlist.htmlPublic
/dashboarddashboard.htmlSession (JS-gated)
/onboardingrenue-research-onboarding.htmlSession
/activerenue-research-active.htmlSession
/completecomplete.htmlSession
/profileprofile.htmlSession
/supportsupport.htmlSession
/resourcesresources.htmlSession
/adminrenue-research-admin.htmlStaff
/docs/*6 doc pagesPublic
/survey/*2 survey pagesSession
Workers API Endpoints (21 routes)
MethodRouteAuthPurpose
POST/api/auth/send-linkPublicSend magic link email (3/hr rate limit)
GET/auth/verifyPublicVerify token, create session, redirect
POST/api/auth/logoutSessionDestroy session, clear cookie
GET/api/auth/mePublicAuth state check (200 or 401)
GET/review-accessSecretStaff auto-login for design review
POST/api/waitlistCORSAdd to waitlist (called from Shopify)
GET/api/dashboardSessionParticipant dashboard + phase
POST/api/daily-notesSessionSubmit daily health survey
POST/api/survey/submitSessionSubmit phase survey
GET/api/survey/statusSessionCheck survey status
POST/api/support/messageSessionSubmit support message
POST/api/admin/override-phaseStaffManual phase change
GET/api/admin/participantsStaffList all participants
POST/api/admin/approve-waitlistStaffApprove waitlist, create participant
GET/api/admin/participant/:idStaffDetailed participant profile
GET/api/admin/activityStaff24h activity feed
GET/api/admin/waitlistStaffList waitlist entries
GET/api/admin/statsStaffKPI stats + sparklines
GET/oura/connectSessionRedirect to Oura OAuth
GET/oura/callbackSessionHandle OAuth callback
GET/api/healthPublicStatus heartbeat
D1 Database Schema (12 tables)
TableKey ColumnsPurpose
participantsid, email (unique), full_name, oura_confirmedRegistered study participants
studiesid, name, duration_days, baseline_days, statusStudy definitions
study_enrollmentsid, participant_id, study_id, phase, phase_started_atEnrollment + phase tracking
daily_notesid, enrollment_id, date, caffeine, alcohol, energy, clarityDaily health survey responses
oura_dataid, enrollment_id, date, deep_sleep_pct, hrvImported Oura sleep/biometric data
oura_tokensid, participant_id, access_token, refresh_token, expires_atOura OAuth2 credentials
sessionstoken (PK), participant_id, expires_at, is_staffActive login sessions (7-day TTL)
magic_linkstoken (PK), email, expires_at, usedPasswordless login tokens (15-min TTL)
waitlistid, email (unique), name, has_oura, sourcePre-enrollment waitlist signups
auth_logid, email, event, detail, created_atAuth events + rate limiting
survey_responsesid, enrollment_id, survey_type, responses_jsonPhase start/end survey data
support_messagesid, participant_id, subject, messageParticipant support requests
External Service Integrations
ServicePurposeStatus
Resend APIMagic link emails via api.resend.com/emailsActive (temp: onboarding@resend.dev)
Oura Cloud APIOAuth2 for sleep data (11 scopes)Scaffolded (Phase 8)
Shopify Admin APIPage deployment via create_shopify_pages.pyActive

Pending: Resend domain verification for noreply.renuebyscience.com. Oura OAuth end-to-end blocked on developer portal.

Deploy Pipeline (see Diagram 3)
StepCommandWhat it does
1. Edit mockupsEdit static/*.htmlSource of truth for all page content
2. Deploy to Shopifypython3 create_shopify_pages.py --updateExtract CSS, strip elements, transform links, re-inject JS, push via Admin API
3. Sync Workers assetsbash scripts/sync-assets.shCopy static/ to assets-built/
4. Deploy Workersnpm run deployWrangler deploy to Cloudflare
5. Verifypython3 test_e2e_full.py12-phase E2E test (440s, all green)

CDN: Shopify CDN caches 15-30 min. Use ?preview_theme_id=159834898690 (staging theme) to bypass. The deploy pipeline diagram above shows where CSS scoping, script stripping, and link transforms happen.

Updated 2026-04-08 (Mentor-reviewed, rev 2) | 7 Shopify pages | 22 Workers pages | 21 API endpoints | 12 D1 tables