# Yggthreads: A tree of names as the database, and an app as a text file of forms

> Source: <https://peterretief.org/posts/names-as-the-database/>
> Published: 2026-12-05 18:44:59+00:00

**Key takeaway:** yggthreads replaces schema, ORM, CRUD screens, permissions and audit log with a .forms text file plus append-only per-name threads, where 'only if' and 'sets' rules enforce workflow state server-side and roles granted at a name apply to everything under it.

# yggthreads: a tree of names as the database, and an app as a text file of forms

THis was written by Claude based on my request, it is really useful development tool so I want to share it.

Most of the software small businesses need comes down to the same few things: some objects, the forms people fill in about them, who is allowed to fill in which form, what state each object is in now, and some totals. A tool-hire shop, a building contractor tracking snags, a ward tracking beds, a company running road signs. Each of these normally becomes a schema, an ORM, a set of CRUD screens, a permissions table and an audit log added later.

yggthreads is my attempt to make that whole stack one idea. It's a proof of concept, about 4,300 lines of Go and one HTML page, and I've written four apps in it so far. This post is what it is, why it's shaped the way it is, and where it falls short.

## The idea

Everything the app tracks gets a **name in a tree**, like a domain name read the other way:

```
eh                     a rental company
eh.north               its north depot
eh.north.i100001       a rotary hammer drill at that depot
eh.c-013               a customer
```

Every name has a **thread**: a list of entries, only ever added to. An entry is a form someone
        filled in, with who, when and from where. The thread *is* the record. There are no tables and no rows
        to update. The drill's thread is its whole life: bought, safety-checked, hired out, returned damaged, sent for
        repair, back, counted in a stock take, written off.

The current state (out, due back Friday, with customer 13) is worked out from the thread, and a search index is built from all the threads. Delete the index and nothing is lost: it's rebuilt at start.

## An app is a text file

The app itself is a `.forms` file. Here is part of the rental one:

```
app rental "Equipment rental"

role manager: process at company branch customer item, read, give roles
role counter: process at company branch customer item, read
role workshop: process at item, read

kind branch
  form add-item "Add an item" -> new item
    title from name
    barcode "Barcode": barcode required
    name "Item": text required
    day_rate "Day rate (R)": number required
    cost "Bought for (R)": number total
    sets status = in

kind item
  form rent "Rent out" -> here
    only if status = in
    customer "Customer": ref customer required
    due "Due back": time required
    sets status = out
    sets customer = $customer
    sets due = $due
    also to customer

  form check-in "Check in" -> here
    only if status = out
    condition "Came back": choice Good | Damaged | Parts missing required
    charged "Rental charged (R)": number required total
    sets status = in
    sets customer = none
    also to state customer
```

That's most of what there is to the language:

- **Kinds and forms.** A form belongs to a kind of name.`-> new item` makes a
          new name under the one you're on;`-> here` adds to this name's own thread.
