# CLAUDE.md - smartbotic-vectorapi C++20 REST API fronting `smartbotic-database` (gRPC) for n8n + other clients. Stores RAG vectors + JSON, organized into **projects** with **multi-key per-project-grant auth**. React admin UI. Ships as Debian `.deb`s. ## Build / test / run ```bash # Backend + web UI (Release) cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_WEBUI=ON -S . cmake --build build -j"$(nproc)" # Tests (GoogleTest). Integration tests need a running smartbotic-database on localhost:9004; # they GTEST_SKIP() cleanly if it's unreachable. BUILD_WEBUI=OFF to skip the npm build during test cycles. cmake -B build -G Ninja -DBUILD_TESTS=ON -DBUILD_WEBUI=OFF -S . && cmake --build build -j"$(nproc)" ctest --test-dir build --output-on-failure # Run locally (use the repo's api/ for /openapi.json,/llms.txt,/docs and the built UI) SMARTBOTIC_VECTORAPI_KEY=dev ./build/src/smartbotic-vectorapi \ --config config/config.json --share-dir "$PWD/api" --webui-dir "$PWD/build/webui/dist" # Native host build: clang, the whole repo including the runner, ~100 s, and the # compile_commands.json that clangd reads. Development only - it links the # host's protobuf/gRPC, not the versions the .deb is built against. scripts/host-build.sh --client # --client also rebuilds libsmartbotic-db-client into the prefix scripts/host-build.sh --test # + ctest, SERIALLY (see the ApiFixture note below) # Web UI only cd webui && npm install && npm run build # → webui/dist ; `npm run dev` for the :3000 proxy dev server # Local backend for UI work, or when you want Debian's exact toolchain # packaging/devstack: DB + API from the release .debs in a Debian 13 container. docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svapi-devstack ``` ## Architecture (where things live) - `src/` - the server. `vectorapi_core` static lib + `main.cpp`. Namespace `svapi`. Flat headers, quoted includes. - `db_gateway` (`qualify(project,coll)` + `DbGateway` over `smartbotic::database::Client`), `settings_store` (global settings **and per-project embedding overrides**, hot-reload, one subscribe stream for both), `project_settings` (`ProjectEmbeddingSettings` + the pure `resolveEmbedding()`), `outbound_http` (User-Agent + TLS defaults for every external call), `key_store` (API keys, hot-reload, bootstrap admin key), `collection_registry` (per-project metadata), `embeddings` (OpenAI), `auth` (sessions, bearer/cookie), `server` (ApiServer + auth helpers), `handlers/*` (one file per route group). - Auth model: pre-routing **authenticates** `/api/*` (401); each handler **authorizes** via `requireKey` → `requireAdmin` / `requireProjectAccess` (403). Keys are referenced by a stable **`id`** (not the secret). **CONSEQUENCE WORTH KNOWING BEFORE YOU PROBE ANYTHING: an unauthenticated request to a NONEXISTENT `/api/*` path answers 401, not 404**, because the pre-routing filter runs before routing and never consults the route table. So a 401 cannot distinguish "the route exists and I lack a key" from "there is no such route" - and reading one as "the service is alive" is a check that answers confidently about a different question. Measured during the 0.12.0 deploy: `/api/v1/healthz` gave 401 unauthenticated and **404 with a valid admin key**, because the health route is `/healthz` and is NOT under `/api/`. Probe liveness at `/healthz`, and when a path matters, send a key so the 404 can reach you. - `webui/` - React 19 + Vite + TS (strict, `erasableSyntaxOnly`) + Tailwind + Monaco. **`npx tsc --noEmit` is NOT the build check** - it passed on a malformed import that `npm run build` (`tsc -b && vite build`) rejected, because the project build uses different settings. Verify a UI change with `npm run build`. - **A `Functions` settings tab exists and is ADMIN-ONLY**, matching its route (`requireAdmin`, not `requireProjectManage`): it bounds what one project may take from a runner every other project shares. It carries the per-kind wall caps and `network_egress`, both of which were previously reachable only by curl - and a control nobody can see is a control nobody knows exists, which mattered most for egress, where an operator could not tell whether a project's functions had outbound access. Egress renders THREE states, because `network_egress` is the effective value and `network_egress_set` says whether it was chosen or inherited: "allow (inherited)" is a different statement from "allow, set here". An empty wall-cap field means NO project cap, which is not a cap of zero, so it is held as a string to keep an empty input and a zero distinguishable all the way to the request. - **The documents filter builder DISABLES the field input for `search`**, rather than annotating it. `search` ignores the field - it is a case-insensitive substring over the whole document, id and keys included - and the three inputs read as field/op/value, which asserts a scope it does not have. A control that cannot affect the result must not look like it can. The hint points at `regex` for a field-scoped substring, and `contains` gets its own hint because array membership is equally easy to misread as a substring. - `SaveButton` IS a `