# Project architecture

Aidget is a cross-platform desktop widget host built with Rust/Tauri 2 and
TypeScript/Vite+. `src/main.rs` dispatches GUI, CLI, and MCP modes in one binary.

- `src/interfaces/` exposes CLI and stdio MCP. CLI widget reads and writes use
  `widgets::store::Store` offline; MCP forwards requests to the resident GUI over
  local IPC, starting it on demand. `src/transport/` owns that IPC, widget resource
  serving, and CSP. IPC uses Unix sockets or Windows named pipes.
- `src/widgets/` owns persisted widget content, metadata, and board frames.
  `src/runtime/` owns native windows, placement, screenshots, and host APIs;
  its watcher reconciles stored changes with running windows.
- `ui/src/main/` implements the management window. `ui/src/widget/` is the trusted
  shell around an opaque-origin sandboxed iframe containing widget content.
  Keep widget content outside the shell's Tauri privileges.
- `src/agents/` manages external Agent integrations; `src/community/` handles the
  widget catalog and package installation; `src/update/` handles app self-update.

# Cross-layer contracts

- Rust owns shared frontend types. Edit their Rust definitions, register new
  exports in `src/bin/typegen.rs`, then run `pnpm typegen`; never edit
  `ui/src/types/rust.ts` by hand. CI verifies it with `pnpm typegen --check`.
- A Tauri command needs registration in `src/runtime/commands.rs`, a window-role
  entry in `src/runtime/command_names.rs`, and a matching capability grant.
  Native authorization and Tauri ACL are separate gates, tested independently.
  `permissions/autogenerated/` is build output; do not edit it.

# Working rules

- Fail fast with explicit errors; do not add fallback logic unless requested.
  Let errors propagate without handling them inside the business layer.
- Preserve existing changes. Do not revert staged files or check out, commit
  from, clean, or delete another session's worktree or logs.

# Required reading

- Before changing code, follow [docs/coding.md](docs/coding.md).
- For local checks, pull requests, merging, and the version model, follow
  [docs/development.md](docs/development.md).
- Before changing the updater, follow [docs/self-update.md](docs/self-update.md).
- Before release work, follow [docs/releasing.md](docs/releasing.md).
- When writing a commit message, follow
  [.github/COMMIT_MESSAGE_INSTRUCTIONS.md](.github/COMMIT_MESSAGE_INSTRUCTIONS.md).
