Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Portal 1.0

Status: proposal, 2026-11-17. The direction for the schema (one key and three rules) is agreed; the details below await review, and nothing is built. This replaces the order in the site store from step 3 on: 1.0 has no NATS, and a site whose programs still need NATS stays on 0.x.

The schema stays as it is

Context, decisions and outcomes are already in the schema:

  • The question is the context. It is the page, and it is what asks.
  • An alternative is a decision. It is one choice.
  • A feature explains the choice. It has requirements, optional or not, that the alternative needs to qualify as a choice. It can also feature a resource.
  • The outcome is what the state machine in aggregates.yaml and the alternative’s own action say follows.

1.0 keeps all of that. It adds what a machine hire showed was missing: time, and choosing from a resource. That takes one key in aggregates.yaml and three rules for requirements.

What a record holds, and when

A hire keeps a machine busy from its first day to its last:

# aggregates.yaml
aggregates:
  - bucket: hires
    initial: confirmed
    states:
      confirmed: { event: confirmed, text: Confirmed }
      out: { event: out, text: Out with the customer }
      returned: { event: returned, text: Returned }
      cancelled: { event: cancelled, text: Cancelled }
    transitions:
      confirmed: [out, cancelled]
      out: [returned]
    holds: { what: machine, from: from, until: until, while: [confirmed, out] }

holds says four things:

  • what: the field naming what is held, here a type: record field of: machines;
  • from and until: the fields holding the first day and the last;
  • while: the states in which the record holds it.

From these, portal keeps a projection over time: for every machine, the days each hire in while holds it.

  • The projection changes in the same transaction as the submission or move that changes it, so it is never behind.
  • A machine is free across two dates when no hire it holds overlaps them.
  • A submission or a move that would put a hire into a while state is refused when its machine is not free across the hire’s days. The person is told in words.

places: and board: stay as they are, for a fixed number of seats at a fixed time, such as a shift or an evening. holds: is for a thing held over days a person chooses, such as a machine, a room or a cabin.

Three rules for requirements

The question that books a hire:

# questions/hire.yaml
name: When do you need a machine?
alternatives:
  - name: Book a machine
    description: Say your days and pick a machine that is free all of them.
    record_as: hires
    action: /hire/thanks
    features:
      - name: Free on your days
        description: Every machine nobody has from your first day to your last.
        resource:
          source: { bucket: machines }
          public: true
          states: [for_hire]        # a machine in the workshop is never offered
        requirements:
          - { name: from, label: First day, type: date }
          - { name: until, label: Last day, type: date }
          - { name: machine, label: The machine, type: record, of: machines }
      - name: Who you are
        description: So the counter can confirm, and tell you if anything changes.
        requirements:
          - { name: name, label: Your name, value: "{user.name}" }
          - { name: email, label: Email, type: email }

1. Two dates narrow a held resource. A pair of type: date requirements beside a resource, named like the from and until of a holds: on it, narrows the list to the records free across those days. They live in the address like any narrowing requirement, so /hire?from=2026-12-01&until=2026-12-05 opens the list already narrowed, and a link, Back and a reload keep it. With no dates given, the list is the whole list. Today only type: text and a select narrow.

2. A recording alternative sends every requirement. On an alternative that records an answer (record_as), every feature’s requirements belong to its form, including the ones beside a resource. They narrow the list and are sent with the answer, so the hire’s days are the days its list was narrowed by. On an alternative that records nothing, they only narrow, as today, where they are never sent.

3. A record requirement beside its resource is picked from it. A type: record requirement beside a featured resource of the same bucket is answered by picking a row of that list, or several with multiple: true.

  • Only listed rows can be picked. The list’s states: decide which records can be picked at all (here, none in the workshop), and the dates decide which are free.
  • Today a type: record field is always hidden, carried in from the address.

What is sent is the record picked. Portal files the answer only if that record is still one the list would show: still in a listed state, and still free across the days. That check happens in the same transaction as the filing. If someone took the machine meanwhile, the visitor is told so, and the list is drawn again.

