DEV Community

Cover image for Why I built a deterministic SVG genogram editor in the browser (with WebCrypto sync)
Poon
Poon

Posted on

Why I built a deterministic SVG genogram editor in the browser (with WebCrypto sync)

A friend finishing a Master of Social Work program asked me for help installing a 1990s Windows desktop app inside a virtual machine on her MacBook. She needed to turn in a three-generation clinical genogram and an ecomap by Friday, and her department syllabus still listed GenoPro because general diagramming tools do not know Bowen family systems notation.

I tried drawing one myself in a few generic canvas apps and an AI diagram generator to see how bad the gap was. Generic canvas tools make you draw every double-border client circle, divorce slash, emotional cutoff bar, and quadrant medical shading by hand. Image models hallucinated extra parents, flipped biological sex symbols, and tangled marriage lines across generations.

That weekend experiment turned into ClearGenogram, a browser-based genogram software for Mac, Windows, and iPad that renders strict SVG layouts and runs without signup.

Here are the three engineering choices that mattered most while building it.

1. Deterministic row layout instead of force-directed graphs

Early on I tested a force-directed graph layout to position family members automatically. It looked clever for five nodes and fell apart on a real intake case.

Clinical genograms follow strict reading conventions from Bowen and McGoldrick:

  • Older generations sit on upper horizontal rows, with siblings ordered left to right by birth year.
  • Partner unions connect via horizontal brackets underneath the couple, with divorce slashes and remarriages staying unambiguous.
  • Shared households use dashed enclosures that cannot swallow non-resident relatives.

Force simulation fights all three rules because spring tension wants symmetry, while real families have divorces, step-siblings, twins, and deceased grandparents on uneven branches.

I ripped out the physics engine and wrote a deterministic three-tier coordinate solver in TypeScript. Each person belongs to an explicit generation row (grandparents, parents, client/siblings, or children). Couples compute a shared union anchor, children project cleanly downward from that union midpoint, and an edge-routing pass checks bounding boxes so relationship lines (conflictual zigzags, emotional cutoffs, close parallel lines) detour instead of colliding with text labels. Users still get a fine-tune horizontal slider per node when a complex blended family needs a manual nudge.

ClearGenogram 3-generation clinical genogram studio

2. Keeping both genogram and ecomap in one state graph

Social workers rarely stop at an internal family tree. Most hospital discharge summaries and child welfare intakes also require an ecomap showing external systems (school IEPs, legal claims, clinics, community support) and directional energy arrows into or out of the household.

Instead of building two separate editors, I kept the household enclosure and family members at the center of the same JSON document. Toggling Ecomap mode preserves the nuclear household inside a dashed circle and attaches external system pills around the perimeter. Each external link stores its type (supportive, strong double-line support, stressful jagged line) and flow direction (into family, out from family, or mutual).

ClearGenogram social work ecomap mode

3. Client-side WebCrypto encryption plus offline JSON

Therapists and students are rightly cautious about putting family health histories into random web apps. For quick drafts, the editor works completely offline in the browser with no account and saves plain .cleargenogram.json files directly to disk.

For users who turn on optional cloud sync across devices, the browser encrypts the diagram payload before any network request leaves the tab using the native WebCrypto API (PBKDF2 with SHA-256 key derivation and AES-256-GCM authenticated encryption):

async function encryptVaultPayload(plainJson: string, passphrase: string) {
  const enc = new TextEncoder();
  const salt = crypto.getRandomValues(new Uint8Array(16));
  const iv = crypto.getRandomValues(new Uint8Array(12));

  const keyMaterial = await crypto.subtle.importKey(
    "raw",
    enc.encode(passphrase),
    "PBKDF2",
    false,
    ["deriveKey"]
  );

  const key = await crypto.subtle.deriveKey(
    { name: "PBKDF2", salt, iterations: 250_000, hash: "SHA-256" },
    keyMaterial,
    { name: "AES-GCM", length: 256 },
    false,
    ["encrypt"]
  );

  const ciphertext = await crypto.subtle.encrypt(
    { name: "AES-GCM", iv },
    key,
    enc.encode(plainJson)
  );

  return { salt, iv, ciphertext };
}
Enter fullscreen mode Exit fullscreen mode

The server only stores the salt, IV, and ciphertext. The trade-off is real: if someone forgets their vault passphrase, I cannot reset it or recover the diagram for them. For local-first clinical drafts, that trade-off felt cleaner than holding decryption keys on a server.

Exporting lightweight vector PDFs instead of blurry screenshots

One surprise during testing was how huge browser PDF exports get if you rasterize a canvas at 300 DPI. A single three-generation intake chart turned into a 6 MB PNG-wrapped PDF that choked university LMS upload limits.

Because the entire diagram already lives in clean SVG paths and text nodes, exporting directly to vector paths keeps A4 and US Letter PDFs sharp at any zoom level while staying under a couple hundred kilobytes.

What I am still working on

Multi-marriage crossover routing still gets tight when a parent has three separate unions with children on the same row, and touch-screen dragging on smaller iPads needs a larger hit target around connection handles.

If you have built custom SVG layout engines or browser-side WebCrypto vaults in TypeScript, I would love to hear how you handled edge crossings or passphrase recovery UX.

Top comments (0)