# Lancashire Digital Design CRM setup

The CRM is available at `crm.html`. It is deliberately hidden from the public navigation and marked `noindex`.

## 1. Create the database

1. Open the Supabase project at `https://sltztogbfyxutxfxtkov.supabase.co`.
2. Open **SQL Editor** and run all of `supabase/schema.sql`.
3. Open **Authentication → Users** and create the CRM user who should be allowed to sign in.

The schema enables Row Level Security. Every CRM record belongs to the signed-in user and cannot be read by another CRM user.

## 2. Connect every device with one shared configuration

1. In Supabase, open **Project Settings → API Keys**.
2. Copy the public **anon** key. Do not use or expose the service-role key.
3. Open `crm-config.js` and replace `PASTE_SUPABASE_ANON_KEY_HERE` with the anon key.
4. Upload the updated project once. Every computer, phone and tablet will then use the same shared connection automatically.
5. Open `crm.html` on any device and sign in with the user created above.

The Connection settings screen remains available as a local fallback, but it is not needed after `crm-config.js` is configured. The anon key is a public browser key protected by Row Level Security. Never place a service-role key in `crm-config.js`.

## 3. Enable the AI studio

The browser never receives the OpenAI key. AI requests go through the included Supabase Edge Function.

Using the Supabase CLI from this project directory:

```sh
supabase link --project-ref sltztogbfyxutxfxtkov
supabase secrets set OPENAI_API_KEY=YOUR_OPENAI_API_KEY
supabase functions deploy ai-studio
```

Supabase automatically provides the function with `SUPABASE_URL` and `SUPABASE_SERVICE_ROLE_KEY`. The function uses the OpenAI Responses API for social copy and SEO suggestions, and GPT Image for original campaign images.

## 4. Hosting

Upload the complete project folder to any static web host. Keep `crm.html` unlinked from the public navigation. For stronger access control, protect the CRM route at the hosting layer as well as using Supabase Authentication.
