Services
Last updated April 7, 2026
The platform services: what runs, what ports they bind, how they compose.
KB Labs is not a monolith. It's a small collection of focused services that talk to each other over HTTP (and one WebSocket tunnel for the host agent). Each service is independently deployable, has its own manifest, and can be started via kb-dev.
The service map
┌──────────────────┐
│ Studio :3000 │ ← browser SPA
└────────┬─────────┘
│ HTTP + WSS
▼
┌──────────────────┐
│ Gateway :4000 │ ← central router
└────────┬─────────┘
│
┌─────────────┼─────────────┬──────────────┐
▼ ▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌───────────┐ ┌────────────┐
│ REST │ │ Workflow │ │Marketplace│ │ Host Agent │
│ :5050 │ │ :7778 │ │ :5070 │ │(user laptop)│
└─────────┘ └──────────┘ └───────────┘ └────────────┘
│ │ │ │
└─────────────┼─────────────┘ │
▼ │
┌───────────────┐ │
│ State Daemon │ │
│ :7777 │ │
└───────────────┘ │
│
◀─── WSS tunnel ───────┘The services
Long-running daemons
| Service | Port | Entry | What it does |
|---|---|---|---|
| Gateway | 4000 | infra/kb-labs-gateway | Central HTTP router, aggregates upstreams, auth termination, WebSocket dispatch |
| REST API | 5050 | platform/kb-labs-rest-api | Fastify service hosting plugin REST routes, platform endpoints, OpenAPI |
| Workflow Daemon | 7778 | platform/kb-labs-workflow/packages/workflow-daemon | Workflow engine, job broker, cron scheduler, approvals API |
| Marketplace | 5070 | platform/kb-labs-marketplace | Install, uninstall, discover entities; manages .kb/marketplace.lock |
| State Daemon | 7777 | platform/kb-labs-core/packages/core-state-daemon | State Broker HTTP server for distributed rate limiting and quotas |
User-invoked
| Service | Entry | What it does |
|---|---|---|
| CLI | platform/kb-labs-cli | The kb command — loads plugins, dispatches commands, renders output |
| Studio | platform/kb-labs-studio/apps/studio | React SPA, hosts plugin pages via Module Federation |
End-user daemons
| Service | Entry | What it does |
|---|---|---|
| Host Agent | infra/kb-labs-host-agent | Runs on developer laptops, tunnels local filesystem and git to cloud workflows |
Shared patterns
Every daemon in the platform follows the same bootstrap template:
- Detect the monorepo root (walk up from
cwdlooking forpnpm-workspace.yaml). - Load
.envfrom the repo root. - Call
createServiceBootstrap({ appId, repoRoot })from@kb-labs/core-runtime— this initializes the global platform singleton (adapters, logger, cache, storage, everything fromkb.config.json). - Build a correlated logger with
serviceId: '<name>'bindings — every log line from the service has the sameserviceId,logsSource, andlayerfields. - Construct whatever business logic the service owns (registry, engine, job broker, whatever).
- Create a Fastify instance with
@kb-labs/shared-httphelpers (OpenAPI, health, readiness, metrics). - Register routes.
- Listen on the configured port.
- Wire
SIGTERM/SIGINTfor graceful shutdown.
This sameness is deliberate. If you've read one service's bootstrap, you've read them all — the differences are in the routes and the business logic, not in the plumbing.
Service manifests
Every long-running daemon (except the host agent) ships with a ServiceManifest that tells kb-dev how to manage it:
interface ServiceManifest {
schema: 'kb.service/1';
id: string; // used as key in dev.config.json
name: string;
version: string;
description?: string;
runtime: {
entry: string; // dist/index.js
port: number;
healthCheck: string; // path, appended to http://localhost:<port>
protocol?: 'http' | 'ws'; // default 'http'
};
dependsOn?: string[]; // service IDs that must start first
env?: Record<string, ServiceEnvVar>;
}Source: infra/kb-labs-plugin/packages/plugin-contracts/src/manifest.ts.
kb-dev reads these manifests, generates a dev.config.json, and uses it to manage the process lifecycle. See Configuration → dev.config.json for the consumer side.
Starting everything
kb-dev start # start all services + infrastructure (Qdrant, Redis, etc.)
kb-dev status # see what's running
kb-dev logs rest -f # tail REST API logs
kb-dev stop # stop everythingOr start individual services:
kb-dev start rest
kb-dev start workflow --force # kill any conflicting process on the port firstdependsOn is respected — starting rest will boot qdrant first because REST depends on it.
What's NOT a service
Two things you might expect to find in this list but won't:
- Plugins are not services. Plugins are loaded inside the CLI, REST API, and workflow daemon. Their code runs as part of those services, not as separate processes.
- Adapters are not services. Adapters are libraries loaded at service bootstrap time. Each service has its own adapter instances, sharing config but not runtime state.
What to read next
- Gateway — the service everything else sits behind.
- Configuration → kb.config.json — the platform config every service loads.
- Configuration → dev.config.json — the
kb-devservice definitions. - The individual service pages linked in the table above.