# oldj/switchhosts architecture

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

- Interactive diagram: https://gitdiagram.com/oldj/switchhosts
- Repository: https://github.com/oldj/switchhosts

## Overview

SwitchHosts is a desktop hosts-file manager. Users organize local, remote, system, group, and folder entries, choose which hosts are active, then apply the resulting content to the system hosts file; they can also refresh remote entries, search, import/export, and switch entries from the tray. The graph separates the renderer, Tauri command layer, domain operations, and filesystem storage. Several backend relationships are supported by the SOURCE INDEX, but unsampled implementation details are not inferred.

Main entry points: [`src-tauri/src/commands.rs`](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/commands.rs) (Tauri commands), [`src-tauri/src/storage/mod.rs`](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/storage/mod.rs) (Persistent storage), [`src-tauri/src/http_api.rs`](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/http_api.rs) (Local HTTP API), [`src-tauri/src/hosts_apply/write.rs`](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/write.rs) (System hosts apply)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Desktop interface"]
  node_renderer["Main window<br/>[index.tsx]"]
  node_hostsmodel["Hosts data model<br/>[useHostsData.ts]"]
  node_editor["Hosts editor<br/>[HostsEditor.tsx]"]
  node_trayui["Tray window<br/>[tray.tsx]"]
end

subgraph group_backend["Tauri backend"]
  node_commands["Tauri commands<br/>[commands.rs]"]
  node_menus["Menus and tray<br/>[app_menu.rs]"]
  node_tray["Tray behavior<br/>[tray.rs]"]
end

subgraph group_domains["Hosts operations"]
  node_find["Find entries<br/>[find.rs]"]
  node_refresh["Remote refresh<br/>[refresh.rs]"]
  node_importexport["Import and export<br/>[import_export.rs]"]
  node_preview["Import preview<br/>[preview.rs]"]
  node_apply["System hosts apply<br/>[write.rs]"]
  node_recovery["Apply recovery<br/>[recovery.rs]"]
  node_helper["Privileged helper client<br/>[helper_client.rs]"]
  node_httpapi["Local HTTP API<br/>[http_api.rs]"]
end

subgraph group_state["Data and state"]
  node_storage[("Persistent storage<br/>[mod.rs]")]
  node_treeformat["Hosts tree format<br/>[tree_format.rs]"]
  node_history[("Apply history<br/>[history.rs]")]
end

node_user(("User"))

node_user -->|"manages entries"| node_renderer
node_user -->|"switches hosts"| node_trayui
node_renderer -.->|"views data"| node_hostsmodel
node_hostsmodel -.->|"requests data and apply"| node_commands
node_renderer -.->|"edits entries"| node_editor
node_trayui -.->|"switches entries"| node_tray
node_commands -->|"references"| node_find
node_commands -->|"references"| node_refresh
node_commands -->|"references"| node_importexport
node_commands -->|"delegates apply"| node_apply
node_commands -->|"uses storage"| node_storage
node_commands -->|"references"| node_httpapi
node_commands -->|"references"| node_menus
node_commands -->|"references"| node_tray
node_importexport -->|"uses preview"| node_preview
node_importexport -->|"uses storage"| node_storage
node_find -->|"reads entries"| node_storage
node_refresh -->|"uses storage"| node_storage
node_httpapi -->|"references"| node_refresh
node_httpapi -->|"references"| node_apply
node_httpapi -->|"references"| node_recovery
node_httpapi -->|"uses storage"| node_storage
node_apply -.->|"privileged write"| node_helper
node_recovery -->|"uses write"| node_apply
node_apply -.->|"records changes"| node_history
node_storage -->|"uses format"| node_treeformat
node_storage -->|"supports history"| node_history
node_menus -->|"routes tray events"| node_tray

