# ibrahimalbarghouthi/anycable-go architecture

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

- Interactive diagram: https://gitdiagram.com/ibrahimalbarghouthi/anycable-go
- Repository: https://github.com/ibrahimalbarghouthi/anycable-go

## Overview

##### Main Components Identification

a) WebSocket Server Layer
- Located in the `server` directory
- Handles WebSocket connections and SSL configuration
- Entry point for client connections

b) Node Management Layer
- Found in the `node` directory
- Manages WebSocket sessions and connection hubs
- Handles disconnections and session state

c) RPC Layer
- Located in the `rpc` directory
- Communicates with the AnyCable RPC server
- Handles message routing and business logic

d) PubSub System
- Found in the `pubsub` directory
- Supports both HTTP and Redis implementations
- Handles broadcast messages and subscriptions

##### Connection Flow

**WebSocket Clients → WebSocket Handler → Session Manager → Hub Controller ↔ RPC Client ↔ AnyCable RPC Server**
- ↕
- PubSub Adapter ↔ Redis/HTTP

##### Additional Elements

Supporting components:
- Metrics system (from `metrics` directory)
- Configuration management (from `config` directory)
- Health check endpoints

##### Specific Implementation Details

- Bidirectional WebSocket communication
- RPC protocol (using Protocol Buffers, as indicated by `etc/rpc.proto`)
- Multiple broadcast options (Redis/HTTP)
- Metrics export capabilities

##### Notes for Implementation

- Configuration options (SSL, Redis Sentinel support)
- Scalability points (multiple instances can run in parallel)
- Monitoring/observability points (Prometheus metrics)

- High-level architecture (showing main components and their interactions)
- Implementation details (protocols, adapters, configuration options)
- Operational aspects (monitoring, scaling, health checks)

Remember to include version compatibility notes, as mentioned in the README (v1.0 being backward compatible with v0.6.x).

This system design should help developers understand both the overall architecture and the specific implementation details of AnyCable-Go, while highlighting its integration points with the broader AnyCable ecosystem.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        WSClients([WebSocket Clients])
        RPCServer([AnyCable RPC Server])
        Redis[(Redis)]
        Prometheus([Prometheus/Metrics])
    end

    subgraph WSServer[WebSocket Server Layer]
        WSHandler["WebSocket Handler"]:::server
        SSLConfig["SSL Config"]:::server
        HealthHandler["Health Handler"]:::server
    end

    subgraph NodeMgmt[Node Management Layer]
        SessionMgr["Session Manager"]:::node
        Hub["Hub Controller"]:::node
        Disconnector["Disconnector"]:::node
        WSController["WS Controller"]:::node
    end

    subgraph RPCLayer[RPC Layer]
        RPCClient["RPC Client"]:::rpc
        ProtoHandler["Protocol Handler"]:::rpc
    end

    subgraph PubSubSystem[PubSub System]
        PubSubAdapter{"PubSub Adapter"}:::pubsub
        HTTPAdapter["HTTP Adapter"]:::pubsub
        RedisAdapter["Redis Adapter"]:::pubsub
    end

    subgraph Support[Support Systems]
        Config["Configuration"]:::config
        Metrics["Metrics System"]:::metrics
        Logger["Logger"]:::utils
    end

    %% Connections
    WSClients --> WSHandler
    WSHandler --> SessionMgr
    SessionMgr --> Hub
    Hub <--> RPCClient
    RPCClient <--> RPCServer
    Hub <--> PubSubAdapter
    PubSubAdapter --> HTTPAdapter
    PubSubAdapter --> RedisAdapter
    RedisAdapter --> Redis
    Metrics --> Prometheus
    WSHandler --> HealthHandler
    Hub --> Disconnector
    Hub --> WSController
    RPCClient --> ProtoHandler

    %% Click Events
    click WSHandler "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/server/server.go"
    click SSLConfig "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/server/ssl_config.go"
    click HealthHandler "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/server/health_handler.go"
    click SessionMgr "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/node/session.go"
    click Hub "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/node/hub.go"
    click Disconnector "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/node/disconnector.go"
    click WSController "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/node/ws_handler.go"
    click RPCClient "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/rpc/rpc.go"
    click ProtoHandler "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/protos/rpc.pb.go"
    click HTTPAdapter "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/pubsub/http.go"
    click RedisAdapter "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/pubsub/redis.go"
    click Metrics "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/metrics/metrics.go"
    click Config "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/config/config.go"
    click Logger "https://github.com/ibrahimalbarghouthi/anycable-go/blob/master/utils/logging.go"

    %% Styles
    classDef server fill:#2196F3,stroke:#1565C0,color:white
    classDef node fill:#4CAF50,stroke:#2E7D32,color:white
    classDef rpc fill:#FFC107,stroke:#FFA000,color:black
    classDef pubsub fill:#FF9800,stroke:#F57C00,color:white
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef metrics fill:#607D8B,stroke:#455A64,color:white
    classDef utils fill:#795548,stroke:#5D4037,color:white
    classDef external fill:#ECEFF1,stroke:#90A4AE,color:black

    %% Legend
    subgraph Legend
        Server["Server Components"]:::server
        NodeMgmt2["Node Management"]:::node
        RPC["RPC Components"]:::rpc
        PubSub["PubSub Components"]:::pubsub
        ConfigLegend["Configuration"]:::config
        MetricsLegend["Metrics"]:::metrics
        UtilsLegend["Utilities"]:::utils
        ExternalLegend["External Systems"]:::external
    end
```