- **A workflow is `only if` plus `sets`.** You can't rent out a drill
          that's already out, or check in one that's on the shelf. The server refuses, and says why ("Rotary hammer
          drill is out, not in").
- **`also to` copies the entry into another thread.** Renting a drill to a customer
          also lands in the customer's thread, so their page shows what they have out and everything they've ever
          hired.`also to state customer` means "whoever the drill is out to now", so the check-in follows
          the rental there.
- **Roles are given at a name and hold for everything under it.** Making someone counter
          staff at`eh.north` lets them work that depot and nothing else. There is no permissions table;
          the grant is itself an entry in`eh.north` 's thread.
- **`total` adds a number up the tree.** Every depot, and the company, shows what
          its stock cost and what it has earned, and counts its items by status (32 out, 55 in, 1 in repair).

The page is generic. It reads the forms files at start and draws every app from them: the tree, the forms you're allowed to fill in where you are, the threads, the totals, search. The rental app also has a barcode field type, so the page grew a scan box and prints Code 128 label sheets. Scan a label and the item opens; pick "Rent out", fill in the customer once and scan five laptops in a row.

## What's on disk

One folder per name, and one file per thread, one JSON line per entry:

```
data/eh/north/i100001/_thread.jsonl

{"id":"01786693320000000000-e733f422","at":"2026-08-14T07:42:00Z",
 "by":"Counter Adams","from":"eh.north.i100001","form":"rent",
 "fields":{"customer":"eh.c-013","due":"2026-08-15T19:00","contract":"C10438"},
 "sets":{"status":"out","customer":"eh.c-013","due":"2026-08-15T19:00"}}
```

You can `cat` any object's history. You can `grep` the whole company. A backup is a copy
        of a folder. The index is SQLite with FTS5 next to it, and searching "everything under `eh.north`"
        is a range scan on the name, so it stays fast however deep the tree goes.

On my desktop, a hospital example with 2,000 patients (21,349 entries) builds its index in 3.9 seconds at start, and searches take 1 to 13 ms. The rental example, 176 items and 120 days of business (4,250 entries), builds in 3.3 seconds.

## Why it's shaped like this

I didn't start from "databases are bad". I started from storage. I run a small group of machines in homes
        and offices ([the first post](https://peterretief.org/posts/build-without-the-cloud/) has more), and the storage spreads
        each file across them as encrypted pieces, six data and four spare, so any four machines can be off.
        That's good for files written once. It's terrible for a database file that changes in place.

Append-only threads fit it well:

- **Merging is taking both.** Two copies of a thread merge by union on the entry ID. An entry
          that arrives late from a box that was offline goes into its place by time. No conflicts to resolve, because
          nothing is ever edited.
- **Every machine builds its own index.** The index is a cache, not the truth, so it never has
          to be replicated.
- **Batches, not files.** New entries are gathered per company and stored about once a minute
          as one encrypted batch. A wiped box gets every thread back from the group. In a test, 1,773 entries came
          back exactly with two of six machines switched off.
- **The audit log is free.** It isn't a feature, it's the data. "Who changed this and when"
          is always the thread.

## What it's like next to things you know

- **Event sourcing,** without the infrastructure. The events are forms people filled in, the
          projection is "state" and "totals", and the event store is a folder.
- **Lotus Notes,** which had documents, forms, workflow by mail and replication between
          servers in 1989. A lot of this is me rediscovering it.
- **Access, FileMaker, Airtable:** the same promise of "describe it, get an app". The
          difference is that history comes first and the current state is derived, rather than the other way round.
- **DNS, LDAP:** the tree of names, and delegation down it. Roles given at a name work like
          delegating a zone.

## Where it falls short

Plenty, so far:

- **No real sign-in yet.** The page asks "You are" and believes you. Roles are enforced on the
          server, but against a name you typed. My public demo sits behind a shared password for this reason.
- **Only the questions the index knows.** Counts by status, totals by field, text search,
          "under this name". Anything else (which customers hire laptops in winter?) means reading the threads
          yourself. There is no query language, and I'm not sure there should be.
- **One object, one place in the tree.** Moving a drill to the other depot means a new name,
          or a move form that both threads record. I haven't built that yet.
- **Old entries keep their old shape.** Change a form and last year's entries still have last
          year's fields. The page shows whatever is there, which works, but there's no version or migration story
          yet.
- **It's meant for small businesses, not high write rates.** One box writes a company's
          threads; other boxes catch up. Tens of entries a minute is fine. A trading system is not what this is for.
- **The code isn't public yet.** It will be once sign-in is in and the forms language has
          settled.

## What I'd like to know

Whether the forms language holds up in an app I didn't design. If you have a small, real process (a
        workshop, a lab's sample tracking, a club's equipment), I'd like to try writing it as a `.forms`
        file and see what's missing. And if you've built on Notes, or on an event-sourced system, I'd like to hear
        what hurt later on, before it hurts me.
