|
1 | | -# Agent instructions -- WebsiteProfiling |
| 1 | +# Agent instructions — Site Audit (WebsiteProfiling) |
2 | 2 |
|
3 | | -**What it is:** `python -m src` from repo root (`src/__main__.py` -> package **`website_profiling`**). Config: stored in **`report.db`** (`pipeline_config` table, `key/value/is_unknown/updated_at`). A shadow **`pipeline-config.txt`** is auto-written next to `report.db` on every Save/Run. CLI loads DB first (`REPORT_DB_PATH` or `cwd/report.db`), then shadow file; `--config` overrides with a file. Reference keys: `input.txt.example` (not auto-loaded). |
| 3 | +**What it is:** `python -m src` from repo root (`src/__main__.py` -> package **`website_profiling`**). Config: stored in **PostgreSQL** (`pipeline_config` table, `key/value/is_unknown/updated_at`). A shadow **`pipeline-config.txt`** is auto-written to `DATA_DIR` on every Save/Run. CLI loads DB first (`DATABASE_URL`), then shadow file; `--config` overrides with a file. Reference keys: `input.txt.example` and `pipeline-config.example.txt` (not auto-loaded). |
4 | 4 |
|
5 | | -**Frontend:** **`web/`** (Next.js) -- server reads `report.db` via `/api/report/*`. |
| 5 | +**LLM / AI:** Settings live in **`llm_config`** table in PostgreSQL. Configure only via web UI **AI** tab (`GET/PUT /api/llm-config`, localhost). Never in `pipeline-config.txt` or `--config`. |
| 6 | + |
| 7 | +**Frontend:** **`web/`** (Next.js) -- server reads PostgreSQL via `/api/report/*`. |
6 | 8 |
|
7 | 9 | **Key paths** |
8 | 10 |
|
9 | | -- `src/website_profiling/` -- `cli.py`, `config.py`, `crawl/`, `db/storage.py`, `lighthouse/`, `reporting/`, `ml/enrich.py`, `tools/` |
10 | | -- `web/app/` -- routes; `web/src/` -- React; pipeline: `PipelineRunnerFab`, `server/pipelineJobs.js`, `server/pipelineConfig.js` |
| 11 | +- `src/website_profiling/` -- `cli.py`, `config.py`, `crawl/`, `db/storage.py`, `lighthouse/`, `reporting/`, `analysis/`, `llm/`, `tools/` |
| 12 | +- `web/app/` -- routes; `web/src/` -- React; pipeline: `PipelineRunnerFab`, `server/pipelineJobs.ts`, `server/pipelineConfig.ts`, `server/llmConfig.ts`, `server/db.ts` |
| 13 | +- `alembic/` -- schema migrations |
| 14 | + |
| 15 | +**Local dev:** `./local-run` (Postgres in Docker `wp-pg`, Next.js on host). See `scripts/local-run.sh`. **Local tests (CI parity):** `./local-test` — see `scripts/local-test.sh`. |
11 | 16 |
|
12 | 17 | **Run / APIs** |
13 | 18 |
|
14 | | -- Pipeline: `python -m src` — reads config from `report.db` (`pipeline_config`); shadow `pipeline-config.txt` if table empty. CLI override: `python -m src --config path` |
15 | | -- Optional step: `crawl` | `report` | `plot` | `lighthouse` | `keywords` | `warnings` | `enrich` |
16 | | -- **`preserve_crawl_history`** (default true): append crawls; `false` recreates crawl tables but restores `report_payload`, Lighthouse, `google_data`, `keyword_data`, `keyword_history`, `keyword_suggest_cache`, and `crawl_runs` |
17 | | -- **`enrich_keywords_after_report`**: when omitted or `auto` (UI: Auto), follows `enable_google_search_console`; when set to Yes/No, explicit override |
18 | | -- **`REPORT_DB_PATH`** env: DB path used by both Python and Next.js (Docker: `/data/report.db`; local default: `report.db` at repo root). Pipeline config lives in this DB. |
19 | | -- **`web/`:** `/api/report/*` (SQLite); `/api/run` spawns Python (localhost only); `/api/pipeline-config` GET/PUT for persistent settings; `PipelineRunnerFab` saves state to `report.db` (`pipeline_config` table) + shadow `pipeline-config.txt` before each run |
20 | | -- **Docker:** `Dockerfile` + `docker-compose.yml`; **`LIGHTHOUSE_CHROME_FLAGS`**; ML caches under `/data/cache/*` in compose |
| 19 | +- Run audit (CLI): `python -m src` — reads config from PostgreSQL (`pipeline_config`); shadow `DATA_DIR/pipeline-config.txt` if table empty. CLI override: `python -m src --config path` |
| 20 | +- Optional step: `crawl` | `report` | `plot` | `lighthouse` | `keywords` | `warnings` | `enrich` | `google` |
| 21 | +- **`preserve_crawl_history`** (default true): append crawls; `false` truncates crawl tables but restores `report_payload`, Lighthouse, `google_data`, `keyword_data`, `keyword_history`, `keyword_suggest_cache`, and `crawl_runs` |
| 22 | +- **`DATABASE_URL`** env: PostgreSQL connection string (required). **`DATA_DIR`**: secrets + shadow config (Docker: `/data`). |
| 23 | +- **Pipeline data** (crawl, edges, nodes, report payload, Lighthouse, keywords, warnings) is stored in **PostgreSQL only** — no JSON/CSV/HTML exports from the main pipeline. |
| 24 | +- **Pool tuning:** `DB_POOL_MIN` / `DB_POOL_MAX` (Python), `PGPOOL_MAX` (Node). Bulk crawl writes via `executemany`; optional **`crawl_stream_to_db`** streams rows during fetch. |
| 25 | +- **`web/`:** `/api/report/*` (PostgreSQL); `/api/run` spawns Python (localhost only); `/api/pipeline-config` GET/PUT; `/api/llm-config` GET/PUT (AI only); `PipelineRunnerFab` saves pipeline + LLM state before each run |
| 26 | +- **Job store:** in-memory on `globalThis` in `web/src/server/pipelineJobs.ts` — job status/log is lost on server restart (single-process dev/Docker only). |
| 27 | +- **Docker:** `Dockerfile` + `docker-compose.yml` (postgres + web); **`LIGHTHOUSE_CHROME_FLAGS`** |
21 | 28 |
|
22 | 29 | **Where to edit** |
23 | 30 |
|
24 | 31 | | Task | Where | |
25 | 32 | |------|--------| |
26 | 33 | | Crawl | `crawl/crawler.py` | |
27 | 34 | | Report | `reporting/builder.py`, `reporting/categories.py` | |
28 | | -| DB schema | `db/storage.py` `init_schema` | |
29 | | -| ML | `ml/enrich.py`, `requirements-ml.txt` | |
| 35 | +| DB schema | `alembic/versions/` | |
| 36 | +| Local analysis | `analysis/local.py`, `requirements.txt` | |
| 37 | +| AI insights (LLM) | `llm/enrich.py`, `llm_config.py`, `requirements-llm.txt` | |
30 | 38 | | Config / CLI | `config.py` (`load_config`, `load_config_from_db`), `cli.py`, `input.txt.example` | |
31 | | -| UI config schema | `web/src/lib/pipelineConfigSchema.js` | |
32 | | -| UI config I/O | `web/src/server/pipelineConfig.js` | |
| 39 | +| UI pipeline schema | `web/src/lib/pipelineConfigSchema.ts` | |
| 40 | +| UI LLM schema | `web/src/lib/llmConfigSchema.ts` | |
| 41 | +| UI config I/O | `web/src/server/pipelineConfig.ts`, `web/src/server/llmConfig.ts` | |
| 42 | + |
| 43 | +Schema changes: add Alembic migration (`alembic revision`). |
33 | 44 |
|
34 | | -Schema changes: edit `init_schema` only (no migration layer). ML stack: prefer Python **3.12** for spaCy/blis; **3.13** may fail pip builds. |
| 45 | +**Company standards:** UI copy in `web/src/strings.json` (Site Audit, Properties, Run audit). Data provenance on `report_meta` in report payload. Docs: `docs/COMPANY_STANDARDS.md`, `docs/GLOSSARY.md`. Migration `003_company_standards` (properties, pipeline_jobs, audit_log). Durable jobs in `web/src/server/pipelineJobsDb.ts`. Export: `GET /api/report/export`, `src/website_profiling/tools/export_audit.py`. |
0 commit comments