What the renderer does with it

  • A featured resource with a type: record requirement beside it is drawn as the list with its rows to pick from, under the feature’s name and description. The rest of the form keeps its place.
  • The two dates sit above the list. The list is drawn again as they change, and the address follows.
  • Lists are live. The store tells the renderer about every commit, and a list on an open page is drawn again when one of its records changes. A machine someone else books leaves your list as you look at it, and a desk sees another desk’s moves as they happen.

What the trainer builds

Two plan keys mirror the two halves:

needs:
  - id: hire-a-machine
    who: Contractors and people who need a machine for a while
    wants: a machine that is free on their days, confirmed at once
    lands_in: hires
    handled_by: counter
    stages: [confirmed, out, returned, cancelled]
    done_when: [returned, cancelled]
    success: [returned]
    holds: { what: machine, from: from, until: until, while: [confirmed, out] }
    collects:
      - { name: from, type: date }
      - { name: until, type: date }
      - { name: machine, of: machines }
      - { name: name }
      - { name: email, type: email }
  • holds on a need goes into the bucket’s holds: in aggregates.yaml.
  • A collected field with of: is a type: record requirement. build puts the featured resource of that bucket beside it, in the same feature, together with the dates when the need holds it.

That is the rule the trainer needs: wherever a need picks something the site keeps (a machine, a shift, a room), the requirement goes beside the resource it is picked from.

The simulator walks it as a visitor would. A persona gives its days, has to find and pick a free machine that fits, and the score counts what it picked.

When a plan has mails, build also puts the asks list on the page of the group that runs the site, and puts that group in mfa_groups. The first person to sign in can then turn mail on (see Mail).

The network

 people ── HTTPS ──► Caddy ──► a site: one process
                                ├ one redb file: log, records, outbox, projections
                                ├ content at a commit, checked by the lint
                                └ an iroh key, dialled by every program beside it
                                          ▲
     ┌────────┬──────────┬─────────┬──────┴───┬─────────────┐
    gdo     kron       learn      kino    a depot's      another
   mail    payments    search     rooms    printer        site

 n8n ◄── signed webhooks from the outbox · n8n ──► HTTPS calls into the site
 Kanidm signs people in (OIDC); programs are known by their keys
 garage and varde keep sealed copies of the redb file; the site writes to them as to a disk

The rules:

  • The site dials no one. Every program beside it dials the site, by key, and holds the call open. Work and questions come down that call; acknowledgements and answers go back up it. Storage is not a program: garage (over S3) and varde (on its socket) keep files the site writes, attachments and sealed backups, as a disk would.
  • Effects are rows in the move’s own transaction. A mail, a payment request, a room message or a webhook is written together with the submission or move that set it off. It is delivered until acknowledged, deduplicated by row.
  • A program moves a record the way a desk button does: through the same transition path and the same access policy. When kron sees the money, the record moves on to its payment.then.

There is one protocol, dhd/1:

callmade byfor
Serveeach program, held openthe program says what it does (mail, payment, search, rooms, print) and what it is waiting for (an ask, below); the site hands it work and questions on this call, and it acknowledges and answers on it. An open Serve is presence
Submita program or another sitean answer into a bucket its key may submit to
Movea programa transition on a record, as a desk button makes one
Notea programwords beside a record: a reply to a mail, a chat thread
Maya programthe access question, strong included
Watcha programwhat its key may see, then every change: the groups for kino, the log for a replica

What the bus carries today maps onto it:

  • kino’s four calls in site-store.md: Groups becomes Watch, Listen becomes Serve, Thread becomes Note, and May stays;
  • $SRV.PING becomes an open Serve;
  • learn.rank becomes a question on learn’s Serve;
  • the content reload becomes the deploy’s Load, below.

Anything that is not Rust uses the same calls over HTTPS:

  • POST /dhd/1/submit, /move and /note, with a key the instance names;
  • Serve and Watch as signed webhooks, each retried until a 2xx acknowledges it.

The deploy and the operator have two calls of their own:

  • Load gives the site a content commit. The site fetches it, checks it, and swaps it in, with the last good one serving until then.
  • Read is portal db.

