# bjn7/passkeyd architecture

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

- Interactive diagram: https://gitdiagram.com/bjn7/passkeyd
- Repository: https://github.com/bjn7/passkeyd

## Overview

#### Purpose and deployment
Passkeyd is a Linux-resident WebAuthn/FIDO authenticator supporting TPM-backed and virtual/non-TPM credentials. The primary daemon is `passkeyd/src/main.rs`, deployed as a system service through `passkeyd.service` and configured by `passkeyd.conf`. It presents itself to browsers and other WebAuthn clients as an authenticator rather than as a web application.

#### Workspace boundaries
The Rust workspace separates protocol/daemon code from shared contracts, persistence, user interaction, administration, and migration:
- Shared ABI, credential/database layout, crypto-facing types, and configuration: `passkeyd-abi/src/lib.rs`, `passkeyd-abi/src/database/mod.rs`, `passkeyd-abi/src/cryptography.rs`.
- Storage implementation boundary: `passkeyd-storage/lib.rs`.
- Localization resources are independently packaged: `passkeyd-locale/src/lib.rs`, `passkeyd-locale/locales/en.yaml`.
This separation allows the daemon, UIs, manager, and migration executable to share persisted data definitions.

#### Authenticator transport and CTAP dispatch
The daemon’s external protocol ingress is CTAP over HID. Transport handling is organized under `passkeyd/src/ctaphid/ctaphid.rs` and `passkeyd/src/ctaphid/hid/mod.rs`, with a virtual HID implementation in `passkeyd/src/ctaphid/hid/vhid.rs`. Requests flow from HID framing into CTAP command handling, forming the boundary between host/browser traffic and internal authenticator state.

#### WebAuthn command handlers
CTAP operations are command-specific handlers: credential creation in `passkeyd/src/handlers/make_credential.rs`, assertion generation in `passkeyd/src/handlers/get_assertion.rs`, and follow-up assertions in `passkeyd/src/handlers/get_next_assertion.rs`. Supporting authenticator operations include client PIN, reset, capability reporting, and selection under `passkeyd/src/handlers/`. These handlers coordinate request validation, credential lookup/creation, user-presence or authorization flow, cryptographic signing, and CTAP responses.

#### Credential and cryptographic backends
Credential lifecycle logic is concentrated in `passkeyd/src/cerds/mod.rs`, with creation and retrieval paths in `passkeyd/src/cerds/make.rs` and `passkeyd/src/cerds/get.rs`. Crypto is abstracted into TPM and virtual implementations: `passkeyd/src/cryptography/tpm/mod.rs` and `passkeyd/src/cryptography/virtual/mod.rs`, including ES256 and RS256 variants. This is the key hardware boundary: handlers should depend on shared crypto behavior while backend modules decide whether keys reside in TPM hardware or a non-TPM implementation.

#### User interaction and authorization
Authenticator interactions are delegated to separate UI executables rather than embedded in the daemon. Enrollment starts at `passkeyd-ui/passkeyd-enroll/src/main.rs`; credential/operation selection is handled by `passkeyd-ui/passkeyd-select/src/main.rs` and `passkeyd-ui/passkeyd-select/src/authorize.rs`; a dedicated selection executable exists at `passkeyd-ui/passkeyd-selection/src/main.rs`. The handler selection path (`passkeyd/src/handlers/selection.rs`) is the daemon-side integration point for this user-mediated boundary. Appearance is externally configurable through `theme.conf`.

#### Administration and data evolution
`passkeyd-manager/src/main.rs` provides a terminal manager over persisted passkeys, with UI/state separation in `passkeyd-manager/src/tui.rs` and `passkeyd-manager/src/list_state.rs`. `passkeyd-migrate/src/main.rs` upgrades prior persisted formats, isolating legacy database and layout knowledge in `passkeyd-migrate/src/old_db.rs` and `passkeyd-migrate/src/old_layout.rs`. This keeps compatibility conversion out of the runtime daemon path.

