Section 6 of 25
Slices
Contents
A slice is one feature of the product. Its name is a singular noun in snake_case: recording, transcript, board, trigger. Not recordings_manager, not utils. Where the product has a front-end, slice names match the front-end's feature folders, so that the same word finds the code on both sides.
A slice exists in two tiers: its domain in core, and its entry (commands, DTOs, events) in app.
6.1. A slice in core
core/src/<slice>/
mod.rs public API of the slice: only `mod …;` and `pub use …;`
model.rs domain types, state enums, identifiers; no I/O, no async
logic.rs pure functions: validation, decisions, mappings, calculations
store.rs this slice's reads from SQL and files, and its write commands through the writer
service.rs use cases: async, composes logic + store + drivers; no state of its own
error.rs optional: the slice's error enum
actor/ only for a slice with background state, section 9
tests.rs optional: unit tests of the slice
Rules:
- A file the slice does not need does not exist. A small slice can be a single
mod.rsholding its model and service until it passes about 400 lines. - A growing file becomes a folder with the same name:
logic.rsbecomeslogic/mod.rspluslogic/<topic>.rs. The role does not change, only the number of files. - A slice that is too big splits into sub-slices:
run/becomesrun/start/,run/step/,run/finish/, each with the same file layout. The parent keeps only amod.rswith re-exports. mod.rsis the slice's front door, likeindex.tsof an Nx library. Other slices import only through it.
A typical mod.rs:
mod logic;
mod model;
mod service;
mod store;
pub use model::{Transcript, TranscriptId, Word};
pub use service::TranscriptService;
6.2. A slice in app
app/src/<slice>/
mod.rs `mod …;` and `pub mod commands;` (the command list itself is in lib.rs, 6.4)
commands.rs #[tauri::command] functions; at most 10 lines each
dto.rs wire types: serde camelCase, #[serde(other)] on enums, From<model>, From<error> for IpcError
events.rs event names and payloads sent to the window; snapshot subscription loops
The rest of the app crate:
app/src/
main.rs calls lib::run(); nothing else
lib.rs run(): Builder, plugins, setup, generate_handler! with every command, grouped by slice
state.rs AppState: the composition root, section 11
error.rs entry error → code and text for the window
platform.rs optional: window and menu settings that depend on the operating system, section 12.3
doors/ entries other than the window: MCP server, bridge for agents, remote hub
6.3. A command, the reference shape
#[tauri::command]
pub async fn transcript_search(
state: State<'_, AppState>,
input: SearchInput,
) -> Result<Vec<TranscriptHitDto>, IpcError> {
let hits = state.transcripts.search(input.into()).await?;
Ok(hits.into_iter().map(Into::into).collect())
}
If a command needs an if, a loop or two calls into the slice, that logic belongs in service.rs or logic.rs. The 10-line limit is not about style. A command that only translates needs no unit test of its own, because its logic is tested in the slice. What is left to prove is the sentence a person sees, and that is tested end to end through the entry (section 14).
6.4. Registering commands
tauri::generate_handler! needs the full path of every command, so lib.rs keeps one list. Keep it grouped by slice, one block per slice, so that adding a command is one line next to its neighbours:
pub fn run() {
tauri::Builder::default()
.setup(setup)
.invoke_handler(tauri::generate_handler![
recording::commands::recording_start,
recording::commands::recording_stop,
recording::commands::recording_list,
transcript::commands::transcript_read,
transcript::commands::transcript_search,
board::commands::board_list,
board::commands::board_sync,
])
.run(tauri::generate_context!())
.expect("the window could not start");
}
A command that exists in a slice but is missing from this list compiles and silently does nothing. Section 16 includes a small check that compares the two and fails when they drift.
6.5. Naming slices
- One noun per feature, in the singular:
trigger, nottriggers. - The name of the thing the user recognizes, not of the technique:
transcript, notwhisper_pipeline. - When two features always change together, they are one slice. When one feature has parts that change independently, they are sub-slices.
- Cross-cutting policy is a slice too: access gates, limits, budgets and secret protection live in
core/<policy>/(for examplecore/guard/) and every other slice calls them.