# {{project_name}}

{{description}}

Scaffolded with [@openlife/cli](https://www.npmjs.com/package/@openlife/cli)
from the `nextjs-supabase-clerk-stripe` template.

## Stack

| Layer | Choice |
|---|---|
| Framework | Next.js 16 (App Router) |
| Auth | Clerk |
| Database | Supabase Postgres (with RLS) |
| Billing | Stripe (subscriptions + customer portal) |
| Styling | Tailwind CSS + shadcn/ui |
| Deploy | Vercel-ready |

## Quick start

```bash
# 1. Fill in your API keys
cp .env.example .env.local
$EDITOR .env.local

# 2. Install dependencies
npm install

# 3. Apply the database migration
#    (requires Supabase CLI: https://supabase.com/docs/guides/cli)
supabase db push

# 4. Start the dev server
npm run dev
# → http://localhost:3000
```

## Architecture map

- `app/layout.tsx` — wraps the app in `ClerkProvider`. Tailwind is imported via `app/globals.css`.
- `middleware.ts` — Clerk auth gate. `/(dashboard)/*` and `/api/*` (except webhooks) require sign-in.
- `app/(auth)/sign-in` + `app/(auth)/sign-up` — Clerk-hosted forms, mounted as routes.
- `app/(dashboard)/` — protected area. Layout shows nav + user menu.
- `app/(dashboard)/billing/page.tsx` — plans + checkout entry point. Looks up the Stripe customer or creates one on first visit.
- `app/api/webhooks/clerk/route.ts` — syncs Clerk users → `users` table.
- `app/api/webhooks/stripe/route.ts` — mirrors subscription lifecycle → `subscriptions` table.
- `lib/db.ts` — Supabase clients (anon vs service-role).
- `lib/stripe.ts` — Stripe SDK + plan definitions + customer lookup.
- `lib/auth.ts` — `requireUserId()` / `getUserId()` server helpers.
- `supabase/migrations/0001_initial.sql` — users + subscriptions tables + RLS policies.

## Deploy to Vercel

```bash
# One-shot
vercel --prod

# Or wire to a git remote:
#   1. Push this repo to GitHub
#   2. Import at https://vercel.com/new
#   3. Add the env vars from .env.example
#   4. vercel.json sets the framework to next, so no config needed
```

After deploy, register the webhooks:

- Clerk: `https://<your-domain>/api/webhooks/clerk` (events: `user.created`, `user.updated`, `user.deleted`)
- Stripe: `https://<your-domain>/api/webhooks/stripe` (events: `customer.subscription.*`, `checkout.session.completed`)

## Adding routes

```bash
# Public marketing page
$EDITOR app/about/page.tsx

# Protected API
$EDITOR app/api/some-action/route.ts   # automatic auth gate via middleware

# New protected dashboard tab
$EDITOR 'app/(dashboard)/settings/page.tsx'
```

## Extending with OpenLife

This scaffold is designed to compose with the rest of OpenLife's surfaces:

```bash
# Pull a brand's design tokens into design/profiles/
openlife design extract https://your-brand.com --catalog

# Apply that design system to the active mode (v1.16+)
openlife design pull stripe   # uses the bundled stripe profile

# Story-driven feature work (v1.12+)
openlife story list           # see what needs building
openlife story execute 1.1    # v1.17 — autonomous loop
```

## License

MIT — see LICENSE if present, or add one before shipping.
