# tasselx/keyden architecture

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

- Interactive diagram: https://gitdiagram.com/tasselx/keyden
- Repository: https://github.com/tasselx/keyden

## Overview

#### Purpose and Runtime
Keyden is a native macOS 12+ menu-bar TOTP authenticator, written in Swift 5.9 with SwiftUI and AppKit. It operates offline-first, generating codes locally and retaining secrets in macOS Keychain. The Xcode project builds both the GUI app and a bundled command-line client: `Keyden.xcodeproj/project.pbxproj`, `Keyden/KeydenApp.swift`, `KeydenCLI/main.swift`.

#### Application Bootstrap and Menu-Bar Shell
The SwiftUI app entry point initializes the app lifecycle; AppKit integration owns menu-bar behavior and likely popup/window coordination. The primary interactive surface is the menu-bar token list rather than a conventional browser or server application.
- `Keyden/KeydenApp.swift`
- `Keyden/App/AppDelegate.swift`
- `Keyden/App/MenuBarController.swift`
- `Keyden/Views/MenuBarContentView.swift`

#### Token Domain and Secure Vault Boundary
`Token` is the central account representation, carrying TOTP identity/configuration used by UI, generation, persistence, sync, import/export, and CLI. `VaultService` coordinates the local token store, while `KeychainService` is the security boundary for encrypted secret persistence through macOS Keychain Services. Secrets should not need to cross this boundary except for explicit backup/sync/import workflows.
- `Keyden/Models/Token.swift`
- `Keyden/Services/VaultService.swift`
- `Keyden/Services/KeychainService.swift`

#### TOTP Generation and Time Flow
TOTP computation is isolated from presentation and backed by CryptoKit. A timer service drives periodic refreshes so menu-bar and management views display current codes and validity windows. UI copy actions consume generated codes, while the CLI uses the same token/generation domain.
- `Keyden/Services/TOTPService.swift`
- `Keyden/Services/TOTPTimerService.swift`
- `Keyden/Views/MenuBarContentView.swift`

#### Token Acquisition, Export, and Management
The management UI supports manual token creation, batch import, ordering/pinning, grouping, and deletion. QR handling forms the visual interchange boundary for standard OTP URIs and token QR export; Google Authenticator migration parsing is a separate import path for its migration QR/link format.
- `Keyden/Views/AddTokenView.swift`
- `Keyden/Views/ManagementView.swift`
- `Keyden/Services/QRCodeService.swift`
- `Keyden/Services/GoogleAuthMigrationService.swift`

#### Optional Integrations and System Services
GitHub Gist sync is an opt-in remote boundary using a user-provided GitHub personal access token and private Gists; local encrypted storage remains the primary source of operation. Global shortcut registration is handled separately. Appearance, update behavior, and user choices are centralized through settings-oriented services/UI.
- `Keyden/Services/GistSyncService.swift`
- `Keyden/Services/HotkeyService.swift`
- `Keyden/Services/ThemeManager.swift`
- `Keyden/Services/UpdateService.swift`
- `Keyden/Views/SettingsView.swift`

#### CLI and Distribution
`keyden` provides automation commands to get, list, and search accounts, and is bundled inside the macOS app for installation by users. GUI and CLI require compatible access to the vault/Keychain data, governed by separate entitlement files. Builds target Apple Silicon, Intel, or universal artifacts and package a DMG; GitHub Actions handles release/version automation.
- `KeydenCLI/main.swift`
- `Keyden/Services/CLIService.swift`
- `Keyden/Keyden.entitlements`
- `KeydenCLI/KeydenCLI.entitlements`
- `Makefile`
- `.github/workflows/release.yml`

