# thinkwatchproject/thinkwatch-lite architecture

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

- Interactive diagram: https://gitdiagram.com/thinkwatchproject/thinkwatch-lite
- Repository: https://github.com/thinkwatchproject/thinkwatch-lite

## Overview

ThinkWatch Lite is a cross-platform desktop app that embeds a local AI gateway. Users connect supported AI clients once, configure upstream providers and routing in the app, then send requests through the gateway; request traces and security findings are available in the interface. The README documents additional capabilities, including client restoration, remote-core operation, MCP and configuration scanning, and request replay. The graph combines those documented workflows with sampled UI/control code; several backend subsystem links are documented rather than verified from excerpts.

Main entry points: [`src-tauri/src/gateway.rs`](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/src/gateway.rs) (Request gateway), [`src/App.tsx`](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/App.tsx) (App shell), [`src/useRequests.ts`](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/useRequests.ts) (Request history), [`src/control.ts`](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/control.ts) (Control bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop app"]
  node_app["App shell<br/>[App.tsx]"]
  node_control["Control bridge<br/>[control.ts]"]
  node_backend["Desktop backend<br/>[lib.rs]"]
end

subgraph group_gateway["Gateway operation"]
  node_gateway["Request gateway<br/>[gateway.rs]"]
  node_routing["Request routing<br/>[requestRouting.ts]"]
  node_security["Request protection"]
end

subgraph group_configuration["Client and provider setup"]
  node_client_setup["Client setup<br/>[ClientsPage.tsx]"]
  node_adoption["Client adoption<br/>[clients.rs]"]
  node_providers["Provider setup<br/>[UpstreamsPage.tsx]"]
  node_routing_ui["Routing setup<br/>[RoutingPage.tsx]"]
end

subgraph group_observability["Monitoring and protection"]
  node_history["Request history<br/>[useRequests.ts]"]
  node_traffic["Traffic explorer<br/>[TrafficPage.tsx]"]
  node_overview["Usage overview<br/>[useLive.ts]"]
  node_security_ui["Security findings<br/>[SecurityPage.tsx]"]
  node_mcp_scan["MCP and config scan<br/>[lib.rs]"]
  node_mcp_ui["MCP interface<br/>[McpPage.tsx]"]
end

node_user(("User"))
node_client(("AI client"))
node_upstream(("AI upstream"))
node_remote(("Remote core"))

node_user -->|"configures"| node_app
node_app -->|"calls"| node_control
node_control -->|"invokes"| node_backend
node_app -->|"connects remotely"| node_remote
node_user -->|"selects clients"| node_client_setup
node_client_setup -.->|"requests adoption"| node_adoption
node_adoption -->|"updates config"| node_client
node_user -->|"configures providers"| node_providers
node_user -->|"defines rules"| node_routing_ui
node_client -->|"sends requests"| node_gateway
node_gateway -->|"checks requests"| node_security
node_gateway -->|"selects route"| node_routing
node_routing -->|"forwards requests"| node_upstream
node_gateway -->|"records requests"| node_history
node_history -.->|"feeds traces"| node_traffic
node_history -.->|"feeds metrics"| node_overview
node_security -->|"reports findings"| node_security_ui
node_mcp_scan -.->|"presents scan"| node_mcp_ui
node_user -->|"reviews clients"| node_mcp_ui
node_user -->|"searches and replays"| node_traffic

click node_app "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/App.tsx"
click node_control "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/control.ts"
click node_backend "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/src/lib.rs"
click node_client_setup "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/clients/ClientsPage.tsx"
click node_adoption "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/crates/tw-adopt/src/clients.rs"
click node_providers "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/upstreams/UpstreamsPage.tsx"
click node_routing_ui "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/routing/RoutingPage.tsx"
click node_gateway "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/src/gateway.rs"
click node_routing "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/requestRouting.ts"
click node_security "https://github.com/thinkwatchproject/thinkwatch-lite/tree/main/src/security"
click node_history "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/useRequests.ts"
click node_traffic "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/traffic/TrafficPage.tsx"
click node_overview "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/overview/useLive.ts"
click node_security_ui "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/security/SecurityPage.tsx"
click node_mcp_scan "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/crates/tw-scan/src/lib.rs"
click node_mcp_ui "https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/mcp/McpPage.tsx"

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_app,node_control,node_backend,node_user,node_client toneBlue
class node_gateway,node_routing,node_security toneAmber
class node_client_setup,node_adoption,node_providers,node_routing_ui toneMint
class node_history,node_traffic,node_overview,node_security_ui,node_mcp_scan,node_mcp_ui toneRose
class node_upstream,node_remote toneIndigo
```

## Components

### Desktop app

- [App shell](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/App.tsx): `src/App.tsx`
- [Control bridge](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/control.ts): `src/control.ts`
- [Desktop backend](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/src/lib.rs): `src-tauri/src/lib.rs`

### Gateway operation

- [Request gateway](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/src/gateway.rs): `src-tauri/src/gateway.rs`
- [Request routing](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/requestRouting.ts): `src/requestRouting.ts`
- [Request protection](https://github.com/thinkwatchproject/thinkwatch-lite/tree/main/src/security): `src/security`

### Client and provider setup

- [Client setup](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/clients/ClientsPage.tsx): `src/clients/ClientsPage.tsx`
- [Client adoption](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/crates/tw-adopt/src/clients.rs): `src-tauri/crates/tw-adopt/src/clients.rs`
- [Provider setup](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/upstreams/UpstreamsPage.tsx): `src/upstreams/UpstreamsPage.tsx`
- [Routing setup](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/routing/RoutingPage.tsx): `src/routing/RoutingPage.tsx`

### Monitoring and protection

- [Request history](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/useRequests.ts): `src/useRequests.ts`
- [Traffic explorer](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/traffic/TrafficPage.tsx): `src/traffic/TrafficPage.tsx`
- [Usage overview](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/overview/useLive.ts): `src/overview/useLive.ts`
- [Security findings](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/security/SecurityPage.tsx): `src/security/SecurityPage.tsx`
- [MCP and config scan](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src-tauri/crates/tw-scan/src/lib.rs): `src-tauri/crates/tw-scan/src/lib.rs`
- [MCP interface](https://github.com/thinkwatchproject/thinkwatch-lite/blob/main/src/mcp/McpPage.tsx): `src/mcp/McpPage.tsx`

### Other components

- **User**
- **AI client**
- **AI upstream**
- **Remote core**

## Connections

- User → App shell: configures (evidence: `README.md`)
- App shell → Control bridge: calls (evidence: `src/App.tsx`)
- Control bridge → Desktop backend: invokes (evidence: `src/control.ts`)
- App shell → Remote core: connects remotely (evidence: `README.md`)
- User → Client setup: selects clients (evidence: `README.md`)
- Client setup → Client adoption: requests adoption
- Client adoption → AI client: updates config (evidence: `README.md`)
- User → Provider setup: configures providers (evidence: `README.md`)
- User → Routing setup: defines rules (evidence: `README.md`)
- AI client → Request gateway: sends requests (evidence: `README.md`)
- Request gateway → Request protection: checks requests (evidence: `README.md`)
- Request gateway → Request routing: selects route (evidence: `README.md`)
- Request routing → AI upstream: forwards requests (evidence: `README.md`)
- Request gateway → Request history: records requests (evidence: `README.md`)
- Request history → Traffic explorer: feeds traces
- Request history → Usage overview: feeds metrics
- Request protection → Security findings: reports findings (evidence: `README.md`)
- MCP and config scan → MCP interface: presents scan
- User → MCP interface: reviews clients (evidence: `README.md`)
- User → Traffic explorer: searches and replays (evidence: `README.md`)
