bkr

architecture

Runtime architecture

How bkr wires the boomkat JS engine to uWebSockets, the native thread pool, and OS resources.

Single binary, embedded JS layer

bkr compiles the boomkat engine from source alongside its C3 runtime code into one executable. At startup, it creates a JS runtime and context, attaches native callbacks to an internal bridge object, evaluates the embedded web-standard prelude (Fetch, Streams, WebSocket, Worker, timers, events), and registers the built-in modules.

Async calls cross from JS into C3 by allocating a 32-bit operation ID paired with a rooted promise capability. When the native side finishes on the event loop, it resolves or rejects that ID, drains microtasks, and checks for unhandled rejections.

Event loop, thread pool, and resource table

Each execution thread owns its own runtime state and uSockets event loop (kqueue on macOS, epoll on Linux). Non-blocking TCP, TLS, HTTP, and timer events run directly on that loop.

Blocking work—filesystem calls, getaddrinfo DNS lookups, waitpid, Argon2id hashing, and crypto.subtle operations—runs on a shared 16-thread native pool and posts completions back to the originating loop.

Streamable handles (stdio, open files, sockets, listeners, child pipes) live in a per-runtime resource table. Each handle ID packs a 12-bit generation counter above a 20-bit slot index so a stale ID after close() never aliases a recycled slot.

HTTP fast paths

The HTTP server wraps uWebSockets through a thin C++ shim in shim/. Common cases skip JS allocations where possible:

Concurrency

Boomkat VMs are single-threaded and share no mutable JS heap across threads:

Optional dependencies and non-goals

On macOS, OpenSSL 3 is weakly linked and SQLite 3.31+ is loaded with dlopen. Plain HTTP and scripts that don't use TLS or SQLite run without either library installed; calling serve({ tls }), https:/wss:, or crypto.subtle without OpenSSL 3 throws with an install hint. On Linux, libssl.so.3 is required at startup.

bkr does not include a Node.js compatibility layer, CommonJS require, node_modules resolution, or remote HTTP imports. Every import specifier is a relative path, an absolute path, or a built-in module name.

Source layout

PathRole
runtime/main.c3, state.c3CLI entry point, argument parsing, bootstrap, thread-local runtime state
runtime/bridge.c3, guard.c3C3/JS marshalling, async op table, rejection tracker, --time-limit watchdog
runtime/loop.c3, timers.c3, immediates.c3uSockets loop glue, nanosecond timer heap, setImmediate queue, 16-thread pool
runtime/http.c3, ws.c3, file_body.c3, stream_sink.c3HTTP server, native route table, WebSocket upgrades, streaming file and sink paths
runtime/net.c3, tls.c3, res.c3TCP/TLS sockets, DNS resolution, OpenSSL verification, generation-tagged resource table
runtime/fs.c3, proc.c3, sqlite.c3Filesystem tasks, environment and child processes, SQLite 3.31+ loader and authorizer
runtime/crypto.c3, subtle.c3, transpile.c3Argon2id pool tasks, OpenSSL Web Crypto natives, TypeScript/JSX transpiler and source maps
runtime/perms.c3, sandbox.c3, toml.c3Permission matching, path canonicalization, interactive prompt, macOS Seatbelt profile, boomkat.toml
runtime/js/*.jsWeb-standard prelude and built-in ES module wrappers
shim/C/C++ shim over uWebSockets, OpenSSL EVP, and SCM_RIGHTS socket passing

Building from source

Requires a sibling checkout of ../boomkat, c3c (v0.8.5+), a C/C++ compiler, and OpenSSL 3:

bash scripts/build_uws.sh
c3c build bkr

This writes the release binary to out/bkr. project.json also defines bkr-opprof and bkr-opprof-th for builds with OP_PROFILE enabled (switch or threaded dispatch).

Related