// The README's diagrams, drawn with rough.js in Excalidraw's hand, as // SVG files under docs/diagrams. Each carries its font (Excalifont, under // the SIL Open Font License, Excalifont-OFL.txt beside this) and both its // light and dark colours, so it reads the same wherever the Markdown is // shown. // // node harness/diagrams.mjs // // Shapes are seeded, so drawing again without a change writes the same // files. Move the coordinates below and draw again, rather than editing // the paths. import { readFileSync, writeFileSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import rough from 'roughjs/bundled/rough.esm.js'; const here = dirname(fileURLToPath(import.meta.url)); const out = join(here, '../docs/diagrams'); const font = readFileSync(join(here, 'Excalifont-Regular.woff2')).toString('base64'); const gen = rough.generator(); // Each colour, light then dark. const COLOURS = { group: ['#e8590c', '#ffa94d'], alice: ['#1971c2', '#74c0fc'], bob: ['#9c36b5', '#e599f7'], ink: ['#1e1e1e', '#d4d4d8'], muted: ['#868e96', '#a1a1aa'], bg: ['#ffffff', '#18181b'] }; const r2 = (s) => s.replace(/-?\d+\.\d+/g, (n) => String(Math.round(+n * 100) / 100)); const esc = (s) => s.replace(/&/g, '&').replace(/ ({ seed: seed++, roughness: 1, bowing: 1, ...o }); const emit = (drawable, colour, sw, dash) => { for (const p of gen.toPaths(drawable)) els.push( `` ); }; const api = { text(x, y, t, colour = 'ink', size = 19, anchor = 'middle') { els.push( `${esc(t)}` ); }, rect(x, y, w, h, colour = 'ink', { sw = 1.6, dash } = {}) { emit(gen.rectangle(x, y, w, h, opts()), colour, sw, dash); }, line(x1, y1, x2, y2, colour = 'ink', { sw = 1.6, dash } = {}) { emit(gen.line(x1, y1, x2, y2, opts()), colour, sw, dash); }, arrow(x1, y1, x2, y2, colour = 'ink', { sw = 1.8, dash, head = 13, both } = {}) { api.line(x1, y1, x2, y2, colour, { sw, dash }); const tip = (fx, fy, tx, ty) => { const a = Math.atan2(ty - fy, tx - fx); for (const d of [-1, 1]) { const b = a + Math.PI + (d * Math.PI) / 6.5; api.line(tx, ty, tx + head * Math.cos(b), ty + head * Math.sin(b), colour, { sw }); } }; tip(x1, y1, x2, y2); if (both) tip(x2, y2, x1, y1); }, dot(x, y, colour, r = 2.6) { els.push(``); }, // A person: their name over a face. person(x, y, name, colour) { api.text(x, y - 34, name, colour, 22); emit(gen.ellipse(x, y, 40, 42, opts()), colour, 2.2); api.dot(x - 7, y - 4, colour); api.dot(x + 7, y - 4, colour); emit( gen.curve( [ [x - 8, y + 6], [x, y + 11], [x + 8, y + 6] ], opts({ roughness: 0.6 }) ), colour, 2 ); } }; return { api, write() { const names = Object.keys(COLOURS); const vars = (i) => names.map((k) => `--${k}:${COLOURS[k][i]};`).join(''); const svg = ` ${esc(label)} ${els.join('\n')} `; writeFileSync(join(out, `${name}.svg`), svg); } }; } // 1. What the host is beside a person's PDS: the same job, for accounts // that are groups, and what a group needs on top. { const d = diagram('host-and-pds', { w: 880, h: 510, label: "On the left, Alice's PDS holds her account: her repo and her repos in spaces. On the right, a group host holds the accounts of two groups, hikers and chess club, each with a repo and repos in spaces, the same as a PDS does. No person has an account there. Below them, the host adds what a group needs: it decides who may read and write each group's spaces, and the group's roles decide what each member, and each app a member signs in, may do." }); const { api } = d; const account = (x, y, name, colour) => { api.rect(x, y, 220, 150, colour); api.text(x + 16, y + 30, name, colour, 19, 'start'); api.rect(x + 16, y + 46, 188, 38, colour); api.text(x + 110, y + 72, 'repo', colour, 18); api.rect(x + 16, y + 96, 188, 38, colour); api.text(x + 110, y + 122, 'repos in spaces', colour, 18); }; api.person(150, 62, 'alice', 'alice'); api.arrow(150, 86, 150, 124, 'alice', { sw: 2.2, head: 11 }); api.rect(20, 130, 260, 230, 'alice'); api.text(40, 160, "alice's PDS", 'alice', 21, 'start'); account(40, 180, "alice's account", 'alice'); api.text(150, 400, 'alice signs in here,', 'muted', 18); api.text(150, 424, 'and so do apps, as her', 'muted', 18); api.text(590, 62, 'no person has an account here', 'muted', 18); api.rect(320, 130, 540, 358, 'group'); api.text(340, 160, 'group host', 'group', 21, 'start'); account(340, 180, 'hikers', 'group'); account(620, 180, 'chess club', 'group'); api.text(840, 352, 'above the line: what any PDS does', 'muted', 16, 'end'); api.line(340, 364, 840, 364, 'group', { dash: '7 7' }); api.text(340, 398, '+ the authority for each group’s spaces:', 'group', 18, 'start'); api.text(360, 422, 'who may read and write them', 'muted', 18, 'start'); api.text(340, 452, '+ roles: what each member, and each app', 'group', 18, 'start'); api.text(360, 476, 'they sign in as the group, may do', 'muted', 18, 'start'); d.write(); } // 2. Who talks to whom: members stay on their own PDSes, apps sign in as // the group at the host, and the host answers to relays and PLC as any PDS. { const d = diagram('network', { w: 880, h: 520, label: "Alice's PDS and Bob's PDS each hold their own repo in the hikers group's space, and tell the group host of each write there. An app a member signed in as hikers writes and reads through the host. The host publishes the group's public repo to relays on its firehose, and signs changes to the group's DID document in the PLC directory." }); const { api } = d; const pds = (y, name, colour) => { api.person(70, y + 50, name, colour); api.rect(120, y, 220, 120, colour); api.text(136, y + 30, `${name}'s PDS`, colour, 19, 'start'); api.rect(136, y + 48, 188, 52, colour); api.text(230, y + 72, 'repo in the', colour, 16); api.text(230, y + 92, 'hikers space', colour, 16); }; pds(70, 'alice', 'alice'); pds(320, 'bob', 'bob'); api.rect(470, 180, 220, 150, 'group'); api.text(580, 212, 'group host', 'group', 21); api.rect(490, 230, 180, 82, 'group'); api.text(580, 258, 'hikers', 'group', 19); api.text(580, 284, 'repo, spaces,', 'group', 16); api.text(580, 302, 'policies, roles', 'group', 16); api.arrow(344, 140, 466, 220, 'alice'); api.arrow(344, 380, 466, 300, 'bob'); api.text(386, 252, 'each tells the host', 'muted', 16); api.text(386, 270, 'of a write there', 'muted', 16); api.rect(560, 20, 300, 70, 'ink'); api.text(710, 50, 'an app a member', 'ink', 18); api.text(710, 74, 'signed in as hikers', 'ink', 18); api.arrow(640, 94, 600, 176, 'ink', { both: true }); api.text(626, 140, 'writes and reads', 'muted', 16, 'start'); api.text(626, 158, 'as the group', 'muted', 16, 'start'); api.rect(740, 230, 120, 56, 'ink'); api.text(800, 264, 'relays', 'ink', 19); api.arrow(694, 258, 736, 258, 'ink'); api.text(800, 310, 'firehose of the', 'muted', 16); api.text(800, 328, 'public repo', 'muted', 16); api.rect(480, 410, 200, 56, 'ink'); api.text(580, 444, 'PLC directory', 'ink', 19); api.arrow(580, 334, 580, 406, 'ink'); api.text(592, 374, "signs the group's", 'muted', 16, 'start'); api.text(592, 392, 'DID changes', 'muted', 16, 'start'); api.text( 440, 504, 'members keep their own accounts, anywhere: the group lives on the host', 'ink', 18 ); d.write(); }