# slavakuntsov/hyper-quant-api-connector architecture

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

- Interactive diagram: https://gitdiagram.com/slavakuntsov/hyper-quant-api-connector
- Repository: https://github.com/slavakuntsov/hyper-quant-api-connector

## Overview

##### Project Overview & Core Purpose
- The project is centered on connecting to external cryptocurrency market data using Bitfinex’s API. It offers two major modes of operation: REST-based data retrieval and WebSocket-based real-time event processing.
- In addition, there is a currency conversion service that integrates with CryptAPI to convert between currencies.
- Although a ConsoleApp exists, the primary application user interface is the WPF application (built with an MVVM pattern) which consumes the API connector functionality.

##### Main Components
a. API Connector Module:
- Contains submodules for the REST API and WebSocket connections.
- REST API Connector:
- Implements IRestApiConnector with methods to retrieve candle series, trades, and ticker data.
- Uses HttpClient (see DI registration example with a base address of https://api-pub.bitfinex.com).
- WebSocket Connector:
- Implements IWebSocketConnector.
- Manages subscriptions, event handling, and real-time incoming messages (candle updates, trade data).
- DTOs, Interfaces, and Models:
- DTOs such as CurrencyConvertDTO and RequestMessageDTO handle data packaging.
- Models like Candle, Trade, Ticker, etc., represent domain objects.
b. Cryptocurrency Converter:
- Implements ICryptocurrencyConverter to convert cryptocurrency amounts using CryptAPI.
c. UI (WPF Application):
- Follows the MVVM pattern.
- Contains Model (Portfolio), View (MainWindow), and ViewModel (MainViewModel).
- Acts as a client consuming the API connectors via dependency injection (DI).

d. External Dependencies:
- Bitfinex APIs (for both REST and WebSocket endpoints).
- CryptAPI for currency conversion.
- Microsoft.Extensions.DependencyInjection for DI and HttpClient configuration.

##### Architectural Patterns & Design Principles
- Use of the Interface Segregation Principle: how ITestConnector was split into IRestApiConnector and IWebSocketConnector.
- DI approach (the code snippets for registering services are a key part of the architecture).
- Mention that the REST methods yield results as asynchronous enumerables to optimize memory usage when dealing with large data sets.
- That the WPF application follows the MVVM pattern (so separate presentation, logic, and data concerns).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Services"
        RESTApi["Bitfinex REST API"]:::external
        WebSocketApi["Bitfinex WebSocket API"]:::external
        CryptAPI["CryptAPI Service"]:::external
    end

    subgraph "API Connector Module"
        DI["Dependency Injection & Service Registration"]:::internal
        RestConnector["REST API Connector (IRestApiConnector)"]:::internal
        WSConnector["WebSocket Connector (IWebSocketConnector)"]:::internal
        CryptoConverter["Cryptocurrency Converter (ICryptocurrencyConverter)"]:::internal

        subgraph "Data Structures"
            DTO1["CurrencyConvertDTO"]:::internal
            DTO2["RequestMessageDTO"]:::internal
            DomainModels["Domain Models (Candle, Trade, Ticker, Cryptocurrency)"]:::internal
        end
    end

    subgraph "Client Layer (WPF Application)"
        ViewModel["MainViewModel"]:::ui
        View["MainWindow (View)"]:::ui
        Model["Portfolio (Model)"]:::ui
    end

    ConsoleApp["Console Application"]:::dev

    %% External calls from API Connectors
    RestConnector -->|"calls"| RESTApi
    WSConnector -->|"connects"| WebSocketApi
    CryptoConverter -->|"calls"| CryptAPI

    %% Dependency Injection wiring
    DI --> RestConnector
    DI --> WSConnector
    DI --> CryptoConverter
    DI --> ViewModel

    %% Client invoking connectors via MVVM
    ViewModel -->|"calls"| RestConnector
    ViewModel -->|"calls"| WSConnector
    ViewModel -->|"calls"| CryptoConverter
    ViewModel --> View
    ViewModel --> Model

    %% Console Application testing connectors
    ConsoleApp -->|"tests"| RestConnector
    ConsoleApp -->|"tests"| WSConnector
    ConsoleApp -->|"tests"| CryptoConverter

    %% Click Events
    click RestConnector "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/ApiConnectors/RestApiConnector.cs"
    click RestConnector "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/Interfaces/Rest/IRestApiConnector.cs"
    click WSConnector "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/ApiConnectors/WebSocketConnector.cs"
    click WSConnector "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/Interfaces/WebSocket/IWebSocketConnector.cs"
    click CryptoConverter "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/CryptocurrencyConverter/CryptocurrencyConverter.cs"
    click CryptoConverter "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/Interfaces/ICryptocurrencyConverter.cs"
    click DTO1 "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/DTOs/CurrencyConvertDTO.cs"
    click DTO2 "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ApiConnector/DTOs/RequestMessageDTO.cs"
    click DomainModels "https://github.com/slavakuntsov/hyper-quant-api-connector/tree/main/src/ApiConnector/Models"
    click Model "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/WpfApp/MVVM/Model/Portfolio.cs"
    click View "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/WpfApp/MVVM/View/MainWindow.xaml"
    click View "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/WpfApp/MVVM/View/MainWindow.xaml.cs"
    click ViewModel "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/WpfApp/MVVM/ViewModel/MainViewModel.cs"
    click ConsoleApp "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ConsoleApp/Program.cs"
    click ConsoleApp "https://github.com/slavakuntsov/hyper-quant-api-connector/blob/main/src/ConsoleApp/ConsoleApp.csproj"

    %% Styles
    classDef external fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef internal fill:#A3E4D7,stroke:#145A32,stroke-width:2px;
    classDef ui fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef dev fill:#F5CBA7,stroke:#943126,stroke-width:2px;
```
