# haohangan/netty-websocket-protobuf architecture

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

- Interactive diagram: https://gitdiagram.com/haohangan/netty-websocket-protobuf
- Repository: https://github.com/haohangan/netty-websocket-protobuf

## Overview

##### Main Components
- Client (JavaScript):
- Located under the “js/netty-websocket-js” directory.
- Contains modules for both “cloud” and “singleServer” deployments (different bundles and test demo HTML files).
- Uses Protobuf (google-protobuf.js, WSMessage_pb.js) to encode/decode messages.
- Server (Java):
- Resides in the “server/netty-websocket” directory.
- Uses Netty for establishing and handling WebSocket connections.
- Organized into sub-packages for modules like “client”, “handler”, “message/protobuf”, “netty_cloud”, “inject”, “user”, and “proxy”.
- Displays clear separation of concerns: messaging processing (AbstractMessageProcess, MessageProgress), client management (WebSocketClientPool and related classes), and server initialization (CloudStart, Start).
- Proxy Component:
- Found in “server/proxy”, with an nginx configuration file (nginx.conf), which likely denotes a reverse proxy setup to support production deployment.
- Build and Configuration Artifacts:
- Webpack configuration exists for bundling the JavaScript code (webpack.config.js).
- Maven’s pom.xml on the server side indicates dependency management and build configuration.

##### Relationships and Interactions
- The client (JavaScript code) establishes WebSocket connections to the server (Java/Netty).
- Data serialization/deserialization is performed using Protobuf (as evident by the various protobuf-related files on both client and server).
- The server contains both client and cloud modules, indicating that it can handle potentially multiple types of message routing or deployment modes (i.e., single server vs. cloud-based architecture).
- A proxy layer (nginx) hints at an additional network component that might route or balance incoming WebSocket connections to the server.

##### Architectural Patterns and Design Principles
- Client/Server Separation: Clear division between the frontend (JavaScript client) and backend (Java server).
- Messaging and Data Serialization: Utilization of Protobuf for defined message structures.
- Module Separation: The server code is modularized into distinct packages (organization by functionality such as handlers, proxy, message, and user management), which helps in maintaining separation of concerns.
- Scalability and Deployment: The presence of “cloud” and “singleServer” builds suggests that the architecture is designed to support different deployment environments, possibly even load-balancing or multi-instance setups managed via a proxy.

##### Relevant Technologies, Frameworks, or Libraries
- Server:
- Netty (networking framework for asynchronous event-driven network application development).
- Maven (for dependency management and build automation).
- Apache Curator (as seen in the “curator” package), likely for service discovery or cluster management.
- Client:
- Standard JavaScript with bundling handled by Webpack.
- Google Protobuf libraries tailored for JavaScript communications.
- Proxy Component:
- Nginx (configured through nginx.conf), possibly handling reverse proxying and load balancing.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Client Layer
    subgraph "Client Layer"
        ClientApp("Client Application"):::client
        ClientCloud("Cloud Deployment Bundle"):::client
        ClientSingle("Single Server Deployment Bundle"):::client
        ClientProtoCloud("Protobuf Modules (Cloud)"):::client
        ClientProtoJS("Protobuf Modules (JS)"):::client
    end

    %% Server Layer
    subgraph "Server Layer"
        ServerApp("Server Application"):::server
        subgraph "Server Components"
            WSClient("WebSocket Client Management"):::server
            ProtoCloud("Protobuf Processing (Cloud)"):::server
            ProtoNetty("Protobuf Processing (Netty)"):::server
            WSHandlerCloud("WebSocket Handler (Cloud)"):::server
            WSHandlerNetty("WebSocket Handler (Netty)"):::server
            InitCloud("Server Initialization (Cloud)"):::server
            InitNetty("Server Initialization (Netty)"):::server
            DICloud("Dependency Injection (Cloud)"):::server
            DINetty("Dependency Injection (Netty)"):::server
            UserMgmt("User Management"):::server
            JavaProxy("Proxy Module (Java)"):::server
            Utility("Utility & Common Components"):::server
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        ProxyConfig("NGINX Proxy Configuration"):::infra
    end

    %% Build Artifacts
    subgraph "Build Artifacts"
        Maven("Maven Build Configuration"):::build
        Webpack("Webpack Configuration"):::build
    end

    %% External Communication
    ClientApp -->|"WebSocket(Protobuf)"| ServerApp
    ClientCloud -->|"Connects_via_WS"| WSHandlerCloud
    ClientSingle -->|"Connects_via_WS"| WSHandlerNetty
    ClientProtoCloud ---|"Protobuf_serialization"| ClientCloud
    ClientProtoJS ---|"Protobuf_serialization"| ClientSingle

    %% Internal Server Flow
    InitCloud -->|"Initializes"| WSClient
    InitCloud -->|"Triggers"| ProtoCloud
    InitNetty -->|"Initializes"| ProtoNetty
    ProtoCloud -->|"Routes_to"| WSHandlerCloud
    ProtoNetty -->|"Routes_to"| WSHandlerNetty
    WSHandlerCloud -->|"Manages"| UserMgmt
    WSHandlerNetty -->|"Manages"| UserMgmt
    DICloud -->|"Injects_into"| ProtoCloud
    DINetty -->|"Injects_into"| ProtoNetty
    Utility -->|"Supports"| WSClient
    JavaProxy -->|"Assists"| WSHandlerCloud

    %% Proxy and Build Connections
    ProxyConfig -->|"Routes_traffic"| ServerApp
    Maven -->|"Builds"| ServerApp
    Webpack -->|"Bundles"| ClientApp

    %% Click Events
    click ClientApp "https://github.com/haohangan/netty-websocket-protobuf/tree/master/js/netty-websocket-js"
    click ClientCloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/js/netty-websocket-js/dist/cloud"
    click ClientSingle "https://github.com/haohangan/netty-websocket-protobuf/tree/master/js/netty-websocket-js/dist/singleServer"
    click ClientProtoCloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/js/netty-websocket-js/src/cloudjs"
    click ClientProtoJS "https://github.com/haohangan/netty-websocket-protobuf/tree/master/js/netty-websocket-js/src/js"
    click ServerApp "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket"
    click WSClient "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/client"
    click ProtoCloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/message/protobuf"
    click ProtoNetty "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_websocket/message/protobuf"
    click WSHandlerCloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/handler"
    click WSHandlerNetty "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_websocket/handler"
    click InitCloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/start"
    click InitNetty "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_websocket/start"
    click DICloud "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/inject"
    click DINetty "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_websocket/inject"
    click UserMgmt "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_websocket/user"
    click JavaProxy "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/netty_cloud/proxy"
    click Utility "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/netty-websocket/src/main/java/org/eva/common"
    click ProxyConfig "https://github.com/haohangan/netty-websocket-protobuf/tree/master/server/proxy"
    click Maven "https://github.com/haohangan/netty-websocket-protobuf/blob/master/server/netty-websocket/pom.xml"
    click Webpack "https://github.com/haohangan/netty-websocket-protobuf/blob/master/js/netty-websocket-js/webpack.config.js"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef server fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef build fill:#E6E6FA,stroke:#000,stroke-width:2px;
```