Main entry points: [`passkeyd/src/cerds/mod.rs`](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cerds/mod.rs) (Credential lifecycle), [`passkeyd-storage/lib.rs`](https://github.com/bjn7/passkeyd/blob/main/passkeyd-storage/lib.rs) (Storage implementation), [`passkeyd/src/ctaphid/ctaphid.rs`](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/ctaphid.rs) (CTAP over HID), [`passkeyd/src/handlers/make_credential.rs`](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/make_credential.rs) (WebAuthn handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_daemon["Authenticator daemon"]
  node_service["System service<br/>deployment<br/>[passkeyd.service]"]
  node_config["Daemon config<br/>configuration<br/>[passkeyd.conf]"]
  node_daemon_main["Passkeyd daemon<br/>Rust executable<br/>[main.rs]"]
  node_ctaphid["CTAP over HID<br/>transport dispatcher<br/>[ctaphid.rs]"]
  node_hid["HID transport<br/>transport layer<br/>[mod.rs]"]
  node_virtual_hid["Virtual HID<br/>HID implementation<br/>[vhid.rs]"]
  node_handlers["WebAuthn handlers<br/>CTAP commands<br/>[make_credential.rs]"]
  node_assertion["Assertion handlers<br/>CTAP assertions<br/>[get_assertion.rs]"]
  node_selection_handler["Selection integration<br/>daemon UI bridge<br/>[selection.rs]"]
  node_credentials["Credential lifecycle<br/>credential service<br/>[mod.rs]"]
  node_crypto_tpm{{"TPM crypto backend<br/>hardware crypto<br/>[mod.rs]"}}
  node_crypto_virtual{{"Virtual crypto backend<br/>software crypto<br/>[mod.rs]"}}
end

subgraph group_shared["Shared contracts &amp; storage"]
  node_abi["Shared ABI &amp; layout<br/>shared Rust crate<br/>[lib.rs]"]
  node_storage[("Storage implementation<br/>persistence backend<br/>[lib.rs]")]
  node_locale["Localization package<br/>resource crate<br/>[lib.rs]"]
end

subgraph group_interaction["User interaction"]
  node_enroll_ui["Enrollment UI<br/>UI executable<br/>[main.rs]"]
  node_select_ui["Authorization UI<br/>UI executable<br/>[main.rs]"]
  node_selection_ui["Selection UI<br/>UI executable<br/>[main.rs]"]
  node_theme["Theme config<br/>appearance config<br/>[theme.conf]"]
end

subgraph group_operations["Administration &amp; migration"]
  node_manager["Passkey manager<br/>terminal executable<br/>[main.rs]"]
  node_migration["Data migration<br/>migration executable<br/>[main.rs]"]
end

node_service -->|"launches"| node_daemon_main
node_config -.->|"configures"| node_daemon_main
node_daemon_main -->|"hosts"| node_ctaphid
node_ctaphid -->|"uses"| node_hid
node_hid -.->|"supports"| node_virtual_hid
node_ctaphid -->|"dispatches create commands"| node_handlers
node_ctaphid -->|"dispatches assertion commands"| node_assertion
node_handlers -->|"creates credentials"| node_credentials
node_assertion -->|"retrieves credentials"| node_credentials
node_handlers -->|"requests selection"| node_selection_handler
node_selection_handler -->|"delegates authorization"| node_select_ui
node_selection_handler -->|"delegates selection"| node_selection_ui
node_enroll_ui -->|"enrolls persisted credentials"| node_storage
node_select_ui -.->|"uses appearance"| node_theme
node_credentials -->|"uses"| node_crypto_tpm
node_credentials -->|"uses"| node_crypto_virtual
node_credentials -->|"persists through"| node_storage
node_credentials -->|"uses contracts"| node_abi
node_storage -->|"implements layout"| node_abi
node_manager -->|"manages passkeys"| node_storage
node_manager -.->|"uses localized resources"| node_locale
node_migration -->|"upgrades data into"| node_storage
node_migration -->|"targets current layout"| node_abi

click node_service "https://github.com/bjn7/passkeyd/blob/main/passkeyd.service"
click node_config "https://github.com/bjn7/passkeyd/blob/main/passkeyd.conf"
click node_daemon_main "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/main.rs"
click node_ctaphid "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/ctaphid.rs"
click node_hid "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/hid/mod.rs"
click node_virtual_hid "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/hid/vhid.rs"
click node_handlers "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/make_credential.rs"
click node_assertion "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/get_assertion.rs"
click node_selection_handler "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/selection.rs"
click node_credentials "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cerds/mod.rs"
click node_crypto_tpm "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cryptography/tpm/mod.rs"
click node_crypto_virtual "https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cryptography/virtual/mod.rs"
click node_abi "https://github.com/bjn7/passkeyd/blob/main/passkeyd-abi/src/lib.rs"
click node_storage "https://github.com/bjn7/passkeyd/blob/main/passkeyd-storage/lib.rs"
click node_locale "https://github.com/bjn7/passkeyd/blob/main/passkeyd-locale/src/lib.rs"
click node_enroll_ui "https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-enroll/src/main.rs"
click node_select_ui "https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-select/src/main.rs"
click node_selection_ui "https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-selection/src/main.rs"
click node_theme "https://github.com/bjn7/passkeyd/blob/main/theme.conf"
click node_manager "https://github.com/bjn7/passkeyd/blob/main/passkeyd-manager/src/main.rs"
click node_migration "https://github.com/bjn7/passkeyd/blob/main/passkeyd-migrate/src/main.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_service,node_config,node_daemon_main,node_ctaphid,node_hid,node_virtual_hid,node_handlers,node_assertion,node_selection_handler,node_credentials,node_crypto_tpm,node_crypto_virtual toneBlue
class node_abi,node_storage,node_locale toneAmber
class node_enroll_ui,node_select_ui,node_selection_ui,node_theme toneMint
class node_manager,node_migration toneRose
```

## Components

### Authenticator daemon

Runtime CTAP authenticator service.

- [System service](https://github.com/bjn7/passkeyd/blob/main/passkeyd.service): deployment · `passkeyd.service`
- [Daemon config](https://github.com/bjn7/passkeyd/blob/main/passkeyd.conf): configuration · `passkeyd.conf`
- [Passkeyd daemon](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/main.rs): Rust executable · Linux-resident WebAuthn authenticator runtime. · `passkeyd/src/main.rs`
- [CTAP over HID](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/ctaphid.rs): transport dispatcher · Frames host requests and dispatches CTAP commands. · `passkeyd/src/ctaphid/ctaphid.rs`
- [HID transport](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/hid/mod.rs): transport layer · `passkeyd/src/ctaphid/hid/mod.rs`
- [Virtual HID](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/ctaphid/hid/vhid.rs): HID implementation · `passkeyd/src/ctaphid/hid/vhid.rs`
- [WebAuthn handlers](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/make_credential.rs): CTAP commands · Includes PIN, reset, capabilities, and selection operations. · `passkeyd/src/handlers/make_credential.rs`
- [Assertion handlers](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/get_assertion.rs): CTAP assertions · Generates assertions and follow-up results. · `passkeyd/src/handlers/get_assertion.rs`
- [Selection integration](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/handlers/selection.rs): daemon UI bridge · `passkeyd/src/handlers/selection.rs`
- [Credential lifecycle](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cerds/mod.rs): credential service · Creates, retrieves, and manages credentials. · `passkeyd/src/cerds/mod.rs`
- [TPM crypto backend](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cryptography/tpm/mod.rs): hardware crypto · Keeps credential keys in TPM-backed implementations. · `passkeyd/src/cryptography/tpm/mod.rs`
- [Virtual crypto backend](https://github.com/bjn7/passkeyd/blob/main/passkeyd/src/cryptography/virtual/mod.rs): software crypto · Provides non-TPM credential implementations. · `passkeyd/src/cryptography/virtual/mod.rs`

### Shared contracts & storage

Persisted layout and backend boundary shared across tools.

- [Shared ABI & layout](https://github.com/bjn7/passkeyd/blob/main/passkeyd-abi/src/lib.rs): shared Rust crate · Defines ABI, credential/database layout, crypto types, and configuration. · `passkeyd-abi/src/lib.rs`
- [Storage implementation](https://github.com/bjn7/passkeyd/blob/main/passkeyd-storage/lib.rs): persistence backend · `passkeyd-storage/lib.rs`
- [Localization package](https://github.com/bjn7/passkeyd/blob/main/passkeyd-locale/src/lib.rs): resource crate · `passkeyd-locale/src/lib.rs`

### User interaction

External executables mediate enrollment and authorization.

- [Enrollment UI](https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-enroll/src/main.rs): UI executable · `passkeyd-ui/passkeyd-enroll/src/main.rs`
- [Authorization UI](https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-select/src/main.rs): UI executable · Mediates credential and operation selection. · `passkeyd-ui/passkeyd-select/src/main.rs`
- [Selection UI](https://github.com/bjn7/passkeyd/blob/main/passkeyd-ui/passkeyd-selection/src/main.rs): UI executable · `passkeyd-ui/passkeyd-selection/src/main.rs`
- [Theme config](https://github.com/bjn7/passkeyd/blob/main/theme.conf): appearance config · `theme.conf`

### Administration & migration

Offline data management and compatibility tooling.

- [Passkey manager](https://github.com/bjn7/passkeyd/blob/main/passkeyd-manager/src/main.rs): terminal executable · Manages persisted passkeys outside the daemon. · `passkeyd-manager/src/main.rs`
- [Data migration](https://github.com/bjn7/passkeyd/blob/main/passkeyd-migrate/src/main.rs): migration executable · Upgrades legacy persisted formats. · `passkeyd-migrate/src/main.rs`

## Connections

- System service → Passkeyd daemon: launches
- Daemon config → Passkeyd daemon: configures
- Passkeyd daemon → CTAP over HID: hosts
- CTAP over HID → HID transport: uses
- HID transport → Virtual HID: supports
- CTAP over HID → WebAuthn handlers: dispatches create commands
- CTAP over HID → Assertion handlers: dispatches assertion commands
- WebAuthn handlers → Credential lifecycle: creates credentials
- Assertion handlers → Credential lifecycle: retrieves credentials
- WebAuthn handlers → Selection integration: requests selection
- Selection integration → Authorization UI: delegates authorization
- Selection integration → Selection UI: delegates selection
- Enrollment UI → Storage implementation: enrolls persisted credentials
- Authorization UI → Theme config: uses appearance
- Credential lifecycle → TPM crypto backend: uses
- Credential lifecycle → Virtual crypto backend: uses
- Credential lifecycle → Storage implementation: persists through
- Credential lifecycle → Shared ABI & layout: uses contracts
- Storage implementation → Shared ABI & layout: implements layout
- Passkey manager → Storage implementation: manages passkeys
- Passkey manager → Localization package: uses localized resources
- Data migration → Storage implementation: upgrades data into
- Data migration → Shared ABI & layout: targets current layout
