Frontend
The web app is a single-page React application in frontend/. This page explains its stack, layout, data flow and the run view. It is for developers who change the UI.
Stack
| Concern | Library |
|---|---|
| UI | React 19, TypeScript |
| Build | Vite 8 |
| Styles | Tailwind CSS 4, with small components built on Radix primitives (src/components/ui) |
| Server data | TanStack Query |
| Client state | Zustand (the run view, reading preferences) |
| Routing | React Router 7 |
| Graph view | React Flow (@xyflow/react) |
| Maths | KaTeX |
| Mind maps | Markmap |
react-pdf (pdf.js). Pages load on demand: pdf.js asks the API for byte ranges (206) and fetches only what the shown page needs (disableAutoFetch, disableStream). nginx serves its worker (.mjs) as text/javascript. | |
| Lint | oxlint |
Versions are pinned exactly in package.json. Fonts are self-hosted, not loaded from a CDN.
Layout
| Folder | What it holds |
|---|---|
src/pages/ | One component per route: Library, Study, Read, Search, Account, Users, Settings, Login, Invite |
src/features/chat/ | The chat screen: sidebar, message list, composer, run panel and its tabs, PDF viewer, the run store |
src/features/code/ | Code cells and the Code tab |
src/features/study/ | The concept map view |
src/features/notes/ | Note cards and note calls |
src/features/account/, src/features/admin/ | Extension tokens; the admin Configuration tab |
src/components/ | Shared pieces: app bar, Markdown view, mind map, reading menu, resize handles, dialogs |
src/api.ts | Types for the API and the api() fetch helper |
src/auth.tsx | The signed-in user and route guards |
src/lib/ | Reading preferences and utilities |
Routes are in src/App.tsx. Admin-only routes (/users, /settings) use RequireAuth admin. Heavy parts (the PDF viewer, the graph, the mind map, the concept map) load lazily, so the first screen stays small.
Talking to the API
The dev server proxies /api to the backend (API_PROXY_TARGET, default http://127.0.0.1:5020, the API started with --port 5020). In the stack, nginx does the same. So the app and the API share one origin, and the cookies stay SameSite=Strict.
api() in src/api.ts sends cookies, parses errors into {code, message}, and on a 401 refreshes the session once and retries. Concurrent requests share one refresh. When the refresh fails, the app sends the user to the sign-in page.
Server data goes through TanStack Query with stable keys, for example ["threads", spaceId] or ["space-sources", id]. Mutations invalidate the keys they change. Lists that change in the background, such as a document being indexed, poll while something is in progress.
A new message sends an Idempotency-Key, so a double click or a retry never starts two runs.
The run view
src/features/chat/runStore.ts holds the run the user is watching. Its core is one pure reducer that turns a run event into the next view: steps, their states and summaries, the streaming draft, the reasoning, candidates, evidence decisions, claims, model calls.
- Live: an
EventSourceon/api/runs/{id}/eventsfeeds events to the reducer as they arrive. On a drop it reconnects with the last event id. - Replay: the stored log of a past run (
GET /api/runs/{id}/log) goes through the same reducer, up to the slider's position.
Because both paths use one function, a replay shows exactly what was shown live.
The run panel's tabs (Flow, Steps, Sources, Viewer, Code, Log, Memory) are views of that state. The Flow tab draws the graph from GET /api/agent/graph, so a change to the answer graph shows up without a UI change.
Answers
MarkdownView renders answers with KaTeX for maths. Citation markers become buttons that open the passage in the Viewer tab. The PDF viewer jumps to the cited page and highlights the quote in the text layer.
Reading preferences
src/lib/prefs.ts keeps the theme (system, light, dark), text size, reading width, reading font (Inter, Roboto, Open Sans or the system font) and code font (Cascadia Code or Fira Code) in local storage. UI text is at least 16 px; answers default to about 18 px.
Checks
From frontend/:
bash
npm run lintbash
npm run typecheckbash
npm run buildThe lint runs with zero warnings.