Skip to content

Add PatternLens onboarding flow & schema migrations#5

Open
Patternslab-ecosystem wants to merge 6 commits intomainfrom
claude/claude-md-mm27fipdhhxrjtca-3ou5J
Open

Add PatternLens onboarding flow & schema migrations#5
Patternslab-ecosystem wants to merge 6 commits intomainfrom
claude/claude-md-mm27fipdhhxrjtca-3ou5J

Conversation

@Patternslab-ecosystem
Copy link
Owner

Summary

Implements the complete onboarding flow for PatternLens (B2C app) with four sequential stages, database schema fixes, and supporting infrastructure. This enables new users to complete intent discovery, consent collection, first-object analysis, and finalization before accessing the dashboard.

Key Changes

Onboarding Flow (4 Stages)

  • /onboarding — Welcome page with pulsing beacon animation
  • /onboarding/intent — 3-step intent discovery (what to change, experience level, preferred moment)
  • /onboarding/first-object — Text input for first behavioral pattern analysis with live character counter (20–280 chars)
  • /onboarding/consent — Consent collection (2 required: AI disclaimer + structural proposal; 2 optional: analytics + notifications)
  • /onboarding/complete — Redirect handler that marks onboarding_completed: true in Supabase profiles and clears localStorage

Database Schema Fixes

  • 20260225_fix_schema.sql — Adds missing columns to profiles, objects, interpretations, and creates consent_logs table for GDPR audit trail
  • 20260225_fix_profiles_stripe.sql — Adds Stripe-related columns (stripe_customer_id, stripe_subscription_id, stripe_subscription_status, pro_since)

API & Analysis

  • /api/analyze — Enhanced with preview rate limiting (1 request per IP per hour) for unauthenticated onboarding analysis
  • /api/voice/upload — Simplified; removed inline transcription logic (deferred to safety middleware per DIPLO v4.0)

Design & Styling

  • design-tokens.css — Complete design token system (colors, spacing, typography, animations) for dark mode + accessibility
  • globals.css — Imports design tokens at top
  • All onboarding pages use CSS custom properties and Tailwind only (zero inline styles)

Middleware & Routing

  • middleware.ts — Added /onboarding to public routes; added onboarding gate check for authenticated users (redirects to /onboarding/complete if not completed)
  • onboarding/layout.tsx — Standalone layout with centered, dark background; no app navigation

Documentation

  • CLAUDE.md — Expanded from 16 lines to 500+ lines with complete ecosystem overview, tech stack, S11 language policy, package architecture, database schema, and code contracts (DIPLO v4.0 reference)

Configuration

  • .env.example — Added Stripe price ID placeholders
  • pricing.ts — Updated with Stripe price ID references
  • claude-integration.ts — Updated Claude model to claude-sonnet-4-20250514

Implementation Details

  • S11 Compliance: All onboarding copy uses S11 terminology (Pattern, Tension, Function, Lens A/B, Proposal, Construction tool) — no therapy/wellness vocabulary
  • Accessibility: ARIA labels, focus management, keyboard navigation, reduced-motion support
  • Offline-ready: Intent and consent data persisted to localStorage before auth; flushed to DB post-signup
  • Type Safety: Full TypeScript strict mode; zero any/unknown
  • Mobile-first: Responsive design with Tailwind; dark mode default via CSS variables
  • Rate Limiting: Preview analysis limited to 1 request/IP/hour to prevent abuse during onboarding

Notes

  • Removed legacy apps/pattern-lens/ directory (old naming convention)
  • Onboarding flow is public; no auth required until consent completion
  • Crisis detection integrated into /api/analyze — redirects to /emergency if triggered
  • All onboarding state cleared after completion; users cannot re-enter flow

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4

Rewrites the minimal CLAUDE.md stub into a full AI assistant reference
covering the actual monorepo state as of 2026-02-25 per DIPLO BIBLE v4.0.

Covers: repo identity, multi-repo ecosystem map, full directory structure,
actual tech stack (Next.js 14/15, React 18/19, Prisma, Supabase, Stripe,
Claude Sonnet, Vitest), S11 language policy with forbidden vocabulary table,
code contract rules, package-by-package status (active vs README-only vs
ROADMAP), database schema, CI/CD gates (SILENCE SENTINEL jobs), dev workflow
commands, env vars reference, CODEOWNERS review gates, roadmap boundary, and
pre-task checklist.

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4
- upgrade/page.tsx: fix fetch to /api/stripe/checkout (was /api/stripe/create-checkout — 404)
- voice/upload: replace broken Claude audio API call with internal forward to /api/voice/transcribe (Whisper)
- stripe/webhook checkout.session.completed: add stripe_customer_id, stripe_subscription_status: "active" to profile update
- migration 20260225_fix_profiles_stripe.sql: add stripe_customer_id, stripe_subscription_id, stripe_subscription_status, pro_since to profiles
- migration 20260225_fix_schema.sql: add all missing columns (profiles, objects, interpretations) and create consent_logs + voice_dumps tables with RLS
- .env.example: add STRIPE_PRO_PRICE_ID, STRIPE_PRICE_{PLN,USD,GBP,EUR}, ENABLE_DEMO_LOGIN, DEMO_ACCOUNT_PASSWORD, NEXT_PUBLIC_ENVIRONMENT
- pricing.ts: replace placeholder price ID strings with process.env references matching lib/stripe/config.ts PRICE_IDS
- claude-integration.ts: unify CLAUDE_MODEL to claude-sonnet-4-20250514 (matches /api/analyze)
- delete apps/pattern-lens/ (confirmed duplicate, flagged in DIPLO_BIBLE_v4.0)

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4
PART 1 — Design tokens
- src/styles/design-tokens.css: full v5.0 token set (bg, accent, text, crisis, spacing, radius, font, easing, max-content-width)
- Beacon keyframe (ob-beacon-pulse 3s, opacity 0.15→0.4), result fade-in (ob-fade-in)
- prefers-reduced-motion guard on all animations
- src/app/globals.css: @import design-tokens.css as first line

