Self-host setup

This page covers running Brainboot yourself. To use the hosted version, just sign up - no setup needed.

Quick Start

01

Clone & Install

git clone <your-repo> brainboot
cd brainboot
npm install
02

Set Up Supabase

1. Create project at supabase.com
2. SQL Editor - run these in order:
     supabase-schema.sql           (core tenancy + auth)
     supabase-schema-v2.sql        (email logs, dunning, trials)
     supabase-onboarding.sql       (users.metadata column)
     supabase-brains.sql           (brain registry)
     supabase-circuits.sql         (circuit catalog + scheduled runs)
     supabase-cognitive-infrastructure.sql
     supabase-moderation.sql       (admin moderation queue)
3. Copy keys from Settings > API
03

Set Up Stripe

1. Create products in Stripe Dashboard:
     Pro    $29/mo   (recurring)
     Team   $99/mo   (recurring)
2. (Optional) Create Circuit products if you want paid Circuits:
     Content Empire     $99/mo
     Sales Engine       $129/mo
     Founder Formation  $149 one-time
   Or run: npx tsx scripts/setup-launch-pricing.ts
3. Create webhook: yourdomain.com/api/stripe/webhook
   Events: customer.subscription.created/updated/deleted, invoice.paid,
           invoice.payment_failed
4. Copy webhook signing secret + price IDs into env
04

Configure Google OAuth (Optional)

1. Google Cloud Console > APIs & Services > Credentials
2. Create OAuth Client ID > Web application
3. Add redirect: http://localhost:3000/auth/callback
4. In Supabase: Auth > Providers > Google > paste credentials
05

Configure Environment

cp .env.example .env.local
# Fill in all required variables (Supabase, Stripe, AI gateway, app URL)
# Optional but recommended for production: Upstash + Sentry
06

Run & Deploy

npm run dev          # localhost:3000
npx vercel           # deploy to production

SQL Migrations

Run these in the Supabase SQL editor in the order listed below. All migrations are idempotent and safe to re-run.

01
supabase-schema.sql

Users, organizations, members, invitations, API keys, usage_log, admin_actions. Run first.

02
supabase-schema-v2.sql

Email logs, webhook failures, dunning, trials.

03
supabase-onboarding.sql

Adds users.metadata JSONB for the onboarding wizard answers.

04
supabase-brains.sql

Brain registry table (bb_brains) and run history.

05
supabase-circuits.sql

Circuit catalog (bb_circuits), subscriptions, scheduled runs, run/model-call logs.

06
supabase-cognitive-infrastructure.sql

Context fabric, reflection runs, telemetry tables.

07
supabase-moderation.sql

Admin moderation queue.

08
supabase-prompts-tier.sql + supabase-prompts-additional.sql + supabase-prompts-batch-3.sql

Curated prompt seed data for the marketplace.

Environment Variables

Copy .env.example to .env.local and fill in your values.

NEXT_PUBLIC_SUPABASE_URL
RequiredClient

Your Supabase project URL. Found in Project Settings > API.

NEXT_PUBLIC_SUPABASE_ANON_KEY
RequiredClient

Supabase anon/public key for client-side auth.

SUPABASE_SERVICE_ROLE_KEY
RequiredServer

Supabase service role key for server-side admin operations. Never expose to the client.

STRIPE_SECRET_KEY
RequiredServer

Stripe API secret key. Use test key (sk_test_) for development.

STRIPE_WEBHOOK_SECRET
RequiredServer

Signing secret for Stripe webhook verification.

STRIPE_PRO_PRICE_ID
RequiredServer

Stripe Price ID for the Pro plan ($29/mo, 1M tokens, all models).

STRIPE_SCALE_PRICE_ID
RequiredServer

Stripe Price ID for the Team plan ($99/mo, 10M tokens shared, all models).

NEXT_PUBLIC_STRIPE_PRO_PRICE_ID
RequiredClient

Same Pro price ID for client-side upgrade buttons.

NEXT_PUBLIC_STRIPE_SCALE_PRICE_ID
RequiredClient

Same Team price ID for client-side upgrade buttons.

NEXT_PUBLIC_APP_URL
RequiredClient

Your app base URL for redirects and callbacks.

AI_GATEWAY_API_KEY
RequiredServer

Vercel AI Gateway key. One key unlocks every model in the catalog (OpenAI, Anthropic, Google, xAI, DeepSeek, Mistral). Get at vercel.com/ai-gateway.

