# foundriesio/fioctl architecture

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

- Interactive diagram: https://gitdiagram.com/foundriesio/fioctl
- Repository: https://github.com/foundriesio/fioctl

## Overview

##### Main Components

a. Client Interface Layer:
- Main CLI entry point (main.go and cmd/root.go)
- Command groups (subcommands directory structure)
- Client package that handles API interactions

b. Core Functionality Blocks:
- Authentication System (login/logout)
- Device Management
- Target Management
- Configuration Management
- PKI/Security Operations
- Event Management
- Factory Management

c. External Integration Points:
- Foundries.io REST API
- HSM Integration (via OpenSC pkcs11-tool)
- Local Configuration Storage

**[User Input Layer]**

**[Command Processing Layer]**

**[Client Layer]**

**[External Services Layer]**

##### Specific Implementation Details

a. User Input Layer:
- Main CLI interface
- Major command groups (devices, targets, config, etc.)

b. Command Processing Layer:
- Subcommands structure
- How commands are organized by functionality
- Common utilities and shared components

c. Client Layer:
- API client implementation (client/* files)
- OAuth handling
- Different API endpoints grouping

d. External Services Layer:
- Foundries.io API connection
- Local filesystem interaction
- HSM/PKCS11 integration

##### Important Relationships to Highlight

- Flow from CLI commands to API client calls
- Authentication flow
- Demonstrate configuration management paths
- Relationship between device management and target management

##### Key Technical Elements

- OAuth2 authentication system
- X.509 certificate handling
- TUF (The Update Framework) integration
- Event system architecture
- Factory management structure

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["CLI Interface Layer"]
        MainCLI["Main CLI Entry Point"]:::cli
        RootCmd["Root Command"]:::cli
    end

    subgraph Commands["Command Processing Layer"]
        Login["Login Command"]:::cmd
        Logout["Logout Command"]:::cmd
        Devices["Device Management"]:::cmd
        Targets["Target Management"]:::cmd
        Config["Configuration"]:::cmd
        Keys["PKI/Keys"]:::cmd
        Events["Events"]:::cmd
        Factories["Factories"]:::cmd
        Version["Version/Updates"]:::cmd
    end

    subgraph Client["Client Layer"]
        APIClient["API Client Interface"]:::client
        OAuth["OAuth Handler"]:::security
        DeviceAPI["Device API"]:::client
        TargetAPI["Target API"]:::client
        EventAPI["Event API"]:::client
        FactoryAPI["Factory API"]:::client
    end

    subgraph External["External Services Layer"]
        FoundriesAPI["Foundries.io REST API"]:::external
        HSM["HSM/PKCS11"]:::security
        LocalFS["Local Storage"]:::storage
        TUF["TUF Integration"]:::security
    end

    subgraph Platform["Platform-Specific"]
        Unix["Unix Implementation"]:::platform
        Windows["Windows Implementation"]:::platform
    end

    %% Relationships
    MainCLI --> RootCmd
    RootCmd --> |Commands| Commands
    Login --> OAuth
    Logout --> OAuth
    Devices --> DeviceAPI
    Targets --> TargetAPI
    Events --> EventAPI
    Factories --> FactoryAPI
    Keys --> HSM
    Keys --> TUF
    Version --> LocalFS
    
    APIClient --> FoundriesAPI
    OAuth --> FoundriesAPI
    Config --> LocalFS

    %% Click Events
    click MainCLI "https://github.com/foundriesio/fioctl/blob/main/main.go"
    click RootCmd "https://github.com/foundriesio/fioctl/blob/main/cmd/root.go"
    click APIClient "https://github.com/foundriesio/fioctl/blob/main/client/foundries.go"
    click Login "https://github.com/foundriesio/fioctl/blob/main/subcommands/login/cmd.go"
    click Logout "https://github.com/foundriesio/fioctl/blob/main/subcommands/logout/cmd.go"
    click OAuth "https://github.com/foundriesio/fioctl/blob/main/client/oauth.go"
    click Devices "https://github.com/foundriesio/fioctl/blob/main/subcommands/devices/cmd.go"
    click DeviceAPI "https://github.com/foundriesio/fioctl/blob/main/client/foundries_device.go"
    click Targets "https://github.com/foundriesio/fioctl/blob/main/subcommands/targets/cmd.go"
    click TargetAPI "https://github.com/foundriesio/fioctl/blob/main/client/foundries_tuf_root.go"
    click Config "https://github.com/foundriesio/fioctl/blob/main/subcommands/config/cmd.go"
    click Keys "https://github.com/foundriesio/fioctl/tree/main/subcommands/keys"
    click Events "https://github.com/foundriesio/fioctl/blob/main/subcommands/events/cmd.go"
    click EventAPI "https://github.com/foundriesio/fioctl/blob/main/client/foundries_events.go"
    click Factories "https://github.com/foundriesio/fioctl/blob/main/subcommands/factories/cmd.go"
    click FactoryAPI "https://github.com/foundriesio/fioctl/blob/main/client/foundries_factories.go"
    click HSM "https://github.com/foundriesio/fioctl/blob/main/x509/storage_pkcs11_tool.go"
    click Unix "https://github.com/foundriesio/fioctl/blob/main/subcommands/common_unix.go"
    click Windows "https://github.com/foundriesio/fioctl/blob/main/subcommands/common_windows.go"
    click Version "https://github.com/foundriesio/fioctl/blob/main/subcommands/version/updates.go"
    click TUF "https://github.com/foundriesio/fioctl/blob/main/subcommands/keys/tuf_root.go"

    %% Styling
    classDef cli fill:#3498db
    classDef cmd fill:#2ecc71
    classDef client fill:#e74c3c
    classDef security fill:#f1c40f
    classDef external fill:#e67e22
    classDef storage fill:#95a5a6
    classDef platform fill:#9b59b6

    %% Legend
    subgraph Legend
        CLI_L["CLI Components"]:::cli
        CMD_L["Command Components"]:::cmd
        CLIENT_L["Client Components"]:::client
        SEC_L["Security Components"]:::security
        EXT_L["External Services"]:::external
        STORE_L["Storage"]:::storage
        PLAT_L["Platform-Specific"]:::platform
    end
```