PART 2 — Onboarding flow (public, pre-auth)
- layout.tsx: standalone dark layout, 480px max-width, no nav
- page.tsx (Stage 1): CSS-only pulsing beacon, headline, CTA → /onboarding/intent
- intent/page.tsx (Stage 2): 3 sub-steps (intent, experience, preferred_moment), progress indicator, back button, single-select cards, 300ms auto-advance, localStorage persistence
- first-object/page.tsx (Stage 3): textarea (min 20 / max 280 chars), char counter, POST /api/analyze?preview=true, PhaseCards (Context expanded, others collapsed), DisclaimerStrip, dual CTA
- consent/page.tsx (Stage 4): 2 required + 2 optional checkboxes, custom 20px checkbox with SVG checkmark, auth-branch (not logged-in → /signup?onboarding=true, logged-in → POST /api/consent → /dashboard)
- complete/page.tsx (Stage 5): useEffect mount, reads localStorage, writes onboarding_completed: true to Supabase if logged in, clears keys, router.replace('/dashboard')

PART 3 — Middleware
- /onboarding added to PUBLIC_ROUTES (pre-auth access)
- If logged in + on /dashboard or /: query profiles.onboarding_completed; redirect to /onboarding if false
- If logged in + on /onboarding path + onboarding_completed = true: redirect to /dashboard (skip re-running flow)

PART 4 — /api/analyze preview mode
- previewRateMap (in-memory): 1 request per IP per hour
- body.preview === true uses preview rate limit + skips auth (route was already public)
- Body parsed before rate limit to read preview flag; existing 20/min limit unchanged for normal requests

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4
- LoginPage: 62/38 golden ratio grid (left: forms, right: brand anchor)
- LoginLeftColumn: MagicLink (primary), Password (collapsible), Google OAuth (tertiary)
- MagicLinkForm + MagicLinkSent: OTP flow with sent state
- PasswordForm: email+password with error protocol BŁĄD_AUTH/BŁĄD_WALIDACJI
- GoogleButton: OAuth provider button
- LoginRightColumn: brand copy, phase preview, disclaimer
- SignupPage: zod-validated registration form with success state
- MergePromptModal: anonymous→account data merge confirmation
- MergePromptWrapper: stub (useMergeOnLogin pending IDB implementation)
- AhaCTA: sticky bottom banner for anonymous users post-analysis
- app/login/page.tsx: replaced monolith with Server Component wrapper + metadata
- app/signup/page.tsx: new route using SignupPage component
All components: design tokens via CSS vars, zero any/unknown, S11-compliant copy

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4
… components

- Create AuthContext wrapping Supabase auth (status/signIn*/signUp/signOut)
- Create useMergeOnLogin hook (localStorage anon_objects → /api/objects/merge)
- Create useAnonStore hook (localStorage-backed IDB stub for hasAha + anonObjectIds)
- Add AuthProvider to root layout wrapping LanguageProvider
- Update MagicLinkForm → useAuth().signInWithOtp
- Update PasswordForm → useAuth().signInWithPassword, redirect /objects
- Update GoogleButton → useAuth().signInWithGoogle
- Update SignupPage → useAuth().signUp + add fullName field, redirect /objects
- Update AhaCTA → useAuth().status replaces direct Supabase session check
- Update MergePromptWrapper → replaces stub with real useMergeOnLogin
- Fix package.json: remove stray trailing char that broke JSON parse
- Add eslint.config.mjs (next/core-web-vitals + next/typescript)

https://claude.ai/code/session_01VHCS526rsACFMoTreq8hn4
@Patternslab-ecosystem
Copy link
Owner Author

Benchmark 2030 — Triage Automatyczny

Status: 🔄 Zakwalifikowany do Sprint 1

Ten issue dotyczy onboarding flow i schema migrations — kluczowego elementu architektury B2C.

Plan działania (Benchmark 2030):

  • Zdefiniować onboarding_steps schema w Supabase migrations
  • Zintegrować z SILENCE.OBJECTS behavioral sequence inicjalizacji
  • Dodać typ OnboardingContract.yaml do Academic Data Contracts (Sprint 3)
  • Test coverage ≥ 80% dla modułu onboarding

Assigned: Sprint 1 (Zero-Debt Foundation)
Labels: enhancement, sprint-1, benchmark-2030

Automatycznie przetriagowany przez Perplexity Benchmark 2030 pipeline — 2026-03-18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants