# eooce/node-ws architecture

> Architecture diagram of the GitHub repository eooce/node-ws, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eooce/node-ws
- Repository: https://github.com/eooce/node-ws

## Overview

#### Purpose and Runtime
Node-ws is a lightweight Node.js Serverless/PaaS proxy service implementing VLESS and Trojan over WebSocket without a bundled proxy core. Its primary runtime entry point is `index.js`; package execution metadata is in `package.json`. It also serves a minimal HTTP-facing page from `index.html`.

#### Process Entry and Configuration
The Node process starts the HTTP/WebSocket service in `index.js`. Runtime behavior is environment-driven: `PORT` selects the listener, `UUID` configures proxy identity, and `DOMAIN` supplies the externally reachable hostname. `SUB_PATH` controls the subscription-information endpoint, while `AUTO_ACCESS` can enable periodic self-access/keepalive behavior.

Paths: `index.js`, `package.json`, `index.html`

#### HTTP and WebSocket Boundary
The service accepts ordinary HTTP requests and WebSocket upgrade traffic on the same Node listener. HTTP is used for the landing/cover response and subscription/node-information route; upgraded WebSocket connections carry the VLESS or Trojan protocol streams. This boundary lets deployments sit behind domain reverse proxies or CDN Worker/Snippet forwarding.

Paths: `index.js`, `index.html`, `README.md`

#### Proxy Protocol Stage
Incoming WebSocket byte streams are interpreted as either VLESS or Trojan authentication/request data. After protocol validation, the service establishes outbound TCP connectivity to the requested target and relays data bidirectionally between the WebSocket and that socket. Credentials are centered on the configured `UUID`, with the implementation intentionally relying on the Node WebSocket ecosystem rather than an external proxy binary.

Paths: `index.js`, `package.json`

#### Subscription and Deployment Interface
A path derived from `SUB_PATH` exposes connection/node information for clients. Generated endpoint information depends on `DOMAIN`, including nonstandard-port deployment cases. The documented hosting model targets Node-capable PaaS and DirectAdmin application hosting, and supports external CDN/reverse-proxy fronting.

Paths: `index.js`, `web-hosting.md`, `README.md`

#### Nezha Monitoring Integration
The process can optionally launch/connect an embedded Nezha agent integration. `NEZHA_SERVER`, `NEZHA_PORT`, and `NEZHA_KEY` select server endpoint and credentials; the documented variables support both Nezha v0 and v1 conventions. `NAME` provides the node-name prefix. This monitoring path is optional and separate from proxy request forwarding.

Paths: `index.js`, `README.md`

#### Packaging and Delivery
The repository packages the service as a Node application and provides a container build definition. GitHub Actions include workflows for Docker/image delivery and Go/Hug-related binary/image builds, indicating multiple deployment artifact targets beyond direct Node hosting.

Paths: `Dockerfile`, `.github/workflows/build-image.yml`, `.github/workflows/build-golang-docker-image.yml`

