App architecture and layout
How an enzim app is structured on disk, which layer owns what, and why every app is its own Cargo workspace.
Every enzim app is a native Rust program built on the iced-based enzUI framework. The apps share one source-organisation rule, the fleet layout policy, so that someone who has read one app can find their way around the others. This page summarises that policy and the reasoning behind it.
One Cargo workspace per app
Each app is its own Cargo workspace root. It is not a member of a shared workspace, and it is not a member of the framework's workspace. This is deliberate:
- one app's build can never change another app's build time,
Cargo.lockor test count; - an app can adopt a framework feature at its own pace;
- a broken app does not break the others.
The app’s Cargo.toml and Cargo.lock pin the Git revisions for enzUI and iced. The root manifest also carries the necessary Cargo patches. Keep the framework and iced revisions aligned. See Building an app for the framework’s dependency guide.
What belongs at the app root
The app root holds only durable inputs:
| Entry | Contents |
|---|---|
Cargo.toml, Cargo.lock | the app's own workspace root |
*.md | app documentation |
src/ | shipped Rust |
tests/ | crate-level behaviour tests, their fixtures (tests/fixtures/) and tooling (tests/tools/) |
assets/ | shipped immutable resources |
packaging/ | package metadata, where the app ships it |
capture.env, sabotage.toml | tracked inputs for the shared capture and positive-control tools |
locales/ | Fluent catalogs, in apps that keep them at the root |
Generated output (captures, run logs, profiling data, temporary homes, build output) is never committed. It goes under an ignored path such as target/ or an explicitly external run directory.
Rust module layers
Apps use the same layers wherever they need them, and create none they do not need:
| Layer | Owns |
|---|---|
main.rs | process entry and iced application construction, nothing else |
app/ | application state, messages, update and subscription routing, lifecycle |
model/ or domain/ | domain state and pure rules |
view/ or ui/ | presentation, grouped by user-visible surface |
services/ | capability interfaces and application-owned orchestration |
platform/ | operating-system and runtime adapters |
persistence/ | serialisation, migration, durable stores |
The rules matter more than the table:
- Split by ownership, not by line count. A split follows a state owner, a protocol or capability boundary, a user-visible surface, or a behaviour family.
part1.rs,misc.rs,helpers.rsand line-range files are not splits. - Keep privacy narrow. Mirror the visibility an item already had. Do not widen an item to
pubto move a test, and do not add wildcard re-export barrels. - No
include!god files. A textually included module shares one namespace with its host. Prefermod. - No cycles between layers. A view reads state; state does not build views.
Large modules split into a directory of parts (app_parts/, view_parts/ and so on) beside the module that declares them, so no crate root holds the whole app. Apps with a substantial GUI-free core put it in its own crate: Photos keeps raster admission, discovery, metadata and edit recipes in crates/photos-library, and Messages keeps identities, timelines and the outbox in crates/messages-core.
The 1,000-line ceiling
Every hand-maintained .rs file finishes strictly below 1,000 physical lines. A file at exactly 1,000 lines is a violation.
The ceiling is a guardrail, not a design method: split first by ownership and the ceiling follows. Generated code or data may be exempt only when the exemption records the generator command and its purpose. Ordinary test fixtures, expectation tables and long-standing large modules are not exceptions.
A layout checker enforces the policy and records any remaining debt in an exact ledger that may only shrink. Individual apps are at different stages of converging on the layers above; the ledger, not a promise, records where each one stands.
Rust policy
Because every app is its own workspace root, the framework's rust-version and workspace lints never reach app code. Each app manifest therefore declares them itself:
- a
rust-versionno lower than the framework's minimum, and a pinned toolchain inrust-toolchain.toml; unsafe_code = "deny"(or"forbid"where an app needs no exception at all).
deny rejects every unannotated unsafe. A reviewed exception, such as production FFI, carries an item-level #[allow(unsafe_code)] on the smallest item that needs it, never a crate-wide allowance.
Tests
- A small private unit test stays next to its owner, or in that module's
tests.rschild. - Cross-module behaviour belongs in
<app>/tests/only when it can use an honest public or test-only boundary. Most apps are binary-only, and exposing internals just to reach them from an integration target is worse than keeping the test in the crate. - Name test files after behaviour, never after issue numbers.
See Testing apps for how suites are run.