# Moore's Benefits Group CRM Portal — Install Guide

This package contains the complete portal: member sign-in, Medicare & Medicaid
enrollment, the full Spanish site (`/es/...`), business enrollment with the
permanent LegalShield link, Stripe premium billing, document vault, agent CRM,
admin dashboard and Google Analytics tracking.

**Licensed software.** See `LICENSE.md`. One paid licence = one installation.

Recommended install domain: **https://crm.moorebenefitsgroup.us**

---

## 1. Requirements

- Node.js 20+ and [Bun](https://bun.sh) (`curl -fsSL https://bun.sh/install | bash`)
- A Supabase project (database, auth, storage)
- A Stripe account (premium payments)
- A Google Analytics 4 property (optional, for conversion tracking)
- Any host that runs a Node/edge server: Cloudflare Workers, Vercel, Netlify, Fly.io

## 2. Install

```bash
unzip moore-crm-portal.zip && cd moore-crm-portal
bun install
cp .env.example .env
```

## 3. Fill in `.env`

| Variable | Where it comes from |
| --- | --- |
| `VITE_SUPABASE_URL`, `VITE_SUPABASE_PUBLISHABLE_KEY`, `VITE_SUPABASE_PROJECT_ID` | Supabase → Project Settings → API |
| `SUPABASE_SERVICE_ROLE_KEY` | Supabase → Project Settings → API (server only, never publish) |
| `STRIPE_LIVE_API_KEY`, `STRIPE_SANDBOX_API_KEY` | Stripe → Developers → API keys |
| `PAYMENTS_LIVE_WEBHOOK_SECRET`, `PAYMENTS_SANDBOX_WEBHOOK_SECRET` | Stripe → Developers → Webhooks → signing secret |
| `VITE_PAYMENTS_CLIENT_TOKEN` | Stripe publishable key (`pk_live_...`) |
| `VITE_LOVABLE_CONNECTOR_GOOGLE_ANALYTICS_API_KEY` | GA4 Measurement ID (`G-XXXXXXX`) |
| `VITE_APP_ORIGIN` | `https://crm.moorebenefitsgroup.us` (your install domain) |

## 4. Database

Apply every file in `supabase/migrations/` in date order using the Supabase SQL
editor or `supabase db push`. This creates clients, policies, documents,
payments, roles, archive tables and all row-level security policies.

Create a private storage bucket named `member-documents`.

## 5. Stripe webhook

Point a Stripe webhook at:

```
https://crm.moorebenefitsgroup.us/api/public/payments/webhook
```

Events: `checkout.session.completed`, `invoice.paid`, `invoice.payment_failed`,
`customer.subscription.updated`, `customer.subscription.deleted`.

## 6. Run and deploy

```bash
bun run dev      # local at http://localhost:8080
bun run build    # production build
```

Deploy the build output to your host and point `crm.moorebenefitsgroup.us` at it.

## 7. After launch

- Create your first admin: sign up at `/auth`, then insert an `admin` row for
  that user id in `user_roles`.
- English site: `/`, `/enroll`, `/billing`, `/business`
- Spanish site: `/es`, `/es/inscribirse`, `/es/facturacion`, `/es/solicitud-medicare`
- Agent workspace: `/agent` · Admin dashboard: `/agent/admin-dashboard`

## Things that cannot be changed

The LegalShield enrollment link (`https://tomekiamoore.legalshieldassociate.com/`)
is a permanent part of the business enrollment experience and is defined in
`src/lib/constants.ts`. Removing or replacing it violates the licence.
