CLAUDE.md 10 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

SmartBotic is a workflow automation and execution platform with a microservices architecture. The backend is C++20 with gRPC communication, and the frontend is React/TypeScript.

Build Commands

C++ Backend

zeus cannot build this project on the host. It is Void Linux with no apt and none of the build dependencies, so cmake -S . -B build fails at configure time in FindPkgConfig. The build happens in Docker:

packaging/build.sh                  # build the .deb and the smartbotic-automation image
packaging/build.sh --rebuild-base   # also rebuild the build-base image (after a pin bump)

The stale build/ directory and the ./build/smartbotic-* binaries in it are leftovers from September, when the services ran from the host. Do not trust them - they are months old and link a client two minor versions behind.

For a quick compile check without producing a deb, build inside the base image:

docker run --rm -v "$PWD":/src -w /src smartbotic-automation-build-base:debian13 sh -c \
    'cmake -S . -B /tmp/b -G Ninja -DCMAKE_BUILD_TYPE=Release && cmake --build /tmp/b -j8'

The services run as Docker containers, not under runit. /etc/sv/smartbotic-* still exists but is not linked into /var/service, so sv restart acts on a service that is not the one serving traffic - and says nothing:

cd deploy/zeus && docker compose -f docker-compose.services.yml up -d
docker compose -f docker-compose.services.yml logs -f smartbotic-webserver
docker ps --filter name=smartbotic

There is no systemctl on zeus at all - it answers "command not found", which reads like a typo rather than the wrong init system. The systemd/user/*.service units are leftovers from when the services ran on mulan, and the runit scripts are leftovers from the step after that.

Tests

./scripts/run-node-tests.sh      # every node, through a running webserver + runner
./scripts/run-cpp-tests.sh       # pure C++ logic, compiled in the build image
python3 scripts/verify-db-212x.py  # database 2.12.x behaviour, needs the live stack

run-cpp-tests.sh compiles each tests/cpp/*_test.cpp in the build image, so a test needing a toolchain brings its own; a test names extra sources on a // sources: line and extra link flags on a // libs: line. storage_read_failures_test.cpp is written against the client 2.12.4 read contract and is expected to FAIL on 2.12.0 - see packaging/Dockerfile.base. verify-db-212x.py covers what a unit test cannot show - concurrent increments, a watcher ignoring its own writes while still seeing other people's, and a refusal arriving classified.

Node tests need the services up, and SMARTBOTIC_RUNNER_API is now always required, not just when the two are on different hosts: they are separate containers, so the runner's localhost is itself and the default leaves four cases failing with "Could not connect to server (http://localhost:8090/...)", which reads like the webserver is down when it is serving fine.

SMARTBOTIC_RUNNER_API=http://smartbotic-webserver:8090 ./scripts/run-node-tests.sh

That host name is the compose service name, the same value the runner already gets as WEBSERVER_ADDRESS. See the {{API}} note under Relocating a service.

Frontend (webui/)

cd webui
npm install
npm run dev      # Dev server (port 3000, proxies to localhost:8090)
npm run build    # Production build
npm run lint     # ESLint

Running Services

The database is not built from this repo - it is the standalone upstream smartbotic-database daemon. It runs on zeus as the Docker container smartbotic-db (moved there 2026-08-09; it and the SD.cpp REST API could not share mulan's memory), so it is neither an APT package nor a system service on the host any more. It is already up; the in-repo services connect to it:

# 1. Database daemon - Docker container `smartbotic-db` on 9004. Not from this repo.
docker ps --filter name=smartbotic-db

# 2. WebServer (HTTP 8090, WebSocket 8091, gRPC 9012 + 9013)
# 3. Runner (gRPC 9011)
# Both are containers from smartbotic-automation:current, not runit services.
docker ps --filter name=smartbotic

Relocating a service

No service may assume another is on the same host. Every address a service needs is an env override, and both runit run scripts (/etc/sv/smartbotic-*/run) state all of them explicitly even where the value is the local default - so moving a service to another machine for load balancing or failover is an edit of one file, not a hunt through the code.

variable service what breaks when it is wrong
DATABASE_ADDRESS both no persistence at all; fails loudly
WEBSERVER_ADDRESS runner the runner never registers
NODE_SYNC_ADDRESS runner no node updates reach it
CREDENTIAL_SERVICE_ADDRESS runner credentials and workflow-control fail
ADVERTISE_ADDRESS runner fails silently - the runner registers as localhost:<port>, reports online, and every dispatch goes to the webserver's own host
NODES_PATH runner no built-in nodes
WEBUI_PATH webserver the UI 404s, the API still works

