# rrqm/touchsocket architecture

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

- Interactive diagram: https://gitdiagram.com/rrqm/touchsocket
- Repository: https://github.com/rrqm/touchsocket

## Overview

TouchSocket is a .NET networking framework for building clients, servers, protocol gateways, and RPC/MCP applications. A typical TCP workflow starts with an application configuring a client or service, establishes a connection, receives and frames data through an adapter, and dispatches lifecycle or receive events through plugins. The framework also provides HTTP/WebSocket, messaging and industrial protocols, RPC, memory and serialization primitives, and hosting/DI integrations. The graph preserves these documented capability branches; several are represented at subsystem level because their implementation was not sampled.

Main entry points: [`src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs`](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs) (TCP sessions), [`src/TouchSocket.Core/Plugins/PluginManager.cs`](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Plugins/PluginManager.cs) (Plugin dispatch), [`src/TouchSocket.Core/BytesPool`](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/BytesPool) (Memory and bytes), [`src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs`](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs) (HTTP and WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_transport["Networking transports"]
  node_tcp["TCP sessions"]
  node_namedpipe["Named pipes"]
  node_serial["Serial ports"]
  node_aspnet["ASP.NET integration"]
end

subgraph group_protocols["Protocols and APIs"]
  node_http["HTTP and WebSocket"]
  node_mqtt["MQTT"]
  node_coap["CoAP<br/>[Components]"]
  node_modbus["Modbus<br/>[Handlers]"]
  node_semi["HSMS / SECS"]
  node_socketio["Socket.IO"]
  node_rpc["RPC<br/>[TouchSocket.Rpc]"]
  node_dmtp["DMTP<br/>[TouchSocket.Dmtp]"]
  node_webapi["Web API<br/>[TouchSocket.WebApi]"]
  node_mcp["MCP<br/>[TouchSocket.Mcp]"]
  node_redis["Redis<br/>[TouchSocket.Redis]"]
end

subgraph group_core["Core runtime"]
  node_adapters["Data adapters<br/>[DataAdapter]"]
  node_memory["Memory and bytes<br/>[BytesPool]"]
  node_config["Configuration and DI"]
  node_plugins["Plugin dispatch<br/>[PluginManager.cs]"]
  node_logging["Logging<br/>[ILog.cs]"]
  node_serialization["Serialization<br/>[Serialization]"]
  node_generators["Source generators"]
end

subgraph group_integration["Hosting and extensions"]
  node_hosting["Generic hosting"]
end

node_app(("Application"))

node_app -->|"configures and connects"| node_tcp
node_tcp -.->|"frames received data"| node_adapters
node_tcp -->|"raises lifecycle events"| node_plugins
node_app -->|"uses unified API"| node_namedpipe
node_app -->|"uses unified API"| node_serial
node_app -->|"uses protocol API"| node_http
node_app -->|"uses protocol API"| node_mqtt
node_app -->|"uses protocol API"| node_coap
node_app -->|"uses protocol API"| node_modbus
node_app -->|"uses protocol API"| node_semi
node_app -->|"uses protocol API"| node_socketio
node_app -->|"registers and invokes"| node_rpc
node_app -->|"uses protocol API"| node_dmtp
node_app -->|"uses server and client"| node_webapi
node_app -->|"uses server or client"| node_mcp
node_app -->|"uses client or server"| node_redis
node_app -->|"configures services"| node_config
node_app -->|"hosts services"| node_hosting
node_app -->|"uses generated code"| node_generators
node_adapters -.->|"uses pooled buffers"| node_memory
node_http -->|"writes framed bytes"| node_memory
node_config -.->|"configures plugins"| node_plugins
node_plugins -.->|"logs events"| node_logging
node_serialization -.->|"serializes to bytes"| node_memory
node_aspnet -->|"hosts WebSocket DMTP"| node_dmtp

click node_tcp "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs"
click node_namedpipe "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.NamedPipe/Components/NamedPipeSessionClientBase.cs"
click node_serial "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.SerialPorts/Components/SerialPortClientBase.cs"
click node_aspnet "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.AspNetCore"
click node_http "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs"
click node_mqtt "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Mqtt/Components/WebSocket/MqttWebSocketSessionClient.cs"
click node_coap "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.CoAP/Components"
click node_modbus "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Modbus/Handlers"
click node_semi "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Semi/Components/HsmsSessionClient.cs"
click node_socketio "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.SocketIo"
click node_rpc "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Rpc"
click node_dmtp "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Dmtp"
click node_webapi "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.WebApi"
click node_mcp "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Mcp"
click node_adapters "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/DataAdapter"
click node_memory "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/BytesPool"
click node_config "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Config/TouchSocketConfig.cs"
click node_plugins "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Plugins/PluginManager.cs"
click node_logging "https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Logger/ILog.cs"
click node_serialization "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/Serialization"
click node_generators "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core.SourceGenerator"
click node_hosting "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Hosting"
click node_redis "https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Redis"

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_tcp,node_namedpipe,node_serial,node_aspnet toneBlue
class node_http,node_mqtt,node_coap,node_modbus,node_semi,node_socketio,node_rpc,node_dmtp,node_webapi,node_mcp,node_redis toneAmber
class node_adapters,node_memory,node_config,node_plugins,node_logging,node_serialization,node_generators toneMint
class node_hosting toneRose
class node_app toneIndigo
```

## Components

### Networking transports

- [TCP sessions](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs): `src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs`
- [Named pipes](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.NamedPipe/Components/NamedPipeSessionClientBase.cs): `src/TouchSocket.NamedPipe/Components/NamedPipeSessionClientBase.cs`
- [Serial ports](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.SerialPorts/Components/SerialPortClientBase.cs): `src/TouchSocket.SerialPorts/Components/SerialPortClientBase.cs`
- [ASP.NET integration](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.AspNetCore): `src/TouchSocket.AspNetCore`

### Protocols and APIs

- [HTTP and WebSocket](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs): `src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs`
- [MQTT](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Mqtt/Components/WebSocket/MqttWebSocketSessionClient.cs): `src/TouchSocket.Mqtt/Components/WebSocket/MqttWebSocketSessionClient.cs`
- [CoAP](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.CoAP/Components): `src/TouchSocket.CoAP/Components`
- [Modbus](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Modbus/Handlers): `src/TouchSocket.Modbus/Handlers`
- [HSMS / SECS](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Semi/Components/HsmsSessionClient.cs): `src/TouchSocket.Semi/Components/HsmsSessionClient.cs`
- [Socket.IO](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.SocketIo): `src/TouchSocket.SocketIo`
- [RPC](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Rpc): `src/TouchSocket.Rpc`
- [DMTP](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Dmtp): `src/TouchSocket.Dmtp`
- [Web API](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.WebApi): `src/TouchSocket.WebApi`
- [MCP](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Mcp): `src/TouchSocket.Mcp`
- [Redis](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Redis): `src/TouchSocket.Redis`

### Core runtime

- [Data adapters](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/DataAdapter): `src/TouchSocket.Core/DataAdapter`
- [Memory and bytes](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/BytesPool): `src/TouchSocket.Core/BytesPool`
- [Configuration and DI](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Config/TouchSocketConfig.cs): `src/TouchSocket.Core/Config/TouchSocketConfig.cs`
- [Plugin dispatch](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Plugins/PluginManager.cs): `src/TouchSocket.Core/Plugins/PluginManager.cs`
- [Logging](https://github.com/rrqm/touchsocket/blob/master/src/TouchSocket.Core/Logger/ILog.cs): `src/TouchSocket.Core/Logger/ILog.cs`
- [Serialization](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core/Serialization): `src/TouchSocket.Core/Serialization`
- [Source generators](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Core.SourceGenerator): `src/TouchSocket.Core.SourceGenerator`

### Hosting and extensions

- [Generic hosting](https://github.com/rrqm/touchsocket/tree/master/src/TouchSocket.Hosting): `src/TouchSocket.Hosting`

### Other components

- **Application**

## Connections

- Application → TCP sessions: configures and connects (evidence: `README.md`)
- TCP sessions → Data adapters: frames received data (evidence: `src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs`)
- TCP sessions → Plugin dispatch: raises lifecycle events (evidence: `src/TouchSocket/Components/Tcp/TcpSessionClientBase.cs`)
- Application → Named pipes: uses unified API (evidence: `README.md`)
- Application → Serial ports: uses unified API (evidence: `README.md`)
- Application → HTTP and WebSocket: uses protocol API (evidence: `README.md`)
- Application → MQTT: uses protocol API (evidence: `README.md`)
- Application → CoAP: uses protocol API (evidence: `README.md`)
- Application → Modbus: uses protocol API (evidence: `README.md`)
- Application → HSMS / SECS: uses protocol API (evidence: `README.md`)
- Application → Socket.IO: uses protocol API (evidence: `README.md`)
- Application → RPC: registers and invokes (evidence: `README.md`)
- Application → DMTP: uses protocol API (evidence: `README.md`)
- Application → Web API: uses server and client (evidence: `README.md`)
- Application → MCP: uses server or client (evidence: `README.md`)
- Application → Redis: uses client or server (evidence: `README.md`)
- Application → Configuration and DI: configures services (evidence: `README.md`)
- Application → Generic hosting: hosts services (evidence: `README.md`)
- Application → Source generators: uses generated code (evidence: `README.md`)
- Data adapters → Memory and bytes: uses pooled buffers
- HTTP and WebSocket → Memory and bytes: writes framed bytes (evidence: `src/TouchSocket.Http/Components/HttpSessionClient.Http2.cs`)
- Configuration and DI → Plugin dispatch: configures plugins
- Plugin dispatch → Logging: logs events
- Serialization → Memory and bytes: serializes to bytes
- ASP.NET integration → DMTP: hosts WebSocket DMTP (evidence: `src/TouchSocket.AspNetCore/Dmtp/Components/WebSocketDmtpSessionClient.cs`)
