# watanabe3tipapa/sarashina-mercury architecture

> Architecture diagram of the GitHub repository watanabe3tipapa/sarashina-mercury, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/watanabe3tipapa/sarashina-mercury
- Repository: https://github.com/watanabe3tipapa/sarashina-mercury

## Overview

Sarashina Mercury is a browser-based PWA for using Sarashina models. Users configure a key and preferences, then enter chat, translation, RAG, or Guard through routed pages; those pages call the API client, which streams or returns results for display. Chat history is persisted locally, and optional input/output safety checks share Guard. README documents a Worker proxy for CORS, but its relationship to the client is configuration-based; the worker forwards requests and does not store keys. Connections below follow excerpts and README; unsampled feature internals are represented by their documented page capabilities.

Main entry points: [`src/App.tsx`](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/App.tsx) (App routes), [`src/store/useSettingsStore.ts`](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/store/useSettingsStore.ts) (Settings state), [`src/lib/api/sarashina.ts`](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/api/sarashina.ts) (Sarashina client), [`src/features/chat/ChatPage.tsx`](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/chat/ChatPage.tsx) (Streaming chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application shell"]
  node_router["App routes<br/>[App.tsx]"]
  node_boundary["Error boundary<br/>[ErrorBoundary.tsx]"]
end

subgraph group_features["User workflows"]
  node_settings["Settings<br/>[SettingsPage.tsx]"]
  node_chat["Streaming chat<br/>[ChatPage.tsx]"]
  node_translate["Translation editor<br/>[TranslatePage.tsx]"]
  node_rag["RAG search<br/>[RAGPage.tsx]"]
  node_guardpage["Guard checker<br/>[GuardPage.tsx]"]
  node_guardnotice["Guard notice<br/>[GuardNotice.tsx]"]
  node_editor["Parallel editor<br/>[EditorPane.tsx]"]
  node_citations["Source citations<br/>[SourceCitation.tsx]"]
end

subgraph group_state["Local state"]
  node_settingsstate["Settings state"]
  node_chatstate["Conversation state<br/>[useChatStore.ts]"]
  node_history[("IndexedDB history<br/>[conversations.ts]")]
  node_theme["Theme behavior<br/>[theme.ts]"]
  node_tokens["Token pricing<br/>[tokens.ts]"]
end

subgraph group_services["Model access"]
  node_api["Sarashina client<br/>[sarashina.ts]"]
  node_worker["CORS proxy<br/>[index.ts]"]
end

node_user(("User"))
node_sarashina{{"Sarashina API"}}

node_user -->|"opens app"| node_router
node_router -->|"routes to"| node_chat
node_router -->|"routes to"| node_settings
node_router -->|"routes to"| node_translate
node_router -->|"routes to"| node_rag
node_router -->|"routes to"| node_guardpage
node_router -->|"wrapped by"| node_boundary
node_chat -->|"reads settings"| node_settingsstate
node_settings -->|"updates settings"| node_settingsstate
node_translate -->|"reads settings"| node_settingsstate
node_rag -->|"reads settings"| node_settingsstate
node_guardpage -->|"reads settings"| node_settingsstate
node_settingsstate -->|"stores preference"| node_theme
node_settingsstate -->|"loads pricing"| node_tokens
node_chat -->|"manages conversations"| node_chatstate
node_chatstate -->|"reads and writes"| node_history
node_chat -->|"streams chat and checks"| node_api
node_translate -->|"translates and checks"| node_api
node_rag -->|"reranks, answers, checks"| node_api
node_guardpage -->|"checks text"| node_api
node_api -->|"sends model requests"| node_sarashina
node_translate -->|"edits paired text"| node_editor
node_rag -->|"shows sources"| node_citations
node_chat -->|"renders verdict"| node_guardnotice
node_translate -->|"renders verdict"| node_guardnotice
node_rag -->|"renders verdict"| node_guardnotice
node_guardpage -->|"renders verdict"| node_guardnotice
node_api -.->|"may target configured proxy"| node_worker
node_worker -->|"forwards requests"| node_sarashina

click node_router "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/App.tsx"
click node_boundary "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/ErrorBoundary.tsx"
click node_settings "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/settings/SettingsPage.tsx"
click node_chat "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/chat/ChatPage.tsx"
click node_translate "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/TranslatePage.tsx"
click node_rag "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/RAGPage.tsx"
click node_guardpage "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/GuardPage.tsx"
click node_guardnotice "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/GuardNotice.tsx"
click node_editor "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/editor/EditorPane.tsx"
click node_citations "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/SourceCitation.tsx"
click node_settingsstate "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/store/useSettingsStore.ts"
click node_chatstate "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/store/useChatStore.ts"
click node_history "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/db/conversations.ts"
click node_theme "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/theme.ts"
click node_tokens "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/tokens.ts"
click node_api "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/api/sarashina.ts"
click node_worker "https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/worker/src/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_router,node_boundary,node_user toneBlue
class node_settings,node_chat,node_translate,node_rag,node_guardpage,node_guardnotice,node_editor,node_citations toneAmber
class node_settingsstate,node_chatstate,node_history,node_theme,node_tokens,node_sarashina toneMint
class node_api,node_worker toneRose
```

## Components

### Application shell

- [App routes](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/App.tsx): `src/App.tsx`
- [Error boundary](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/ErrorBoundary.tsx): `src/components/ErrorBoundary.tsx`

### User workflows

- [Settings](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/settings/SettingsPage.tsx): `src/features/settings/SettingsPage.tsx`
- [Streaming chat](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/chat/ChatPage.tsx): `src/features/chat/ChatPage.tsx`
- [Translation editor](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/TranslatePage.tsx): `src/features/tools/TranslatePage.tsx`
- [RAG search](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/RAGPage.tsx): `src/features/tools/RAGPage.tsx`
- [Guard checker](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/features/tools/GuardPage.tsx): `src/features/tools/GuardPage.tsx`
- [Guard notice](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/GuardNotice.tsx): `src/components/GuardNotice.tsx`
- [Parallel editor](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/editor/EditorPane.tsx): `src/components/editor/EditorPane.tsx`
- [Source citations](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/components/SourceCitation.tsx): `src/components/SourceCitation.tsx`

### Local state

- [Settings state](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/store/useSettingsStore.ts): `src/store/useSettingsStore.ts`
- [Conversation state](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/store/useChatStore.ts): `src/store/useChatStore.ts`
- [IndexedDB history](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/db/conversations.ts): `src/lib/db/conversations.ts`
- [Theme behavior](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/theme.ts): `src/lib/theme.ts`
- [Token pricing](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/tokens.ts): `src/lib/tokens.ts`

### Model access

- [Sarashina client](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/src/lib/api/sarashina.ts): `src/lib/api/sarashina.ts`
- [CORS proxy](https://github.com/watanabe3tipapa/sarashina-mercury/blob/main/worker/src/index.ts): `worker/src/index.ts`

### Other components

- **User**
- **Sarashina API**

## Connections

- User → App routes: opens app (evidence: `README.md`)
- App routes → Streaming chat: routes to (evidence: `src/App.tsx`)
- App routes → Settings: routes to (evidence: `src/App.tsx`)
- App routes → Translation editor: routes to (evidence: `src/App.tsx`)
- App routes → RAG search: routes to (evidence: `src/App.tsx`)
- App routes → Guard checker: routes to (evidence: `src/App.tsx`)
- App routes → Error boundary: wrapped by (evidence: `src/main.tsx`)
- Streaming chat → Settings state: reads settings (evidence: `src/features/chat/ChatPage.tsx`)
- Settings → Settings state: updates settings (evidence: `src/features/settings/SettingsPage.tsx`)
- Translation editor → Settings state: reads settings (evidence: `src/features/tools/TranslatePage.tsx`)
- RAG search → Settings state: reads settings (evidence: `src/features/tools/RAGPage.tsx`)
- Guard checker → Settings state: reads settings (evidence: `src/features/tools/GuardPage.tsx`)
- Settings state → Theme behavior: stores preference (evidence: `src/store/useSettingsStore.ts`)
- Settings state → Token pricing: loads pricing (evidence: `src/store/useSettingsStore.ts`)
- Streaming chat → Conversation state: manages conversations (evidence: `src/features/chat/ChatPage.tsx`)
- Conversation state → IndexedDB history: reads and writes (evidence: `src/store/useChatStore.ts`)
- Streaming chat → Sarashina client: streams chat and checks (evidence: `src/features/chat/ChatPage.tsx`)
- Translation editor → Sarashina client: translates and checks (evidence: `src/features/tools/TranslatePage.tsx`)
- RAG search → Sarashina client: reranks, answers, checks (evidence: `src/features/tools/RAGPage.tsx`)
- Guard checker → Sarashina client: checks text (evidence: `src/features/tools/GuardPage.tsx`)
- Sarashina client → Sarashina API: sends model requests (evidence: `src/lib/api/sarashina.ts`)
- Translation editor → Parallel editor: edits paired text (evidence: `src/features/tools/TranslatePage.tsx`)
- RAG search → Source citations: shows sources (evidence: `README.md`)
- Streaming chat → Guard notice: renders verdict (evidence: `src/features/chat/ChatPage.tsx`)
- Translation editor → Guard notice: renders verdict (evidence: `src/features/tools/TranslatePage.tsx`)
- RAG search → Guard notice: renders verdict (evidence: `src/features/tools/RAGPage.tsx`)
- Guard checker → Guard notice: renders verdict (evidence: `src/features/tools/GuardPage.tsx`)
- Sarashina client → CORS proxy: may target configured proxy (evidence: `README.md`)
- CORS proxy → Sarashina API: forwards requests (evidence: `README.md`)