RESEND_API_KEY
OptionalServer

Resend API key. If not set, emails log to console.

EMAIL_FROM
OptionalServer

Sender address. Defaults to "Brainboot <noreply@yourdomain.com>".

EMAIL_REPLY_TO
OptionalServer

Reply-to address. Defaults to "support@yourdomain.com".

UPSTASH_REDIS_REST_URL
OptionalServer

Upstash Redis REST URL. Enables distributed rate limiting across serverless instances. Without it the app falls back to in-memory rate limiting (per-instance only).

UPSTASH_REDIS_REST_TOKEN
OptionalServer

Upstash Redis REST token, paired with the URL above.

SENTRY_DSN
OptionalServer

Sentry DSN for error tracking. Without it, errors only land in server logs.

NEXT_PUBLIC_SENTRY_DSN
OptionalClient

Same Sentry DSN for client-side error capture.

LABS_ENABLED
OptionalServer

Set to "true" on private Labs deployments to expose /nrfi, /f3, /parlays, /labs, /engines and the related cron jobs. Leave unset on the public Brainboot deployment.

SUPABASE_PAT
OptionalServer

Supabase Personal Access Token. Only required when running scripts/seed-circuits.py or scripts/seed-invariants.py against a project. Generate at supabase.com/dashboard/account/tokens.

What's Included

Authentication

  • Email/password signup & login
  • Google OAuth
  • Password reset flow
  • Email verification gate
  • Session refresh via middleware
  • Suspended-user state

Billing & Payments

  • Stripe subscriptions (Free / Pro $29 / Team $99)
  • Checkout + billing portal
  • Webhook lifecycle handling with idempotency
  • 7-day dunning with grace period
  • Cancel at period end + reactivation
  • Free trials with/without card
  • Per-circuit one-time and recurring purchases

Multi-Tenant Teams

  • Organizations with roles (owner/admin/member)
  • Email invitations with 7-day expiry
  • Org switcher for multi-org users
  • Org-level token pooling
  • API key management (SHA-256 hashed)
  • Row Level Security on every table

Cognitive Engineering

  • Brain registry + editor + marketplace
  • Streaming chat with brain-loaded conversations
  • Multi-model support (14+ via Vercel AI Gateway)
  • Plan-tier model gating (free->Haiku, Pro+->all)
  • Cost-weighted token metering
  • Compiler: plain language to deployed circuit
  • Reflection engine + scheduled blueprint runs

Admin & Operations

  • Admin panel with user/org management
  • Impersonation mode for support
  • Webhook failure monitoring
  • Audit logging (admin_actions table)
  • 9 transactional email templates
  • Distributed rate limiting (Upstash, optional fallback to in-memory)
  • Global error boundary + Sentry integration (optional)

Developer Experience

  • Demo mode runs without any keys configured
  • withAuth/withAdmin wrappers for new API routes
  • Idempotent SQL migrations (safe to re-run)
  • Idempotent Stripe seed scripts
  • Labs feature flag isolates side projects

Customization Guide

Change branding

Update metadata in src/app/layout.tsx, text in src/components/nav.tsx, logo in src/components/logo.tsx, colors in src/app/globals.css, email branding in src/lib/email.ts.

Modify pricing plans

Edit PLAN_LIMITS and PLAN_PRICES in src/lib/supabase.ts. Update MODEL_ACCESS_BY_PLAN in src/lib/models.ts to change which model tiers each plan can run. Then rerun npx tsx scripts/setup-launch-pricing.ts to provision matching Stripe products and prices.

Add a new model

Append an entry to MODELS in src/lib/models.ts (id from Vercel AI Gateway catalog, tier cheap/standard/flagship, costWeight). It is automatically gated and metered.

Add a new API route

Create src/app/api/your-feature/route.ts. Use withAuth() wrapper for automatic auth + rate limiting and consistent error envelope.

Track usage

Call incrementOrgUsage(orgId, weightedTokens) from any API route after a successful LLM call. Atomic via Supabase RPC, race-safe.

Add email templates

Add to the templates object in src/lib/email.ts. Send with sendEmail({ to, template, data }). All sends log to email_logs.

Enable Labs (NRII / F3 / NFL)

Set LABS_ENABLED=true in the environment. The middleware (src/middleware.ts) gates all /nrfi, /f3, /parlays, /labs, /engines routes plus the related cron paths. Public Brainboot deployments leave this unset.