switchoff
README.md
# SwitchOff: what breaks if you turn it off?
A small business runs on things nobody wrote down: an automation that needs a login, a login that needs one person's phone, a timer that only works while one PC is on. SwitchOff loads that inventory into [Relate by Neo4j](https://relatedb.ai) as a graph and answers:
- **Blast radius**: what breaks if I turn off X, lose this login, or this person is away? Every affected item comes with its shortest dependency path and the **evidence line** for each edge.
- **Single points of failure**: things with no backup on record that would break a customer-facing output, worst first.
- **Safe to retire**: jobs and accounts nothing depends on and no customer sees.
Three ways in, one graph underneath: a **web UI** (Relate compiled to WebAssembly, running in your browser), a **CLI**, and an **MCP server** so an AI agent can ask the same questions.
**Live demo:** https://switchoff-relate.impactlayer.workers.dev (no sign-in; nothing is uploaded, the graph lives in your browser tab).

The sample business, Tidewell Print & Frame, is **fictional**. Every name and host is invented.
## 2-minute setup
Needs Node.js 20 or later. No Relate install is needed: the npm package carries the engine.
```bash
git clone https://github.com/dragonacademy4/switchoff && cd switchoff
npm ci
npm test # 12 tests, including MCP over stdio
node bin/switchoff.js blast person-maren # what breaks if the owner is away?
node bin/switchoff.js spof
node bin/switchoff.js orphans
npm start # web UI at the address Vite prints
```
Use `node bin/switchoff.js list` to see item ids. Use `--inventory my.yaml` for your own business.
## The inventory format
One YAML file. Every dependency needs an `evidence` line (where you know it from); the loader rejects a dependency without one.
```yaml
business: My Shop
items:
- id: acct-email
name: Shared mailbox
kind: account # person | account | key | device | service | timer | automation | output
backup: "" # optional: what covers for it. An item with a backup is not a single point of failure.
customer_facing: false # true for outputs a customer sees
note: ""
depends_on:
- { id: person-owner, evidence: "owner is the only admin" }
```
`A depends_on B` means "A stops working if B goes away". See [`inventory/tidewell.yaml`](inventory/tidewell.yaml).
## Relate mode: single file
SwitchOff runs Relate embedded as a **single file**. The persistent store is [`data/tidewell.rl`](data/tidewell.rl), built from the sample inventory with `node bin/switchoff.js build --out data/tidewell.rl`. Every CLI and MCP command can use it directly with `--db data/tidewell.rl`, and the `relate` CLI can open it too. A single file suits a small business's inventory: one portable file to keep, back up or hand to an agent, with no server to run. (The hosted browser demo rebuilds the same graph in memory from the YAML, so judges can edit it live.)
## How Relate is used
Each item is an `(:Item)` node and each dependency is a `[:DEPENDS_ON {evidence}]` relationship. Load is two `UNWIND` statements ([`src/inventory.js`](src/inventory.js)). The questions are Cypher ([`src/queries.js`](src/queries.js)):
- Blast radius: `MATCH p = shortestPath((t:Item)-[:DEPENDS_ON*1..12]->(x:Item {id: $id}))` for every item `t`, returning `nodes(p)` and the evidence on `relationships(p)`.
- Single points of failure: variable-length paths from every customer-facing output to each candidate, counted with `count(DISTINCT ...)`.
- Orphans: `NOT EXISTS { MATCH (:Item)-[:DEPENDS_ON]->(x) }`.
The same code runs unchanged on three Relate surfaces: the Node package `@relate/relate` (CLI, MCP, tests), the WASM package `@relate/relate-wasm` (web UI, in a module worker), and the `relate` CLI itself, which can open the store the SwitchOff CLI writes:
```bash
node bin/switchoff.js build --out graph.rl
relate --database graph.rl --read-only "MATCH (n:Item) RETURN count(n) AS items" # needs the relate CLI
relate serve --mcp stdio --database graph.rl --read-only # Relate's own generic MCP over the same graph
```
## MCP tools
`node bin/switchoff.js mcp` serves over stdio. Claude Code example:
```bash
claude mcp add switchoff -- node /path/to/repo/bin/switchoff.js mcp
```
Tools: `list_items`, `blast_radius`, `what_if_all_unavailable`, `single_points_of_failure`, `orphaned_jobs`. Results come back as text plus structured JSON. Then ask: "What breaks if Maren is away for a week?"
## Hosting and cost
The web UI is static files plus Relate's WASM, served by a Cloudflare Worker with static assets (free plan). `npm run build` builds into `dist/`; `npm run deploy` runs `wrangler deploy`. Cost: nothing.
## Checks
`npm test` runs the traversal, validation, cycle, MCP and CLI-store tests. `npm run qa -- <url>` drives the web UI in Playwright at 1440 and 390 wide and checks for console errors (needs `npx playwright install`).
## Limits, stated plainly
- The graph is only as good as the inventory. SwitchOff does not discover anything by itself.
- "Backup" is a free-text field you fill in; it is not verified.
- Paths shown are the shortest path per item; an item may depend on the target by several routes.
- Browser build: the graph is in memory and is rebuilt from the YAML on each load.
- Traversals stop at 12 hops and do not warn if that cap is hit.
- "Backup" means full cover. A partly covered item (for example read-only access) should leave `backup` empty and say so in `note`.
- Orphans are items with no incoming dependency; a dead cluster that only depends on itself is not flagged.
Licence: MIT. Relate itself is Apache 2.0.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues