This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ioBroker.javascript is a Rules Engine adapter for ioBroker that executes user-written JavaScript, TypeScript, Blockly, and Rules scripts in sandboxed Node.js VM environments. It provides a rich API for home automation (state subscriptions, scheduling, pattern matching, notifications) and includes a full-featured browser-based editor with Monaco, Blockly, and debugging support.
# Install all dependencies (root + src-editor + src-admin)
npm run npm
# Full build (backend TypeScript + editor/admin UIs + tasks)
npm run build
# Backend only (TypeScript compilation)
npm run build-backend
# Editor UI only
npm run build-editor
# Admin UI only
npm run admin-build# Full test suite (declaration checks + integration tests)
npm test
# Individual test suites
npm run test:integration # Mocha integration tests
npm run test:declarations # TypeScript/JS declaration compilation checks
npm run test:package # Package file validation
npm run test:scheduler # Scheduler-specific tests
# Run a single test file
npx mocha test/testScheduler.js --exit
# Run tests matching a pattern
npx mocha --grep "pattern" --exitnpm run lint # Lint backend (src/) only
npm run lint-all # Lint backend + src-editor + src-adminESLint uses flat config (eslint.config.mjs) extending @iobroker/eslint-config. Prettier config inherits from the same package.
The project has three independent npm packages (not using workspaces):
| Directory | Purpose | Build Tool |
|---|---|---|
/ (root) |
Backend adapter + tests | TypeScript (tsc) |
src-editor/ |
Script editor React SPA | Vite + Module Federation |
src-admin/ |
Admin settings panel | Vite + Module Federation |
Each has its own package.json, eslint.config.mjs, and tsconfig.json.
src/main.ts (~19k lines) - The adapter class extending ioBroker.Adapter. Handles the full lifecycle: object/state change events, script compilation and execution, TypeScript compilation, debug sessions, message handling, and script mirroring.
src/lib/sandbox.ts (~5.5k lines) - Creates the sandboxed execution environment for each user script. Exposes the automation API: setState(), getState(), on(), schedule(), $() selector, exec(), HTTP helpers, notifications, etc. Each script gets its own sandbox instance with isolated timers and subscriptions.
Key supporting modules in src/lib/:
| Module | Role |
|---|---|
protectFs.ts |
Wraps Node.js fs to restrict script filesystem access |
scheduler.ts |
Manages cron, astro (sunrise/sunset), and interval schedules |
typescriptTools.ts |
In-memory TypeScript compilation via virtual-tsc |
debugger.ts |
Breakpoint debugging via child process fork |
mirror.ts |
Bidirectional sync between ioBroker DB scripts and filesystem |
patternCompareFunctions.ts |
Pattern matching for state subscriptions |
eventObj.ts |
Event object creation for subscription callbacks |
- Script object created/updated in ioBroker object DB
main.tsdetects change, compiles if TypeScript/Blockly- Global scripts compile first (provide shared declarations)
- Script wrapped in Node.js
vm.Scriptwith sandbox context - Sandbox tracks all timers, subscriptions, schedules per script
- On script stop/update, all resources are cleaned up
React SPA with Monaco editor, Blockly visual editor, Rules editor, debugger UI, and AI chat panel. Communicates with the backend adapter via ioBroker admin WebSocket connection. Uses Module Federation for dynamic loading.
React component for adapter instance configuration in the ioBroker admin panel. Uses @iobroker/adapter-react-v5 and Material-UI.
tasks.js orchestrates builds using @iobroker/build-tools:
- Backend:
tsc -p tsconfig.build.jsoncompilessrc/tobuild/ - Editor: Vite build in
src-editor/, output copied toadmin/ - Admin: Vite build in
src-admin/, output copied toadmin/custom/
io-package.json- ioBroker adapter metadata, instance settings schema, supported featuresadmin/jsonConfig.json- Admin UI configuration schema (rendered by ioBroker admin)tsconfig.build.json- Backend build config (CommonJS output, ES2022 target)
- Node.js >= 18 required
- Backend TypeScript compiles to CommonJS (
module: "commonjs") @types/nodemajor version should match the lowest supported Node.js version- Test framework is Mocha with
@iobroker/testinghelpers - CI runs tests across Node 18/20/22/24 on Ubuntu/Windows/macOS
- Releases use
@alcalzone/release-scriptwith Sentry notifications