Skip to content
fullstackedorgPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

FullStacked Tunnels

FullStacked Tunnels is a token-routed tunnel server that runs as a Hub or an Edge. It connects the FullStacked runtime to backend services (databases, caches, object storage, internal APIs), across the internet or a LAN, without port forwarding, static public IPs, or firewall changes on the private side.

flowchart LR
    subgraph Runtimes["FullStacked Runtimes"]
        Dev1["Laptop"]
        Dev2["Workstation"]
        Dev3["Mobile / CI"]
    end

    Tunnels["Tunnels"]

    subgraph Services["Backend Services"]
        SvcA[("PostgreSQL")]
        SvcB[("Redis")]
        SvcC[("S3 / MinIO")]
    end

    Dev1 -->|"Token A"| Tunnels
    Dev2 -->|"Token B"| Tunnels
    Dev3 -->|"Token C"| Tunnels

    Tunnels -->|"Tunnel A"| SvcA
    Tunnels -->|"Tunnel B"| SvcB
    Tunnels -->|"Tunnel C"| SvcC

    classDef runtime fill:#1f2937,stroke:#3b82f6,stroke-width:2px,color:#fff;
    classDef tunnels fill:#1e1b4b,stroke:#8b5cf6,stroke-width:2px,color:#fff;
    classDef service fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#fff;

    class Dev1,Dev2,Dev3 runtime;
    class Tunnels tunnels;
    class SvcA,SvcB,SvcC service;
Loading

Principles

  • Protocol-agnostic: raw bidirectional byte streams, no payload inspection. Works with PostgreSQL, MySQL/MariaDB, Redis, MongoDB, HTTP/1.1, HTTP/2, gRPC, interactive SSH, and FullStacked P2P control sockets. TCP half-close is not propagated (see Protocol Spec).
  • Resilient: every WebSocket runs a bidirectional heartbeat that keeps it alive through NATs, proxies, and load balancers and detects dead peers. Edges reconnect with exponential backoff and full jitter, and fall back to slow polling only when their credential is revoked.
  • Open by default, for tinkering: no TLS setup, no admin credentials, no identity provider. Anyone can start a Hub on a laptop in seconds. Tokens are bearer secrets and are all a client needs.
  • Secured with hooks: authentication, IP allowlists, signed requests, rate limits, and multi-tenancy are added with hooks. See Extending Security.
  • Un-metered by default: the core counts nothing; telemetry hooks expose the sockets so plugins can meter bytes and time sessions.
  • One codebase, two roles: the same entry point runs a Hub, or an Edge when HUB_URL is set.

Quickstart (Local, Zero Dependencies)

Requires Node.js 24 LTS or newer.

1. Start a Hub

node src/main.ts --port 3000

Filesystem storage in ./data, in-memory KV, plain ws://localhost:3000. Or with the Docker image:

docker run -d -p 3000:3000 -v tunnels-data:/data fullstackedorg/tunnels

2. Register a Tunnel

The Hub generates the token:

curl -X POST http://localhost:3000/tunnels \
  -H "Content-Type: application/json" \
  -d '{ "name": "my-database", "internalHost": "127.0.0.1", "internalPort": 5432 }'

# { "id": "e4b1b36e-...", "token": "tun_4f8a9e2d1c3b...", "name": "my-database",
#   "internalHost": "127.0.0.1", "internalPort": 5432, "edgeId": null, "metadata": {} }

3. Connect from the FullStacked Runtime

tunnel.register takes the Hub's address (host, plus port and unsecure when it is not wss:// on 443) and the tunnel token, and returns a virtual host for native drivers. The runtime keeps a small pool of tunnel sessions (WebSockets) to the Hub and carries every driver connection to that host as a stream on one of them, so pools work unchanged. The Hub always connects to the tunnel's internalHost:internalPort; the port configured in the driver does not affect routing.

import tunnel from "fullstacked/tunnel";
import pg from "pg";

const host = await tunnel.register({
    host: "localhost",
    port: 3000,
    unsecure: true, // plain ws:// to a local Hub
    authorization: "tun_4f8a9e2d1c3b...",
});

const client = new pg.Client({ host, port: 5432, user: "postgres" });
await client.connect();

Note

Standard browser WebSockets cannot pass custom handshake headers like Authorization per the WHATWG WebSocket API specification, meaning direct browser WebSockets connecting to Hub tunnel endpoints are rejected with 401 Unauthorized.

In the FullStacked runtime, window.WebSocket is overridden by FullStacked's WebSocketCore. Calling tunnel.register returns a generated string (or you can supply a custom name). When you create your WebSocket using that name:

const tunnelName = await tunnel.register({ host, authorization });
const tunneledWS = new window.WebSocket("ws://" + tunnelName);

FullStacked's WebSocketCore will use tunnels with the registered authorization credentials.


Reaching Private Networks with an Edge

# 1. Register an Edge (the Hub generates its token)
curl -X POST http://localhost:3000/edges \
  -H "Content-Type: application/json" \
  -d '{ "name": "home-lab" }'
# { "id": "a1c2e3d4-...", "token": "edg_a1c2e3d4...", "name": "home-lab", ... }

# 2. Register a tunnel bound to that Edge
curl -X POST http://localhost:3000/tunnels \
  -H "Content-Type: application/json" \
  -d '{ "name": "home-postgres", "internalHost": "192.168.1.50", "internalPort": 5432, "edgeId": "a1c2e3d4-..." }'

# 3. Start the Edge inside the private network (outbound connection only)
HUB_URL="wss://tunnels.example.com" TOKEN="edg_a1c2e3d4..." node src/main.ts

A Hub reachable from the internet must sit behind a TLS-terminating reverse proxy; see Deployment Requirement: TLS.


Documentation

Section Document Description
Concepts Glossary Definitions of every term used in these docs.
Architecture Topology, direct and relayed sequences, trust boundaries.
Internals Components and runtime profiles.
Protocol Spec Handshake, rejection statuses, lifeline orders, heartbeat, timeouts, close codes and reasons.
Nodes Configuration Every setting, valid dependency combinations, TLS requirement.
Hub Running the Hub, schema initialization, shutdown.
Edge Running the Edge, reconnection, revocation, splicing, multi-worker mode.
Subsystems HTTP Server Ingress routing, req.deny(), client IP resolution.
WebSocket Server Handshake, duplex adapter, heartbeat sweep.
Tunnel Handler Session lifecycle, splicing, session registry and revocation.
Warden Lifelines, presence, relay sessions, orders, clustered socket moves.
REST API Endpoints, validation, pagination, operation pipelines, token rolling.
Entity Schemas Edge and Tunnel, tokens, token resolution cache.
Storage Layer Filesystem and PostgreSQL providers.
KV Store Memory and Redis providers, key registry.
Logger Levels, text/JSON output, breadcrumbs, log hook.
Extensibility Hooks Catalog Every hook, execution model, plugin loading.
Extending Security Admin key, IP allowlist, signed requests, rate limits, tenancy, target restrictions.
Extending Monitoring Prometheus metrics, access logs, alerts.
Development Standards & Style Formatting (Prettier, 4 spaces), 300 LOC limit, file naming logic, Node 24+ type stripping.
Workflow & Tooling Docs-as-Code & TDD lifecycle, direct Node 24+ execution, package scripts, test runner, quality gates.
Cookbook Examples PostgreSQL, Redis, MySQL, S3, HTTP, Edge, and plugin examples.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages