Section 17 of 25

Recipes

Contents

Every recipe starts with a test that fails on the old code, on an assertion and not on compilation. In Rust, write the signature first with todo!(), so the test compiles and fails for the right reason.

17.1. A new read (Query)

  1. core/<s>/model.rs: the result type, if it does not exist.
  2. core/<s>/store.rs: the read function. Test it on a temporary database.
  3. core/<s>/service.rs: pub async fn <verb>(…) that calls store and logic.
  4. core/<s>/mod.rs: pub use the new function or type.
  5. app/<s>/dto.rs: the DTO and From<model>.
  6. app/<s>/commands.rs: a command of at most 10 lines; register it.
  7. Front-end: the data-access layer calls the command.

17.2. A new change without background state (Command)

As 17.1, and the decision (is it allowed, what changes) is written in logic.rs as a pure function with a test. service.rs only calls it and performs the write.

17.3. A new slice

  1. Name: the feature as a singular noun in snake_case.
  2. core/src/<s>/mod.rs plus only the files it needs; pub mod <s>; in core/src/lib.rs.
  3. app/src/<s>/mod.rs, commands.rs, dto.rs; register its commands.
  4. If the slice has background state: recipe 17.4.

17.4. A new flow with state (actor)

  1. Check the three conditions from 9.1. If one fails: recipe 17.2.
  2. msg.rs, state.rs, snapshot.rs: the types.
  3. update.rs: tests first (message in, expected effects and state out), then the implementation.
  4. effect.rs: execute for every effect; results return as Msg.
  5. run.rs and handle.rs: the loop and the door.
  6. AppState gets exactly one field: the registry or the Handle.
  7. app/<s>/events.rs: subscribe to the Snapshot and emit("<s>:snapshot").

17.5. A new driver (the outside world)

  1. drivers/src/<name>.rs or a folder. A driver knows no slices and no database.
  2. A trait only when there are at least two implementations.
  3. A process: process group, kill escalation, proof of death; secrets kept out of arguments and logs. All of it through the contracts of platform (12.2), never through a system call in the driver.
  4. A slice uses the driver from service.rs or from effect.rs.

17.6. A new event for the window

  1. A change in core publishes a Snapshot or an Event on a channel.
  2. app/<s>/events.rs subscribes and emits <s>:<event>.
  3. Front-end: the data-access layer listens and updates its store.

17.7. A new platform

Section 12.7.

17.8. Where does this go? (decision tree)

Does it call Tauri, the window, MCP or a remote hub?   → app (commands, events, doors)
Does it depend on the operating system?                → drivers/src/platform/ (section 12)
Does it talk to a process, the network, a keychain?    → drivers (through platform contracts)
Is it a database read/write or the schema?             → store (connection) / core/<s>/store.rs (queries)
Is it a pure decision or a calculation?                → core/<s>/logic.rs (or update.rs in an actor)
Is it a domain type?                                   → core/<s>/model.rs
Is it a sequence of steps with I/O?                    → core/<s>/service.rs
Is it state that lives in the background and the window watches? → core/<s>/actor/
Can the user switch it off while the rest keeps working?          → a plugin slice (section 23)
Does it have no domain at all (time, paths, ids, files)?          → kit

The first question is about the entry alone: the command, the emit, the listener of an MCP server or of a remote hub. What such an entry does (pairing, encryption, the messages a bridge carries, the rules of a remote session) is domain, and lives in a core slice that the entry calls.