@loop/my-loop-health — Customer Portal & Platform API
Dual-purpose application serving as both the customer-facing web portal and the backend Platform API. Handles user authentication, protocol management, commerce integrations, and patient health data.
Purpose
The my-loop-health app serves two critical functions:
Customer Portal (Next.js)
- User dashboard with protocol overview
- Order history and subscription management
- Health data visualization and biomarker tracking
- Educational content and protocol guidance
- Support ticket system
Platform API (Hono)
- RESTful API for mobile app and integrations
- BigCommerce/Shopify webhook processing
- Stripe payment processing
- ReCharge subscription management
- Patient data aggregation and analysis
- Third-party integrations (Rupa Health, Vibrant, etc.)
Consolidates what were previously separate microservices into a unified application with clear separation between web routes and API routes.
Architecture
Route Structure
Next.js Routes (app/)
/— Dashboard home/protocols— Active protocols and dosing schedules/orders— Order history and tracking/biomarkers— Lab results and trends/settings— Account settings and preferences/support— Help center and ticket system
API Routes (app/api/v1/)
/api/v1/auth/*— Authentication endpoints/api/v1/protocols/*— Protocol management/api/v1/biomarkers/*— Lab result ingestion/api/v1/commerce/*— Order and subscription webhooks/api/v1/patient-graph/*— Patient data queries/api/health— Health check and status
Key Components
Dashboard (app/(dashboard)/)
- Protocol adherence tracking
- Upcoming doses and reminders
- Recent lab results
- Personalized recommendations
Commerce Integration (app/api/v1/commerce/)
- BigCommerce order sync
- Stripe payment processing
- ReCharge subscription webhooks
- Inventory reconciliation
Biomarker Processing (app/api/v1/biomarkers/)
- PDF parsing (Rupa Health, Vibrant, LabCorp)
- Result normalization and storage
- Trend analysis and visualization
- Out-of-range alerts
Patient Graph (app/api/v1/patient-graph/)
- Unified patient data queries
- Protocol effectiveness analysis
- Cohort comparisons
- Health score calculations
Key Features
Customer Portal Features
- Protocol Dashboard: Visual timeline of protocols, dose logs, progress tracking
- Biomarker Trends: Interactive charts showing lab result changes over time
- Order Management: View orders, track shipments, manage subscriptions
- Education Hub: Protocol guides, research links, dosing instructions
- Support Center: Ticket submission, chat history, FAQ search
Platform API Features
- Authentication: Clerk-based auth with JWT validation
- Commerce Sync: Real-time order creation from BigCommerce/Shopify
- Subscription Management: ReCharge webhook processing and subscription state sync
- Lab Result Ingestion: Automated PDF parsing and biomarker extraction
- Patient Data API: GraphQL-style queries for complex patient data relationships
- Webhook Validation: HMAC signature verification for all integrations
Integrations
- BigCommerce: Order sync, product catalog, inventory
- Shopify: Alternative commerce platform support
- Stripe: Payment processing and subscription billing
- ReCharge: Subscription management and renewal automation
- Rupa Health: Lab order placement and result retrieval
- Vibrant Wellness: Direct lab result imports
- Calendly: Expert call scheduling integration
Tech Stack
- Framework: Next.js 15 (App Router) + Hono for API routes
- Database: Supabase PostgreSQL (
health.*tables) - Auth: Clerk SSO with role-based access
- Commerce: BigCommerce, Shopify, Stripe, ReCharge
- Labs: Rupa Health API, Vibrant Wellness API
- Validation: Zod 3.x
- Charts: Recharts for data visualization
- Styling: Tailwind CSS + shadcn/ui components
Package Dependencies
@loop/core— Result type, error handling, logging, circuit breakers@loop/shared— Zod schemas, types, constants@loop/database— Supabase repositories for health data@loop/commerce— BigCommerce/Shopify clients, webhook handlers@loop/patient-graph— Patient data query engine@loop/biomarker-parser— Lab PDF parsing utilities@loop/hono— Shared Hono middleware@loop/auth— Clerk authentication helpers
Development
Local Setup
# Install dependencies
pnpm install
# Set environment variables
cp apps/my-loop-health/.env.example apps/my-loop-health/.env.local
# Run development server
pnpm --filter @loop/my-loop-health dev
# Access app at http://localhost:3000Required Environment Variables
# Database
DATABASE_URL=postgresql://...
SUPABASE_URL=https://okjpxbiipeghfhwksoit.supabase.co
SUPABASE_ANON_KEY=eyJhbGc...
SUPABASE_SERVICE_KEY=eyJhbGc...
# Clerk Auth
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_...
CLERK_SECRET_KEY=sk_...
# Commerce
BIGCOMMERCE_CLIENT_ID=...
BIGCOMMERCE_CLIENT_SECRET=...
BIGCOMMERCE_ACCESS_TOKEN=...
SHOPIFY_STORE_DOMAIN=...
SHOPIFY_ACCESS_TOKEN=...
STRIPE_SECRET_KEY=sk_test_...
RECHARGE_API_KEY=...
# Labs
RUPA_API_KEY=...
VIBRANT_API_KEY=...
# External Services
TRIGGER_DEV_API_KEY=...API Testing
# Test health endpoint
curl http://localhost:3000/api/health
# Test authenticated endpoint (requires token)
curl -H "Authorization: Bearer <clerk-token>" \
http://localhost:3000/api/v1/protocolsCommands
pnpm dev # Start dev server (port 3000)
pnpm build # Production build
pnpm start # Start production server
pnpm typecheck # Type check
pnpm lint # Lint code
pnpm test # Run testsDeployment
- Platform: Vercel
- Environments:
- Production:
mainbranch → my.loop.health - Staging:
stagingbranch → staging-my.loop.health - Development:
developbranch → dev-my.loop.health
- Production:
- Database: Shared Supabase project (
healthschema) - Edge Functions: API routes run on Vercel Edge Runtime
- Auto-Deploy: Push to branch triggers deployment
Webhook Configuration
After deployment, configure webhooks in external services:
BigCommerce: https://my.loop.health/api/v1/commerce/bigcommerce/webhook
Shopify: https://my.loop.health/api/v1/commerce/shopify/webhook
ReCharge: https://my.loop.health/api/v1/commerce/recharge/webhook
Stripe: https://my.loop.health/api/v1/commerce/stripe/webhook