# Deck Hearth on Dokploy (CT 112)

Homelab deploy: Postgres + Redis + MinIO on CT 102, app on Dokploy, public URL via CT 100 Traefik → CT 112.

## 1. Prerequisites (CT 102)

- [x] `deckhearth` Postgres — `provision-deckhearth.sh`
- [x] MinIO bucket — `provision-deckhearth-minio.sh` (axiom-server)
- [ ] Neon data copy — `npm run migrate-neon-to-homelab` (one-time; run once then archive Neon. Script reads `NEON_DATABASE_URL` (source) and `POSTGRES_URL_DIRECT` (target). Requires `pg_dump` + `pg_restore` on PATH. If starting fresh with no Neon data, skip this step.)

## 2. Dokploy application

**Dashboard:** https://dokploy.stillwell.cloud

| Setting | Value |
| --- | --- |
| Source | Git (Forgejo/GitHub) → this repo |
| Build type | **Dockerfile** |
| Dockerfile path | `Dockerfile` (repo root — must be pushed to GitHub) |
| Branch | `main` (production) |
| Domain in Dokploy | `http://deckhearth.stillwell.cloud` (use `http://`, not `https://`) |
| Port | `3000` |

## 3. Environment variables (Dokploy → Environment)

```bash
# Database (CT 102)
POSTGRES_URL=postgresql://deckhearth:YOUR_PASSWORD@192.168.68.102:5432/deckhearth

# Redis rate limits (CT 102, DB index 5)
REDIS_URL=redis://:YOUR_REDIS_PASSWORD@192.168.68.102:6379/5

# MinIO object storage (CT 102)
S3_ENDPOINT=http://192.168.68.102:9000
S3_ACCESS_KEY_ID=deckhearth-app
S3_SECRET_ACCESS_KEY=YOUR_MINIO_SECRET
S3_BUCKET=deckhearth
S3_PUBLIC_BASE_URL=https://cdn.stillwell.cloud/deckhearth
S3_REGION=us-east-1

# Auth
JWT_SECRET=openssl rand -base64 32

# AI (kept on Vercel AI Gateway)
AI_GATEWAY_API_KEY=vck_…

# Email (external — Resend until self-hosted)
RESEND_API_KEY=re_…

# Cron (n8n on CT 105 hits this weekly)
CRON_SECRET=openssl rand -base64 24

# Optional
NODE_ENV=production
```

## 4. Traefik (CT 100)

Route added in `axiom-server/proxmox/ct100/traefik/config/dynamic/ct112-dokploy.yml`:

- Host: `deckhearth.stillwell.cloud`
- Backend: `http://192.168.68.112:80` (Dokploy Traefik)

After editing locally: `./proxmox/scripts/sync.sh push-traefik`

## 5. Catalog sync cron (replaces Vercel Cron)

Vercel `vercel.json` crons are removed. Schedule in **n8n** (CT 105) or cron:

```bash
curl -fsS -H "Authorization: Bearer $CRON_SECRET" \
  https://deckhearth.stillwell.cloud/api/cron/sync-catalog
```

Weekly: `0 6 * * 1` (Mondays 06:00).

## 6. Decommission Vercel

1. [ ] **Run the data copy first** — `npm run migrate-neon-to-homelab` (see § 1). If there is no Neon data to migrate, skip to step 2.
2. [ ] **Verify DNS** — confirm `deckhearth.stillwell.cloud` resolves to Traefik (CT 100). Already configured for `*.stillwell.cloud` → CT 100; verify in your DNS provider or AdGuard.
3. [ ] **Delete the Vercel project** at vercel.com. After confirming the Dokploy deployment is stable and serving traffic, delete the Vercel project to stop billing and auto-deploys.
4. [ ] **Remove old env vars from Vercel dashboard** — Neon connection string, Blob storage, Upstash/Redis vars are no longer used by the app.

## 7. Local dev

Same env vars in `.env.local` with homelab URLs (LAN required).

```bash
npm run dev
```
