# facebookincubator/socketrocket architecture

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

- Interactive diagram: https://gitdiagram.com/facebookincubator/socketrocket
- Repository: https://github.com/facebookincubator/socketrocket

## Overview

##### Main Components

a. Core WebSocket Client Components:
- WebSocket Connection Handler (SRWebSocket)
- Delegate System (SRWebSocketDelegate)
- Security Layer (SRSecurityPolicy)
- Internal Components:
- Delegate Controller
- IO Consumer System
- Run Loop Management
- Proxy Support
- Security Implementation

b. Supporting Systems:
- Utility Services
- Testing Infrastructure
- Demo Application (TestChat)

**[Client Application] ←→ [SRWebSocket Public Interface]**

**┌─────────────────────────────────────────┐**
- SRWebSocket Core             │
- ┤
- Connection Management                 │
- Message Processing                    │
- Security Handling                     │
- Delegate Communication                │
- ┘

**┌─────────────┐ ┌──────────┐ ┌───────────┐**
- IO Consumer │ │ Security │ │   Proxy   │
- ┘ └──────────┘ └───────────┘
- ↑               ↑            ↑
- ┴────────────┘

##### Key Relationships to Highlight

a. External Interactions:
- WebSocket connection to server
- SSL/TLS security layer
- HTTP proxy support
- Client application integration

b. Internal Communications:
- Delegate pattern for event handling
- IO Consumer pool management
- Run loop thread management

##### Technical Details

- Support for multiple platforms (iOS, macOS, tvOS)
- RFC 6455 compliance notation
- TLS/SSL support indication
- IPv4/IPv6 support
- Asynchronous operation indicators

##### Implementation Notes

- Public API surface (SRWebSocket.h interface)
- Delegate protocol methods
- Security policy configuration
- Background thread handling

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        App[Client Application]
        TestApp[TestChat Demo]:::demo
    end

    subgraph Public["Public Interface Layer"]
        WebSocket["SRWebSocket Interface"]:::core
        SecurityPolicy["Security Policy Interface"]:::security
        DelegateProtocol["WebSocket Delegate Protocol"]:::core
    end

    subgraph Core["Core Implementation Layer"]
        WebSocketCore["WebSocket Core Implementation"]:::core
        DelegateController["Delegate Controller"]:::internal
        ErrorHandler["Error Handling"]:::utility
        Constants["Constants & Configuration"]:::utility
    end

    subgraph Internal["Internal Components Layer"]
        subgraph IO["I/O Management"]
            IOConsumer["I/O Consumer Pool"]:::internal
            RunLoop["Run Loop Thread"]:::internal
        end

        subgraph Security["Security Components"]
            SecImpl["Security Implementation"]:::security
            ProxySupport["Proxy Support"]:::internal
        end

        subgraph Utils["Utility Services"]
            Utilities["Utility Functions"]:::utility
        end
    end

    subgraph Testing["Testing Layer"]
        TestInfra["Testing Infrastructure"]:::test
    end

    %% Relationships
    App --> WebSocket
    TestApp --> WebSocket
    WebSocket --> WebSocketCore
    WebSocket --> SecurityPolicy
    WebSocket --> DelegateProtocol
    WebSocketCore --> DelegateController
    WebSocketCore --> ErrorHandler
    WebSocketCore --> Constants
    DelegateController --> IOConsumer
    WebSocketCore --> IOConsumer
    IOConsumer --> RunLoop
    WebSocketCore --> SecImpl
    SecImpl --> ProxySupport
    WebSocketCore --> Utilities
    TestInfra --> WebSocketCore

    %% Click Events
    click WebSocket "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/SRWebSocket.h"
    click WebSocketCore "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/SRWebSocket.m"
    click SecurityPolicy "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/SRSecurityPolicy.h"
    click DelegateController "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/Delegate/SRDelegateController.h"
    click IOConsumer "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/IOConsumer/SRIOConsumerPool.h"
    click RunLoop "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/RunLoop/SRRunLoopThread.h"
    click ProxySupport "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/Proxy/SRProxyConnect.h"
    click SecImpl "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/Security/SRPinningSecurityPolicy.h"
    click Utilities "https://github.com/facebookincubator/SocketRocket/tree/main/SocketRocket/Internal/Utilities"
    click TestInfra "https://github.com/facebookincubator/SocketRocket/tree/main/Tests"
    click TestApp "https://github.com/facebookincubator/SocketRocket/tree/main/TestChat"
    click Constants "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/SRConstants.h"
    click ErrorHandler "https://github.com/facebookincubator/SocketRocket/blob/main/SocketRocket/Internal/Utilities/SRError.h"

    %% Styling
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef security fill:#d62828,stroke:#d62828,color:#fff
    classDef internal fill:#457b9d,stroke:#457b9d,color:#fff
    classDef utility fill:#a8dadc,stroke:#a8dadc,color:#000
    classDef test fill:#f4a261,stroke:#f4a261,color:#000
    classDef demo fill:#2a9d8f,stroke:#2a9d8f,color:#fff

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Security Components]:::security
        L3[Internal Components]:::internal
        L4[Utility Components]:::utility
        L5[Testing Components]:::test
        L6[Demo Application]:::demo
    end
```
