# Run or self-host Sales CRM
- [Run it locally](#run-it-locally) to try the app with fictional data and simulated integrations. You can complete this path without cloud accounts.
- [Deploy to the cloud](#deploy-to-the-cloud) to host your own installation and connect the services you choose.
## Run it locally
You need Node 24, npm, and a running Docker daemon. The app and database run on your computer with synthetic data. Supabase Docker images and npm dependencies download during setup.
```sh
npm ci
npm run demo:setup
npm run dev -- --hostname 127.0.0.1 --port 4370
```
Open [http://127.0.0.1:4370](http://127.0.0.1:4370). Select **Sign in as demo owner** to enter the workspace. The staff demo is `staff@cedar.example` with password `Cedar-demo-only-2026`. The local Supabase API is on port 54721 and Postgres is on 54722. Keep the app origin the same when opening it and testing forms. Set `SALES_CRM_PORT` before setup and change the dev port together if 4370 is taken.
The setup script creates a restricted Postgres login and a local `.env.local`. Running it again applies pending local migrations and preserves existing demo records. `npm run demo:setup -- --reset` explicitly replaces **this CRM’s local demo data**. Use it when you want a fresh fixture. `npx supabase stop` stops this project’s local stack.
Choose **Campaigns → Run email simulator** to process due mail and see its result in Delivery. The demo uses local Auth and the same database queue, journey logic, and reply matching as live mode. Provider calls are simulated. If you opt in on the public inquiry form, the simulator exposes the confirmation link under Delivery.
```sh
npm run check
npm run test:db
npx playwright install chromium
npm run test:e2e
```
The database and browser suites create synthetic records in this local project. Set `PLAYWRIGHT_CHROME=1` to use installed Google Chrome or set `PLAYWRIGHT_EXECUTABLE_PATH` to a compatible Chromium executable. Browser tests save screenshots in `artifacts/`.
## Deploy to the cloud
Use this path when you want an online installation. Set up the cloud accounts, configure the app, then verify the workflow with test data before enabling live integrations.
### Accounts to set up
Set up Supabase and Vercel first. The CRM owner and staff sign in with Supabase email and password. You can use contacts, pipelines and tasks with `EMAIL_MODE=disabled` and no Resend account. Configure Resend to send live email from the CRM, including campaigns and opt-in confirmations, and to receive replies.
| Account | When you need it | What to prepare |
| --- | --- | --- |
| [Supabase](https://supabase.com/) | **Required** for data and sign-in | A new project for this CRM, a database password, a publishable key, and a Supabase Auth owner account. |
| [Vercel](https://vercel.com/) | **Required** for hosting with this guide | A team with access to your GitHub repo. Use Pro or Enterprise for the configured five-minute Cron Job. |
| [Resend](https://resend.com/) | **Optional for core setup. Required** for live CRM email and replies | A verified sending domain, a receiving domain or assigned Resend inbound domain, an API key for sending, credentials that can retrieve received email, and a webhook signing secret. |
| Domain DNS provider | **Required when configuring Resend** | Access to add Resend’s verification records. An assigned Resend inbound domain can receive replies without changing existing mailboxes. |
| Google Cloud | **Optional** for Google sign-in | An OAuth app and credentials if you enable Google sign-in. |
Each installation hosts one business. Use a separate Supabase project and deployment for each business. If you enable live email, set up a separate sending identity and receiving configuration as well. Keep passwords and API keys in environment settings. If instructions are being followed by an agent, enter secrets directly in the provider dashboard or `.env.local`. Share only variable names and status with the agent.
#### Hosted plan limits
For a small hosted installation, you can start with [Supabase Free](https://supabase.com/pricing) and use [Resend Free](https://resend.com/pricing?product=transactional) for eligible email volume. See the [README’s cloud dependency table](../README.md#deploy-it-to-the-cloud) for current quota links and the test options for optional integrations. Free Supabase projects can pause after a week of low activity. Keep domain registration separate from the Resend subscription.
#### Daily scheduling on Vercel Hobby
The background worker advances email journeys, works the broadcast and reply queues, and processes inbound replies. A daily run can suit low-volume drips measured in days. Replies, confirmations, broadcasts and retries can wait until the next run. Each invocation processes up to 30 outbound messages, subject to its time budget. Choose a UTC hour that fits the business sending window throughout the year. A run outside that window defers campaign mail to a later eligible run.
Vercel Hobby permits personal, noncommercial use and runs each cron job at most once a day, sometime within the selected UTC hour. Use Pro or Enterprise for commercial use on Vercel and the checked-in five-minute schedule. [Hobby plan](https://vercel.com/docs/plans/hobby) · [Cron limits](https://vercel.com/docs/schedules/cron-jobs/usage-and-pricing)
For a personal evaluation, follow the hosted environment setup below. In your own checkout, change only the cron schedule in `vercel.json` from `*/5 * * * *` to `0 18 * * *` or another once-daily UTC time. Keep its endpoint and configure `CRON_SECRET`. Keep `EMAIL_MODE=disabled` while reviewing setup with test data. For a full simulated workflow, use the local demo.
Import a repository owned by your personal account, or deploy a source copy without the `.git` directory using the Vercel CLI. In the source copy, keep the daily cron edit, link your personal Hobby project, and configure its environment variables before running `vercel deploy --prod`. [Git integration limits](https://vercel.com/docs/git) · [CLI deploy](https://vercel.com/docs/cli/deploy)
### Set up Supabase and the owner
1. Create the new Supabase project and wait until it is healthy. Sign in with `npx supabase login`, link it with `npx supabase link --project-ref `, verify the linked project, then run `npx supabase db push`. Use the DB password prompt if required. Keep the GitHub fork private while setting up.
2. Open Supabase’s SQL editor as the project database administrator. Create a dedicated runtime login using the group installed by the migration.
```sql
create role sales_crm_runtime
login inherit
in role sales_crm_access
password '';
```
Set `DATABASE_URL` to the project’s **shared transaction pooler** string from Connect. Use port 6543 and username `sales_crm_runtime.` in place of `postgres.`. URL-encode the password and use `sslmode=require`. For an IPv6-capable direct connection, the username is `sales_crm_runtime` without the project suffix. The app disables prepared statements for transaction pooling. Leave the private `crm` schema out of the Supabase Data API and keep the runtime login separate from the administrator login. [Supabase connection guidance](https://supabase.com/docs/guides/database/connecting-to-postgres)
3. Set Supabase Authentication’s Site URL to your final app origin and add that origin’s exact `/auth/callback` URL to the redirect allowlist if using Google. Disable public sign-ups in Authentication. Create the owner user in **Authentication → Users**. Set a unique password and confirm the user there as appropriate. Copy the user UUID. From a clean checkout with the **intended** database’s `DATABASE_URL` configured, run:
```sh
npm run owner:setup -- "Owner name"
```
Use the same database URL in the Vercel project. Create teammates in Supabase Auth first, then add their UUID and role in **Settings → Team access**. Supabase Auth users without active workspace membership cannot enter the CRM.
4. For Google single sign-on, use Supabase’s [Google provider setup](https://supabase.com/docs/guides/auth/social-login/auth-google). Enable it with `GOOGLE_SIGN_IN_ENABLED=true`. The Google account must resolve to an active Supabase member UUID. Verify account sign-in and membership before sharing access with staff.
### Deploy with email disabled
1. Import the repo into the intended Vercel team and use the pinned Node 24 runtime. Set `APP_URL` to the exact HTTPS deployment origin, with no path. Set `NEXT_PUBLIC_SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`, and `DATABASE_URL`. Generate two separate secrets of 32 characters or longer for `APP_LINK_SECRET` and `CRON_SECRET`. You can use `openssl rand -hex 32` in a private terminal. Vercel uses `CRON_SECRET` to authorize `GET /api/cron/email`. [Vercel Cron Jobs](https://vercel.com/docs/cron-jobs/usage-and-pricing)
2. Leave `EMAIL_MODE=disabled` while verifying sign-in, the public inquiry from an incognito window, member permissions, and the company mailing address and sending window in Settings. Use an isolated Supabase project for any remote preview that needs data. A preview deployment always disables provider email.
3. Run the migrations before making the deployment the app’s active URL. Project owners can confirm that authorized cron calls report the current email mode and that unauthorized calls return 401. The five-minute schedule may start soon after a production deployment, so keep live secrets scoped to the intended environment.
### Set up Resend
Complete this section when you are ready to enable live CRM email and replies. Leave `EMAIL_MODE=disabled` until you approve a live email test.
- Verify the sending domain and enter a single sender like `Business Name ` in `EMAIL_FROM`. Store a server-only Resend sending key as `RESEND_API_KEY`. Prefer a key with sending access scoped to that domain.
- Set `RESEND_INBOUND_DOMAIN` to the assigned Resend receiving domain or your dedicated receiving subdomain, with no leading `@`. If separate credentials are needed, set `RESEND_RECEIVING_API_KEY` to a server-only key able to call the received-email retrieval API. The app uses this key, or falls back to `RESEND_API_KEY` when it has sufficient access. Each outgoing message uses an opaque address at the configured domain. [Resend receiving](https://resend.com/docs/dashboard/receiving/introduction) · [Retrieve received email](https://resend.com/docs/api-reference/emails/retrieve-received-email)
- Create a webhook for `/api/webhooks/resend` and store its signing secret as `RESEND_WEBHOOK_SECRET`. Subscribe to `email.received`, `email.sent`, `email.delivered`, `email.failed`, `email.bounced`, `email.complained`, and `email.suppressed`. If you opt into engagement tracking, enable it in Resend, add `email.opened` and `email.clicked`, and set `EMAIL_TRACKING_ENABLED=true` in the app. Tracking reflects events received after it is enabled. Click waits use the click events Resend reports for that enrollment. Reported opens and clicks can include automated activity. [Resend event types](https://resend.com/docs/webhooks/event-types)
- Set `EMAIL_TEST_RECIPIENTS` to the comma-separated addresses approved for controlled template tests. Use the separate live-email check below before activating customer campaigns.
- Record explicit marketing permission before starting journeys or broadcasts. Confirm that the sender identity, business mailing address, and unsubscribe links are correct. Staff can edit drafts and reply. An owner or manager must approve sending, enrollment, or activation. [Resend Acceptable Use Policy](https://resend.com/legal/acceptable-use)
### Run the live-email check
1. Obtain approval for the exact deployment, sender and recipient addresses. Use an isolated test deployment and database if the main installation has customer records or queued email. Verify the sending window and business mailing address. Set `EMAIL_MODE=live` on the approved deployment. Vercel previews continue to disable sending.
2. Use **Templates → Queue test email** to check content, sender, Resend acceptance and confirmed delivery. Template tests are only for delivery and content. Use an approved campaign contact to exercise replies and unsubscribe.
3. Create opted-in records for the approved test mailboxes. For reply and unsubscribe, use a small manually enrolled journey with an initial email, a delay and a second message. Confirm that only the approved mailboxes are enrolled. Reply from one mailbox and use the unsubscribe link from the other. Verify the signed webhook events, the stopped runs, an in-thread response from the workspace, the opted-out record and the campaign results.
4. Pause the test journey and return email to disabled if you are still setting up. Review the sender, consent evidence and the first customer audience before approving any live campaign.
### Operate the queue
Review **Campaigns → Delivery** for queued, accepted, and delivered messages. The worker honors the configured sending window and moves repeat campaign emails for the same address to a later sending day. The CRM sends via Resend’s emails API, so your Resend transactional quota and API rate limits apply to both journeys and broadcasts. A message marked **Needs review** requires a check in Resend before you record an accepted provider ID or close the message as failed. Review the existing message before taking further action. Provider acceptance and delivery are reported independently. [Resend plans](https://resend.com/pricing?product=transactional)
Pause a journey or stop future sends for a broadcast from the CRM. If you need to stop all dispatch, set `EMAIL_MODE=disabled` and redeploy. Already accepted or in-flight mail may still arrive. Keep queued history and provider receipts for reconciliation. Rotating `APP_LINK_SECRET` invalidates existing confirmation and unsubscribe links. Plan that rotation around active messages.
See [Release verification](release-readiness.md) for upgrade, backup and live-email checks.