# solokeys/solo1 architecture

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

- Interactive diagram: https://gitdiagram.com/solokeys/solo1
- Repository: https://github.com/solokeys/solo1

## Overview

##### Project Type and Purpose
- This is a firmware-centric embedded/security project implementing the FIDO2 (CTAP2) and U2F (CTAP1) protocols for a USB/NFC security key (SoloKey).
- It also includes a host-side simulation application for development (Linux/Mac/Windows), build scripts, tooling, and documentation.

##### Key Components in the File Structure
- crypto/           → Collection of cryptographic primitives (AES-GCM, SHA-256, ECC, etc.)
- fido2/            → Core CTAP1/CTAP2 protocol implementation (APDU parsing, CTAPHID, extensions, storage)
- targets/stm32l432/→ STM32L432-specific hardware layer: startup code, HAL, USB/NFC drivers, bootloader, linker scripts
- pc/               → Host-side application (“solo” simulator) sending/receiving USB HID over UDP
- tools/            → Utility scripts (certificate generation, log conversion, USB-to-UDP shim, test helpers)
- udev/             → Linux udev rules for real hardware
- metadata/         → JSON metadata statements for FIDO2 authenticators
- builds/           → Output directory for compiled `.hex` files
- Dockerfile/Makefile/mkdocs.yml → Build automation, CI/CD, documentation site configuration

