# chaitanyabiswas/bluetoothautoconnect architecture

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

- Interactive diagram: https://gitdiagram.com/chaitanyabiswas/bluetoothautoconnect
- Repository: https://github.com/chaitanyabiswas/bluetoothautoconnect

## Overview

Bluetooth Auto Connect is a Windows desktop app and optional CLI that discovers nearby or paired devices, applies trusted-device rules, and connects or pairs matches. In the desktop flow, the UI adapter observes discovery through the agent watcher; the policy engine checks whitelist and retry rules, and connection requests can use the privileged service over a local named pipe or user-session Bluetooth APIs. Persistence stores whitelist rules and device history in SQLite. The README documents tray operation, notifications, manual connection, and CLI scanning and management; some subsystem links rely on documentation because those source files were not excerpted.

Main entry points: [`BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs`](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs) (Bluetooth UI adapter), [`BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs`](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs) (Bluetooth discovery agent), [`BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs`](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs) (Shared SQLite database), [`BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs`](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs) (Whitelist repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_ui["WinUI interface<br/>[MainPage.xaml.cs]"]
  node_viewmodel["Main view model<br/>[MainViewModel.cs]"]
  node_adapter["Bluetooth UI adapter"]
  node_tray["Tray and notifications<br/>[SystemTrayIcon.cs]"]
  node_diagnostics["Diagnostic logging<br/>[DiagnosticLog.cs]"]
end

subgraph group_agent["Discovery and policy"]
  node_watcher["Bluetooth discovery agent"]
  node_policy["Connection policy"]
  node_userbluetooth["User-session pairing"]
  node_ipcclient["Named-pipe client<br/>[AgentIpcClient.cs]"]
end

subgraph group_service["Privileged Bluetooth"]
  node_hostipc["Service IPC server<br/>[IpcServer.cs]"]
  node_btservice["Windows Bluetooth service"]
end

subgraph group_data["Persistence"]
  node_whitelistrepo["Whitelist repository"]
  node_historyrepo["Device history repository"]
  node_db[("Shared SQLite database")]
  node_whitelist["Trusted-device rules<br/>[WhitelistEntry.cs]"]
  node_history["Device history records<br/>[DeviceHistory.cs]"]
end

subgraph group_cli["Command-line client"]
  node_cli["CLI commands<br/>[Program.cs]"]
  node_cliagent["CLI discovery agent"]
end

node_user(("Desktop user"))

node_user -->|"manages devices"| node_ui
node_ui -->|"invokes actions"| node_viewmodel
node_viewmodel -->|"uses adapter"| node_adapter
node_adapter -->|"observes discovery"| node_watcher
node_adapter -->|"checks matches"| node_whitelistrepo
node_adapter -->|"logs activity"| node_diagnostics
node_watcher -->|"evaluates devices"| node_policy
node_watcher -->|"requests service actions"| node_ipcclient
node_watcher -->|"uses user APIs"| node_userbluetooth
node_ipcclient -->|"sends pipe requests"| node_hostipc
node_hostipc -->|"dispatches requests"| node_btservice
node_policy -->|"matches rules"| node_whitelistrepo
node_policy -->|"checks replacements"| node_historyrepo
node_whitelistrepo -->|"reads and writes"| node_db
node_historyrepo -->|"reads and writes"| node_db
node_db -->|"stores"| node_whitelist
node_db -->|"stores"| node_history
node_user -->|"runs commands"| node_cli
node_cli -->|"starts discovery"| node_cliagent
node_cliagent -->|"runs discovery"| node_watcher
node_cli -->|"manages rules"| node_whitelistrepo
node_tray -->|"logs tray activity"| node_diagnostics
node_adapter -.->|"signals connection events"| node_tray

click node_ui "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/MainPage.xaml.cs"
click node_viewmodel "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/ViewModels/MainViewModel.cs"
click node_adapter "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs"
click node_tray "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/SystemTrayIcon.cs"
click node_diagnostics "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/DiagnosticLog.cs"
click node_watcher "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs"
click node_policy "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PolicyEngine/Policy/BluetoothPolicyEngine.cs"
click node_userbluetooth "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/UserSessionBluetoothService.cs"
click node_ipcclient "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/AgentIpcClient.cs"
click node_hostipc "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PrivilegedHost/IPC/IpcServer.cs"
click node_btservice "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PrivilegedHost/Bluetooth/BluetoothService.cs"
click node_cli "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent.Cli/Program.cs"
click node_cliagent "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent.Cli/Services/CliBluetoothAgent.cs"
click node_whitelistrepo "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs"
click node_historyrepo "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Repositories/DeviceHistoryRepository.cs"
click node_db "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs"
click node_whitelist "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Entities/WhitelistEntry.cs"
click node_history "https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Entities/DeviceHistory.cs"

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_ui,node_viewmodel,node_adapter,node_tray,node_diagnostics,node_user toneBlue
class node_watcher,node_policy,node_userbluetooth,node_ipcclient toneAmber
class node_hostipc,node_btservice toneMint
class node_whitelistrepo,node_historyrepo,node_db,node_whitelist,node_history toneRose
class node_cli,node_cliagent toneIndigo
```

## Components

### Desktop experience

- [WinUI interface](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/MainPage.xaml.cs): `BlueToothAutoConnect.UserAgent/MainPage.xaml.cs`
- [Main view model](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/ViewModels/MainViewModel.cs): `BlueToothAutoConnect.UserAgent/ViewModels/MainViewModel.cs`
- [Bluetooth UI adapter](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs): `BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs`
- [Tray and notifications](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/SystemTrayIcon.cs): `BlueToothAutoConnect.UserAgent/Services/SystemTrayIcon.cs`
- [Diagnostic logging](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent/Services/DiagnosticLog.cs): `BlueToothAutoConnect.UserAgent/Services/DiagnosticLog.cs`

### Discovery and policy

- [Bluetooth discovery agent](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs): `BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs`
- [Connection policy](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PolicyEngine/Policy/BluetoothPolicyEngine.cs): `BlueToothAutoConnect.PolicyEngine/Policy/BluetoothPolicyEngine.cs`
- [User-session pairing](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/UserSessionBluetoothService.cs): `BlueToothAutoConnect.AgentCore/UserSessionBluetoothService.cs`
- [Named-pipe client](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.AgentCore/AgentIpcClient.cs): `BlueToothAutoConnect.AgentCore/AgentIpcClient.cs`

### Privileged Bluetooth

- [Service IPC server](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PrivilegedHost/IPC/IpcServer.cs): `BlueToothAutoConnect.PrivilegedHost/IPC/IpcServer.cs`
- [Windows Bluetooth service](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.PrivilegedHost/Bluetooth/BluetoothService.cs): `BlueToothAutoConnect.PrivilegedHost/Bluetooth/BluetoothService.cs`

### Persistence

- [Whitelist repository](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs): `BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs`
- [Device history repository](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Repositories/DeviceHistoryRepository.cs): `BlueToothAutoConnect.Persistence/Repositories/DeviceHistoryRepository.cs`
- [Shared SQLite database](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs): `BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs`
- [Trusted-device rules](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Entities/WhitelistEntry.cs): `BlueToothAutoConnect.Persistence/Entities/WhitelistEntry.cs`
- [Device history records](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.Persistence/Entities/DeviceHistory.cs): `BlueToothAutoConnect.Persistence/Entities/DeviceHistory.cs`

### Command-line client

- [CLI commands](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent.Cli/Program.cs): `BlueToothAutoConnect.UserAgent.Cli/Program.cs`
- [CLI discovery agent](https://github.com/chaitanyabiswas/bluetoothautoconnect/blob/main/BlueToothAutoConnect.UserAgent.Cli/Services/CliBluetoothAgent.cs): `BlueToothAutoConnect.UserAgent.Cli/Services/CliBluetoothAgent.cs`

### Other components

- **Desktop user**

## Connections

- Desktop user → WinUI interface: manages devices (evidence: `README.md`)
- WinUI interface → Main view model: invokes actions (evidence: `BlueToothAutoConnect.UserAgent/MainPage.xaml.cs`)
- Main view model → Bluetooth UI adapter: uses adapter (evidence: `BlueToothAutoConnect.UserAgent/ViewModels/MainViewModel.cs`)
- Bluetooth UI adapter → Bluetooth discovery agent: observes discovery (evidence: `BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs`)
- Bluetooth UI adapter → Whitelist repository: checks matches (evidence: `BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs`)
- Bluetooth UI adapter → Diagnostic logging: logs activity (evidence: `BlueToothAutoConnect.UserAgent/Services/BluetoothAgentViewModelAdapter.cs`)
- Bluetooth discovery agent → Connection policy: evaluates devices (evidence: `BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs`)
- Bluetooth discovery agent → Named-pipe client: requests service actions (evidence: `BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs`)
- Bluetooth discovery agent → User-session pairing: uses user APIs (evidence: `BlueToothAutoConnect.AgentCore/BluetoothAgentWatcher.cs`)
- Named-pipe client → Service IPC server: sends pipe requests (evidence: `BlueToothAutoConnect.AgentCore/AgentIpcClient.cs`)
- Service IPC server → Windows Bluetooth service: dispatches requests (evidence: `BlueToothAutoConnect.PrivilegedHost/IPC/IpcServer.cs`)
- Connection policy → Whitelist repository: matches rules (evidence: `BlueToothAutoConnect.PolicyEngine/Policy/BluetoothPolicyEngine.cs`)
- Connection policy → Device history repository: checks replacements (evidence: `BlueToothAutoConnect.PolicyEngine/Policy/BluetoothPolicyEngine.cs`)
- Whitelist repository → Shared SQLite database: reads and writes (evidence: `BlueToothAutoConnect.Persistence/Repositories/WhitelistRepository.cs`)
- Device history repository → Shared SQLite database: reads and writes (evidence: `BlueToothAutoConnect.Persistence/Repositories/DeviceHistoryRepository.cs`)
- Shared SQLite database → Trusted-device rules: stores (evidence: `BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs`)
- Shared SQLite database → Device history records: stores (evidence: `BlueToothAutoConnect.Persistence/Data/BluetoothDbContext.cs`)
- Desktop user → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → CLI discovery agent: starts discovery (evidence: `BlueToothAutoConnect.UserAgent.Cli/Program.cs`)
- CLI discovery agent → Bluetooth discovery agent: runs discovery (evidence: `BlueToothAutoConnect.UserAgent.Cli/Services/CliBluetoothAgent.cs`)
- CLI commands → Whitelist repository: manages rules (evidence: `BlueToothAutoConnect.UserAgent.Cli/Program.cs`)
- Tray and notifications → Diagnostic logging: logs tray activity (evidence: `BlueToothAutoConnect.UserAgent/Services/SystemTrayIcon.cs`)
- Bluetooth UI adapter → Tray and notifications: signals connection events
