# anytls/anytls-go architecture

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

- Interactive diagram: https://gitdiagram.com/anytls/anytls-go
- Repository: https://github.com/anytls/anytls-go

## Overview

AnyTLS is a Go reference implementation of a TLS-wrapped proxy protocol. The documented client workflow accepts local proxy connections, opens or reuses an AnyTLS session, and carries destination streams to a server; the server authenticates the initial exchange and routes streams to TCP or UDP-over-TCP handling. The graph preserves padding negotiation and TLS setup as distinct capabilities. Some handlers and outbound implementations are represented from the tree and README, but their internal wiring is omitted where the supplied excerpts do not establish it.

Main entry points: [`cmd/client/main.go`](https://github.com/anytls/anytls-go/blob/main/cmd/client/main.go) (Client entry and URI), [`proxy/session/session.go`](https://github.com/anytls/anytls-go/blob/main/proxy/session/session.go) (Session framing and dispatch), [`cmd/server/main.go`](https://github.com/anytls/anytls-go/blob/main/cmd/server/main.go) (Server entry), [`cmd/client/myclient.go`](https://github.com/anytls/anytls-go/blob/main/cmd/client/myclient.go) (Proxy stream adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Example client"]
  node_client_entry["Client entry and URI<br/>[main.go]"]
  node_client_listener["Local proxy listener<br/>[inbound.go]"]
  node_client_adapter["Proxy stream adapter<br/>[myclient.go]"]
  node_client_tls["TLS client transport<br/>[main.go]"]
end

subgraph group_server["Example server"]
  node_server_entry["Server entry<br/>[main.go]"]
  node_server_tls["TLS certificate setup<br/>[mkcert.go]"]
  node_server_ingress["TLS and authentication<br/>[inbound_tcp.go]"]
  node_server_adapter["Server configuration<br/>[myserver.go]"]
  node_destination_route["Destination routing<br/>[inbound_tcp.go]"]
  node_tcp_outbound["TCP outbound<br/>[outbound_tcp.go]"]
end

subgraph group_protocol["AnyTLS protocol"]
  node_session_pool["Client session pool<br/>[client.go]"]
  node_session_core["Session framing and dispatch<br/>[session.go]"]
  node_stream["Multiplexed streams<br/>[stream.go]"]
  node_frames["Frame encoding<br/>[frame.go]"]
end

subgraph group_support["Protocol support"]
  node_system_dialer["System dialer<br/>[system_dialer.go]"]
  node_padding_policy["Padding policy<br/>[padding.go]"]
  node_settings_map["Settings encoding<br/>[string_map.go]"]
  node_pipe["Synchronous pipe<br/>[io_pipe.go]"]
  node_pipe_deadline["Pipe deadlines<br/>[deadline.go]"]
end

node_user(("Local proxy user"))
node_network(("Destination services"))

node_user -->|"configures"| node_client_entry
node_client_entry -->|"accepts through"| node_client_listener
node_client_entry -->|"creates"| node_client_adapter
node_client_entry -->|"dials via"| node_system_dialer
node_client_entry -->|"wraps connection"| node_client_tls
node_client_adapter -->|"creates and opens"| node_session_pool
node_client_adapter -->|"writes destination"| node_session_pool
node_session_pool -->|"creates sessions"| node_session_core
node_session_core -->|"creates and dispatches"| node_stream
node_server_entry -->|"handles connections"| node_server_ingress
node_server_entry -->|"configures"| node_server_adapter
node_server_entry -->|"generates certificate"| node_server_tls
node_server_entry -->|"loads scheme"| node_padding_policy
node_server_ingress -->|"starts session"| node_session_core
node_server_ingress -->|"routes streams"| node_destination_route
node_destination_route -->|"dispatches TCP"| node_tcp_outbound
node_destination_route -.->|"dispatches UDP-over-TCP"| node_network
node_session_core -->|"generates padding"| node_padding_policy
node_session_core -->|"parses settings"| node_settings_map
node_stream -.->|"uses frame protocol"| node_frames
node_pipe -->|"uses deadlines"| node_pipe_deadline

click node_client_entry "https://github.com/anytls/anytls-go/blob/main/cmd/client/main.go"
click node_client_listener "https://github.com/anytls/anytls-go/blob/main/cmd/client/inbound.go"
click node_client_adapter "https://github.com/anytls/anytls-go/blob/main/cmd/client/myclient.go"
click node_session_pool "https://github.com/anytls/anytls-go/blob/main/proxy/session/client.go"
click node_session_core "https://github.com/anytls/anytls-go/blob/main/proxy/session/session.go"
click node_stream "https://github.com/anytls/anytls-go/blob/main/proxy/session/stream.go"
click node_frames "https://github.com/anytls/anytls-go/blob/main/proxy/session/frame.go"
click node_client_tls "https://github.com/anytls/anytls-go/blob/main/cmd/client/main.go"
click node_system_dialer "https://github.com/anytls/anytls-go/blob/main/proxy/system_dialer.go"
click node_server_entry "https://github.com/anytls/anytls-go/blob/main/cmd/server/main.go"
click node_server_tls "https://github.com/anytls/anytls-go/blob/main/util/mkcert.go"
click node_server_ingress "https://github.com/anytls/anytls-go/blob/main/cmd/server/inbound_tcp.go"
click node_server_adapter "https://github.com/anytls/anytls-go/blob/main/cmd/server/myserver.go"
click node_destination_route "https://github.com/anytls/anytls-go/blob/main/cmd/server/inbound_tcp.go"
click node_tcp_outbound "https://github.com/anytls/anytls-go/blob/main/cmd/server/outbound_tcp.go"
click node_padding_policy "https://github.com/anytls/anytls-go/blob/main/proxy/padding/padding.go"
click node_settings_map "https://github.com/anytls/anytls-go/blob/main/util/string_map.go"
click node_pipe "https://github.com/anytls/anytls-go/blob/main/proxy/pipe/io_pipe.go"
click node_pipe_deadline "https://github.com/anytls/anytls-go/blob/main/proxy/pipe/deadline.go"

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_client_entry,node_client_listener,node_client_adapter,node_client_tls,node_user toneBlue
class node_server_entry,node_server_tls,node_server_ingress,node_server_adapter,node_destination_route,node_tcp_outbound toneAmber
class node_session_pool,node_session_core,node_stream,node_frames toneMint
class node_system_dialer,node_padding_policy,node_settings_map,node_pipe,node_pipe_deadline toneRose
class node_network toneIndigo
```

## Components

### Example client

- [Client entry and URI](https://github.com/anytls/anytls-go/blob/main/cmd/client/main.go): `cmd/client/main.go`
- [Local proxy listener](https://github.com/anytls/anytls-go/blob/main/cmd/client/inbound.go): `cmd/client/inbound.go`
- [Proxy stream adapter](https://github.com/anytls/anytls-go/blob/main/cmd/client/myclient.go): `cmd/client/myclient.go`
- [TLS client transport](https://github.com/anytls/anytls-go/blob/main/cmd/client/main.go): `cmd/client/main.go`

### Example server

- [Server entry](https://github.com/anytls/anytls-go/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [TLS certificate setup](https://github.com/anytls/anytls-go/blob/main/util/mkcert.go): `util/mkcert.go`
- [TLS and authentication](https://github.com/anytls/anytls-go/blob/main/cmd/server/inbound_tcp.go): `cmd/server/inbound_tcp.go`
- [Server configuration](https://github.com/anytls/anytls-go/blob/main/cmd/server/myserver.go): `cmd/server/myserver.go`
- [Destination routing](https://github.com/anytls/anytls-go/blob/main/cmd/server/inbound_tcp.go): `cmd/server/inbound_tcp.go`
- [TCP outbound](https://github.com/anytls/anytls-go/blob/main/cmd/server/outbound_tcp.go): `cmd/server/outbound_tcp.go`

### AnyTLS protocol

- [Client session pool](https://github.com/anytls/anytls-go/blob/main/proxy/session/client.go): `proxy/session/client.go`
- [Session framing and dispatch](https://github.com/anytls/anytls-go/blob/main/proxy/session/session.go): `proxy/session/session.go`
- [Multiplexed streams](https://github.com/anytls/anytls-go/blob/main/proxy/session/stream.go): `proxy/session/stream.go`
- [Frame encoding](https://github.com/anytls/anytls-go/blob/main/proxy/session/frame.go): `proxy/session/frame.go`

### Protocol support

- [System dialer](https://github.com/anytls/anytls-go/blob/main/proxy/system_dialer.go): `proxy/system_dialer.go`
- [Padding policy](https://github.com/anytls/anytls-go/blob/main/proxy/padding/padding.go): `proxy/padding/padding.go`
- [Settings encoding](https://github.com/anytls/anytls-go/blob/main/util/string_map.go): `util/string_map.go`
- [Synchronous pipe](https://github.com/anytls/anytls-go/blob/main/proxy/pipe/io_pipe.go): `proxy/pipe/io_pipe.go`
- [Pipe deadlines](https://github.com/anytls/anytls-go/blob/main/proxy/pipe/deadline.go): `proxy/pipe/deadline.go`

### Other components

- **Local proxy user**
- **Destination services**

## Connections

- Local proxy user → Client entry and URI: configures (evidence: `readme.md`)
- Client entry and URI → Local proxy listener: accepts through (evidence: `cmd/client/main.go`)
- Client entry and URI → Proxy stream adapter: creates (evidence: `cmd/client/main.go`)
- Client entry and URI → System dialer: dials via (evidence: `cmd/client/main.go`)
- Client entry and URI → TLS client transport: wraps connection (evidence: `cmd/client/main.go`)
- Proxy stream adapter → Client session pool: creates and opens (evidence: `cmd/client/myclient.go`)
- Proxy stream adapter → Client session pool: writes destination (evidence: `cmd/client/myclient.go`)
- Client session pool → Session framing and dispatch: creates sessions (evidence: `proxy/session/client.go`)
- Session framing and dispatch → Multiplexed streams: creates and dispatches (evidence: `proxy/session/session.go`)
- Server entry → TLS and authentication: handles connections (evidence: `cmd/server/main.go`)
- Server entry → Server configuration: configures (evidence: `cmd/server/main.go`)
- Server entry → TLS certificate setup: generates certificate (evidence: `cmd/server/main.go`)
- Server entry → Padding policy: loads scheme (evidence: `cmd/server/main.go`)
- TLS and authentication → Session framing and dispatch: starts session (evidence: `cmd/server/inbound_tcp.go`)
- TLS and authentication → Destination routing: routes streams (evidence: `cmd/server/inbound_tcp.go`)
- Destination routing → TCP outbound: dispatches TCP (evidence: `cmd/server/inbound_tcp.go`)
- Destination routing → Destination services: dispatches UDP-over-TCP (evidence: `cmd/server/inbound_tcp.go`)
- Session framing and dispatch → Padding policy: generates padding (evidence: `proxy/session/session.go`)
- Session framing and dispatch → Settings encoding: parses settings (evidence: `proxy/session/session.go`)
- Multiplexed streams → Frame encoding: uses frame protocol
- Synchronous pipe → Pipe deadlines: uses deadlines (evidence: `proxy/pipe/io_pipe.go`)
