# timokoessler/2faguard architecture

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

- Interactive diagram: https://gitdiagram.com/timokoessler/2faguard
- Repository: https://github.com/timokoessler/2faguard

## Overview

2FAGuard is a Windows TOTP authenticator. Its main user workflow is to add tokens (by importing or entering details), unlock access, and view or export codes. The desktop app and CLI share core authentication, token, and storage services; optional Windows Hello and WebAuthn provide additional authentication. The graph includes README-documented capabilities whose wiring was not sampled, but leaves those links unverified rather than implying specific calls. Evidence is limited to the supplied excerpts, SOURCE INDEX references, and README.

Main entry points: [`Guard.Core/Security/Auth.cs`](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/Auth.cs) (Authentication), [`Guard.CLI/Commands/GetCodeCommand.cs`](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Commands/GetCodeCommand.cs) (Get code), [`Guard.WPF/Core/TokenManager.cs`](https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/TokenManager.cs) (Token manager), [`Guard.CLI/Program.cs`](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Program.cs) (CLI entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop app"]
  node_desktop_app["Desktop app<br/>[MainWindow.xaml.cs]"]
  node_add_token["Add token<br/>[Add]"]
  node_bridge_server["Bridge server<br/>[CliBridgeServer.cs]"]
  node_i18n["Localization<br/>[I18n.cs]"]
end

subgraph group_token["Token workflows"]
  node_token_manager["Token manager<br/>[TokenManager.cs]"]
  node_import["Token import<br/>[Import]"]
  node_export["Token export<br/>[Export]"]
  node_totp["TOTP helper<br/>[TOTPTokenHelper.cs]"]
end

subgraph group_security["Security and access"]
  node_auth["Authentication<br/>[Auth.cs]"]
  node_encryption["Encryption"]
  node_windows_hello["Windows Hello<br/>[WindowsHello.cs]"]
  node_webauthn["WebAuthn<br/>[WebAuthnHelper.cs]"]
end

subgraph group_storage["Local persistence"]
  node_database[("Token database<br/>[Database.cs]")]
  node_settings["Settings<br/>[SettingsManager.cs]"]
end

subgraph group_cli["Command line"]
  node_cli["CLI entry<br/>[Program.cs]"]
  node_cli_get["Get code<br/>[GetCodeCommand.cs]"]
  node_cli_list["List tokens<br/>[ListCommand.cs]"]
  node_desktop_bridge["Desktop bridge"]
end

node_user(("User"))

node_user -->|"uses"| node_desktop_app
node_user -->|"adds tokens"| node_add_token
node_user -->|"imports tokens"| node_import
node_user -->|"exports tokens"| node_export
node_token_manager -->|"loads tokens"| node_database
node_token_manager -->|"builds helpers"| node_totp
node_token_manager -->|"checks login"| node_auth
node_totp -->|"uses"| node_encryption
node_cli -->|"registers"| node_cli_get
node_cli -->|"registers"| node_cli_list
node_cli_get -->|"reads tokens"| node_database
node_cli_get -->|"uses"| node_totp
node_cli_get -.->|"requests codes"| node_desktop_bridge
node_auth -->|"uses"| node_encryption
node_auth -->|"invokes"| node_windows_hello
node_auth -->|"uses"| node_webauthn
node_webauthn -->|"uses"| node_encryption
node_settings -->|"initializes"| node_desktop_app
node_desktop_app -->|"uses"| node_i18n
node_cli -.->|"initializes context"| node_database
node_desktop_bridge -.->|"communicates"| node_bridge_server

click node_desktop_app "https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/MainWindow.xaml.cs"
click node_add_token "https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Views/Pages/Add"
click node_token_manager "https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/TokenManager.cs"
click node_import "https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Core/Import"
click node_export "https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Core/Export"
click node_totp "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Models/TOTPTokenHelper.cs"
click node_database "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Storage/Database.cs"
click node_auth "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/Auth.cs"
click node_encryption "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/EncryptionHelper.cs"
click node_windows_hello "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/WindowsHello.cs"
click node_webauthn "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/WebAuthn/WebAuthnHelper.cs"
click node_settings "https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Storage/SettingsManager.cs"
click node_cli "https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Program.cs"
click node_cli_get "https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Commands/GetCodeCommand.cs"
click node_cli_list "https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Commands/ListCommand.cs"
click node_desktop_bridge "https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Core/CliDesktopBridgeClient.cs"
click node_bridge_server "https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/CliBridge/CliBridgeServer.cs"
click node_i18n "https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/I18n.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_desktop_app,node_add_token,node_bridge_server,node_i18n,node_user toneBlue
class node_token_manager,node_import,node_export,node_totp toneAmber
class node_auth,node_encryption,node_windows_hello,node_webauthn toneMint
class node_database,node_settings toneRose
class node_cli,node_cli_get,node_cli_list,node_desktop_bridge toneIndigo
```

## Components

### Desktop app

- [Desktop app](https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/MainWindow.xaml.cs): `Guard.WPF/MainWindow.xaml.cs`
- [Add token](https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Views/Pages/Add): `Guard.WPF/Views/Pages/Add`
- [Bridge server](https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/CliBridge/CliBridgeServer.cs): `Guard.WPF/Core/CliBridge/CliBridgeServer.cs`
- [Localization](https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/I18n.cs): `Guard.WPF/Core/I18n.cs`

### Token workflows

- [Token manager](https://github.com/timokoessler/2faguard/blob/main/Guard.WPF/Core/TokenManager.cs): `Guard.WPF/Core/TokenManager.cs`
- [Token import](https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Core/Import): `Guard.WPF/Core/Import`
- [Token export](https://github.com/timokoessler/2faguard/tree/main/Guard.WPF/Core/Export): `Guard.WPF/Core/Export`
- [TOTP helper](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Models/TOTPTokenHelper.cs): `Guard.Core/Models/TOTPTokenHelper.cs`

### Security and access

- [Authentication](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/Auth.cs): `Guard.Core/Security/Auth.cs`
- [Encryption](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/EncryptionHelper.cs): `Guard.Core/Security/EncryptionHelper.cs`
- [Windows Hello](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/WindowsHello.cs): `Guard.Core/Security/WindowsHello.cs`
- [WebAuthn](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Security/WebAuthn/WebAuthnHelper.cs): `Guard.Core/Security/WebAuthn/WebAuthnHelper.cs`

### Local persistence

- [Token database](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Storage/Database.cs): `Guard.Core/Storage/Database.cs`
- [Settings](https://github.com/timokoessler/2faguard/blob/main/Guard.Core/Storage/SettingsManager.cs): `Guard.Core/Storage/SettingsManager.cs`

### Command line

- [CLI entry](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Program.cs): `Guard.CLI/Program.cs`
- [Get code](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Commands/GetCodeCommand.cs): `Guard.CLI/Commands/GetCodeCommand.cs`
- [List tokens](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Commands/ListCommand.cs): `Guard.CLI/Commands/ListCommand.cs`
- [Desktop bridge](https://github.com/timokoessler/2faguard/blob/main/Guard.CLI/Core/CliDesktopBridgeClient.cs): `Guard.CLI/Core/CliDesktopBridgeClient.cs`

### Other components

- **User**

## Connections

- User → Desktop app: uses
- User → Add token: adds tokens
- User → Token import: imports tokens
- User → Token export: exports tokens
- Token manager → Token database: loads tokens (evidence: `Guard.WPF/Core/TokenManager.cs`)
- Token manager → TOTP helper: builds helpers (evidence: `Guard.WPF/Core/TokenManager.cs`)
- Token manager → Authentication: checks login (evidence: `Guard.WPF/Core/TokenManager.cs`)
- TOTP helper → Encryption: uses (evidence: `Guard.Core/Models/TOTPTokenHelper.cs`)
- CLI entry → Get code: registers (evidence: `Guard.CLI/Program.cs`)
- CLI entry → List tokens: registers (evidence: `Guard.CLI/Program.cs`)
- Get code → Token database: reads tokens (evidence: `Guard.CLI/Commands/GetCodeCommand.cs`)
- Get code → TOTP helper: uses (evidence: `Guard.CLI/Commands/GetCodeCommand.cs`)
- Get code → Desktop bridge: requests codes (evidence: `Guard.CLI/Commands/GetCodeCommand.cs`)
- Authentication → Encryption: uses (evidence: `Guard.Core/Security/Auth.cs`)
- Authentication → Windows Hello: invokes (evidence: `Guard.Core/Security/Auth.cs`)
- Authentication → WebAuthn: uses (evidence: `Guard.Core/Security/Auth.cs`)
- WebAuthn → Encryption: uses (evidence: `Guard.Core/Security/WebAuthn/WebAuthnHelper.cs`)
- Settings → Desktop app: initializes
- Desktop app → Localization: uses
- CLI entry → Token database: initializes context
- Desktop bridge → Bridge server: communicates
