# youngyangyang04/muduo-core architecture

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

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

## Overview

muduo-core is a C++ TCP networking library for event-driven servers. A server application configures and starts TcpServer; its acceptor accepts clients, connections are assigned to event loops, and callbacks deliver received data to the application. Responses use connection buffers and are written when the socket is ready. The implementation separates server/connection handling, the Reactor event-dispatch machinery, and low-level networking and support utilities. Relationships are based on the excerpts, SOURCE INDEX references, and README; some detailed wiring is documented rather than shown in sampled implementation excerpts.

Main entry points: [`src/TcpConnection.cc`](https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpConnection.cc) (TCP connection), [`src/TcpServer.cc`](https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpServer.cc) (TCP server), [`src/EventLoop.cc`](https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoop.cc) (Event loop), [`src/Channel.cc`](https://github.com/youngyangyang04/muduo-core/blob/main/src/Channel.cc) (Event channel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Server connections"]
  node_tcpserver["TCP server<br/>[TcpServer.cc]"]
  node_acceptor["Connection acceptor<br/>[Acceptor.cc]"]
  node_connection["TCP connection<br/>[TcpConnection.cc]"]
  node_buffer["I/O buffers<br/>[Buffer.cc]"]
end

subgraph group_reactor["Reactor dispatch"]
  node_eventloop["Event loop<br/>[EventLoop.cc]"]
  node_channel["Event channel<br/>[Channel.cc]"]
  node_poller["Poller interface<br/>[Poller.cc]"]
  node_epoll["epoll poller<br/>[EPollPoller.cc]"]
  node_defaultpoller["Poller selection<br/>[DefaultPoller.cc]"]
  node_threadpool["Loop thread pool"]
  node_loopthread["Loop thread<br/>[EventLoopThread.cc]"]
end

subgraph group_network["Network primitives"]
  node_socket["Socket wrapper<br/>[Socket.cc]"]
  node_address["Internet address<br/>[InetAddress.cc]"]
end

subgraph group_support["Runtime support"]
  node_thread["Thread wrapper<br/>[Thread.cc]"]
  node_currentthread["Thread identity<br/>[CurrentThread.cc]"]
  node_logger["Logging<br/>[Logger.cc]"]
  node_timestamp["Timestamps<br/>[Timestamp.cc]"]
end

node_app(("Server application"))
node_peer(("TCP clients"))

node_app -->|"configures and starts"| node_tcpserver
node_tcpserver -->|"sets up listener"| node_acceptor
node_acceptor -->|"reports accepted clients"| node_tcpserver
node_tcpserver -->|"selects loop threads"| node_threadpool
node_threadpool -->|"creates loop threads"| node_loopthread
node_loopthread -->|"runs loop"| node_eventloop
node_tcpserver -->|"creates connections"| node_connection
node_connection -->|"registers callbacks"| node_channel
node_connection -->|"schedules I/O work"| node_eventloop
node_connection -->|"writes and shuts down"| node_socket
node_connection -->|"reads and buffers data"| node_buffer
node_connection -->|"delivers message callbacks"| node_app
node_peer -.->|"connects to listener"| node_acceptor
node_channel -->|"updates registration"| node_eventloop
node_eventloop -->|"polls active channels"| node_poller
node_eventloop -->|"dispatches ready events"| node_channel
node_poller -->|"tracks channels"| node_channel
node_defaultpoller -->|"selects implementation"| node_epoll
node_epoll -->|"returns ready channels"| node_channel
node_tcpserver -->|"uses listen address"| node_address
node_acceptor -->|"accepts connections"| node_socket
node_socket -->|"uses socket addresses"| node_address
node_thread -->|"records thread identity"| node_currentthread
node_eventloop -->|"checks loop thread"| node_currentthread
node_tcpserver -->|"logs server events"| node_logger
node_connection -->|"logs connection events"| node_logger
node_eventloop -->|"records poll time"| node_timestamp
node_channel -->|"timestamps read events"| node_timestamp
node_epoll -->|"returns poll time"| node_timestamp
node_logger -->|"formats log time"| node_timestamp

click node_tcpserver "https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpServer.cc"
click node_acceptor "https://github.com/youngyangyang04/muduo-core/blob/main/src/Acceptor.cc"
click node_connection "https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpConnection.cc"
click node_buffer "https://github.com/youngyangyang04/muduo-core/blob/main/src/Buffer.cc"
click node_eventloop "https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoop.cc"
click node_channel "https://github.com/youngyangyang04/muduo-core/blob/main/src/Channel.cc"
click node_poller "https://github.com/youngyangyang04/muduo-core/blob/main/src/Poller.cc"
click node_epoll "https://github.com/youngyangyang04/muduo-core/blob/main/src/EPollPoller.cc"
click node_defaultpoller "https://github.com/youngyangyang04/muduo-core/blob/main/src/DefaultPoller.cc"
click node_threadpool "https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoopThreadPool.cc"
click node_loopthread "https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoopThread.cc"
click node_socket "https://github.com/youngyangyang04/muduo-core/blob/main/src/Socket.cc"
click node_address "https://github.com/youngyangyang04/muduo-core/blob/main/src/InetAddress.cc"
click node_thread "https://github.com/youngyangyang04/muduo-core/blob/main/src/Thread.cc"
click node_currentthread "https://github.com/youngyangyang04/muduo-core/blob/main/src/CurrentThread.cc"
click node_logger "https://github.com/youngyangyang04/muduo-core/blob/main/src/Logger.cc"
click node_timestamp "https://github.com/youngyangyang04/muduo-core/blob/main/src/Timestamp.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_tcpserver,node_acceptor,node_connection,node_buffer,node_peer toneBlue
class node_eventloop,node_channel,node_poller,node_epoll,node_defaultpoller,node_threadpool,node_loopthread toneAmber
class node_socket,node_address,node_app toneMint
class node_thread,node_currentthread,node_logger,node_timestamp toneRose
```

## Components

### Server connections

- [TCP server](https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpServer.cc): `src/TcpServer.cc`
- [Connection acceptor](https://github.com/youngyangyang04/muduo-core/blob/main/src/Acceptor.cc): `src/Acceptor.cc`
- [TCP connection](https://github.com/youngyangyang04/muduo-core/blob/main/src/TcpConnection.cc): `src/TcpConnection.cc`
- [I/O buffers](https://github.com/youngyangyang04/muduo-core/blob/main/src/Buffer.cc): `src/Buffer.cc`

### Reactor dispatch

- [Event loop](https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoop.cc): `src/EventLoop.cc`
- [Event channel](https://github.com/youngyangyang04/muduo-core/blob/main/src/Channel.cc): `src/Channel.cc`
- [Poller interface](https://github.com/youngyangyang04/muduo-core/blob/main/src/Poller.cc): `src/Poller.cc`
- [epoll poller](https://github.com/youngyangyang04/muduo-core/blob/main/src/EPollPoller.cc): `src/EPollPoller.cc`
- [Poller selection](https://github.com/youngyangyang04/muduo-core/blob/main/src/DefaultPoller.cc): `src/DefaultPoller.cc`
- [Loop thread pool](https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoopThreadPool.cc): `src/EventLoopThreadPool.cc`
- [Loop thread](https://github.com/youngyangyang04/muduo-core/blob/main/src/EventLoopThread.cc): `src/EventLoopThread.cc`

### Network primitives

- [Socket wrapper](https://github.com/youngyangyang04/muduo-core/blob/main/src/Socket.cc): `src/Socket.cc`
- [Internet address](https://github.com/youngyangyang04/muduo-core/blob/main/src/InetAddress.cc): `src/InetAddress.cc`

### Runtime support

- [Thread wrapper](https://github.com/youngyangyang04/muduo-core/blob/main/src/Thread.cc): `src/Thread.cc`
- [Thread identity](https://github.com/youngyangyang04/muduo-core/blob/main/src/CurrentThread.cc): `src/CurrentThread.cc`
- [Logging](https://github.com/youngyangyang04/muduo-core/blob/main/src/Logger.cc): `src/Logger.cc`
- [Timestamps](https://github.com/youngyangyang04/muduo-core/blob/main/src/Timestamp.cc): `src/Timestamp.cc`

### Other components

- **Server application**
- **TCP clients**

## Connections

- Server application → TCP server: configures and starts (evidence: `README.md`)
- TCP server → Connection acceptor: sets up listener (evidence: `README.md`)
- Connection acceptor → TCP server: reports accepted clients (evidence: `README.md`)
- TCP server → Loop thread pool: selects loop threads (evidence: `README.md`)
- Loop thread pool → Loop thread: creates loop threads (evidence: `src/EventLoopThreadPool.cc`)
- Loop thread → Event loop: runs loop (evidence: `src/EventLoopThread.cc`)
- TCP server → TCP connection: creates connections (evidence: `README.md`)
- TCP connection → Event channel: registers callbacks (evidence: `src/TcpConnection.cc`)
- TCP connection → Event loop: schedules I/O work (evidence: `src/TcpConnection.cc`)
- TCP connection → Socket wrapper: writes and shuts down (evidence: `src/TcpConnection.cc`)
- TCP connection → I/O buffers: reads and buffers data (evidence: `src/TcpConnection.cc`)
- TCP connection → Server application: delivers message callbacks (evidence: `src/TcpConnection.cc`)
- TCP clients → Connection acceptor: connects to listener
- Event channel → Event loop: updates registration (evidence: `src/Channel.cc`)
- Event loop → Poller interface: polls active channels (evidence: `src/EventLoop.cc`)
- Event loop → Event channel: dispatches ready events (evidence: `src/EventLoop.cc`)
- Poller interface → Event channel: tracks channels (evidence: `src/Poller.cc`)
- Poller selection → epoll poller: selects implementation (evidence: `src/DefaultPoller.cc`)
- epoll poller → Event channel: returns ready channels (evidence: `src/EPollPoller.cc`)
- TCP server → Internet address: uses listen address
- Connection acceptor → Socket wrapper: accepts connections
- Socket wrapper → Internet address: uses socket addresses (evidence: `src/Socket.cc`)
- Thread wrapper → Thread identity: records thread identity (evidence: `src/Thread.cc`)
- Event loop → Thread identity: checks loop thread
- TCP server → Logging: logs server events (evidence: `src/TcpServer.cc`)
- TCP connection → Logging: logs connection events (evidence: `src/TcpConnection.cc`)
- Event loop → Timestamps: records poll time
- Event channel → Timestamps: timestamps read events
- epoll poller → Timestamps: returns poll time
- Logging → Timestamps: formats log time (evidence: `src/Logger.cc`)
