> Every Taji docs page as Markdown: https://docs.taji.is/llms.txt

# Architecture

Taji is one local Rust process, the [kernel](https://docs.taji.is/reference/glossary.md#kernel) (`taji`), that owns all state: accounts, orders, desks and data. Everything else is a client of it or a child of it. Its two clients, Taji's window and your agent over MCP, speak one loopback wire, and every request carries one of the tokens the kernel mints at each launch. This page shows each process, how it reaches the kernel and what it is refused.

## What runs on your machine?

```mermaid
flowchart LR
  platform["Agent platform"] -->|"stdio, MCP"| bridge["Bridge, taji-mcp"]
  bridge -->|"wire"| kern["Kernel"]
  win["Window: main, page, sheet"] -->|"wire"| kern
  link["taji-link, taji ui"] -->|"wire"| kern
  kern <-->|"ACP over stdio"| acp["Agent adapter"]
  kern <-->|"stdio, sandboxed"| proc["Process plugins"]
  kern <-->|"vault credentials"| ext["Venues, vendors, messaging apps"]
  kern --> disk[("State dir, store root")]
```

Read it from the left. Your agent platform starts the bridge as its own child and talks MCP to it; the bridge, the window and the terminal tools each reach the kernel over the wire. The kernel starts the rest: your agent's ACP adapter for the window's conversation, and each process plugin inside the OS sandbox. Only the kernel talks to venues and data vendors, and only it writes the state dir and the store root ([Configuration](https://docs.taji.is/reference/configuration.md) says where they are).

| Process | Built with | What it does | Code |
|---|---|---|---|
| Kernel | Rust | Holds the vault, each account's order path, the hub and every compiled-in plugin, and serves the wire. One per state dir and per store root: a second boot on either stops with "another Taji owns". It runs with the window or without it (headless). | `engine/crates/taji/src/kernel.rs` |
| Window | Electron | Boots or attaches to the kernel, then shows the page. One window per state dir; on macOS, closing it leaves the kernel running and a menu-bar item. | `window/src/main.ts` |
| Page | React, Vite; three.js draws the chart | The terminal you see. Its build is embedded in the kernel binary; `TAJI_UI_DIR` overrides it for development. | `ui/`, `engine/crates/taji/src/wire/app.rs` |
| Sheet | A second web contents in the window | Where you type a secret and consent to a plugin. It runs no plugin code, and the page cannot reach it. | `window/src/sheet.ts` |
| Bridge | TypeScript on Bun | The MCP server, `taji-mcp`. Stateless: every tool is a wire call. With nothing on the port it boots a detached headless kernel. No tool takes a secret. | `agent/src/mcp/catalog.ts`, `stdio.ts`, `boot.ts` |
| `taji-link` | TypeScript on Bun | The terminal's door for a secret: you type it with hidden input, and it posts to the wire, so no key passes through your agent. | `agent/src/mcp/link.ts` |
| Agent adapter | Your agent's own | Your agent's ACP adapter, a child process on an allowlisted environment and your own login. Taji sees none of its credentials. | `engine/crates/taji/src/agent.rs` |
| Process plugins | Any language | Tier 2 plugins and the Python sources, each inside the OS sandbox with no network but the kernel's proxy to the hosts its manifest declares. | `engine/crates/taji-host/src/process.rs` |

Taji embeds no model: the window's conversation runs your own agent through its adapter ([0002](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0002-taji-embeds-no-model.md)). The adapter is Claude Code's or Codex's npm package, installed from its shipped lockfile and run by `node`, or the platform's own command, such as `agy acp` or `cursor-agent acp`.

## How does each client talk to the kernel?

Each line in the diagram is one of these interfaces.

| Interface | Framing | Auth | Code |
|---|---|---|---|
| Agent platform to `taji-mcp` | MCP, JSON-RPC over stdio | none: the platform's own child | `agent/src/mcp/stdio.ts` |
| `taji-mcp` to the kernel | HTTP JSON; an Arrow IPC stream for a `get/<product>` read; `/ws/live` for changes | `x-taji-token` from `<state dir>/agent-token` | `agent/src/mcp/wire.ts` |
| `taji-link`, `taji ui`, Electron main to the kernel | HTTP JSON | `x-taji-token` from `<state dir>/wire-token` | `agent/src/mcp/link.ts`, `engine/crates/taji/src/subcommands.rs`, `window/src/main.ts` |
| Page, sheet to the kernel | HTTP JSON; `/app/*` static | `POST /app/token` trades a one-use nonce for the `page` or `sheet` token, held in memory | `packages/plugin/state/wire.ts`, `window/src/sheet.ts` |
| Any client to `/ws/live`, `/ws/agent`, `/ws/voice`, `/ws/market` | binary frames: a u32 LE header length, the JSON header, then Arrow bytes if any | a first message `auth` holding a token within 5 s, or on `/ws/market` the `x-taji-token` header; an `Origin`, if sent, must be this port's page | `engine/crates/taji/src/wire/ws.rs` |
| Kernel to Electron main | argv and environment; the window key, one line on stdin | the key | `spawn_window` in `engine/crates/taji/src/subcommands.rs` |
| Kernel to `taji-register` | argv; one JSON line on stdout | none | `engine/crates/taji/src/wire/agents.rs` |
| Kernel and the agent adapter | ACP, JSON-RPC 2.0, one message a line over stdio | none | `engine/crates/taji/src/agent.rs` |
| Kernel and a process plugin | JSON lines, the first `{"hello": "taji-plugin/1", "id"}` | the OS sandbox; no token | `engine/crates/taji-host/src/process.rs` |
| Kernel to venues, vendors and messaging apps | each vendor's own API | credentials from the vault, where it takes one | each plugin's crate under `plugins/` |

The four sockets split the traffic. `/ws/market` carries every `get/<product>` read the page makes and every stream it subscribes; `/ws/live` the change feed; `/ws/agent` the conversation's chats; `/ws/voice` the page's audio.

Every route is one row of one catalog, the `//!` header of `engine/crates/taji/src/wire/mod.rs`, and `GET /read/routes` serves it ([0006](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0006-one-route-catalog.md)). The wire's conventions are in [Wire](https://docs.taji.is/reference/wire.md).

## How does the kernel know who is calling?

By the token a request holds, never by a header it sets. The kernel mints one token per scope at each launch, 32 random bytes in hex:

| Scope | Held by | Where it lives |
|---|---|---|
| `local` | the window's main process, `taji-link`, `taji ui`, your scripts | `<state dir>/wire-token`, mode 0600 |
| `agent` | the MCP bridge | `<state dir>/agent-token`, mode 0600 |
| `page` | the page | memory only, bought with a nonce through `POST /app/token` |
| `sheet` | the sheet | memory only, bought the same way |

The page and the sheet each also have a by-hand token, bought with a nonce that only the window the kernel started can mint, using the key it handed that window on stdin. A by-hand token acts as `page` or `sheet` does, and it is how the kernel tells your own click from a script's call.

Every `POST` is admitted by its token's scope before any handler runs; a route whose scopes omit it answers 403 `scope`. That is where the boundaries between clients are drawn:

- The `agent` token cannot open the vault, set the data budget, approve a parked call, turn an account's approvals on or off, or drive the window's conversation. A link it posts with a secret field is refused 403 `secret`: you type keys in the sheet or in `taji-link` ([0005](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0005-no-key-reaches-a-client.md)).
- The `page` token reaches no verb that puts a secret in: sealing and unlocking the vault answer `local` and `sheet` only.
- While an account's approvals are on, the default for a live one, its orders park until you approve them in the window. Only a by-hand call skips the park, so nothing your agent or a script sends can ([0008](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0008-live-orders-wait-for-approval.md)).
- The `agent` token is charged against 600 reads and 120 other calls a sliding minute; past either, 429 `rate_limited`.

Two refusals come before any token is read. A request whose `Host` is not `127.0.0.1` or `localhost` is 421 `host`, so a web page reaching the port through a rebound name gets nothing. A proxy request is 405 `not_a_proxy`: the kernel dials nothing for a wire request.

## Where do data and orders cross the kernel?

Through one seam each, so that no client and no plugin needs to know which vendor answers.

| Seam | What passes through it | More |
|---|---|---|
| The hub, `engine/crates/taji-trading/src/hub.rs` | Every market data read. Providers answer it; clients read its products. A plugin never ranks itself among the hub's sources. | [Data](https://docs.taji.is/architecture/data.md) |
| The order path | Every order, through the account's stadium (risk gate, journal, venue, reconciler), and read back from the venue. Nothing above the trading root holds a broker handle or a credential (`engine/crates/taji-trading/tests/dependency_audit.rs`). | [Orders](https://docs.taji.is/architecture/orders.md) |
| The plugin seam | A tier 1 plugin is a crate on `taji-plugin` alone; a tier 2 plugin is a process speaking the protocol in `schema/taji.json`. One registry routes both. | [Plugins](https://docs.taji.is/architecture/plugins.md) |

Three rules hold these seams. The kernel computes every figure with trading meaning, a price, P&L or a greek, and serves it as a read field or a pushed view, so the window and your agent never disagree on one ([0001](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0001-kernel-computes.md)). A plugin depends on its SDK alone, never on the kernel or another plugin, and vendor code lives in its plugin ([0003](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0003-plugin-on-sdk-alone.md)). A provider's capability reaches you only as a hub product or the brokerage interface, and no route names a vendor, so a provider adds no surface of its own ([0004](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0004-capabilities-through-the-hub.md)).

Process plugins are held to one more. At boot the kernel runs a canary, its own binary under a plugin's sandbox policy behind a proxy that declares no host, and starts no process plugin unless the canary is refused every check (`engine/crates/taji-host/src/sandbox.rs`). An installed pane sends no order: its verbs reach nothing under `trading/` ([Window contract](https://docs.taji.is/plugins/window.md)). What each process can reach is in [Security](https://docs.taji.is/architecture/security.md).

## How do the binaries and the skill reach your machine?

`engine/crates/taji/scripts/stage.sh` stages every package from the same tree:

- `bin/`: the kernel `taji`; the Bun binaries `taji-mcp`, `taji-link`, `taji-register` and `taji-whatsapp`; the Go sidecar `taji-tailscale`; and `uv`.
- `resources/`: the `taji` skill and a `digest` of its files.
- `python/`: the interpreter the kernel's Python processes run.

At a headless boot the kernel compares that `digest` with the one in the Taji home and lays each resource directory there when they differ (`engine/crates/taji/src/resources.rs`). When `agent/connect` is posted, the kernel runs `taji-register` (`agent/src/register.ts`), which registers the bridge as `taji` and copies the skill for each agent platform the call names, or every one it finds. The install gates post it, and your agent can; your agent's call waits for your approval.

## Which platforms does it run on?

| OS | State |
|---|---|
| macOS | Apple Silicon, macOS 26 or later; `make dev` builds and opens the window. |
| Linux | x64. Builds and tests in CI on Ubuntu 24.04 (`.github/workflows/ci.yml`), the plugin sandbox (bubblewrap) included; [Build from source](https://docs.taji.is/guide/install.md) names Debian 13. |
| Windows | Windows 11 24H2, build 26100.9278 or later (x64), the plugin sandbox's floor (`engine/crates/taji-host/src/sandbox.rs`). CI builds it from source (`.github/workflows/windows.yml`), and no passing run of that build has been seen; CI runs the sandbox suite on Windows 11 arm64. Steps: [Build from source](https://docs.taji.is/guide/install.md#windows). |

## See also

- [What is Taji](https://docs.taji.is/guide/what-is-taji.md): the short tour of the same pieces.
- [Data](https://docs.taji.is/architecture/data.md): how the hub answers a read.
- [Orders](https://docs.taji.is/architecture/orders.md): how an order reaches a venue and is read back.
- [Security](https://docs.taji.is/architecture/security.md): what each process and client can reach.
- [Plugins](https://docs.taji.is/architecture/plugins.md): how plugins are composed, loaded and hosted.
- [Wire](https://docs.taji.is/reference/wire.md): the wire's conventions.
- [Decisions](https://github.com/TajiAI/Taji/blob/main/docs/decisions/README.md): why each rule stands.
