# rms1000watt/tcp-over-http architecture

> Architecture diagram of the GitHub repository rms1000watt/tcp-over-http, 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/rms1000watt/tcp-over-http
- Repository: https://github.com/rms1000watt/tcp-over-http

## Overview

##### Project Overview and Identification
- The project is a network utility to tunnel TCP traffic over HTTP, useful when typical TCP connections are blocked.
- It comprises two main components: a client and a server, each represented by client.ts and server.ts respectively.
- It involves external components (for testing) like a Dockerized TCP echo server or an OpenSSH server container.

##### Primary Components
a. Client Component:
- Represented by client.ts.
- Initiates and manages the TCP-over-HTTP tunneling process.
- Acts as a bridge between your local TCP application (e.g., telnet or ssh) and the HTTP connection.
b. Server Component:
- Represented by server.ts.
- Runs on the remote side of the tunnel (possibly behind a corporate proxy or API gateway).
- Receives requests forwarded over HTTP and translates them back to TCP traffic.
c. External Services / Endpoints:
- A TCP Echo/SSH server running in Docker (as indicated by the examples in the README), which is the ultimate TCP endpoint.
- Possibly an HTTP proxy or API gateway that allows only HTTP(S) traffic. (This is implied as the reason for tunneling.)

##### Architectural Relationships and Data Flow
- The Client triggers a TCP connection from a local terminal (telnet/ssh request).
- The Client encapsulates TCP data within HTTP requests.
- These HTTP requests traverse through the corporate proxy/API gateway.
- The Server decapsulates the HTTP requests back into TCP traffic and forwards the traffic to the actual TCP service (like the echo server or ssh server running in Docker).
- For responses, the reverse process occurs where the server re-encapsulates the TCP data in an HTTP response before sending it back to the client.

##### Architectural Patterns and Key Technologies
- Even though it’s a small project, it follows a client-server pattern, with clearly demarcated roles.
- That data encapsulation/decapsulation is a core pattern here.
- Technologies or frameworks involved include Node.js (with TypeScript execution via tsx) and Docker, which runs the testing environments (echo server and OpenSSH server).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        A["Local TCP App (telnet/ssh)"]:::local
        B["TCP Over HTTP Client"]:::client
    end

    %% Network Layer
    subgraph "Network Layer"
        C["HTTP Proxy/API Gateway"]:::proxy
    end

    %% Server Side
    subgraph "Server Side"
        D["TCP Over HTTP Server"]:::server
        E["Dockerized TCP Echo Server / OpenSSH Server"]:::external
    end

    %% Data Flow Arrows
    A -->|"encapsulate_TCP"| B
    B -->|"send_HTTP_req"| C
    C -->|"forward_req"| D
    D -->|"forward_TCP"| E
    E -->|"response_TCP"| D
    D -->|"HTTP_response"| C
    C -->|"relay_response"| B
    B -->|"deliver_TCP"| A

    %% Click Events
    click B "https://github.com/rms1000watt/tcp-over-http/blob/main/client.ts"
    click D "https://github.com/rms1000watt/tcp-over-http/blob/main/server.ts"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef server fill:#F08080,stroke:#000,stroke-width:2px;
    classDef proxy fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef local fill:#FFD700,stroke:#000,stroke-width:2px;
```