click node_renderer "https://github.com/oldj/switchhosts/blob/master/src/renderer/pages/index.tsx"
click node_hostsmodel "https://github.com/oldj/switchhosts/blob/master/src/renderer/models/useHostsData.ts"
click node_editor "https://github.com/oldj/switchhosts/blob/master/src/renderer/components/Editor/HostsEditor.tsx"
click node_trayui "https://github.com/oldj/switchhosts/blob/master/src/renderer/pages/tray.tsx"
click node_commands "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/commands.rs"
click node_menus "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/app_menu.rs"
click node_tray "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/tray.rs"
click node_find "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/find.rs"
click node_refresh "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/refresh.rs"
click node_importexport "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/import_export.rs"
click node_preview "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/import_export/preview.rs"
click node_apply "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/write.rs"
click node_recovery "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/recovery.rs"
click node_helper "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/helper_client.rs"
click node_httpapi "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/http_api.rs"
click node_storage "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/storage/mod.rs"
click node_treeformat "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/storage/tree_format.rs"
click node_history "https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/history.rs"

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_renderer,node_hostsmodel,node_editor,node_trayui,node_user toneBlue
class node_commands,node_menus,node_tray toneAmber
class node_find,node_refresh,node_importexport,node_preview,node_apply,node_recovery,node_helper,node_httpapi toneMint
class node_storage,node_treeformat,node_history toneRose
```

## Components

### Desktop interface

- [Main window](https://github.com/oldj/switchhosts/blob/master/src/renderer/pages/index.tsx): `src/renderer/pages/index.tsx`
- [Hosts data model](https://github.com/oldj/switchhosts/blob/master/src/renderer/models/useHostsData.ts): `src/renderer/models/useHostsData.ts`
- [Hosts editor](https://github.com/oldj/switchhosts/blob/master/src/renderer/components/Editor/HostsEditor.tsx): `src/renderer/components/Editor/HostsEditor.tsx`
- [Tray window](https://github.com/oldj/switchhosts/blob/master/src/renderer/pages/tray.tsx): `src/renderer/pages/tray.tsx`

### Tauri backend

- [Tauri commands](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/commands.rs): `src-tauri/src/commands.rs`
- [Menus and tray](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/app_menu.rs): `src-tauri/src/app_menu.rs`
- [Tray behavior](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/tray.rs): `src-tauri/src/tray.rs`

### Hosts operations

- [Find entries](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/find.rs): `src-tauri/src/find.rs`
- [Remote refresh](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/refresh.rs): `src-tauri/src/refresh.rs`
- [Import and export](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/import_export.rs): `src-tauri/src/import_export.rs`
- [Import preview](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/import_export/preview.rs): `src-tauri/src/import_export/preview.rs`
- [System hosts apply](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/write.rs): `src-tauri/src/hosts_apply/write.rs`
- [Apply recovery](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/recovery.rs): `src-tauri/src/hosts_apply/recovery.rs`
- [Privileged helper client](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/helper_client.rs): `src-tauri/src/hosts_apply/helper_client.rs`
- [Local HTTP API](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/http_api.rs): `src-tauri/src/http_api.rs`

### Data and state

- [Persistent storage](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/storage/mod.rs): `src-tauri/src/storage/mod.rs`
- [Hosts tree format](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/storage/tree_format.rs): `src-tauri/src/storage/tree_format.rs`
- [Apply history](https://github.com/oldj/switchhosts/blob/master/src-tauri/src/hosts_apply/history.rs): `src-tauri/src/hosts_apply/history.rs`

### Other components

- **User**

## Connections

- User → Main window: manages entries (evidence: `README.md`)
- User → Tray window: switches hosts (evidence: `README.md`)
- Main window → Hosts data model: views data
- Hosts data model → Tauri commands: requests data and apply
- Main window → Hosts editor: edits entries
- Tray window → Tray behavior: switches entries
- Tauri commands → Find entries: references (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Remote refresh: references (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Import and export: references (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → System hosts apply: delegates apply (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Persistent storage: uses storage (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Local HTTP API: references (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Menus and tray: references (evidence: `src-tauri/src/commands.rs`)
- Tauri commands → Tray behavior: references (evidence: `src-tauri/src/commands.rs`)
- Import and export → Import preview: uses preview (evidence: `src-tauri/src/import_export.rs`)
- Import and export → Persistent storage: uses storage (evidence: `src-tauri/src/import_export.rs`)
- Find entries → Persistent storage: reads entries (evidence: `src-tauri/src/find.rs`)
- Remote refresh → Persistent storage: uses storage
- Local HTTP API → Remote refresh: references (evidence: `src-tauri/src/http_api.rs`)
- Local HTTP API → System hosts apply: references (evidence: `src-tauri/src/http_api.rs`)
- Local HTTP API → Apply recovery: references (evidence: `src-tauri/src/http_api.rs`)
- Local HTTP API → Persistent storage: uses storage (evidence: `src-tauri/src/http_api.rs`)
- System hosts apply → Privileged helper client: privileged write
- Apply recovery → System hosts apply: uses write (evidence: `src-tauri/src/hosts_apply/recovery.rs`)
- System hosts apply → Apply history: records changes
- Persistent storage → Hosts tree format: uses format (evidence: `src-tauri/src/storage/mod.rs`)
- Persistent storage → Apply history: supports history (evidence: `src-tauri/src/hosts_apply/history.rs`)
- Menus and tray → Tray behavior: routes tray events (evidence: `src-tauri/src/lib.rs`)