##### Architectural Patterns and Relationships
- Layered Architecture:
- Hardware Abstraction Layer (HAL) in targets/stm32l432/lib calls into peripheral drivers (USB, RNG, Flash, NFC).
- Core Protocol Layer in fido2/ implements CTAP1/2 state machines, APDU/CBOR parsing, and storage API.
- Crypto Layer in crypto/ provides primitives to the protocol layer.
- Bootloader/Application split in targets: bootloader handles firmware signing/upgrade, application runs CTAP code.
- Platform Switch: same fido2/ + crypto/ code compiles for STM32 target or PC host (pc/main.c).
- Toolchain/Build Pipeline: Makefiles orchestrate builds for embedded and host, Docker container isolates ARM toolchain, `solo1` CLI scripts handle flashing.
- External Integration: python-fido2 test suite communicates over UDP (when in host mode) or USB HID (when on real hardware).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Build & CI
    subgraph "Build & CI"
        Makefile["Makefile"] 
        Dockerfile["Dockerfile"] 
        MKDOCS["mkdocs.yml"]
        Travis[".travis.yml"]
    end

    %% Crypto & Protocol Layer
    subgraph "Crypto & Protocol Layer"
        Crypto["Crypto Library\n(crypto/)"] 
        CTAP["CTAP Core\n(fido2/)"]
        CTAPHID["CTAPHID Transport\n(ctaphid.c/h)"]
        Extensions["Protocol Extensions\n(fido2/extensions/)"]
        TinyCBOR["TinyCBOR\n(tinycbor/)"]
        Metadata["Metadata Store\n(metadata/)"]
    end

    %% Embedded Firmware
    subgraph "Embedded Firmware"
        subgraph Bootloader
            BL["Bootloader\n(targets/stm32l432/bootloader/)"]
        end
        subgraph Application
            App["Application Firmware\n(targets/stm32l432/src/)"]
            HAL["HAL & Drivers\n(targets/stm32l432/lib/)"]
        end
    end

    %% Host & Simulator
    subgraph "Host Simulator"
        Host["Host Simulator\n(pc/)"]
    end

    %% Tools & Utilities
    subgraph "Tools & Utilities"
        Tools["Tools & CLI\n(tools/)"]
    end

    %% Test & External
    subgraph "Test & Documentation"
        TestSuite["Test Suite\n(python-fido2)"]
        Udev["Udev Rules\n(udev/)"]
        Docs["Documentation\n(docs/, README.md)"]
    end

    %% Build Output
    Builds["Build Output\n(builds/)"]

    %% External Interfaces
    USB["USB HID"] 
    NFC["NFC"]
    UDP["UDP HID"]

    %% Relationships
    Crypto -->|used by| CTAP
    TinyCBOR -->|CBOR encode/decode| CTAP
    Metadata -->|store metadata| CTAP
    CTAP -->|APDU/CBOR| Extensions
    CTAP -->|HID reports| CTAPHID

    CTAP -->|protocol calls| HAL
    HAL -->|peripheral access| App
    CTAP -->|business logic| App
    BL -->|signs/updates| App
    App -->|firmware| BL

    USB -->|USB HID| HAL
    NFC -->|NFC frames| HAL
    UDP -->|UDP HID| Host
    Host -->|UDP HID| CTAPHID

    Tools -->|CLI commands| Host
    Tools -->|flash| BL
    Tools -->|flash| App
    Tools -->|shim| UDP
    Tools -->|simulate| USB

    TestSuite -->|drives| Tools
    TestSuite -->|tests via| Host
    TestSuite -->|uses rules| Udev

    Makefile -->|orchestrates build| Crypto
    Makefile -->|orchestrates build| CTAP
    Makefile -->|orchestrates build| TinyCBOR
    Makefile -->|orchestrates build| HAL
    Makefile -->|orchestrates build| Host
    Makefile -->|orchestrates build| Tools
    Makefile -->|outputs| Builds

    Docs -->|references| Crypto
    Docs -->|references| CTAP
    Docs -->|references| Host

    %% Click Events
    click Crypto "https://github.com/solokeys/solo1/tree/master/crypto/"
    click CTAP "https://github.com/solokeys/solo1/tree/master/fido2/"
    click CTAPHID "https://github.com/solokeys/solo1/blob/master/fido2/ctaphid.c"
    click CTAPHID "https://github.com/solokeys/solo1/blob/master/fido2/ctaphid.h"
    click Extensions "https://github.com/solokeys/solo1/tree/master/fido2/extensions/"
    click Metadata "https://github.com/solokeys/solo1/tree/master/metadata/"
    click TinyCBOR "https://github.com/solokeys/solo1/tree/master/tinycbor/"
    click BL "https://github.com/solokeys/solo1/tree/master/targets/stm32l432/bootloader/"
    click App "https://github.com/solokeys/solo1/tree/master/targets/stm32l432/src/"
    click HAL "https://github.com/solokeys/solo1/tree/master/targets/stm32l432/lib/"
    click Host "https://github.com/solokeys/solo1/blob/master/pc/main.c"
    click Host "https://github.com/solokeys/solo1/blob/master/pc/device.c"
    click Host "https://github.com/solokeys/solo1/blob/master/pc/app.h"
    click Tools "https://github.com/solokeys/solo1/tree/master/tools/"
    click Udev "https://github.com/solokeys/solo1/tree/master/udev/"
    click Builds "https://github.com/solokeys/solo1/tree/master/builds/"
    click Makefile "https://github.com/solokeys/solo1/tree/master/Makefile"
    click Dockerfile "https://github.com/solokeys/solo1/tree/master/Dockerfile"
    click MKDOCS "https://github.com/solokeys/solo1/blob/master/mkdocs.yml"
    click Travis "https://github.com/solokeys/solo1/blob/master/.travis.yml"
    click Docs "https://github.com/solokeys/solo1/tree/master/docs/"
    click Docs "https://github.com/solokeys/solo1/blob/master/README.md"

    %% Styles
    classDef cryptoProt fill:lightblue,stroke:#333,color:#000
    classDef embedded fill:lightgreen,stroke:#333,color:#000
    classDef host fill:lightcoral,stroke:#333,color:#000
    classDef tools fill:lightgoldenrodyellow,stroke:#333,color:#000
    classDef external fill:lightgray,stroke:#333,color:#000

    class Crypto,CTAP,CTAPHID,Extensions,TinyCBOR,Metadata cryptoProt
    class HAL,App,BL embedded
    class Host host
    class Tools tools
    class TestSuite,Udev,Docs,Builds,Makefile,Dockerfile,MKDOCS,Travis external
```