How far a site reaches:

  • One process: pages, forms, lists and states.
  • Programs beside it: whatever the content asks for, linked into the binary or run as a unit next to it, over the same protocol either way.
  • Another host: dialled by key, through a relay on the host with the public address.
  • One organisation with several depots is one site. A depot is a group and a field. Its printer or scanner is a program that dials out, so nothing is opened at the depot.
  • Two organisations are two sites. One calls the other’s Submit (a housing co-op’s application into the municipality’s register) where the receiving site’s policy names its key. Each site stays the only writer of its own log.

A program that asks for its own login

A program beside a site that needs a login it does not have asks the site for it, the way kron already asks for its Vipps keys (dhd::asks).

  • The ask lists the fields, which of them are secret, a line about where each is found, and the key to seal them to (age, x25519).
  • A page lists what is waiting with source: { kind: asks }, behind a group in mfa_groups, so a password alone never opens it.
  • On submit, portal seals every secret field to the program’s key before anything is written. What it keeps is a portal_credentials record with the public fields and a fingerprint per secret.
  • The program opens what it was given with the identity only it holds, tries it, and answers running, or refused with the server’s own words.

Portal can seal and cannot open. Today the ask travels on the $SRV ping; in 1.0 it travels on the program’s Serve call.

Mail

gdo stays a program beside the site and asks each site for a mail login of its own, so whoever sets up a site turns mail on from the site itself:

# questions/owners/index.yaml
      - name: What the site is waiting for
        description: Services that need a login before they can work for the site. What you give goes to them sealed.
        resource:
          source: { kind: asks }
          requires_group: owners

The ask has three fields:

  • Address: the one the site sends from, such as post@vel.example. It must be the address site.yaml’s mail.from names.
  • Password, secret: an app password, where the provider uses two-step sign-in.
  • Server, optional: left empty, gdo finds it from the address.

What gdo does with the answer:

  1. It opens the password and finds the server from the address’s domain: JMAP at /.well-known/jmap first, then the provider’s published submission server (an RFC 6186 SRV record, or the provider’s autoconfig).
  2. It signs in and sends one mail to the address itself, as proof.
  3. It answers running (“Sends as post@vel.example over JMAP, and reads replies from the same mailbox”) or refused with the server’s words, such as “535 authentication failed”, or “no mail server published for vel.example: fill in Server”. Once mail runs, the ask leaves the page and the outbox starts to drain.

What follows from it:

  • Each site sends from its own mailbox, signed by its own provider. A site keeps the address it already has, and nothing changes in DNS on the host’s side. Today every site on a host sends through the host’s mail.
  • JMAP gives the most. The account’s Sent mailbox shows what the site sent, replies come back as notes, and an event goes into the same account’s calendar over CalDAV. An SMTP login only sends.
  • Until a site answers, gdo sends through the host’s own mail as now, where the operator has set that up.

What goes

  • NATS, and everything built to use a broker as a database:

    • crates/core/src/namespace.rs;
    • crates/portal/src/adopt.rs (2,086 lines) and its tests (1,139): gone;
    • presence.rs;
    • the mend and SETTLE: gone;
    • dhd’s streams, subjects and consumers;
    • the JetStream half of the store.

    The tests that need a live JetStream (jetstream.rs, durable.rs) run on the in-memory store instead.

  • In content, nothing. The three rules change what type: date, narrowing requirements and type: record do. holds: is new.

Order

  1. holds: and the three rules, reviewed in this doc.

  2. gdo asks each site for its own mail login, over today’s asks. The ask moves to Serve with dhd/1. Built (gdo dd2f9c1, 79af085, f425375): it asks where SMTP_HOST is unset, keeps the login in its state directory, may be given a new one while it works, and asks in the site’s language. Not yet ticked: it has not sent a real mail through a site’s own mailbox.

  3. The store on redb alone (portal_core::store), with an outbox, holds, a feed of its commits, lazy batches and a format.

  4. One transaction per submission and per move, with its outbox rows and the holds projection. The app moves onto the store one area at a time, its reads and writes together, so every commit runs:

    • sessions: the sessions bucket, flushed every minute and as the site stops;
    • every record and the event log: a submission, a move, a desk’s save and a restate are one batch each (answers::write_logged), so the mend, SETTLE and adoption are gone; the lists in memory follow the store’s commits; the ledger takes an event’s postings in one batch;
    • the work a move sets off (mail, payments, announcements) as outbox rows in its batch, relayed onto NATS until dhd/1 (outbox): a mail, a request for money or an announcement exists exactly when its move does, and waits while NATS is away;
    • the holds projection, with step 5: kept with every write of the record (store::Batch::hold, holds).

    Until step 6, a program that wrote records from its own process (the kit’s approval desk, portal import, portal ledger rebuild, iris replay --report-only) opens the site’s store, and so runs while the site is stopped.

  5. holds: and the three rules in the lint, the renderer and the trainer, with live lists:

    • live lists (live): an open page hears which of its lists a commit changed, only those the person may read, and reads them again as it read them first;
    • holds: (holds), the dates above a list, a picked row sent with the form, and the three rules in the content checks iris runs and in the renderer;
    • the trainer’s holds: on a need and of: on a collected field: build writes the bucket’s holds: and puts a picked field, its list and the days beside each other;
    • the simulator walking a booking: a plan need lists samples:, the example records needs.yaml carries and a picked field offers the simulated visitor by name.
  6. dhd/1 over irpc and iroh, and over HTTPS. gdo, kron and learn move to it, cnats moves as kino, and varde keeps the backups:

    • the protocol (dhd::one) and the site’s end (network): its key, the programs DHD_KEYS names, Serve handing outbox rows down and their acknowledgements back, the relay leaving a served outbox alone, and May; open values travel as JSON text;
    • gdo serves mail and hands replies back as Note (gdo’s one-oh branch, PORTAL_DHD); tried end to end with this site;
    • kron serves payments and tells the site what the provider says as a Move on the payment (kron’s one-oh branch), with no NATS: its ledger in a file of its own, and its Vipps keys asked for down its Serve (credentials), its word back as a Move;
    • the site’s side of kino: room messages through the outbox (rooms, served over dhd/1), Watch of the groups, May;
    • Move for desks: a program site.yaml’s programs: names moves records as a desk button does (a Service in the policy);
    • the chat’s threads as Notes (subject: thread, kept in portal_threads; kino sends one as a thread grows);
    • learn’s ranking as a question on its Serve (Work::Ask, learn serve --dhd), asked before NATS and a spawn;
    • backups: a snapshot of the store every six hours, sealed to the operator’s age key on the site, to garage, or into varde, pinned closed and pushed to trusted peers that keep it (backup);
    • the chat as kino: a new program on dhd/1, uhhm/kino. Released (0.1.1, in the [uhhm] registry for x86_64) and run beside a local site; a run beside a site with real sign-in is to come, and its aarch64 package does not build on that runner yet;
    • the HTTPS binding: /dhd/1/submit, /move and /note with a named token, and outboxes posted as signed webhooks (hooks); presence from open Serves;
  7. Load (the deploy’s: a commit fetched, checked and swapped in, over iroh or POST /dhd/1/load) and Read (portal db: a bucket, a record or its log, from the running site).

  8. The NATS code goes, and 1.0 is released:

    • the site listens on nothing and relays nothing on NATS; its Instance has no NATS; what NATS kept for a while is in the store (store::Kept); learn, rooms, reloads, invites and search counts are off it; the integration tests run on a store in memory;
    • the sites the kit writes are 1.0 sites: no NATS of their own, the store in the unit’s StateDirectory= or on a volume, and their CI posts Load with a token the site names load; learn serves over dhd/1 alone;
    • the kit’s queue of briefs, the last thing on NATS: a brief is a record in the built-in portal_kit, its row in the kit outbox is the worker’s over dhd/1, the worker’s word on its end carries the fields, the mails and the filing on the owner’s desk, and the desk’s yes comes back down the same outbox (briefs, dhd::kit); async-nats is out of core, portal and bratac;
    • dhd’s NATS names, once gdo and kron drop their NATS modes (the 0.x sites’ programs still read them);
    • the chat on dhd/1 (kino), which the site now waits for: what it says in a room stays in the rooms outbox until a chat serves it;
    • the release. Candidates are out (v1.0.0-rc.7), and the first site runs on one: a preview moved from 0.20.1 with its deploy, its import and its Load from CI. one-oh is not merged to main.