# Build an app with Waft

Do each step yourself; ask the user only where a step says so.

1. **Tools:** Waft apps use nightly Rust (`#![feature(arbitrary_self_types)]`, pinned automatically by the `rust-toolchain.toml` that `cargo waft new` writes). Install the CLI with `cargo install waft-cli` and run `cargo waft doctor` to check which platforms this machine can build for.
2. **Scaffold:** `cargo waft new <name> --template winui` for a desktop, web, or cross-platform app, or `cargo waft new <name> --template cupertino` for a mobile-first iOS/Android app. The app lives in `src/lib.rs` (built as both `cdylib` and `rlib`), with a thin desktop entry in `src/main.rs`.
3. **Read the guides:** Read the Waft documentation at https://waft.rs/docs (or fetch https://waft.rs/llms-full.txt for all pages in one Markdown document):
   - `from-flutter` (https://waft.rs/docs/from-flutter.md) first, before writing any Waft code: how Flutter's code reads in Waft, and the traps that compile and then do the wrong thing (argument order, insets, `Option`s, `.into()`).
   - `architecture` (https://waft.rs/docs/architecture.md): how an app is structured into **Logic** (plain Rust), **State** (`Entity<T>`), and **UI** (thin `StatelessWidget`s).
   - `state` (https://waft.rs/docs/state.md) and `handles` (https://waft.rs/docs/handles.md): `Entity<T>` vs `Ref<T>` and `Handle<T>`, and the borrow rule (`let val = { entity.read(app).field.clone() };` before the next `&mut App` call).
   - `kits` (https://waft.rs/docs/kits.md), `layout` (https://waft.rs/docs/layout.md), `text-input` (https://waft.rs/docs/text-input.md), `pages` (https://waft.rs/docs/pages.md), and `shortcuts` (https://waft.rs/docs/shortcuts.md).
   - Full Rust API docs are on docs.rs: `waft`, `waft-winui`, `waft-cupertino`, `waft-material`, `waft-markdown`, `waft-test`.
4. **Architecture & testing first:** Keep business rules in plain Rust structs and app state in `Entity<T>` handles (`app.new_entity(|_cx| ...)`). Write unit tests for your Logic and State layers using `AppCell::new()` and `waft-test` (`https://waft.rs/docs/testing.md`) and run `cargo test` — no display is required.
5. **Icon & metadata:** Configure `[package.metadata.waft]` in `Cargo.toml` (`identifier`, `name`, `icon = "assets/icon.png"`, `resources`, `file_associations`, `usage_descriptions`). Replace `assets/icon.png` with a clean 1024×1024 RGBA PNG.
6. **Run & package:**
   - Run locally: `cargo waft run` (desktop), `cargo waft run -d ios`, `cargo waft run -d android`, or `cargo waft run -d web`.
   - Look at the running app instead of guessing from pixels: `cargo waft ext tree` prints your widgets with the text each shows, the file and line that made it and its id; `cargo waft ext tree <id>` shows that widget's subtree with its properties; `cargo waft ext screenshot <id>` writes one widget's picture to `waft_01.png`; `cargo waft ext layout '<CSS selector>'` gives a widget's size, constraints and place in its parent, and `offset` where it is on screen; `cargo waft ext tap|long-press|enter-text|text-input-action|scroll|scroll-until-visible|wait-for|get-text '<CSS selector>'` drives the app, as `tap 'ListTile:has([text="Wi-Fi"]) Switch'`, acting only on what is on screen; `tap 'Tooltip[message=Back]'` goes back a page (https://waft.rs/docs/inspecting.md).
   - Build a distributable: `cargo waft build <target>` (`macos`, `dmg`, `windows`, `msi`, `nsis`, `linux`, `deb`, `appimage`, `ios`, `ipa`, `apk`, `web`, or `wasm`). See https://waft.rs/docs/cli.md for signing and platform details.
