---
name: egui-app-architecture
description: >-
  Use this skill when exploring, understanding, scaffolding, structuring, or auditing a multi-crate Rust and egui application (strict L0–L7 dependency layering, xtask layer enforcement, panic-free/unsafe-free lint gates, and Cargo profile tuning for native + WebAssembly targets).
title: egui-app-architecture
canonical_url: https://skilld.dev/gh/domesticmouse/skills/egui-app-architecture
last_updated: 2026-10-28T00:30:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/layering-and-profiles.md](https://skilld.dev/api/skills-raw/domesticmouse/skills/egui-app-architecture/references/layering-and-profiles.md).
>
> If the user asked to install this Skill, run `npx skilld install domesticmouse/skills/egui-app-architecture`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/egui-app-architecture`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/domesticmouse/skills/egui-app-architecture) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/egui-app-architecture`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/egui-app-architecture --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/egui-app-architecture --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Engine-First egui Application Architecture (`L0`–`L7`)

This skill guides you through setting up and maintaining a pure-Rust, engine-first desktop (`eframe`/`egui`), CLI, and WebAssembly application with strict architectural boundaries.

## Architectural Principles

1. **Strict Acyclic Layering (`L0`–`L7`):** Every workspace crate is assigned a layer in `xtask/src/layers.rs`. A crate at layer $N$ may only depend on crates in layers $< N$ (plus explicit intra-layer chains).
2. **Standalone Format & OS Helper Crates:** Reusable parsers/encoders (`codecs`, `formats`) and isolated OS helpers are classified as `Standalone` at `L0` and must have **zero workspace dependencies** so they remain independently publishable and testable.
3. **UI Containment (`L6+` only):** No crate below `L6` may depend on UI or windowing crates (`egui`, `eframe`, `winit`, `rfd`). `L0`–`L5` must compile headlessly and for `wasm32-unknown-unknown`.
4. **Never Crash (No Panic, No Unsafe):** Workspace-wide `unsafe_code = "forbid"` and `#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]` on every library and binary crate. If an isolated OS integration crate requires FFI, isolate it in its own `L0` crate with `unsafe_code = "deny"` and explicit `SAFETY:` comments and platform tests.

---

## Step-by-Step Workflow

### 1. Organize the Cargo Workspace into Layers

Structure the repository into `crates/*`, `apps/*`, and `xtask` (adapt layers as needed for your domain):

- **`L0` Foundation:** Core primitives, geometry, math, and copy-on-write data containers.
- **`L0` Standalone:** Format parsers/writers and OS helpers with no workspace dependencies.
- **`L1` Document / Domain Model:** `doc` — pure serializable data structures (document tree, entities, metadata). No rendering or UI logic.
- **`L2` Operations & Algorithms:** `ops` (undo/redo history), `algo` (domain transformations, queries, and processing).
- **`L3` Rendering & Native Persistence:** CPU/GPU rendering backends (`wgpu`) and `format` (content-addressed or structured native bundle).
- **`L4` I/O & Plugins:** `io` (maps standalone formats $\leftrightarrow$ `doc::Document`), optional sandboxed plugins.
- **`L5` Engine Façade:** `engine` (`Session`, `CommandSpec` registry, background `Jobs`, `Preferences`).
- **`L6` Shells & Automation:** `ui-egui` (thin `egui` frontend + optional JSON control protocol), `automation` (MCP server + headless JSON-RPC).
- **`L7` Binaries (`Exempt`):** `apps/<app>` (desktop `eframe` binary), `apps/<app>-cli` (headless CLI + MCP/RPC host), `apps/<app>-web` (browser Wasm), `xtask`.

### 2. Configure Workspace Lints and Cargo Profiles

Apply the workspace lint gates and build profiles in the root `Cargo.toml`.
See [layering-and-profiles.md](https://skilld.dev/api/skills-raw/domesticmouse/skills/egui-app-architecture/references/layering-and-profiles.md) for the exact `Cargo.toml` configuration:
- Optimize dependencies in dev builds (`[profile.dev.package."*"] opt-level = 2`) so rendering and compute loops run at interactive speeds during development.
- Use `debug = "line-tables-only"` in `[profile.dev]` to halve link times and symbol sizes.
- Set `[profile.test.package.<ui-crate>] opt-level = 0` to speed up UI test compilation.
- Configure `[profile.wasm-release]` with `lto = "fat"` and per-crate `opt-level` overrides (`"z"` for data/parsers/UI, `3` for hot compute crates).

### 3. Enforce Layering with `cargo xtask layers`

Whenever adding a crate or dependency:
1. Register the crate in `xtask/src/layers.rs` (`TABLE`).
2. Add the crate header lints (`#![forbid(unsafe_code)]` and `#![deny(clippy::unwrap_used, ...)]`) to its `src/lib.rs`.
3. Write or update `Cargo.toml` atomically if working alongside parallel agents.

### 4. Validation Steps

Run these commands to verify architectural compliance (see [egui-testing-infrastructure](../egui-testing-infrastructure/SKILL.md) for the full 7-tier verification, corpus, performance, and scorecard workflow):

```sh
cargo xtask layers
cargo xtask wasm
cargo clippy --workspace --all-targets -- -D warnings
```
