Renue Research Portal — System Architecture

Page map, data flow, and external integrations

Shopify (renuebyscience.com)
Cloudflare Workers
D1 Database
External APIs
System Overview
%%{init: {'theme': 'dark', 'themeVariables': { 'primaryColor': '#0f766e', 'primaryTextColor': '#e2e8f0', 'lineColor': '#475569', 'secondaryColor': '#1e293b', 'tertiaryColor': '#1e293b' }}}%%
flowchart TB
  subgraph SHOPIFY["☁️ Shopify Store — renuebyscience.com"]
    direction TB
    S_LANDING["📄 /pages/research\nResearch Landing"]
    S_NAD["📄 /pages/research-nad-complete-sleep-study\nNAD+ Sleep Study"]
    S_SERUM["📄 /pages/research-renue-blue-serum-28-day-study\nRenue Blue Serum Study"]
    S_APIGENIN["📄 /pages/research-liposomal-apigenin-deep-sleep-study\nApigenin Deep Sleep Study"]
    S_WAITLIST["📄 /pages/research-join-waitlist\nJoin Waitlist (Form)"]
    S_PRIVACY["📄 /pages/research-privacy\nPrivacy Policy"]
    S_CONSENT["📄 /pages/research-consent\nInformed Consent"]
  end

  subgraph WORKERS["⚡ Cloudflare Workers — renue-research.rod-1b4.workers.dev"]
    direction TB
    subgraph PORTAL["Participant Portal (22 pages)"]
      W_HOME["🏠 / Landing"]
      W_LOGIN["🔐 /login"]
      W_DASH["📊 /dashboard"]
      W_PROFILE["👤 /profile"]
      W_ADMIN["🛡️ /admin"]
      W_DOCS["📚 /docs/* (6 pages)"]
      W_SURVEYS["📝 /survey/* (2 pages)"]
      W_OTHER["📄 /active, /complete,\n/onboarding, /support,\n/resources, /index"]
    end
    subgraph API["REST API (21 endpoints)"]
      A_AUTH["🔑 Auth API\nPOST /api/auth/send-link\nGET /auth/verify\nPOST /api/auth/logout\nGET /api/auth/me\nGET /review-access"]
      A_PART["👥 Participant API\nGET /api/dashboard\nPOST /api/daily-notes\nPOST /api/survey/submit\nGET /api/survey/status\nPOST /api/support/message"]
      A_ADMIN["🛡️ Admin API\n7 endpoints"]
      A_WAITLIST["📋 POST /api/waitlist\n(CORS: public)"]
      A_OURA["💍 Oura OAuth\nGET /oura/connect\nGET /oura/callback"]
      A_HEALTH["💚 GET /api/health"]
    end
    W_CRON["⏰ Cron: checkPhases\nDaily 19:00 UTC"]
  end

  subgraph D1["💾 Cloudflare D1 — renue-research"]
    DB_PART["participants"]
    DB_ENROLL["study_enrollments"]
    DB_NOTES["daily_notes"]
    DB_SESSIONS["sessions + magic_links"]
    DB_WAITLIST["waitlist"]
    DB_OURA["oura_data + oura_tokens"]
    DB_OTHER["studies, auth_log,\nsurvey_responses,\nsupport_messages"]
  end

  subgraph EXTERNAL["🌐 External Services"]
    EXT_RESEND["📧 Resend API\nMagic link emails"]
    EXT_OURA["💍 Oura Cloud API\nOAuth2 + sleep data"]
    EXT_SHOPIFY_API["🛒 Shopify Admin API\nPage deployment"]
  end

  %% Shopify → Workers links
  S_WAITLIST -->|"POST /api/waitlist\n(cross-origin fetch)"| A_WAITLIST
  S_LANDING -->|"POST /api/waitlist\n(subscribe form)"| A_WAITLIST
  S_LANDING -.->|"href links"| W_LOGIN
  S_NAD -.->|"href links"| W_LOGIN

  %% Shopify internal links
  S_LANDING --> S_NAD
  S_LANDING --> S_SERUM
  S_LANDING --> S_APIGENIN
  S_LANDING --> S_WAITLIST
  S_NAD --> S_WAITLIST
  S_PRIVACY --> S_LANDING
  S_CONSENT --> S_LANDING
  S_NAD --> S_PRIVACY
  S_NAD --> S_CONSENT

  %% Workers API → D1
  A_AUTH --> DB_SESSIONS
  A_PART --> DB_ENROLL
  A_PART --> DB_NOTES
  A_ADMIN --> DB_PART
  A_WAITLIST --> DB_WAITLIST
  A_OURA --> DB_OURA
  W_CRON --> DB_ENROLL

  %% Workers → External
  A_AUTH -->|"Send magic link"| EXT_RESEND
  A_OURA -->|"OAuth2 flow"| EXT_OURA

  %% Deploy pipeline
  EXT_SHOPIFY_API -.->|"create_shopify_pages.py\n(deploys mockup HTML)"| SHOPIFY

  style SHOPIFY fill:#1e3a5f,stroke:#60a5fa,stroke-width:2px,color:#e2e8f0
  style WORKERS fill:#0f3b35,stroke:#5eead4,stroke-width:2px,color:#e2e8f0
  style D1 fill:#2e1065,stroke:#a78bfa,stroke-width:2px,color:#e2e8f0
  style EXTERNAL fill:#3b2408,stroke:#fb923c,stroke-width:2px,color:#e2e8f0
  style PORTAL fill:#0f3b35,stroke:#5eead4,stroke-width:1px,color:#e2e8f0
  style API fill:#0f3b35,stroke:#5eead4,stroke-width:1px,color:#e2e8f0
Data Flow: User Journey
%%{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 → Shopify Admin API. CSS extracted & scoped to .research-portal-content. Theme template: page.research-portal.json.

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_atParticipant-study enrollment + 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 (Monday 11686890353). Oura OAuth end-to-end blocked on developer portal (Monday 11529000917).

Deploy Pipeline
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 → push via Admin API
3. Sync Workers assetscd workers && bash scripts/sync-assets.shCopy static/ → assets-built/
4. Deploy Workersnpm run deployWrangler deploy to Cloudflare
5. Verifykit screenshot + npm testVisual check + 199 tests

CDN note: Shopify CDN caches page content for 15-30 min. Use ?preview_theme_id=159834898690 (staging theme) to bypass during development.

Generated 2026-04-08 · Renue Research Portal · 7 Shopify pages · 22 Workers pages · 21 API endpoints · 12 D1 tables