config/*.json is tracked in git and its defaults are all localhost, so it must not be edited per host. config/*.local.json is gitignored but nothing reads it - the mechanism is ${VAR:default} substitution.

Tests must not assume co-location either. A case whose node fetches the API writes {{API}}, which the harness substitutes from SMARTBOTIC_RUNNER_API. Three cases hardcoded http://localhost:8090 and broke the day the runner moved.

SD.cpp stays on mulan (https://mulan:8077) because that is where the GPU is. zeus needs its self-signed certificate in two stores - the trusted-certificate store for host mulan (for the runner) and the system CA store (for the test harness's Python probe).

Both the database address and the project namespace are configurable everywhere, via config/webserver.json and config/runner.json:

Key Default Env override
database_address localhost:9004 DATABASE_ADDRESS
database_project smartbotic-automation DATABASE_PROJECT

One smartbotic-database instance is shared by several projects. database_project is the multi-tenant namespace (upstream client >= 2.3): the client transparently sends every collection as <project>:<collection>, so our data stays isolated from other services on the same daemon. Never set it to default - that is the shared back-compat namespace where projects collide.

Architecture

Two In-Repo Services + External Database

  1. WebServer Service (src/webserver/) - HTTP REST API, WebSocket for real-time updates, JWT auth, runner registry
  2. Runner Service (src/runner/) - Workflow execution engine with QuickJS for JavaScript node evaluation

Both persist through the external smartbotic-database daemon (upstream repo: ssh://git@git.smartbotics.ai:10022/fszontagh/smartbotic-database.git), consumed as the libsmartbotic-db-client-dev APT package. cmake/FindPackages.cmake locates it via find_package(smartbotic-db-client CONFIG REQUIRED) → target smartbotic::db-client. lib/storage/storage_client.{hpp,cpp} is a thin PIMPL adapter over smartbotic::database::Client, so callers never touch the upstream API directly.

Data Flow

WebUI (React) → HTTP/WebSocket → WebServer → gRPC → smartbotic-database (external)
                                     ↓
                              gRPC → Runner(s) → executes workflows

Key Directories

  • lib/ - Shared libraries (common utilities, config loader, logging, storage client)
  • proto/ - Protocol Buffer definitions for gRPC services
  • src/ - Microservice implementations
  • nodes/ - Built-in workflow node definitions (JavaScript modules)
  • webui/ - React frontend
  • config/ - Runtime JSON configuration files

Node System

Workflow nodes are JavaScript modules in nodes/ with this interface:

module.exports = {
  configSchema: { /* JSON Schema */ },
  inputSchema: { /* JSON Schema */ },
  outputSchema: { /* JSON Schema */ },
  execute: async (config, input, context) => { /* returns output */ }
}

Nodes are loaded by the Runner service and executed in QuickJS. Hot-reload is supported.

See docs/nodes.md for complete node creation guide.

See docs/node-roadmap.md for nodes worth building next.

Migrating Nodes to Database

After creating or modifying nodes in nodes/, migrate them to the running database:

# 1. Login to get JWT token
TOKEN=$(curl -s http://localhost:8090/api/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "admin"}' | jq -r '.accessToken')

# 2. Migrate nodes from filesystem to database
curl -X POST http://localhost:8090/api/v1/nodes/migrate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"nodesPath": "./nodes"}'

# 3. Verify nodes are loaded
curl -s http://localhost:8090/api/v1/nodes \
  -H "Authorization: Bearer $TOKEN" | jq '.nodes[] | "\(.id) - \(.name)"'

Runners automatically receive node updates via gRPC streaming - no restart required.

Configuration

Services load JSON configs from config/ directory:

  • webserver.json - HTTP port, JWT settings, runner load balancing, database_address
  • runner.json - Runner ID, max concurrent executions, hot reload settings, database_address

The database daemon has its own config at /etc/smartbotic-database/config.json, owned by the upstream package - not by this repo.

Environment variables can override config values using ${VAR_NAME:default} syntax.

C++ Standards

  • C++20 required (strict compliance, no extensions)
  • Compiler warnings: Wall, Wextra, Wpedantic
  • Key libraries: gRPC, Protobuf, cpp-httplib, QuickJS, spdlog, nlohmann/json, bcrypt

Frontend Stack

  • React 18.2 + TypeScript + Vite
  • State: Zustand + React Query
  • UI: TailwindCSS + Lucide icons
  • Workflow editor: ReactFlow