Main entry points: [`index.js`](https://github.com/eooce/node-ws/blob/main/index.js) (HTTP/WS Server), [`Dockerfile`](https://github.com/eooce/node-ws/blob/main/Dockerfile) (Container Build), [`package.json`](https://github.com/eooce/node-ws/blob/main/package.json) (Package Metadata), [`.github/workflows/build-image.yml`](https://github.com/eooce/node-ws/blob/main/.github/workflows/build-image.yml) (Image Delivery Workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_service["Node Service"]
  node_package["Package Metadata<br/>Node package<br/>[package.json]"]
  node_entry["HTTP/WS Server<br/>Node runtime<br/>[index.js]"]
  node_env{{"Environment Settings<br/>runtime config<br/>[index.js]"}}
  node_landing["Landing Page<br/>HTTP asset<br/>[index.html]"]
  node_subscription["Subscription Endpoint<br/>HTTP route<br/>[index.js]"]
  node_nezha["Embedded Nezha Agent<br/>monitoring integration<br/>[index.js]"]
end

subgraph group_traffic["Traffic Flow"]
  node_ws["WebSocket Upgrade<br/>connection boundary<br/>[index.js]"]
  node_protocol["VLESS / Trojan Parser<br/>protocol stage<br/>[index.js]"]
  node_relay["TCP Relay<br/>proxy transport<br/>[index.js]"]
  node_target(("Requested Target<br/>external TCP service"))
end

subgraph group_delivery["Delivery"]
  node_docker["Container Build<br/>Docker image"]
  node_image_workflow["Image Delivery Workflow<br/>GitHub Actions<br/>[build-image.yml]"]
  node_golang_workflow["Go/Hug Build Workflow<br/>GitHub Actions"]
end

node_clients(("HTTP and Proxy Clients<br/>external clients"))
node_reverse_proxy["CDN / Reverse Proxy<br/>external fronting"]
node_nezha_server(("Nezha Server<br/>external monitoring"))

node_package -->|"runs"| node_entry
node_env -.->|"configures"| node_entry
node_clients -->|"requests"| node_reverse_proxy
node_reverse_proxy -->|"forwards"| node_entry
node_clients -.->|"direct access"| node_entry
node_entry -->|"serves HTTP"| node_landing
node_entry -->|"routes HTTP"| node_subscription
node_entry -->|"upgrades"| node_ws
node_ws -->|"byte stream"| node_protocol
node_protocol -->|"validated request"| node_relay
node_relay -->|"outbound TCP"| node_target
node_entry -.->|"optionally starts"| node_nezha
node_nezha -->|"reports to"| node_nezha_server
node_docker -->|"packages"| node_entry
node_image_workflow -->|"builds and delivers"| node_docker
node_golang_workflow -->|"builds image artifacts"| node_docker

click node_package "https://github.com/eooce/node-ws/blob/main/package.json"
click node_entry "https://github.com/eooce/node-ws/blob/main/index.js"
click node_env "https://github.com/eooce/node-ws/blob/main/index.js"
click node_landing "https://github.com/eooce/node-ws/blob/main/index.html"
click node_subscription "https://github.com/eooce/node-ws/blob/main/index.js"
click node_ws "https://github.com/eooce/node-ws/blob/main/index.js"
click node_protocol "https://github.com/eooce/node-ws/blob/main/index.js"
click node_relay "https://github.com/eooce/node-ws/blob/main/index.js"
click node_nezha "https://github.com/eooce/node-ws/blob/main/index.js"
click node_docker "https://github.com/eooce/node-ws/blob/main/Dockerfile"
click node_image_workflow "https://github.com/eooce/node-ws/blob/main/.github/workflows/build-image.yml"
click node_golang_workflow "https://github.com/eooce/node-ws/blob/main/.github/workflows/build-golang-docker-image.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package,node_entry,node_env,node_landing,node_subscription,node_nezha toneBlue
class node_ws,node_protocol,node_relay,node_target toneAmber
class node_docker,node_image_workflow,node_golang_workflow toneMint
class node_clients,node_reverse_proxy,node_nezha_server toneNeutral
```

## Components

### Node Service

- [Package Metadata](https://github.com/eooce/node-ws/blob/main/package.json): Node package · Defines application execution and dependencies. · `package.json`
- [HTTP/WS Server](https://github.com/eooce/node-ws/blob/main/index.js): Node runtime · Starts the shared HTTP and WebSocket listener. · `index.js`
- [Environment Settings](https://github.com/eooce/node-ws/blob/main/index.js): runtime config · PORT, UUID, DOMAIN, SUB_PATH, and AUTO_ACCESS control service behavior. · `index.js`
- [Landing Page](https://github.com/eooce/node-ws/blob/main/index.html): HTTP asset · `index.html`
- [Subscription Endpoint](https://github.com/eooce/node-ws/blob/main/index.js): HTTP route · Publishes node information derived from SUB_PATH and DOMAIN. · `index.js`
- [Embedded Nezha Agent](https://github.com/eooce/node-ws/blob/main/index.js): monitoring integration · Optionally connects using NEZHA_SERVER, NEZHA_PORT, and NEZHA_KEY. · `index.js`

### Traffic Flow

- [WebSocket Upgrade](https://github.com/eooce/node-ws/blob/main/index.js): connection boundary · Accepts proxy streams on the HTTP listener. · `index.js`
- [VLESS / Trojan Parser](https://github.com/eooce/node-ws/blob/main/index.js): protocol stage · Validates incoming authentication and target requests. · `index.js`
- [TCP Relay](https://github.com/eooce/node-ws/blob/main/index.js): proxy transport · Relays bytes bidirectionally after target connection. · `index.js`
- **Requested Target**: external TCP service

### Delivery

- [Container Build](https://github.com/eooce/node-ws/blob/main/Dockerfile): Docker image · `Dockerfile`
- [Image Delivery Workflow](https://github.com/eooce/node-ws/blob/main/.github/workflows/build-image.yml): GitHub Actions · `.github/workflows/build-image.yml`
- [Go/Hug Build Workflow](https://github.com/eooce/node-ws/blob/main/.github/workflows/build-golang-docker-image.yml): GitHub Actions · Builds additional binary and image artifacts. · `.github/workflows/build-golang-docker-image.yml`

### Other components

- **HTTP and Proxy Clients**: external clients
- **CDN / Reverse Proxy**: external fronting
- **Nezha Server**: external monitoring

## Connections

- Package Metadata → HTTP/WS Server: runs
- Environment Settings → HTTP/WS Server: configures
- HTTP and Proxy Clients → CDN / Reverse Proxy: requests
- CDN / Reverse Proxy → HTTP/WS Server: forwards
- HTTP and Proxy Clients → HTTP/WS Server: direct access
- HTTP/WS Server → Landing Page: serves HTTP
- HTTP/WS Server → Subscription Endpoint: routes HTTP
- HTTP/WS Server → WebSocket Upgrade: upgrades
- WebSocket Upgrade → VLESS / Trojan Parser: byte stream
- VLESS / Trojan Parser → TCP Relay: validated request
- TCP Relay → Requested Target: outbound TCP
- HTTP/WS Server → Embedded Nezha Agent: optionally starts
- Embedded Nezha Agent → Nezha Server: reports to
- Container Build → HTTP/WS Server: packages
- Image Delivery Workflow → Container Build: builds and delivers
- Go/Hug Build Workflow → Container Build: builds image artifacts
