{"ok":true,"generator":"rulebook-to-node-postgres-api","rulebookName":"tetst","rulebookDescription":"A starter rulebook. Replace the HelloWhos entity with your own.","startHere":["GET /api/view-health  — confirm Postgres can plan every generated view","GET /api/integrity — run the full dangling-relationship audit separately from discovery","GET /api/tables/:table — read fields[], pkField, and one row; that is the contract","GET /api/rulespeak — the business rules in plain English","GET /api/source — the generated Postgres / API / portal source actually running here"],"conventions":[{"id":"read-snake-write-pascal","summary":"Reads return snake_case column names; writes take the rulebook’s PascalCase field names, or the same snake_case names.","detail":"GET /api/tables/:table returns rows keyed by Postgres column name (snake_case, e.g. total_sales). PATCH/POST bodies use the rulebook field name (PascalCase, e.g. TotalSales); the snake_case column name (total_sales) is accepted too and means the same field. Only raw and relationship fields can be written: a row read from a view also carries calculated and lookup fields, so send just the fields you change."},{"id":"calculated-fields-are-read-only","summary":"Calculated / lookup / aggregation fields cannot be written, and must not be recomputed client-side.","detail":"Write the raw inputs; the derived field recomputes in Postgres and comes back on the next read. Attempting to write one returns 400 with \"is not a raw field\". Re-deriving a calculated field in frontend code duplicates a business rule outside the rulebook — the exact failure mode this stack exists to prevent. Render the value; know nothing about why."},{"id":"select-only-the-fields-you-need","summary":"Name the fields a screen uses: ?fields=A,B,C. Postgres evaluates only the columns a read names.","detail":"GET /api/tables/:table?fields=Name,Status (and /rows/:id?fields=...) returns rows holding only those columns, the primary key, and the __fk_label of any relationship among them; fields[] stays the full schema and selectedFields lists what the rows carry. Every column left out skips its calc_* function, so a read that names three fields of a view with forty aggregations costs milliseconds where the whole row costs seconds. Ask for the whole row only on a record page that shows the whole row. ?fields= (empty) reads the pk alone: the cheapest way to learn a table’s shape and row count. An unknown field name is a 400."},{"id":"numerics-are-strings","summary":"Postgres numeric/decimal values arrive as JSON strings (e.g. \"250\").","detail":"Coerce with Number() for display, comparison, and sorting; send real JSON numbers on write."},{"id":"check-view-health-first","summary":"Every read goes through vw_<table>. The health route plans every view without executing the whole DAG.","detail":"GET /api/view-health before building against this API. Anything other than {\"ok\":true,\"brokenCount\":0} means the rulebook itself needs fixing — do not code around it. The probe uses EXPLAIN to validate the complete view shape without evaluating every calculated field merely to draw navigation. Row-dependent runtime errors still surface on the actual table read."},{"id":"no-push-refetch-after-rebuild","summary":"There is no websocket push to app clients; re-fetch after a rebuild.","detail":"Poll GET /api/admin/build-status until running:false, or subscribe to GET /api/admin/build-log/stream (SSE). Never cache schema or rows in module scope — the schema itself changes when the rulebook changes."},{"id":"cors-is-open","summary":"CORS allows all origins (only localhost ones when CORS_LOCALHOST_ONLY=1); a dev server can call this API directly.","detail":"No Vite/webpack proxy block is needed. With CORS_LOCALHOST_ONLY=1 (Loops Desktop) a page from any non-localhost origin gets 403 origin_not_allowed."},{"id":"table-set-changes-need-a-restart","summary":"The table LIST is read once at boot; formula and data changes are picked up live.","detail":"Adding or removing a TABLE and only triggering a rebuild leaves this API serving the previous table list (Postgres correct, API stale). Re-run the editor’s edit-rulebook.sh — it is the supported, idempotent stop/rebuild/restart cycle. Do not hand-roll `docker restart`."}],"tables":[{"name":"HelloWhos","description":"The smallest complete rulebook: an id, a display name, and a rule that derives a greeting from it."}],"routes":[{"methods":["GET"],"path":"/api/activity-log"},{"methods":["GET"],"path":"/api/admin/auto-save-setting"},{"methods":["PATCH"],"path":"/api/admin/auto-save-setting"},{"methods":["GET"],"path":"/api/admin/build-log/stream"},{"methods":["GET"],"path":"/api/admin/build-status"},{"methods":["GET"],"path":"/api/admin/editor-settings"},{"methods":["PATCH"],"path":"/api/admin/editor-settings"},{"methods":["POST"],"path":"/api/admin/run-build"},{"methods":["GET"],"path":"/api/admin/transpilers"},{"methods":["PATCH"],"path":"/api/admin/transpilers/:name"},{"methods":["POST"],"path":"/api/admin/transpilers/:name/run"},{"methods":["GET"],"path":"/api/admin/transpilers/:name/run-log/stream"},{"methods":["GET"],"path":"/api/admin/transpilers/:name/run-status"},{"methods":["POST"],"path":"/api/chat"},{"methods":["GET"],"path":"/api/custom/ping"},{"methods":["POST"],"path":"/api/discard-changes"},{"methods":["GET"],"path":"/api/docs"},{"methods":["GET"],"path":"/api/erb"},{"methods":["GET"],"path":"/api/erb/:erbTable"},{"methods":["POST"],"path":"/api/erb/:erbTable/rows"},{"methods":["PATCH"],"path":"/api/erb/:erbTable/rows/:id"},{"methods":["DELETE"],"path":"/api/erb/:erbTable/rows/:id"},{"methods":["GET"],"path":"/api/erb/drift"},{"methods":["GET"],"path":"/api/erb/modules/:name"},{"methods":["POST"],"path":"/api/erb/modules/:name/disable"},{"methods":["POST"],"path":"/api/erb/modules/:name/enable"},{"methods":["PATCH"],"path":"/api/erb/modules/:name/settings"},{"methods":["GET"],"path":"/api/erb/schema"},{"methods":["GET"],"path":"/api/erb/security/preview"},{"methods":["POST"],"path":"/api/erb/sync"},{"methods":["GET"],"path":"/api/health"},{"methods":["POST"],"path":"/api/import/xlsx"},{"methods":["GET"],"path":"/api/integrity"},{"methods":["PATCH"],"path":"/api/meta"},{"methods":["GET"],"path":"/api/rulebook/schema/:tableName"},{"methods":["GET"],"path":"/api/rulebook/tables"},{"methods":["GET"],"path":"/api/rulespeak"},{"methods":["POST"],"path":"/api/save-changes"},{"methods":["GET"],"path":"/api/source"},{"methods":["GET"],"path":"/api/source/:group/*"},{"methods":["GET"],"path":"/api/state"},{"methods":["POST"],"path":"/api/tables"},{"methods":["GET"],"path":"/api/tables/:tableName"},{"methods":["PATCH"],"path":"/api/tables/:tableName/column-order"},{"methods":["GET"],"path":"/api/tables/:tableName/csv"},{"methods":["POST"],"path":"/api/tables/:tableName/csv-import"},{"methods":["POST"],"path":"/api/tables/:tableName/fields"},{"methods":["POST"],"path":"/api/tables/:tableName/rows"},{"methods":["GET"],"path":"/api/tables/:tableName/rows/:rowId"},{"methods":["PATCH"],"path":"/api/tables/:tableName/rows/:rowId"},{"methods":["DELETE"],"path":"/api/tables/:tableName/rows/:rowId"},{"methods":["POST"],"path":"/api/tables/:tableName/rows/bulk-delete"},{"methods":["POST"],"path":"/api/tables/:tableName/rows/bulk-update"},{"methods":["GET"],"path":"/api/uncommitted-status"},{"methods":["POST"],"path":"/api/undo-last-change"},{"methods":["POST"],"path":"/api/view-error-assistant"},{"methods":["GET"],"path":"/api/view-health"}],"related":{"rulespeak":"/api/rulespeak","source":"/api/source","schema":"/api/rulebook/schema/:tableName","viewHealth":"/api/view-health","integrity":"/api/integrity"}}