# diloabininyeri/socket architecture

> Architecture diagram of the GitHub repository diloabininyeri/socket, 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/diloabininyeri/socket
- Repository: https://github.com/diloabininyeri/socket

## Overview

##### Core Components (Main Layer)
- It to an "AbstractSocketClientHandler" component, showing inheritance relationship
- "SocketClient" component as a separate entity

##### Channel Management Layer
- Channel component (handles channel subscriptions)
- Broadcast component (manages message broadcasting)
- Message component (handles message formatting)
- HandShake component (manages WebSocket protocol handshaking)

##### Communication Flow
- Client connections → SocketServer
- Message flow through channels
- Broadcast patterns
- Client-to-channel relationships

##### Key Features Layer
Create sections for:
- Wildcard Pattern Matching
- JSON Message Handling
- Route Management
- Client Status Tracking

- Blue: Core components (SocketServer, AbstractSocketClientHandler)
- Green: Channel-related components
- Orange: Client-related components
- Purple: Message handling components

Component Relationships:
**[External Clients] ←→ [SocketServer]**
- ↓
**[AbstractSocketClientHandler]**
- ↓
- [Channel Manager]
- /      |       \
**[Channels] [Broadcast] [Messages]**

Special Considerations:
##### Message flow for both direct and broadcast messages

Technical Details to Include:
- WebSocket protocol handling
- Channel subscription patterns
- Message broadcasting paths
- Client management system
- Exception handling flow

Important Notes:
- Keep the main components clearly separated
- Both server-side and client-side interactions
- Macro system for extensibility
- Demonstrate the channel subscription/unsubscription flow

##### Extension points through the macro system

- Component types and their roles
- Special patterns (wildcards, routes)

This system design should capture both the architectural complexity and the flexibility of the socket channels implementation while maintaining clarity about the core functionality and extension points.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    SocketServer["Socket Server"]:::core
    AbstractHandler["Abstract Socket Client Handler"]:::core
    SocketClient["Socket Client"]:::core
    
    %% Channel Management
    subgraph ChannelManagement["Channel Management Layer"]
        ChannelMgr["Channel Manager"]:::channel
        Channel["Channel Component"]:::channel
        Broadcast["Broadcast Component"]:::channel
        Message["Message Component"]:::message
        HandShake["HandShake Protocol"]:::protocol
    end

    %% Client Management
    subgraph ClientManagement["Client Management"]
        ClientId["Client Identification"]:::client
        ClientStatus["Client Status Tracking"]:::client
    end

    %% Message Handling
    subgraph MessageSystem["Message Handling System"]
        MessageSender["Message Sender"]:::message
        MessageFlow["Message Router"]:::message
    end

    %% Extension System
    subgraph Extensions["Extension Layer"]
        MacroSystem["Macro System"]:::extension
        Debugger["Debugger"]:::extension
    end

    %% Exception Handling
    subgraph ErrorHandling["Exception Handling"]
        ClientExc["Client Exceptions"]:::error
        SocketExc["Socket Exceptions"]:::error
        PatternExc["Pattern Exceptions"]:::error
    end

    %% Relationships
    ExternalClients(("External Clients")):::external --> SocketServer
    SocketServer --> AbstractHandler
    AbstractHandler --> SocketClient
    SocketServer --> ChannelMgr
    ChannelMgr --> Channel
    ChannelMgr --> Broadcast
    ChannelMgr --> Message
    SocketServer --> HandShake
    SocketClient --> ClientId
    Message --> MessageSender
    MessageSender --> MessageFlow
    SocketServer --> MacroSystem
    
    %% Error Flows
    SocketServer -.-> ErrorHandling
    ChannelMgr -.-> ErrorHandling
    SocketClient -.-> ErrorHandling

    %% Click Events
    click SocketServer "https://github.com/diloabininyeri/socket/blob/main/src/SocketServer.php"
    click AbstractHandler "https://github.com/diloabininyeri/socket/blob/main/src/AbstractSocketClientHandler.php"
    click SocketClient "https://github.com/diloabininyeri/socket/blob/main/src/SocketClient.php"
    click Channel "https://github.com/diloabininyeri/socket/blob/main/src/Channel.php"
    click Broadcast "https://github.com/diloabininyeri/socket/blob/main/src/Broadcast.php"
    click Message "https://github.com/diloabininyeri/socket/blob/main/src/Message.php"
    click HandShake "https://github.com/diloabininyeri/socket/blob/main/src/HandShake.php"
    click MessageSender "https://github.com/diloabininyeri/socket/blob/main/src/Send.php"
    click MacroSystem "https://github.com/diloabininyeri/socket/blob/main/src/MacroTrait.php"
    click ClientExc "https://github.com/diloabininyeri/socket/blob/main/src/Exceptions/ClientException.php"
    click SocketExc "https://github.com/diloabininyeri/socket/blob/main/src/Exceptions/SocketException.php"
    click PatternExc "https://github.com/diloabininyeri/socket/blob/main/src/Exceptions/InvalidPatternException.php"
    click Debugger "https://github.com/diloabininyeri/socket/blob/main/src/Debugger.php"
    click ClientId "https://github.com/diloabininyeri/socket/blob/main/src/Id.php"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef channel fill:#2ecc71,stroke:#27ae60,color:white
    classDef client fill:#e67e22,stroke:#d35400,color:white
    classDef message fill:#9b59b6,stroke:#8e44ad,color:white
    classDef protocol fill:#34495e,stroke:#2c3e50,color:white
    classDef extension fill:#f1c40f,stroke:#f39c12,color:black
    classDef error fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Channel Components"]:::channel
        L3["Client Components"]:::client
        L4["Message Components"]:::message
        L5["Protocol Handlers"]:::protocol
        L6["Extensions"]:::extension
        L7["Error Handlers"]:::error
    end
```
