# AutoKap (backend package)

AI-powered website screenshot capture across every device, language, and
theme.

This npm package (`autokap`) is the **backend** that runs the AutoKap capture
engine. It is consumed by the AutoKap Cloud Run service that handles
`npx autokap auto-recapture --cloud` jobs, by CI pipelines, and for local
preset runs.

The commands `autokap login`, `autokap run`, `autokap doctor`, and
`autokap auto-recapture` are available for users who need a scriptable backend
(CI/CD, custom orchestrators). Project, preset, and capture management happens
in the AutoKap web dashboard.

## Recapture Cloud in CI/CD

The official CI/CD flow is Recapture Cloud. Generate a signed webhook secret
from the project Recapture page, store it in your CI secret manager, then call
the webhook on deploy. CI never needs an AutoKap CLI key.

```bash
BODY='{}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$AUTOKAP_WEBHOOK_SECRET" -binary | xxd -p -c 256)
curl -X POST "https://autokap.app/api/webhooks/cloud-recapture/<project-id>" \
  -H "Content-Type: application/json" \
  -H "X-AutoKap-Signature: sha256=$SIG" \
  -d "$BODY"
```

Recapture Cloud always captures the project's `prod` environment. Use the
other project environments for local debugging and staging checks.

The local CLI remains available for advanced debugging:

```bash
AUTOKAP_API_KEY=ak_cli_... autokap run <preset-id> --env staging
```

## Auth Setup (Supabase)

AutoKap uses Supabase Auth for user authentication. You need to configure the following providers in your Supabase dashboard:

### 1. Email/Password

- Go to **Authentication > Providers > Email** in the Supabase dashboard
- Enable **Email provider**
- Configure email templates if needed
- Enable/disable **Confirm email** depending on your needs

### 2. Google OAuth

- Go to **Authentication > Providers > Google**
- Enable the Google provider
- Create OAuth credentials in the [Google Cloud Console](https://console.cloud.google.com/apis/credentials):
  - Create an OAuth 2.0 Client ID (Web application)
  - Add `https://<your-supabase-project>.supabase.co/auth/v1/callback` as an authorized redirect URI
- Copy the **Client ID** and **Client Secret** into the Supabase Google provider settings

### 3. GitHub OAuth

- Go to **Authentication > Providers > GitHub**
- Enable the GitHub provider
- Create an OAuth App in [GitHub Developer Settings](https://github.com/settings/developers):
  - Set the **Authorization callback URL** to `https://<your-supabase-project>.supabase.co/auth/v1/callback`
- Copy the **Client ID** and **Client Secret** into the Supabase GitHub provider settings

### 4. Database Schema

Make sure the `captures` table has a `run_id` UUID column:

```sql
ALTER TABLE captures ADD COLUMN IF NOT EXISTS run_id UUID;
CREATE INDEX IF NOT EXISTS idx_captures_run_id ON captures(run_id);
```

## Architecture

- **Web App**: Next.js 16 (App Router) + Tailwind CSS 4 + shadcn/ui + framer-motion
- **Backend**: Node.js + Playwright for browser automation + AI agent (OpenRouter)
- **Database**: Supabase (PostgreSQL + Storage + Auth)
- **Routes**: `/presets`, `/capture/new`, `/capture/live`, `/gallery`, `/login`
