Files
descrybe/README.md
T
2026-10-14 20:02:42 +02:00

304 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> **Latest update (October 2026):** All 25 platform default category prompt languages now use the same canonical title/HTML description/SEO meta formula. Run `npm run seed:category-prompts:i18n` after `npm run migrate` to upgrade old untouched defaults, including old English five-H2 templates. No translation LLM or API key is required. See [docs/canonical-product-prompts-v6.md](docs/canonical-product-prompts-v6.md).
# Descrybe v2
Go API + SvelteKit frontend + PostgreSQL rewrite of Descrybe (no Clerk).
## Stack
- **API:** Go, chi, pgx, sqlc, goose, River jobs
- **Web:** SvelteKit 2, Svelte 5, Tailwind
- **DB:** PostgreSQL 16
- **Migrator:** MySQL → Postgres ETL with Clerk ID remapping
## Local setup (any OS)
Docker Compose runs **Postgres only** (host **:5433**). API, web, and worker run on the host via `npm run setup` + `npm run dev` (fast reload; no Laragon/XAMPP required). OS-specific Docker notes: [docs/docker.md](docs/docker.md). Ports match `docker-compose.yml` + `scripts/dev-ports.mjs`.
**After the stack is up:** operator path (login → feed → process → export) → [docs/getting-started.md](docs/getting-started.md).
### Two-step path (recommended)
```bash
npm run setup # .env (if missing) + docker Postgres :5433 + goose migrate
npm install && npm run dev # API :28471 + web :28472 + worker (needed for /readyz + jobs)
```
Same on Windows PowerShell, macOS, and Linux (Node scripts; Docker Desktop or Engine + Compose v2). Equivalents: `make setup` then `make` targets / `npm run …`.
Optional: `npm run seed` (demo login) · `npm run health` (`/healthz` + `/readyz`).
### Prerequisites
| Tool | Version / notes |
|------|-----------------|
| **Docker** | Docker Engine + Compose v2 (`docker compose`) — Postgres only on **:5433** |
| **Node.js** | **≥ 20** (`package.json` `engines.node`) |
| **Go** | **1.25.0** (`apps/api/go.mod`) |
| **sqlc** (optional) | On `PATH` for migrate regen; scripts fall back to `go run …/sqlc` if missing |
| **Make** (optional) | `make setup` / `make up` / `make migrate` — macOS/Linux/WSL; Windows can use `npm run …` |
### Local ports (canonical)
| Service | Host |
|---------|------|
| Postgres | `localhost:5433` → container `5432` (`postgres:16-alpine`) |
| API | `http://localhost:28471` (`HTTP_ADDR=:28471`) |
| Web | `http://localhost:28472` (Vite `strictPort`; proxies `/api`, `/healthz`, `/readyz`) |
Do **not** use older docs that mention `:8080` / `:5174` for day-to-day `npm run dev`.
### Environment (one file)
Use a **single root `.env`** (copy from [`.env.example`](.env.example)). Do **not** create `apps/api/.env`. `npm run setup` creates `.env` from the example and fills empty `TOKEN_SIGNING_SECRET` / `APP_ENCRYPTION_KEY` with local random hex (never commit `.env`).
| Variable | Local default / note |
|----------|----------------------|
| `DATABASE_URL` | `postgres://descrybe:descrybe@localhost:5433/descrybe?sslmode=disable` (matches `docker-compose.yml`) |
| `HTTP_ADDR` | `:28471` |
| `WEB_ORIGIN` | `http://localhost:28472` |
| `PUBLIC_API_URL` | `http://localhost:28471` |
| `APP_ENV` | `development` |
| `SESSION_SECURE` | `false` locally; `true` in production |
| `TOKEN_SIGNING_SECRET` | `openssl rand -hex 32` (or let `npm run setup` generate) |
| `APP_ENCRYPTION_KEY` | Prefer this for at-rest secrets (`CREDENTIALS_ENCRYPTION_KEY` is legacy). Same generate rule |
Leave OpenAI, Stripe, EPREL, marketing mail, Woo, and Shopify **out of** `.env` for day-to-day setup. Configure them in the app after login:
| Integration | Where |
|-------------|--------|
| AI (OpenAI-compatible / BYOK) | `/integrations/ai` (tenant) and/or `/admin/settings` (platform) |
| Stripe, EPREL, feed private-URL allowlist | `/admin/settings` (`GET/PUT /api/admin/settings` → `values.*`; env optional fallback) |
| Marketing email (Resend / SMTP) | `/integrations/email` |
| Stores (Woo / Shopify / feeds) | `/stores` |
Platform set-password / invite SMTP may still use process `SMTP_*` when you enable live invite mail (see [docs/ops-runtime.md](docs/ops-runtime.md)). Session/encryption fail-closed rules are in `.env.example` and [docs/production-checklist.md](docs/production-checklist.md). Production does **not** require Stripe secrets at boot.
The API/worker load the **monorepo-root** `.env` automatically (`apps/api/internal/config` `loadDotEnv`).
### Manual steps (if you skip `npm run setup`)
`docker-compose.yml` defines **only** Postgres (`descrybe-v2-postgres`, user/db/password `descrybe`, volume `descrybe_v2_pg`, `pg_isready` healthcheck). OS-specific Docker Desktop / Engine notes: [docs/docker.md](docs/docker.md).
```bash
cp .env.example .env # PowerShell: Copy-Item .env.example .env
docker compose up -d # or: npm run db:up / make up
npm run migrate # goose up + sqlc (loads root .env)
npm install && npm run dev
```
Migrate wrappers: `bash scripts/migrate.sh` · `.\scripts\migrate.ps1` · `make migrate` (all call `scripts/migrate.mjs`).
### Worker and `/readyz`
`npm run dev` starts **API + web + worker**. Processing jobs and `GET /readyz` need that worker heartbeat (stale after **60s**).
| Script | What runs |
|--------|-----------|
| `npm run dev` / `npm run dev:app` | api + web + worker |
| `npm run dev:backend` / `make backend` | api + worker (no web; enough for `/readyz`) |
| `npm run dev:api` | api only → `/readyz` 503 until a worker is started |
| `npm run dev:worker` | worker only |
| `make worker` / `.\scripts\run-api.ps1 worker` | worker only |
### Verify
```bash
npm run health
# or:
curl -sS http://127.0.0.1:28471/healthz
curl -sS http://127.0.0.1:28471/readyz
```
Open the app: [http://localhost:28472](http://localhost:28472). Demo seed: `npm run seed`.
### Split processes (optional)
```bash
npm run dev:web # web only
npm run dev:api # API only (readyz 503 without worker)
npm run dev:worker # worker only
npm run dev:backend # api + worker
npm run dev:ps1 # PowerShell: api + web + worker
```
### OS notes
- **Windows / macOS / Linux Docker details** (Desktop vs Engine, WSL2, ports): [docs/docker.md](docs/docker.md).
- **Windows:** Docker Desktop running; use `npm run setup` / `npm run migrate` / `npm run seed` (Node) — no Git Bash required. Optional: `.\scripts\migrate.ps1`, `.\scripts\dev.ps1`.
- **macOS / Linux:** same npm commands; `make setup` / `make migrate` work if Make is installed.
- **WSL2:** Docker Desktop WSL integration or Linux engine; keep `DATABASE_URL` on `localhost:5433` from the same environment as the API.
### Troubleshooting: `/readyz` returns 503
`GET /healthz` = process liveness. `GET /readyz` = Postgres ping **and** a fresh worker heartbeat (`worker_id=processing`, stale after **60s**). On worker failure the JSON keeps a short `error` and adds operator `reason` (how to start the host worker). See also [docs/ops-runtime.md](docs/ops-runtime.md) and [docs/production-checklist.md](docs/production-checklist.md).
| Symptom | Meaning | Fix |
|---------|---------|-----|
| `/healthz` 200, `/readyz` 503, `checks.worker` = `missing`, error `worker heartbeat missing` | API up, **worker never started** (or migrations before `039_worker_heartbeats`) | Use `npm run dev` (includes worker), or `npm run dev:worker` / `make worker`; ensure goose is up through **039**. Read JSON `reason`. |
| `/readyz` 503, `checks.worker` = `stale`, error `worker heartbeat stale` | Worker was up but heartbeat older than 60s | Restart the worker; confirm it stays running. Read JSON `reason`. |
| `/readyz` 503, `checks.database` = `fail` / `unavailable` | DB down or bad `DATABASE_URL` | `docker compose ps`, fix URL (host **5433**), re-run migrate |
| `/readyz` still 503 after starting worker | Heartbeat table missing or wrong DB | Re-run migrate; confirm worker and API share the same `DATABASE_URL` |
**Expected:** API-only local (`cmd/api` without `cmd/worker`, or `npm run dev:api`) → `/readyz` **503**. That is not a broken API binary — start the worker (`npm run dev`, `npm run dev:backend`, or `npm run dev:worker`) before treating readiness as green. Jobs on `/processing` also need the worker. Compose does **not** start the worker (Postgres only).
### Routes
| Path | Purpose |
|------|---------|
| `/` | Public marketing homepage (sell copy, FAQ, pricing teaser; no app shell) |
| `/pricing` | Public marketing pricing (Free→Enterprise; no client deals) |
| `/features` | Optional features deep-dive (not primary nav) |
| `/privacy`, `/terms` | Legal pages |
| `/login`, `/register` | Auth (login success → `/dashboard`) |
| `/dashboard` | App home (sidebar shell) |
| `/plans` | In-app plans (authenticated) |
| `/standard-fields`, `/feeds`, `/feeds/{id}/mapping` | Catalog ingest + mapping |
| `/products`, `/processing` | Catalog + background process jobs |
| `/export-feeds` | Outbound CSV/XML templates + generate |
| `/stores`, `/stores/shopify` | Store connectors hub (Woo, Shopify sibling, feed URL, CSV) |
| `/campaigns`, `/seo`, `/brand`, `/marketing/calendar` | Marketing suite |
| `/reviews` | Alias to WooCommerce Reviews tab |
| `/admin/*` | Platform admin |
### Demo login (migrated staging data)
Alias `demo@descrybe.test` is also seeded. Platform admin + **admin of Platform Demo only** (not A1). Default session company: **Platform Demo**. Act for A1 via Admin → Users → Switch to user (`a1-primary@descrybe.local`). Details: [docs/demo-user.md](docs/demo-user.md), [docs/safe-test-fixtures.md](docs/safe-test-fixtures.md).
```bash
npm run seed
# or: node scripts/seed-local.mjs
# or: pwsh -File .\scripts\seed-local.ps1
```
## Migrations
Prefer the cross-platform script (loads root `.env`):
```bash
npm run migrate
# equivalents: node scripts/migrate.mjs | make migrate | .\scripts\migrate.ps1
```
Manual:
```bash
cd apps/api
go run github.com/pressly/goose/v3/cmd/goose@v3.24.3 -dir sql/schema postgres "$DATABASE_URL" up
sqlc generate
```
## Migrator
Live MySQL → staging Postgres load **succeeded** (2026-08-03); production cutover is still **NO-GO** until emails/roles/SMTP login are proven. Evidence: [docs/migration-run-log.md](docs/migration-run-log.md).
```bash
cd apps/api
go run ./cmd/migrator -mysql "$MIGRATE_MYSQL_DSN" -postgres "$DATABASE_URL" -dry-run
```
## Docs
- **[Local setup (README)](README.md#local-setup-any-os)** — any-OS Docker/Node/Go/migrate; `/readyz` 503 troubleshooting
- **[docs/getting-started.md](docs/getting-started.md)** — operator checklist: login → feed → process → export
- **[docs/store-connectors.md](docs/store-connectors.md)** — Woo / Shopify / feed URL / CSV / export REST
- **[docs/marketing-suite-user-guide.md](docs/marketing-suite-user-guide.md)** — seasons, Black Friday in 5 clicks, tutorial start
- **[docs/free-tier.md](docs/free-tier.md)** — Free plan 0 AI credits + marketing gates
- **[docs/green-chat-ai.md](docs/green-chat-ai.md)** — Green Chat / OPENAI_BASE_URL for processing + campaign AI
- **[docs/mock-llm.md](docs/mock-llm.md)** — Tiny OpenAI-compatible stub (`cmd/mock-llm`) for CI/dev processing without production keys
- [Email sending](docs/email-sending.md) — Resend/SMTP, encryption, dry-run
- **[docs/process-and-sell-summary.md](docs/process-and-sell-summary.md)** — process & sell E2E test path (standard fields, sync/process, EPREL, export, public API)
- **[docs/demo-user.md](docs/demo-user.md)** — demo login + company data counts for staging testing
- **[docs/woocommerce-demo.md](docs/woocommerce-demo.md)** — Woo store setup, WOO_* env, seed-woo-demo, audience/campaigns
- **[docs/go-live-checklist.md](docs/go-live-checklist.md)** — go/no-go cutover checklist (design, stubs, migrate, set-password)
- [docs/migration-run-log.md](docs/migration-run-log.md) — live dry-run + staging load report
- [docs/status-and-gaps.md](docs/status-and-gaps.md) — what works, what's stubbed, what's missing, priority order
- [docs/design-gaps.md](docs/design-gaps.md) — UI/UX parity vs legacy
- [docs/migration-readiness.md](docs/migration-readiness.md) — ETL status + post-import set-password
- [docs/features.md](docs/features.md) — phase checklist
- [docs/schema-map.md](docs/schema-map.md) — MySQL → Postgres ID maps
- [docs/cutover.md](docs/cutover.md) — production cutover runbook
- [docs/ops-runtime.md](docs/ops-runtime.md) — SMTP, sessions, Woo encryption
## Offline category prompt translations and A1 cleanup
Run `npm run migrate`, then `npm run seed:category-prompts:i18n -- -dry-run`
for a preview or `npm run seed:category-prompts:i18n` to apply. This uses
pretranslated local resources for all 25 content languages, **no OPENAI_API_KEY
and no external translation service**. New default categories reuse translations
from the shared DB cache; custom company prompts are preserved. The same seed
upgrades recognizable obsolete A1 benefit boilerplate to the semantic SEO
body, including previously half-cleaned templates and empty JSON columns.
Unrelated custom descriptions, titles and meta rules remain untouched. Optional
standalone A1 command:
`npm run cleanup:a1:prompts -- -apply`. Future A1 seed/WordPress imports now
normalize duplicates on ingest. See `docs/category-prompt-translations.md`.
## SEO product formulas v4 (25 content languages)
All supported languages now use the same **semantic product-page HTML skeleton** with
localized instructions in `{...}`: one verified introductory `<p>`, an optional
feature `<h2>` and `<p>` when product facts justify them, then an optional technical
specification `<h2>` and `<ul><li>` list. Never generate an `<h1>` inside the
body, an empty list, fabricated product claims, or repeat a fixed number of
100-word sales sections. Product `name`, `meta_title`, and `meta_description` are
separate **plain-text JSON fields**, not HTML in the body. Keep structured data,
product-page H1, and the real page heading in the storefront template.
`apps/api/internal/aiprompts/defaults/prompt-rules-25.json` is the canonical
**offline** set of 25 language versions; the category editor examples carry the
same instructions. The API now parses the `<ul><li>` formula as one list section,
keeps optional sections optional during validation, and prefers the category
formula over generic short-copy system instructions. Translations do not require
an OpenAI key (product *generation* still uses the configured AI integration).
After deploying the API, worker, web frontend, and running migration scripts:
```bash
npm run migrate
npm run seed:category-prompts:i18n -- -dry-run
npm run seed:category-prompts:i18n
```
Only prompts identifiable as unchanged built-in defaults are upgraded; custom
company formulas are preserved. A1's recognizable historical repeated boilerplate
is repaired by the seed, and can also be repaired independently with:
```bash
npm run cleanup:a1:prompts -- -apply
```
**Existing processed products are not rewritten by a prompt seed**. Reprocess
those products to regenerate descriptions, where the company has AI processing
configured. A1 and the Platform Demo currently have a separate deliberate
backend rule that omits SEO meta from their processed product fields: updating
prompt instructions alone does not change that store-level policy.
## A1 empty-JSON / partially cleaned category fix (Oct 14, 2026)
Earlier versions of the offline seed reported `unexpected end of JSON input`
for A1 categories whose `description_template` column was empty. It also missed
A1's two- or three-pair historical prompts and left mixed 100-word and third-
benefit instructions visible in the editor. Both defects are fixed.
After deployment, preview and repair **only A1**, without touching any other
tenants' prompts (no migration or OpenAI key needed for this code-only fix):
```bash
npm run cleanup:a1:prompts
npm run cleanup:a1:prompts -- -apply
```
Alternatively, `npm run seed:category-prompts:i18n` incorporates the same
A1 cleanup when the global offline defaults should also be seeded. Re-running
either command is safe. No existing processed product descriptions are changed
until they are processed again. Only recognizable A1-imported boilerplate is
replaced; category-specific title/meta rules are preserved.
Regression coverage includes the exact reported partially cleaned Slovenian
prompt, missing description-template JSON, redundant HTML H1, old 3–10 technical
specification lists, structured-formula metadata, and idempotence. The bundled
`scripts/seed/a1-category-prompts.json` was normalized as well.