← cd .. (back to the actual site)
view source ↗/howdidimakethis/interview-tools

$ whoami
> someone sketching a system design, or running a two-sum

$ cat ./README.md | head -2
> a whiteboard and a code runner for interviews, with no backend

$ ./reveal --app=interview-tools
> booting write-up...

Two interview tools, and neither one has a server.

/whiteboard is draw.io in an iframe; /playground runs JavaScript and TypeScript in a Web Worker. Both ship in the same static export as the rest of the site — the visitor's browser does all the work.

$ cat decisions.md

why embed, and why run code in the browser

draw.io, not a home-made canvas. The ask was to use jgraph/drawio-desktop — but that's an Electron app, and Electron can't be dropped into a web page. What it wraps is the jgraph/drawio web editor, which also ships an official embed mode at embed.diagrams.net: the same editor, every shape library, driven by a parent page over postMessage. Self-hosting that editor was on the table too, but it's ~110 MB of static files to carry in the repo and deploy for a feature that works fine from draw.io's own host.

Client-side execution, not a sandbox service. The site is output: "export" — there's no server to run code on, and running other people's code server-side means building a sandbox (containers, resource limits, abuse handling). A browser already is a sandbox. The trade-off is that only browser-compatible JavaScript runs: no fs, no http, no require().

$ cat architecture.md

what talks to what

Everything below happens in the visitor's browser. Nothing new got provisioned for either tool; the dashed boxes are third-party hosts this repo doesn't own.

/whiteboard — the visitor's browserWhiteboard.tsxboards, toolbar,20s load watchdogdraw.io in an <iframe>embed.diagrams.net · embed=1&proto=jsonreferrerPolicy="no-referrer"load · exportinit · autosave · exportlocalStoragenamed boards → .drawio XMLautosaved XML• never sees the diagram's storage — only the XML it's handed in `load`• PNG / SVG export comes back as a data: URI → downloaded by the page/playground — the visitor's browserMonaco editorJS / TS IntelliSenseCtrl/⌘ + Enteremit + rewriteTS worker → JS"lodash" → esm.sh/lodashWeb Workerimport(blob: URL)console.* capturedconsole panelutil.inspect-styleformatted linespostMessageStop / 10s → worker.terminate()cdn.jsdelivr.netMonaco + npm .d.ts filesesm.shany npm package as ESMtypings → IntelliSenseimport

Top: the whiteboard page and draw.io trade JSON messages across the iframe boundary. Bottom: the playground compiles, rewrites and runs code in a worker, pulling packages from esm.sh and typings from jsDelivr.

$ cat components/whiteboard/Whiteboard.tsx | grep event

the whiteboard is a postMessage handshake

1. The iframe loads embed.diagrams.net/?embed=1&proto=json&libraries=1. When the editor is ready it posts {event: "init"} to the parent — and then waits, showing its menus over an empty, greyed-out canvas, until it's handed a diagram.
2. The page answers with {action: "load", xml, autosave: 1} — the active board's saved XML. Messages are only accepted from that origin and from the current iframe's own contentWindow.
3. With autosave on, every edit comes back as {event: "autosave", xml}, which is written straight to localStorage under that board. Boards are just named XML strings — one per interview — so they also open from and download to plain .drawio files.
4. PNG and SVG export is the same trick in reverse: the page sends {action: "export", format}, draw.io renders it and replies with a data: URI the page downloads.
5. Switching the site between light and dark mode re-keys the iframe with the matching draw.io theme. Autosave has already stored the XML, so the reload loses nothing.
$ git log --grep=403

the bug that looked like a broken editor

The first version worked in every test and failed on the dev machine: draw.io drew its menus, then nothing — no shapes panel, nothing clickable. That's exactly what step 1 above looks like when step 2 never happens. The browser console had the real answer: embed.diagrams.net was returning 403 Forbidden for the iframe whenever the Referer was http://localhost:3000. The same URL loaded fine from an https page, and fine from localhost with the referrer stripped.

The fix is one attribute: referrerPolicy="no-referrer" on the iframe — the embed has no use for knowing who's embedding it. The lesson went in too: if draw.io hasn't sent init within 20 seconds, the page now says so, with a Retry button, instead of leaving a blank canvas that reads like a bug in the editor.

$ ls lib/playground/

the playground: compile, rewrite, run, format

A Web Worker, not an iframe or eval. A while (true) {} in the page's own thread would freeze the whole tab. In a worker it can't, and the worker can be killed: Stop calls worker.terminate(), and so does a 10-second timeout if the code never finishes evaluating. Each run gets a fresh worker, so nothing leaks between runs.

Any npm package, with no bundler. Before running, imports.ts rewrites bare specifiers — import _ from "lodash" becomes https://esm.sh/lodash, which serves any npm package as a browser-ready ES module. The rewritten code becomes a blob: URL that the worker import()s, which is also why top-level await just works.

TypeScript without shipping TypeScript. Monaco already runs the TypeScript language service in its own worker for IntelliSense. The playground asks that same worker for getEmitOutput on the model, so transpiling costs no extra download.

IntelliSense for the packages you import. types.ts is a small "automatic type acquisition": for each imported package it reads package.json from jsDelivr, follows types (or falls back to @types/*), walks the .d.ts import graph, and registers every file with Monaco under file:///node_modules/… — so the language service resolves them exactly like a local install. Type _.chu and chunk comes up with its signature.

Output that reads like Node. The worker replaces console.* with a small util.inspect-style formatter — nested objects, Map/Set, circular references, %s/%d, console.table as a box-drawn table — and posts finished strings back to the page. Stack traces have their blob: URLs rewritten to main.js:line:col.

Sharing is a URL hash. "Share link" base64-encodes the code into #code=…. The hash never reaches a server, so sending a candidate a starting problem doesn't store anything anywhere.

$ cat trade-offs.md

what this deliberately doesn't do

No live collaboration. Boards and code live in one browser's localStorage; during an interview, the candidate sees them through screen-share. Real-time co-editing would need a sync backend, which is the one thing this whole design avoids.

Three third-party hosts. draw.io's embed host, esm.sh and jsDelivr all have to be reachable. Monaco is pinned to an exact version so an upstream release can't change behaviour silently; packages imported in the playground resolve to their latest version unless the code pins one (lodash@4).

$ cat package.json | grep monaco

stack

draw.io embed mode (proto=json)postMessage + localStorage@monaco-editor/react — Monaco 0.52.2 from jsDelivrMonaco's TypeScript worker for transpilingModule Web Worker + blob: URLsesm.sh — npm packages as ES modulesjsDelivr — .d.ts type acquisitionStatic export — no new infrastructure