Most note apps show you a graph of your notes as a nice extra. I wanted the graph to be the app, and I wanted it to tell me something: which notes I actually use, and which ones I've forgotten.

So I built Graph Notes: a note-taking app where every note is a body in a physics simulation. It has zero dependencies and is plain JavaScript.

Try it in your browser: https://sathvik8317.github.io/graph-notes/ (it opens with demo notes)
Repo: https://github.com/sathvik8317/graph-notes

What it does

Recency gravity. Notes you open or edit get pulled to the centre. Notes you haven't touched drift out to the edge. Colour goes from warm (recent) to cool (stale). After a few weeks of use the layout becomes a picture of what you're actually thinking about.

Drag to link. Drop one note onto another in the graph and a Related: [[Target]] line gets added to the note you dragged. No typing.

Time travel. Press Replay and watch the graph grow from your first note. Notes appear on the day you created them, and links appear when you first wrote them.

Replay mode: an earlier, smaller version of the graph

It also has what you'd expect: Markdown with [[wikilinks]] (headings and aliases too), [[ autocomplete, backlinks, renames that rewrite every link, search, JSON export/import, dark mode and a phone layout.

Dark mode with a note open and its backlinks

How the physics works

I studied how Obsidian's graph view is put together (physics in a Web Worker, flat typed arrays, Barnes-Hut) and wrote my own engine in the style of d3-force. No Obsidian code is used.

Each tick does four things:

  1. Link springs pull linked notes together.
  2. Many-body repulsion pushes every note away from every other note. Doing that pair by pair is O(n²), so it uses a Barnes-Hut quadtree (θ = 0.9): a far-away group of notes is treated as one heavy point.
  3. Gravity pulls each note towards the centre.
  4. Collision on a grid stops circles from overlapping.

The engine runs in a Web Worker, so typing in the editor never stutters. Positions come back to the main thread as a transferred Float32Array, which is a handover rather than a copy. With 2,000 nodes a tick takes about 9 ms.

Recency gravity turned out to be one line. Each note gets its own gravity multiplier:

g = 0.25 + 2.75 * 0.5 ** (age / halfLife) 

A note you just touched gets 3x pull, and one you've ignored for a long time gets 0.25x. Repulsion does the rest and pushes the low-gravity notes outward. You set the half-life in the settings.

Three bugs that taught me something

The target ran away. My first drag-to-link never worked. Every note repels every other note, so when I dragged a note towards its target, the target slid away from it. The fix: while you hold a note, it becomes a "ghost" that doesn't repel or collide with anything.

Links inside code blocks. If a note contains a code sample with [[something]] in it, that's not a link. The parser has to skip code spans and fenced blocks, or you get phantom edges.

The camera. If you fit the view once on load, it fits the starting jumble and the graph then grows off screen. If you fit only once it settles, the screen is empty for a second. So it fits twice: once early so something is visible, and again when the layout settles, unless you've already panned or zoomed yourself.

Try it

The quickest way is the live demo: https://sathvik8317.github.io/graph-notes/

To run it locally, you need Node 20+ and nothing else:

git clone https://github.com/sathvik8317/graph-notes cd graph-notes node serve.mjs # http://localhost:5173 

It opens with demo notes so you can play with the graph right away. Notes are stored in your browser's localStorage, so use Export for backups. There are 21 tests covering the physics engine, the data model and the Markdown renderer (node --test test/).

What's next

  • Ghost links: on-device embeddings that suggest links between related notes you never connected
  • Continents: detect clusters and give them names and soft outlines
  • WebAssembly engine for very large graphs

If you use a graph view in your own notes app: do you actually look at it, or is it just pretty? I'm curious whether recency gravity would change that for you.