# trakx/fireblocks-api-client architecture

> Architecture diagram of the GitHub repository trakx/fireblocks-api-client, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trakx/fireblocks-api-client
- Repository: https://github.com/trakx/fireblocks-api-client

## Overview

##### Main Components
- API Client Library Core: At the heart of the project is the client library (found under src/Trakx.Fireblocks.ApiClient) that contains classes such as FireblocksApiClients, FireblocksApiClientsFactory, and interfaces/models to interact with the Fireblocks API.
- Configuration Module: This includes all configuration classes (e.g., FireblocksApiConfiguration, FireblocksApiCredentialsConfiguration, AuthorisedClient, ClientConfigurator) that manage API base URLs, authentication keys, and other setup properties.
- Credential Providers: Under the Utils folder you have both ApiKeyCredentialsProvider and BearerCredentialsProvider along with their corresponding interfaces, which encapsulate the logic for handling authentication.
- Health Check Module: The Health folder (with FireblocksApiHealthCheck and HealthCheckExtensions) provides functionality to verify the connectivity and availability of the Fireblocks API.
- Dependency Injection/Registration: The Registration folder contains code to register all these client components (e.g., DependencyInjection and IFireblocksApiClientBase) for easy integration into consuming applications.
- Testing Environment (for context): Your tests directory contains both integration and unit tests that illustrate how the components interact, though these are not necessarily included in the production system design. They do, however, imply boundaries for the client interactions.

##### Relationships and Data Flow
- The API Client Library’s core components rely on the Configuration Module to initialize values required to access the Fireblocks API (e.g., BaseUrl and credentials).
- Credential Providers are used by the core components to attach API keys or bearer tokens to outgoing requests.
- The Factory (FireblocksApiClientsFactory) is responsible for instantiating and encapsulating the creation of various API clients. It pulls in configuration and uses the credential providers.
- The Health Check components interact with the client to monitor the service's connectivity.
- Dependency Injection registration bridges the library to downstream consumers and ensures that everything is correctly wired up.
- The NSwag-based code generation process (triggered during a build when the GenerateApiClient property is toggled) regenerates client stubs ensuring the client is always aligned with the Fireblocks API specification.

##### Relevant Architectural Patterns and Design Principles
- Modularity & Separation of Concerns: Each major functionality (configuration, health check, client instantiation, credential management) is isolated in its own folder and module.
- Factory Pattern: The FireblocksApiClientsFactory abstracts the complexity of client instantiation.
- Dependency Injection: Registration classes facilitate the integration of the library into wider .NET applications.
- Code Generation: NSwag automates integrating live API definitions to client code, minimizing manual overhead and ensuring consistency.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration and Credential Setup
    A["Configuration Module"]:::config
    B["Credential Providers"]:::credential

    %% API Client Library Core
    subgraph "API Client Library Core"
        C["FireblocksApiClients"]:::core
        D["FireblocksApiClientsFactory"]:::core
        E["FireblocksApiInterfacesAndModels"]:::core
    end

    %% Supporting Services
    F["Dependency Injection"]:::di
    G["Health Check Module"]:::health

    %% Build Process: NSwag Code Generation
    subgraph "Code Generation Flow"
        H["nswag.json"]:::codegen
        I["openApi3.yaml"]:::codegen
    end

    %% Testing Environment and External API
    J["Testing Environment"]:::tests
    K["External Fireblocks API"]:::external

    %% Relationships
    A -->|"feeds"| D
    B -->|"supplies"| D
    H -->|"generates"| D
    I -->|"generates"| D
    D -->|"creates"| C
    F -->|"registers"| C
    G -->|"monitors"| C
    C -->|"calls"| K
    J -->|"verifies"| C

    %% Click Events
    click A "https://github.com/trakx/fireblocks-api-client/tree/dev/src/Trakx.Fireblocks.ApiClient/Configuration"
    click B "https://github.com/trakx/fireblocks-api-client/tree/dev/src/Trakx.Fireblocks.ApiClient/Utils"
    click C "https://github.com/trakx/fireblocks-api-client/blob/dev/src/Trakx.Fireblocks.ApiClient/FireblocksApiClients.cs"
    click D "https://github.com/trakx/fireblocks-api-client/blob/dev/src/Trakx.Fireblocks.ApiClient/FireblocksApiClientsFactory.cs"
    click E "https://github.com/trakx/fireblocks-api-client/blob/dev/src/Trakx.Fireblocks.ApiClient/FireblocksApiInterfacesAndModels.cs"
    click F "https://github.com/trakx/fireblocks-api-client/tree/dev/src/Trakx.Fireblocks.ApiClient/Registration"
    click G "https://github.com/trakx/fireblocks-api-client/tree/dev/src/Trakx.Fireblocks.ApiClient/Health"
    click H "https://github.com/trakx/fireblocks-api-client/blob/dev/src/Trakx.Fireblocks.ApiClient/nswag.json"
    click I "https://github.com/trakx/fireblocks-api-client/blob/dev/src/Trakx.Fireblocks.ApiClient/openApi3.yaml"
    click J "https://github.com/trakx/fireblocks-api-client/blob/dev/tests/Trakx.Fireblocks.ApiClient.Tests"

    %% Styles
    classDef config fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef credential fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef core fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef health fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
    classDef di fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef codegen fill:#D6EAF8,stroke:#5DADE2,stroke-width:2px;
    classDef tests fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
```
