# lepicekmichal/signalrkore architecture

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

- Interactive diagram: https://gitdiagram.com/lepicekmichal/signalrkore
- Repository: https://github.com/lepicekmichal/signalrkore

## Overview

Based on our analysis of the file tree and README, this project is a Kotlin Multiplatform (KMM) client library—SignalRKore—that enables real‐time communication with an ASP.NET Core server (i.e. a SignalR Core server). The library is structured to support Android, JVM, and iOS using shared “commonMain” code together with platform-specific implementations. Its core responsibilities include establishing hub connections, handling messages (invoking, sending, streaming), negotiating handshakes, managing different transport types (WebSockets, Server-Sent Events, Long Polling), and implementing automatic reconnection policies.

##### Major Components
- Core Library (Common): This includes the main classes in the “signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore” directory. Key classes include HubConnection, various HubMessage types, HubProtocol (with JsonHubProtocol), Handshake requests/responses, and utilities.
- Transport Implementations: Components found in “transports” such as LongPollingTransport, SSE, and WebSocketTransport. These implement the different communication backends.
- Reconnection Mechanism: The AutomaticReconnect classes and policies (Active, Exponential Backoff, Custom) that are defined/used to handle connection lifecycle stability.
- HTTP Client & Serialization: The project leverages Ktor’s HTTP client (often using OkHttp engine when passed explicitly) as well as kotlinx.serialization for custom and adaptable JSON message conversion.
- Platform-Specific Layers: Separate codebases exist under androidMain, iosMain, and jvmMain (e.g., customized UUID implementations and possibly other platform-targeted nuances).
- Build and Configuration: While not part of the run-time architecture, the buildSrc and Gradle configuration files indicate a modular and standard Gradle-based build process that supports multiplatform development.

- “Hub Protocol & JSON Parsing” (which handles message serialization/deserialization)
- “Transport Layer” (with separate sub-components for WebSocket, SSE, LongPolling)
- “Reconnection Policy Manager” (managing automatic reconnect logic)
- “Logger & Error Handling” (custom logging interface and logging flow)

##### Architectural Patterns and Principles
- Asynchronous and Reactive Flows: The system relies on Kotlin coroutines and flows (for receiving messages, streaming, and reconnect policies). Mark these flows next to relevant components to indicate asynchronous data handling.
- Separation of Concerns: Notice that transport specifics, message parsing, and connection state management are clearly decoupled, facilitating better maintainability and easier future extension.

##### Relevant Technologies
- Kotlin (Core, Multiplatform)
- Ktor as the network engine (with notes on OkHttp for Android-specific configuration)
- kotlinx.serialization for message handling
- Custom logger interface for logging messages
- Gradle for build configuration (illustrate the Gradle build process loosely if needed)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library Subgraph
    subgraph "Core Library"
        HCB["HubConnectionBuilder"]:::common
        HC["HubConnection"]:::common
        HP["HubProtocol"]:::common
        JHP["JsonHubProtocol"]:::common
        HCB -->|"creates"| HC
        HC -->|"uses"| HP
        HC -->|"uses"| JHP
    end

    %% Transport Layer Subgraph
    subgraph "Transport Layer"
        WST["WebSocketTransport"]:::transport
        SSET["SSETransport"]:::transport
        LPT["LongPollingTransport"]:::transport
    end

    %% Platform Specific Subgraph
    subgraph "Platform Specific"
        AND["Android"]:::platform
        IOS["iOS"]:::platform
        JVM["JVM"]:::platform
    end

    %% Other Components
    RPM["Reconnection Policies"]:::recon
    HTTPC["HTTP Client (Ktor)"]:::common
    Logger["Logger & Error Handling"]:::logging
    Build["Gradle Build & Configuration"]:::build

    %% Relationships between Core Library and other components
    HC -->|"selects"| WST
    HC -->|"selects"| SSET
    HC -->|"selects"| LPT
    HC -->|"configures"| RPM
    HC -->|"communicatesVia"| HTTPC
    HC -->|"logsVia"| Logger
    Build -->|"builds"| HCB

    %% Platform Abstraction from Core Library
    HC -->|"platformAbstraction"| AND
    HC -->|"platformAbstraction"| IOS
    HC -->|"platformAbstraction"| JVM

    %% Styles
    classDef common fill:#9fc5e8,stroke:#1c4587,stroke-width:2px;
    classDef transport fill:#f9cb9c,stroke:#e69138,stroke-width:2px;
    classDef recon fill:#b6d7a8,stroke:#38761d,stroke-width:2px;
    classDef logging fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef build fill:#d9d2e9,stroke:#674ea7,stroke-width:2px;
    classDef platform fill:#d0e0e3,stroke:#115e67,stroke-width:2px;

    %% Click Events
    click HC "https://github.com/lepicekmichal/signalrkore/tree/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore"
    click HP "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/HubProtocol.kt"
    click JHP "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/JsonHubProtocol.kt"
    click WST "https://github.com/lepicekmichal/signalrkore/tree/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/transports"
    click SSET "https://github.com/lepicekmichal/signalrkore/tree/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/transports"
    click LPT "https://github.com/lepicekmichal/signalrkore/tree/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/transports"
    click RPM "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/AutomaticReconnect.kt"
    click Logger "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/commonMain/kotlin/eu/lepicekmichal/signalrkore/Logger.kt"
    click AND "https://github.com/lepicekmichal/signalrkore/tree/main/signalrkore/src/androidMain"
    click IOS "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/iosMain/kotlin/eu/lepicekmichal/signalrkore/UUID.ios.kt"
    click JVM "https://github.com/lepicekmichal/signalrkore/blob/main/signalrkore/src/jvmMain/kotlin/eu/lepicekmichal/signalrkore/UUID.jvm.kt"
    click Build "https://github.com/lepicekmichal/signalrkore/blob/main/buildSrc/src/main/kotlin/eu/lepicekmichal/signalrkore/HubCommunicationTask.kt"
```
