How lepicekmichal/signalrkore works
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)