● Set up · How the parts talk
Architecture
who talks to whom.
One picture of where each piece runs and which way data moves. The short version: trading happens between the user's browser tab and Hyperliquid; your server holds settings and calls the AI, and never sees a wallet key or an order.
01Data flow
02Every arrow, with the code behind it
| From → to | What moves | Code |
|---|---|---|
| Browser tab → Hyperliquid | Market list, candles, funding, prices (REST and WebSocket); account state; for testnet and mainnet runs, orders and cancels signed by the agent key in the tab. | src/hl/market.ts, src/hl/trade.ts, src/landing/live.ts |
| Browser wallet → Hyperliquid | Two one-time signatures: approveAgent (the expiring trading key) and, if you set a builder fee, approveBuilderFee. A Pro payment is a usdSend the user signs. | src/hl/trade.ts |
| Browser tab → Telegram | Alert messages, with the user's own bot token. Only when the user sets up Telegram alerts. | src/live/telegram.ts |
| Browser tab → THESIS server | GET /api/config (public settings), POST /api/strategy (chart image or candles, for AI chart reading), /api/pro/* (plan sign-in by a signed message). | src/config.ts, src/ui/actions.ts, src/ui/pro.ts → server/app.ts |
| Operator's browser → THESIS server | The admin console and its API under /admin/api/*, with an HttpOnly session cookie. | packages/admin-kit/server/kit.ts |
| Server → Anthropic | The chart or candles and the prompt, with your key. Only when AI is on and a key is set. | server/ai.ts |
| Server → Postgres or SQLite | Admin settings, owner and team, sessions, audit log, history, encrypted secrets. | packages/admin-kit/server/postgres.ts, sqlite.ts; chosen in server/node.ts and server/app.ts |
| Server → stats file or Vercel Blob | Aggregate daily counters (AI requests, tokens, page loads). No visitor is identified. | server/store.ts |
| Server → Hyperliquid (read only) | Status checks (mainnet and testnet answer, builder address value), your pay-to address ledger for Pro payments, reward claims for Revenue. No key, no orders. | server/admin-kit.ts, server/revenue.ts |
On Vercel, api/[...path].ts passes every /api/* and /admin/api/* request to the same handler; on your own server server/node.ts does, and also serves the built pages from dist/.
03How the boundaries are enforced
- Content-Security-Policy: the pages may connect only to their own origin, the Hyperliquid hosts (mainnet and testnet,
api.andrpc., HTTPS and WSS) andhttps://api.telegram.org. The list is inserver/csp.ts(Node) andvercel.json(Vercel). A request to any other host is blocked by the browser. - Network log: the desk's key panel lists every host the tab contacted, so you and your users can check it (Using the desk).
- No key on the server: the agent key is generated in the tab (
src/hl/trade.ts) and kept in memory orsessionStorage; the server code has no signing path for orders. - Secrets at rest: the Anthropic key, the webhook secret and two-factor secrets are encrypted with
ADMIN_SECRET_KEY(Secrets and backups).