# xinhai12310/muduo architecture

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

- Interactive diagram: https://gitdiagram.com/xinhai12310/muduo
- Repository: https://github.com/xinhai12310/muduo

## Overview

Muduo is a multithreaded C++ networking library built around a reactor. Its core workflow is to accept or initiate TCP connections, process I/O through event loops, and expose callbacks and buffers to application protocols. Major branches include HTTP and inspection, protobuf RPC, and optional Thrift and Redis integrations. The graph also shows the base logging and threading layer. Some runtime wiring is based on explicit README or source-index references; where the excerpts do not establish a call, the edge is omitted or marked unverified.

Main entry points: [`muduo/net/TcpClient.cc`](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpClient.cc) (TCP client), [`muduo/net/EventLoop.cc`](https://github.com/xinhai12310/muduo/blob/master/muduo/net/EventLoop.cc) (Event loop), [`muduo/net/TcpConnection.cc`](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpConnection.cc) (TCP connection), [`muduo/net/inspect/Inspector.cc`](https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/Inspector.cc) (Inspector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Reactor and TCP"]
  node_tcp_client["TCP client<br/>[TcpClient.cc]"]
  node_connector["Connection dialer<br/>[Connector.cc]"]
  node_tcp_server["TCP server<br/>[TcpServer.h]"]
  node_tcp_connection["TCP connection<br/>[TcpConnection.cc]"]
  node_event_loop["Event loop<br/>[EventLoop.cc]"]
  node_channel["I/O channel<br/>[Channel.cc]"]
  node_poller["Poller<br/>[EPollPoller.cc]"]
  node_buffer["Network buffer<br/>[Buffer.cc]"]
  node_timers["Timer queue<br/>[TimerQueue.cc]"]
end

subgraph group_protocols["Protocols and RPC"]
  node_http_context["HTTP parser<br/>[HttpContext.cc]"]
  node_http_request["HTTP request<br/>[HttpRequest.h]"]
  node_http_response["HTTP response<br/>[HttpResponse.cc]"]
  node_http_server["HTTP server<br/>[HttpServer.cc]"]
  node_inspector["Inspector<br/>[Inspector.cc]"]
  node_process_inspector["Process inspector"]
  node_performance_inspector["Performance inspector"]
  node_system_inspector["System inspector<br/>[SystemInspector.cc]"]
  node_protobuf_codec["Protobuf codec"]
  node_rpc_channel["RPC channel<br/>[RpcChannel.cc]"]
  node_rpc_server["RPC server<br/>[RpcServer.cc]"]
end

subgraph group_integrations["External Integrations"]
  node_thrift_server["Thrift server<br/>[ThriftServer.h]"]
  node_thrift_connection["Thrift connection"]
  node_hiredis_client["Redis client<br/>[Hiredis.cc]"]
end

subgraph group_base["Base Utilities"]
  node_logging["Logging<br/>[Logging.h]"]
  node_log_stream["Log stream<br/>[LogStream.cc]"]
  node_thread_pool["Thread pool<br/>[ThreadPool.cc]"]
end

node_application(("Application"))
node_redis[("Redis service")]

node_application -.->|"initiates connection"| node_tcp_client
node_application -.->|"serves TCP"| node_tcp_server
node_tcp_client -->|"creates"| node_connector
node_tcp_client -->|"schedules callbacks"| node_event_loop
node_tcp_client -->|"creates"| node_tcp_connection
node_event_loop -.->|"dispatches I/O"| node_channel
node_poller -->|"polls channels"| node_channel
node_tcp_connection -->|"uses"| node_buffer
node_event_loop -.->|"schedules timers"| node_timers
node_http_context -->|"parses from"| node_buffer
node_http_context -->|"populates"| node_http_request
node_http_server -.->|"parses requests"| node_http_context
node_http_server -.->|"sends responses"| node_http_response
node_inspector -->|"delegates to"| node_process_inspector
node_inspector -->|"delegates to"| node_performance_inspector
node_inspector -->|"delegates to"| node_system_inspector
node_protobuf_codec -->|"encodes messages on"| node_tcp_connection
node_rpc_channel -.->|"uses codec"| node_protobuf_codec
node_thrift_server -->|"wraps"| node_tcp_server
node_thrift_connection -->|"processes frames from"| node_tcp_connection
node_thrift_connection -->|"uses server"| node_thrift_server
node_hiredis_client -->|"integrates with"| node_event_loop
node_hiredis_client -->|"registers I/O"| node_channel
node_hiredis_client -.->|"issues commands"| node_redis
node_logging -->|"formats through"| node_log_stream
node_thrift_server -.->|"uses workers"| node_thread_pool

click node_tcp_client "https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpClient.cc"
click node_connector "https://github.com/xinhai12310/muduo/blob/master/muduo/net/Connector.cc"
click node_tcp_server "https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpServer.h"
click node_tcp_connection "https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpConnection.cc"
click node_event_loop "https://github.com/xinhai12310/muduo/blob/master/muduo/net/EventLoop.cc"
click node_channel "https://github.com/xinhai12310/muduo/blob/master/muduo/net/Channel.cc"
click node_poller "https://github.com/xinhai12310/muduo/blob/master/muduo/net/poller/EPollPoller.cc"
click node_buffer "https://github.com/xinhai12310/muduo/blob/master/muduo/net/Buffer.cc"
click node_timers "https://github.com/xinhai12310/muduo/blob/master/muduo/net/TimerQueue.cc"
click node_http_context "https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpContext.cc"
click node_http_request "https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpRequest.h"
click node_http_response "https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpResponse.cc"
click node_http_server "https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpServer.cc"
click node_inspector "https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/Inspector.cc"
click node_process_inspector "https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/ProcessInspector.cc"
click node_performance_inspector "https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/PerformanceInspector.cc"
click node_system_inspector "https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/SystemInspector.cc"
click node_protobuf_codec "https://github.com/xinhai12310/muduo/blob/master/muduo/net/protobuf/ProtobufCodecLite.cc"
click node_rpc_channel "https://github.com/xinhai12310/muduo/blob/master/muduo/net/protorpc/RpcChannel.cc"
click node_rpc_server "https://github.com/xinhai12310/muduo/blob/master/muduo/net/protorpc/RpcServer.cc"
click node_thrift_server "https://github.com/xinhai12310/muduo/blob/master/contrib/thrift/ThriftServer.h"
click node_thrift_connection "https://github.com/xinhai12310/muduo/blob/master/contrib/thrift/ThriftConnection.cc"
click node_hiredis_client "https://github.com/xinhai12310/muduo/blob/master/contrib/hiredis/Hiredis.cc"
click node_logging "https://github.com/xinhai12310/muduo/blob/master/muduo/base/Logging.h"
click node_log_stream "https://github.com/xinhai12310/muduo/blob/master/muduo/base/LogStream.cc"
click node_thread_pool "https://github.com/xinhai12310/muduo/blob/master/muduo/base/ThreadPool.cc"

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_client,node_connector,node_tcp_server,node_tcp_connection,node_event_loop,node_channel,node_poller,node_buffer,node_timers toneBlue
class node_http_context,node_http_request,node_http_response,node_http_server,node_inspector,node_process_inspector,node_performance_inspector,node_system_inspector,node_protobuf_codec,node_rpc_channel,node_rpc_server,node_redis toneAmber
class node_thrift_server,node_thrift_connection,node_hiredis_client toneMint
class node_logging,node_log_stream,node_thread_pool toneRose
class node_application toneIndigo
```

## Components

### Reactor and TCP

- [TCP client](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpClient.cc): `muduo/net/TcpClient.cc`
- [Connection dialer](https://github.com/xinhai12310/muduo/blob/master/muduo/net/Connector.cc): `muduo/net/Connector.cc`
- [TCP server](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpServer.h): `muduo/net/TcpServer.h`
- [TCP connection](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TcpConnection.cc): `muduo/net/TcpConnection.cc`
- [Event loop](https://github.com/xinhai12310/muduo/blob/master/muduo/net/EventLoop.cc): `muduo/net/EventLoop.cc`
- [I/O channel](https://github.com/xinhai12310/muduo/blob/master/muduo/net/Channel.cc): `muduo/net/Channel.cc`
- [Poller](https://github.com/xinhai12310/muduo/blob/master/muduo/net/poller/EPollPoller.cc): `muduo/net/poller/EPollPoller.cc`
- [Network buffer](https://github.com/xinhai12310/muduo/blob/master/muduo/net/Buffer.cc): `muduo/net/Buffer.cc`
- [Timer queue](https://github.com/xinhai12310/muduo/blob/master/muduo/net/TimerQueue.cc): `muduo/net/TimerQueue.cc`

### Protocols and RPC

- [HTTP parser](https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpContext.cc): `muduo/net/http/HttpContext.cc`
- [HTTP request](https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpRequest.h): `muduo/net/http/HttpRequest.h`
- [HTTP response](https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpResponse.cc): `muduo/net/http/HttpResponse.cc`
- [HTTP server](https://github.com/xinhai12310/muduo/blob/master/muduo/net/http/HttpServer.cc): `muduo/net/http/HttpServer.cc`
- [Inspector](https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/Inspector.cc): `muduo/net/inspect/Inspector.cc`
- [Process inspector](https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/ProcessInspector.cc): `muduo/net/inspect/ProcessInspector.cc`
- [Performance inspector](https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/PerformanceInspector.cc): `muduo/net/inspect/PerformanceInspector.cc`
- [System inspector](https://github.com/xinhai12310/muduo/blob/master/muduo/net/inspect/SystemInspector.cc): `muduo/net/inspect/SystemInspector.cc`
- [Protobuf codec](https://github.com/xinhai12310/muduo/blob/master/muduo/net/protobuf/ProtobufCodecLite.cc): `muduo/net/protobuf/ProtobufCodecLite.cc`
- [RPC channel](https://github.com/xinhai12310/muduo/blob/master/muduo/net/protorpc/RpcChannel.cc): `muduo/net/protorpc/RpcChannel.cc`
- [RPC server](https://github.com/xinhai12310/muduo/blob/master/muduo/net/protorpc/RpcServer.cc): `muduo/net/protorpc/RpcServer.cc`

### External Integrations

- [Thrift server](https://github.com/xinhai12310/muduo/blob/master/contrib/thrift/ThriftServer.h): `contrib/thrift/ThriftServer.h`
- [Thrift connection](https://github.com/xinhai12310/muduo/blob/master/contrib/thrift/ThriftConnection.cc): `contrib/thrift/ThriftConnection.cc`
- [Redis client](https://github.com/xinhai12310/muduo/blob/master/contrib/hiredis/Hiredis.cc): `contrib/hiredis/Hiredis.cc`

### Base Utilities

- [Logging](https://github.com/xinhai12310/muduo/blob/master/muduo/base/Logging.h): `muduo/base/Logging.h`
- [Log stream](https://github.com/xinhai12310/muduo/blob/master/muduo/base/LogStream.cc): `muduo/base/LogStream.cc`
- [Thread pool](https://github.com/xinhai12310/muduo/blob/master/muduo/base/ThreadPool.cc): `muduo/base/ThreadPool.cc`

### Other components

- **Application**
- **Redis service**

## Connections

- Application → TCP client: initiates connection (evidence: `README`)
- Application → TCP server: serves TCP (evidence: `README`)
- TCP client → Connection dialer: creates (evidence: `muduo/net/TcpClient.cc`)
- TCP client → Event loop: schedules callbacks (evidence: `muduo/net/TcpClient.cc`)
- TCP client → TCP connection: creates (evidence: `muduo/net/TcpClient.cc`)
- Event loop → I/O channel: dispatches I/O
- Poller → I/O channel: polls channels (evidence: `muduo/net/poller/EPollPoller.cc`)
- TCP connection → Network buffer: uses
- Event loop → Timer queue: schedules timers
- HTTP parser → Network buffer: parses from (evidence: `muduo/net/http/HttpContext.cc`)
- HTTP parser → HTTP request: populates
- HTTP server → HTTP parser: parses requests
- HTTP server → HTTP response: sends responses
- Inspector → Process inspector: delegates to (evidence: `muduo/net/inspect/Inspector.cc`)
- Inspector → Performance inspector: delegates to (evidence: `muduo/net/inspect/Inspector.cc`)
- Inspector → System inspector: delegates to (evidence: `muduo/net/inspect/Inspector.cc`)
- Protobuf codec → TCP connection: encodes messages on (evidence: `muduo/net/protobuf/ProtobufCodecLite.cc`)
- RPC channel → Protobuf codec: uses codec
- Thrift server → TCP server: wraps (evidence: `contrib/thrift/ThriftServer.h`)
- Thrift connection → TCP connection: processes frames from
- Thrift connection → Thrift server: uses server (evidence: `contrib/thrift/ThriftConnection.cc`)
- Redis client → Event loop: integrates with (evidence: `contrib/hiredis/Hiredis.cc`)
- Redis client → I/O channel: registers I/O (evidence: `contrib/hiredis/Hiredis.cc`)
- Redis client → Redis service: issues commands
- Logging → Log stream: formats through (evidence: `muduo/base/Logging.h`)
- Thrift server → Thread pool: uses workers
