RCMbox Docs

Billing API

The Billing API is an HTTP server (Fastify) that serves as the control plane for RCMbox. It triggers workflow execution, manages the config project via git, serves the admin UI, and handles inbound webhooks from subscription triggers.

Responsibilities

AreaWhat the API does
Workflow runsStarts workflows via Temporal, returns run status and activity outputs
Config projectClones the repo, creates branches and worktrees, pushes changes
TriggersReceives Aidbox subscription webhooks, runs input mapping, starts workflows
ActivitiesLists available activities (built-in and project-specific) with metadata
Validation rulesLists validation rules from the config project manifest
AI agentSpawns Claude Code sessions scoped to a branch worktree

Key endpoints

Workflow execution

MethodPathPurpose
POST/workflows/:id/runTrigger a workflow with input parameters
GET/workflows/:id/runsList all runs for a workflow
GET/workflows/:id/runs/:runIdGet run details with activity outputs
GET/workflowsList all workflow definitions

Config project management

MethodPathPurpose
POST/repo/syncClone or pull the config repo
GET/repo/statusCurrent commit, branch, and remote URL
GET/repo/branchesList remote branches
POST/repo/branchesCreate a new branch with worktree
POST/repo/worktreesCreate worktree for existing branch
POST/repo/pushPush a branch to remote
GET/repo/diffView changes vs main
GET/repo/commitsCommit history for a branch
POST/repo/sync-built-inSync built-in activity type declarations

Triggers and webhooks

MethodPathPurpose
GET/triggersList all subscription and schedule triggers
POST/triggers/syncRegister trigger definitions with Aidbox
POST/triggers/:triggerId/webhookReceive Aidbox subscription events

AI agent

MethodPathPurpose
POST/agent/chatStart a Claude Code editing session
GET/agent/status/:workflowIdPoll agent execution status

Branch-aware routing

Every endpoint accepts an optional ?branch= query parameter. The API resolves the config project directory based on the branch:

  • Main branch — reads from /data/repo
  • Feature branches — reads from /data/worktrees/{branch-name}

This means the admin UI can browse workflows, activities, and validation rules from any branch without affecting production.

Webhook flow

When an Aidbox subscription fires:

  1. Aidbox sends a FHIR Bundle to POST /triggers/:triggerId/webhook
  2. The API extracts the modified resources from the bundle
  3. The trigger's input-mapping.ts script maps resources to workflow input parameters
  4. The API starts a Temporal workflow on the billing task queue

Startup tasks

On boot, the API:

  1. Syncs the config repo from GIT_REPO_URL (if configured)
  2. Registers itself as an Aidbox App (/App/ts-billing-app)
  3. Uploads seed resources (AidboxQuery definitions, FAR packages)
  4. Syncs trigger definitions from the config project

Access control via Aidbox App

The Billing API is not exposed directly to clients. Instead, it registers itself as an Aidbox App (ts-billing-app) on startup, and all endpoints are proxied through Aidbox's RPC protocol via POST /rpc. Each endpoint is registered as an Aidbox operation (e.g., ts-billing-app.run-workflow, ts-billing-app.repo-sync).

This means Aidbox manages all access control — authentication, authorization, and tenant scoping are handled by Aidbox's access policies before requests reach the Billing API. The admin UI and any external clients call Aidbox, never the API directly.

Configuration

VariableDefaultPurpose
API_PORT3000Server listen port
WORKFLOW_DIR/data/repoConfig project directory
BUILT_IN_DIR../built-in-activitiesBuilt-in activities path
WORKTREES_DIR/data/worktreesGit worktree storage
CONFIG_BRANCH(required)Main branch name
GIT_REPO_URLConfig repo URL for auto-sync
GIT_TOKENGitHub access token
TS_API_BASE_URLhttp://host.docker.internal:3000Public URL for Aidbox App registration

FHIR server and Temporal connection settings are shared with the worker — see Aidbox and Temporal.

See also

Last updated: