Jump to content

MindAttic.Relay/BIBLE

From MindAttic Docs

MindAttic.Relay — Project Bible

Single source of truth for what Relay IS, is NOT, and the rules that keep it coherent. README says how to build and run it; this says how to think about it. The finish line lives in docs/RELEASE.md. The full architecture is docs/design/relay.md.

1. The one sentence

Relay is the one way MindAttic apps send each other messages: a local NATS + JetStream server, one contracts package and one client library.

2. The product promise

  • An app publishes an event or calls a command through MindAttic.Relay.Client and never touches NATS directly.
  • Every message is a versioned Protocol Buffers contract with the same envelope headers, so routing, de-duplication and tracing never need to open the payload.
  • Relay is secure on one machine too: loopback only, TLS, credentials required from the first connection.
  • Nothing depends on Relay to keep working: an app whose Relay link is down keeps doing its own job.

3. What it is NOT

  • Not a database. The database is the record; a message is the news.
  • Not exactly-once delivery. Delivery is at least once; handlers are idempotent.
  • Not (yet) a multi-machine network. Hub, leaf nodes, device enrollment and the hub-and-spoke plan are out of scope until the single-machine milestone ships (docs/RELEASE.md §5).
  • Not a code runner: Relay carries messages; apps decide what to do with them.

4. Architecture canon

 Orchestrator.Desktop        Tickets.Desktop
        |  MindAttic.Relay.Client  |
        +-----------+--------------+
                    | localhost, TLS, per-app credential (from MindAttic.Vault)
           +--------v---------+
           | Relay server     |  nats-server + JetStream, Windows service,
           | (one per machine)|  store under %ProgramData%\MindAttic\Relay
           +------------------+
                    ^
              relay CLI (install, status, creds, tail, streams, dead-letters)

4.1 Projects (planned; nothing built yet)

Project Role
relay CLI Install/uninstall the pinned nats-server service, status, credentials, diagnostics
MindAttic.Relay.Contracts .proto contracts with generated C# types, envelope header names, subject builders
MindAttic.Relay.Client Publish/subscribe (durable consumers, ack after handler), request/reply, DI via AddMindAtticRelay()

4.2 Domain model (the nouns)

  • Subject: <app>.<noun>.<event>[.<key>] for events, <app>.cmd.<verb> for commands. Lowercase, dot-separated, no personal data or secrets. App tokens: orch, tix, relay (more as apps join).
  • Stream: one JetStream stream per app (TIX = tix.>); each subscribing app has its own durable consumer.
  • Envelope: headers Nats-Msg-Id (UUIDv7), Relay-Type, Relay-Version, Relay-Source, Relay-Correlation, Relay-Sent.
  • Credential: one NATS user per app per machine, with the subjects it may publish and subscribe to.

4.3 Key operations (the verbs)

  • Event: "this happened", JetStream, at least once, replayable (tix.ticket.changed.<id>).
  • Command: "please do this", core NATS request/reply with a timeout (orch.cmd.show-worker, tix.cmd.open-ticket).

5. The Laws

Inherits MindAttic.HouseRules.md by reference.

  1. Apps only talk to their own machine's server, through the client library.
  2. The database is the record; a message is the news. Relay never replaces a table.
  3. Handlers are idempotent. Ack only after the handler succeeds; skip an already-processed Nats-Msg-Id.
  4. Commands time out loudly in plain words ("Tickets Desktop didn't answer") and never silently retry an unsafe command.
  5. Poison messages go to a dead-letter stream after a set number of failed deliveries, with the reason.
  6. Contracts change by adding fields. A breaking change is a new Relay-Version; consumers skip types and versions they don't know, and count them.
  7. Credentials and TLS from day one, loopback included; secrets live in MindAttic.Vault.
  8. Nothing depends on Relay to keep working. The named-pipe AppBus stays as a fallback.
  9. The nats-server version is pinned in the repo, verified by SHA-256, and upgraded deliberately.

6. Verified state

Nothing built. Design accepted 2026-10-27 (commit ba9744e). The bus it replaces is live today in MindAttic.Orchestrator (Core/Status/AppBus.cs, AppBusHub.cs) and MindAttic.Tickets (Desktop/Bus/AppBus.cs, AppBusClient.cs).

7. Active frontier

docs/RELEASE.md: milestone MS-8, "Relay 1.0: Orchestrator and Tickets talk over a local Relay", epics M.RLY-T80 (server and CLI), M.RLY-T81 (contracts and client), M.RLY-T82 (AppBus on Relay).

8. Quality bar

A feature is done when it builds clean, has NUnit tests (integration tests run against a throwaway nats-server, never the installed service), follows the Laws above, and its README/BIBLE lines match the code.

9. Glossary

  • NATS: the message server. JetStream: its persistence layer (streams, durable consumers).
  • Durable consumer: a named read position in a stream that survives restarts.
  • AppBus: today's named-pipe bus between Orchestrator.Desktop and Tickets.Desktop.
  • Leaf node / hub: multi-machine NATS topology; out of scope for 1.0.
From MindAttic.Relay/docs/BIBLE.md via MindAttic.Docs; synced automatically, so edit the repo, not this page.