Skip to content

Build your first module ​

A module adds behaviour to Bitstream without changing Bitstream. This guide copies the Hello example, changes one filter, packs it and installs it in the panel.

You need Go 1.26, Node 20 with pnpm, and a panel where you are an admin with 2FA set up. Field by field details are in the modules reference.

1. Copy the example ​

bash
cp -r examples/modules/hello examples/modules/greeter
cd examples/modules/greeter
rm -rf dist ui/build ui/node_modules hello-*.zip

What is inside:

PathWhat
module.jsonThe manifest: id, version, permissions, hooks, jobs, settings, strings.
backend/main.goThe backend. It talks JSON-RPC on stdin and stdout.
ui/The frontend: Vue components built into one ui/index.js.
build.shBuilds everything and packs hello-<version>.zip.

2. Edit module.json ​

Change at least these fields:

json
{
  "id": "greeter",
  "name": "Greeter",
  "version": "0.1.0",
  "permissions": ["streams:read"],
  "hooks": { "filters": [{ "name": "playlist" }], "events": [] },
  "jobs": []
}
  • Ask only for the permissions you use. The admin sees each one on the review screen.
  • Remove client_routes if you do not serve public URLs.
  • Keep bitstream as >=1.0.0 <2.0.0 unless you need something newer.

In ui/src/index.ts, change register('hello', ...) to register('greeter', ...). In build.sh, the zip name follows version, and the binary names follow backend.exec; rename them if you like.

3. Write a filter ​

Filters change data on its way to a viewer. The playlist filter gets every entry of a get.php playlist and returns the entries to write.

In backend/main.go, the filter function handles each hook. Replace the playlist case with one that hides adult groups:

go
case "playlist":
	var d map[string]any
	if err := json.Unmarshal(data, &d); err != nil {
		return nil, err
	}
	entries, _ := d["entries"].([]any)
	keep := []any{}
	for _, e := range entries {
		if g, _ := e.(map[string]any)["group"].(string); !strings.EqualFold(g, "adult") {
			keep = append(keep, e)
		}
	}
	d["entries"] = keep
	return map[string]any{"data": d}, nil

Rules to keep in mind:

  • You have 200 ms by default (timeout_ms). Do the slow work in a job or an event and keep the result in storage.
  • If your module fails, the playlist is sent without your change. That is fail-open, and usually what you want.
  • URLs carry {username} and {password} placeholders. You never see line passwords.

Update backend/main_test.go to match, then test it without the panel:

bash
cd examples/modules && go test ./greeter/...

4. Build the package ​

bash
./build.sh

You get greeter-0.1.0.zip with module.json, the backends and ui/index.js. Every file is pinned by its sha256 in module.json.

5. Sign it, or turn on developer mode ​

The panel installs only signed packages, unless developer mode is on.

To sign:

bash
go run ../bspack keygen

Save the private key in a file outside the repository, for example ~/greeter.key. Then:

  1. In the panel, open Modules and add the public key to the trusted keys. You confirm with your password and 2FA code.
  2. Build again with the key: KEY=~/greeter.key ./build.sh.

To test quickly on your own machine instead, turn on developer mode on the Modules page. Turn it off again when you are done: in developer mode anyone with your password can install code that runs on the server.

6. Install it ​

  1. Open Modules and choose Install from file.
  2. Pick the zip. The panel checks it and shows what it asks for: permissions, hooks, routes, jobs, and whether it is signed.
  3. Read the list. Then type your password and 2FA code and install.
  4. Enable it.

Download the playlist of a test line. The adult group is gone.

7. Check health and logs ​

Open the module on the Modules page:

  • Health: state, restarts, calls, errors, timeouts, p95 latency, last error.
  • Logs: what the module wrote to stderr, plus messages from the panel.

After 5 failures in a row the panel turns the module off and says why. Fix it, build a higher version, install it again (that upgrades it) and enable it.

8. If something goes wrong ​

  • The panel acts strange after installing. Disable the module on the Modules page. Its frontend, hooks and routes go away at once.
  • The panel does not open at all. Start bs-control with BS_MODULES_SAFE_MODE=1. No module is loaded. Sign in, fix or uninstall the module, then remove the variable and restart.
  • You want it gone. Uninstall it. Choose whether to keep its stored data for a later install.

Next ​

  • Add a page, a dashboard widget or a field on the line form: see the frontend slots in the modules reference.
  • React to new lines or failed streams with events instead of filters.
  • Read panel data with the api callback. It runs as the module's own API key, limited to its permissions.

Bitstream documentation