Main entry points: [`Keyden/Services/VaultService.swift`](https://github.com/tasselx/keyden/blob/main/Keyden/Services/VaultService.swift) (Vault Service), [`Keyden/Views/MenuBarContentView.swift`](https://github.com/tasselx/keyden/blob/main/Keyden/Views/MenuBarContentView.swift) (Menu Bar Content), [`Keyden/Services/CLIService.swift`](https://github.com/tasselx/keyden/blob/main/Keyden/Services/CLIService.swift) (CLI Service), [`Keyden/App/MenuBarController.swift`](https://github.com/tasselx/keyden/blob/main/Keyden/App/MenuBarController.swift) (Menu Bar Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["macOS App"]
  node_app_entry["SwiftUI App Entry<br/>bootstrap<br/>[KeydenApp.swift]"]
  node_app_delegate["App Delegate<br/>AppKit lifecycle<br/>[AppDelegate.swift]"]
  node_menu_controller["Menu Bar Controller<br/>menu-bar shell"]
  node_menu_view["Menu Bar Content<br/>SwiftUI view"]
  node_management_ui["Management UI<br/>SwiftUI views"]
  node_add_token_ui["Add Token UI<br/>SwiftUI view<br/>[AddTokenView.swift]"]
  node_settings_ui["Settings UI<br/>SwiftUI view<br/>[SettingsView.swift]"]
end

subgraph group_core["Core Vault &amp; Codes"]
  node_token["Token<br/>domain model<br/>[Token.swift]"]
  node_vault["Vault Service<br/>token repository<br/>[VaultService.swift]"]
  node_keychain[("Keychain Service<br/>secure storage")]
  node_totp["TOTP Service<br/>code generator<br/>[TOTPService.swift]"]
  node_timer["TOTP Timer Service<br/>refresh scheduler"]
end

subgraph group_interop["Import, Sync &amp; System"]
  node_qr["QR Code Service<br/>OTP URI interchange"]
  node_google_migration["Google Migration Service<br/>migration importer"]
  node_gist_sync["Gist Sync Service<br/>optional remote sync"]
  node_hotkey["Hotkey Service<br/>global shortcut"]
  node_preferences["Theme &amp; Update Services<br/>system preferences<br/>[ThemeManager.swift]"]
end

subgraph group_delivery["CLI &amp; Delivery"]
  node_cli["keyden CLI<br/>command-line client<br/>[main.swift]"]
  node_cli_service["CLI Service<br/>CLI commands<br/>[CLIService.swift]"]
  node_build_release["Build &amp; Release<br/>packaging automation"]
end

node_app_entry -->|"starts"| node_app_delegate
node_app_delegate -->|"owns"| node_menu_controller
node_menu_controller -->|"presents"| node_menu_view
node_menu_view -->|"loads tokens"| node_vault
node_management_ui -->|"manages"| node_vault
node_add_token_ui -->|"scans/imports"| node_qr
node_add_token_ui -->|"imports migrations"| node_google_migration
node_qr -->|"creates tokens"| node_vault
node_google_migration -->|"creates tokens"| node_vault
node_vault -->|"stores"| node_token
node_vault -->|"persists secrets"| node_keychain
node_menu_view -->|"displays codes"| node_totp
node_totp -->|"computes from"| node_token
node_timer -->|"refreshes"| node_menu_view
node_gist_sync -.->|"backs up/syncs"| node_vault
node_settings_ui -->|"configures"| node_preferences
node_hotkey -->|"activates"| node_menu_controller
node_cli -->|"runs commands"| node_cli_service
node_cli_service -->|"reads accounts"| node_vault
node_cli_service -->|"generates codes"| node_totp
node_build_release -->|"builds app"| node_app_entry
node_build_release -->|"bundles CLI"| node_cli

click node_app_entry "https://github.com/tasselx/keyden/blob/main/Keyden/KeydenApp.swift"
click node_app_delegate "https://github.com/tasselx/keyden/blob/main/Keyden/App/AppDelegate.swift"
click node_menu_controller "https://github.com/tasselx/keyden/blob/main/Keyden/App/MenuBarController.swift"
click node_menu_view "https://github.com/tasselx/keyden/blob/main/Keyden/Views/MenuBarContentView.swift"
click node_management_ui "https://github.com/tasselx/keyden/blob/main/Keyden/Views/ManagementView.swift"
click node_add_token_ui "https://github.com/tasselx/keyden/blob/main/Keyden/Views/AddTokenView.swift"
click node_settings_ui "https://github.com/tasselx/keyden/blob/main/Keyden/Views/SettingsView.swift"
click node_token "https://github.com/tasselx/keyden/blob/main/Keyden/Models/Token.swift"
click node_vault "https://github.com/tasselx/keyden/blob/main/Keyden/Services/VaultService.swift"
click node_keychain "https://github.com/tasselx/keyden/blob/main/Keyden/Services/KeychainService.swift"
click node_totp "https://github.com/tasselx/keyden/blob/main/Keyden/Services/TOTPService.swift"
click node_timer "https://github.com/tasselx/keyden/blob/main/Keyden/Services/TOTPTimerService.swift"
click node_qr "https://github.com/tasselx/keyden/blob/main/Keyden/Services/QRCodeService.swift"
click node_google_migration "https://github.com/tasselx/keyden/blob/main/Keyden/Services/GoogleAuthMigrationService.swift"
click node_gist_sync "https://github.com/tasselx/keyden/blob/main/Keyden/Services/GistSyncService.swift"
click node_hotkey "https://github.com/tasselx/keyden/blob/main/Keyden/Services/HotkeyService.swift"
click node_preferences "https://github.com/tasselx/keyden/blob/main/Keyden/Services/ThemeManager.swift"
click node_cli "https://github.com/tasselx/keyden/blob/main/KeydenCLI/main.swift"
click node_cli_service "https://github.com/tasselx/keyden/blob/main/Keyden/Services/CLIService.swift"
click node_build_release "https://github.com/tasselx/keyden/blob/main/Makefile"

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_entry,node_app_delegate,node_menu_controller,node_menu_view,node_management_ui,node_add_token_ui,node_settings_ui toneBlue
class node_token,node_vault,node_keychain,node_totp,node_timer toneAmber
class node_qr,node_google_migration,node_gist_sync,node_hotkey,node_preferences toneMint
class node_cli,node_cli_service,node_build_release toneRose
```

## Components

### macOS App

Menu-bar runtime and management surfaces.

- [SwiftUI App Entry](https://github.com/tasselx/keyden/blob/main/Keyden/KeydenApp.swift): bootstrap · `Keyden/KeydenApp.swift`
- [App Delegate](https://github.com/tasselx/keyden/blob/main/Keyden/App/AppDelegate.swift): AppKit lifecycle · `Keyden/App/AppDelegate.swift`
- [Menu Bar Controller](https://github.com/tasselx/keyden/blob/main/Keyden/App/MenuBarController.swift): menu-bar shell · `Keyden/App/MenuBarController.swift`
- [Menu Bar Content](https://github.com/tasselx/keyden/blob/main/Keyden/Views/MenuBarContentView.swift): SwiftUI view · Primary interactive token list and code-copy surface. · `Keyden/Views/MenuBarContentView.swift`
- [Management UI](https://github.com/tasselx/keyden/blob/main/Keyden/Views/ManagementView.swift): SwiftUI views · Creates, organizes, pins, groups, and deletes tokens. · `Keyden/Views/ManagementView.swift`
- [Add Token UI](https://github.com/tasselx/keyden/blob/main/Keyden/Views/AddTokenView.swift): SwiftUI view · `Keyden/Views/AddTokenView.swift`
- [Settings UI](https://github.com/tasselx/keyden/blob/main/Keyden/Views/SettingsView.swift): SwiftUI view · `Keyden/Views/SettingsView.swift`

### Core Vault & Codes

Shared token, secure storage, and TOTP flow.

- [Token](https://github.com/tasselx/keyden/blob/main/Keyden/Models/Token.swift): domain model · Shared TOTP account identity and configuration. · `Keyden/Models/Token.swift`
- [Vault Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/VaultService.swift): token repository · Coordinates the local token store. · `Keyden/Services/VaultService.swift`
- [Keychain Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/KeychainService.swift): secure storage · macOS Keychain boundary for secret persistence. · `Keyden/Services/KeychainService.swift`
- [TOTP Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/TOTPService.swift): code generator · CryptoKit-backed local TOTP computation. · `Keyden/Services/TOTPService.swift`
- [TOTP Timer Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/TOTPTimerService.swift): refresh scheduler · `Keyden/Services/TOTPTimerService.swift`

### Import, Sync & System

Optional external and macOS integrations.

- [QR Code Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/QRCodeService.swift): OTP URI interchange · Imports standard OTP URIs and exports token QR codes. · `Keyden/Services/QRCodeService.swift`
- [Google Migration Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/GoogleAuthMigrationService.swift): migration importer · Parses Google Authenticator migration QR/link data. · `Keyden/Services/GoogleAuthMigrationService.swift`
- [Gist Sync Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/GistSyncService.swift): optional remote sync · Uses private GitHub Gists with a user-provided token. · `Keyden/Services/GistSyncService.swift`
- [Hotkey Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/HotkeyService.swift): global shortcut · `Keyden/Services/HotkeyService.swift`
- [Theme & Update Services](https://github.com/tasselx/keyden/blob/main/Keyden/Services/ThemeManager.swift): system preferences · Centralizes appearance and update behavior. · `Keyden/Services/ThemeManager.swift`

### CLI & Delivery

Automation client and release packaging.

- [keyden CLI](https://github.com/tasselx/keyden/blob/main/KeydenCLI/main.swift): command-line client · Gets, lists, and searches accounts using the shared vault domain. · `KeydenCLI/main.swift`
- [CLI Service](https://github.com/tasselx/keyden/blob/main/Keyden/Services/CLIService.swift): CLI commands · `Keyden/Services/CLIService.swift`
- [Build & Release](https://github.com/tasselx/keyden/blob/main/Makefile): packaging automation · Builds app and bundled CLI, packages DMGs, and automates releases. · `Makefile`

## Connections

- SwiftUI App Entry → App Delegate: starts
- App Delegate → Menu Bar Controller: owns
- Menu Bar Controller → Menu Bar Content: presents
- Menu Bar Content → Vault Service: loads tokens
- Management UI → Vault Service: manages
- Add Token UI → QR Code Service: scans/imports
- Add Token UI → Google Migration Service: imports migrations
- QR Code Service → Vault Service: creates tokens
- Google Migration Service → Vault Service: creates tokens
- Vault Service → Token: stores
- Vault Service → Keychain Service: persists secrets
- Menu Bar Content → TOTP Service: displays codes
- TOTP Service → Token: computes from
- TOTP Timer Service → Menu Bar Content: refreshes
- Gist Sync Service → Vault Service: backs up/syncs · Explicit optional interchange flow.
- Settings UI → Theme & Update Services: configures
- Hotkey Service → Menu Bar Controller: activates
- keyden CLI → CLI Service: runs commands
- CLI Service → Vault Service: reads accounts
- CLI Service → TOTP Service: generates codes
- Build & Release → SwiftUI App Entry: builds app
- Build & Release → keyden CLI: bundles CLI
