# About the desktop shell

The desktop app has no UI or API of its own. `src-tauri/` is a thin Rust
shell that starts the same Node server you run from source and points a
webview at it. This page explains why it is built that way and what the
shell is responsible for. At startup the shell does three things:

```text
+------------------------------------------------------------+
| Tauri (Rust)                                               |
|   1. spawns  <NODE> <APP>/server/dist/cli.js --port 17494  |
|   2. waits for /api/health                                 |
|   3. webview  -->  http://127.0.0.1:17494                  |
+------------------------------------------------------------+
```

`<NODE>` is the Node shipped with the app, or in a checkout `SOUNDBOX_NODE`
or the `node` on `PATH`. `<APP>` is the server the shell found, as described
in [Where the server comes from](#where-the-server-comes-from).

## One app, two wrappers

Because the server serves the built frontend at `/`, the HTTP API under
`/api` and the MCP server at `/mcp` on one port, the desktop app and a
browser tab show the same app. After the splash screen, nothing differs. A
fix to the web app is a fix to the desktop app, and the two cannot drift.

The cost is a Node runtime inside the installer. The installed app runs on
the Node shipped beside its executable, not on whatever Node the machine has,
because its native module, `better-sqlite3`, was built for that Node's ABI.
`SOUNDBOX_NODE` overrides it.

## Where the server comes from

The shell finds a server to run in this order:

1. `SOUNDBOX_PROJECT_ROOT`, if set.
2. The copy installed with the app, at `$RESOURCE/app/server`.
3. A checkout, found by walking up from the executable, then from the working
   directory, to `server/package.json`. In a checkout with no build yet, the
   shell runs `server/src/cli.ts` with the workspace's `tsx`.

The installed copy is laid out like the repository: `server/dist`,
`server/web`, `server/skills`, the production `node_modules`, and `README.md`
plus `docs/` for the in-app assistant. So the server finds everything
relative to itself the same way in both places.

The server serves the UI from `server/web/`, which `scripts/build.mjs` fills
from `app/dist`. If the shell starts a server that was never built, the
window shows a JSON stub saying the UI is not bundled. The shell's own markup
is only `src-tauri/splash/`, the loading screen. `tauri.conf.json` also names
it as `frontendDist`, so the shell compiles without a web build.

## Starting, adopting and stopping

If a server already answers on the shell's port (17494, or
`MIRLI_DESKTOP_PORT`), the shell adopts it instead of starting a second one.
That lets the desktop app and `npm run dev` share a server.

When the window closes, the shell stops the server it started. On Windows
it also does so after a crash or a force-kill, through a job object, because
a graceful-shutdown handler cannot run when a process is killed, and an
orphaned server would keep holding the GPU and the port.

## Why the installer is staged separately

`npm run desktop:build` merges `src-tauri/tauri.bundle.conf.json` into the
Tauri config. That file adds the staging step, ships the pinned Node as an
`externalBin` beside the executable, and ships `build/desktop/` as the `app`
resource folder. Keeping those in a separate file means `cargo check`,
`npm run desktop` and CI need nothing staged.

## No weights in the installer

The app does not bundle model weights. They are gigabytes, and several models
have non-commercial licences (see the licence table in the README). Weights
download from the **Models** page, as in the web app.

## Logs

The shell writes its lifecycle lines, including any error the splash screen
shows, to `soundbox-desktop.log` in the system temp folder, because a release
build on Windows has no console. Everything after the server starts goes to
the server's own log in the data folder; see
[Find the server log](https://mirli.app/docs/install-troubleshooting/index.md#find-the-server-log). The
shell's environment variables are listed in
[Environment variables](https://mirli.app/docs/install-env/index.md).
