# hoshimiaya/hoshimnet architecture

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

- Interactive diagram: https://gitdiagram.com/hoshimiaya/hoshimnet
- Repository: https://github.com/hoshimiaya/hoshimnet

## Overview

HoshiMNet is a small C++ TCP networking framework organized as a reusable library plus a top-level executable entry point. The codebase is built with CMake and is split into a low-level “base” layer and a network stack under `hoshiMNet/net`.

The architecture is centered on an event-driven reactor model. `EventLoop` owns the per-thread dispatch loop, `Epoller` wraps Linux `epoll`, and `Channel` represents an fd plus the events/callbacks registered for it. This is the core boundary for I/O handling: sockets are not actively polled by application code; they are driven by the loop through epoll notifications.

The socket and address layer is intentionally thin. `Socket` wraps the underlying TCP socket operations, and `InetAddress` encapsulates endpoint information. These types feed into higher-level connection and listener components without exposing raw system calls to the rest of the stack.

Server-side connection acceptance flows through `Acceptor` into `TcpServer`. `Acceptor` listens on the server socket and produces new inbound connections; `TcpServer` owns the listening lifecycle, creates `TcpConnection` instances, and typically manages the connection map and connection-level callbacks. This is the main ingress path for external clients.

`TcpConnection` is the per-connection abstraction. It sits between the socket/channel layer and the application-facing callbacks, handling state, read/write readiness, and connection teardown. This is likely the main place where application logic attaches to network events.

Client-side outbound connections are handled separately by `TcpClient`. That suggests the library supports both server and client roles with a shared core, rather than being server-only.

Concurrency is split between generic utilities and I/O threading. `EventLoopThreadPool` distributes event loops across threads for scalable network I/O, while `base/ThreadPool` appears to be a more general-purpose worker pool. This implies a design where networking remains reactor-based, but auxiliary tasks can be offloaded to worker threads.

The `base` directory also contains infrastructure code: `Log` for diagnostics, `MpmcQueue` for concurrent producer/consumer communication, `Observer` for callback-style notification, and `Singleton` for globally shared objects. These are supporting building blocks rather than the main data path.

The primary data flow is: external TCP client/server traffic enters through the socket, `Acceptor` or `TcpClient` creates/uses a `TcpConnection`, the fd is registered with `Channel`, `Epoller` signals readiness, and `EventLoop` dispatches the corresponding callbacks back into connection logic. That loop is the key diagrammatic cycle.

The repository appears Linux-oriented because `epoll` is the central polling primitive. That means the runtime architecture is tied to POSIX sockets and event-driven I/O rather than a portable abstraction like select/poll or an async runtime from a higher-level framework.

`main.cpp` is the only top-level application source visible, so the repo likely ships as a framework/library with a minimal executable or example harness. The most important diagram boundary is therefore between the reusable networking core and whatever application logic is attached through callbacks in `TcpServer`/`TcpClient`.

For an architecture diagram, the essential subsystems are:
1) build and entry point,
2) base utilities,
3) socket/address abstractions,
4) reactor core (`EventLoop`/`Epoller`/`Channel`),
5) server acceptor and connection management,
6) client outbound path,
7) loop/thread pools,
8) cross-cutting logging and concurrency helpers.

Main entry points: [`hoshiMNet/net/TcpServer.h`](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpServer.h) (TcpServer), [`hoshiMNet/net/EventLoop.h`](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/EventLoop.h) (EventLoop), [`hoshiMNet/net/TcpConnection.h`](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpConnection.h) (TcpConnection), [`hoshiMNet/net/TcpClient.h`](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpClient.h) (TcpClient)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build & entry"]
  node_cmake_root["CMake<br/>build system<br/>[CMakeLists.txt]"]
  node_cmake_lib["Library CMake<br/>module build<br/>[CMakeLists.txt]"]
  node_cmake_base["Base CMake<br/>module build<br/>[CMakeLists.txt]"]
  node_cmake_net["Net CMake<br/>module build<br/>[CMakeLists.txt]"]
  node_main(("Main<br/>entrypoint<br/>[main.cpp]"))
end

subgraph group_base["Base layer"]
  node_log["Log<br/>diagnostics<br/>[Log.h]"]
  node_queue["Queue<br/>[MpmcQueue.h]"]
  node_observer["Observer<br/>callback utility<br/>[Observer.h]"]
  node_singleton["Singleton<br/>global helper<br/>[Singleton.h]"]
  node_threadpool["ThreadPool<br/>worker pool<br/>[ThreadPool.h]"]
end

subgraph group_net["Networking stack"]
  node_inet["InetAddress<br/>endpoint<br/>[InetAddress.h]"]
  node_socket["Socket<br/>[Socket.h]"]
  node_channel["Channel<br/>fd event<br/>[Channel.h]"]
  node_epoller["Epoller<br/>epoll wrapper<br/>[Epoller.h]"]
  node_eventloop(("EventLoop<br/>reactor loop<br/>[EventLoop.h]"))
  node_loop_pool["Loop Pool<br/>loop threads"]
  node_acceptor["Acceptor<br/>listener<br/>[Acceptor.h]"]
  node_conn["TcpConnection<br/>[TcpConnection.h]"]
  node_server["TcpServer<br/>[TcpServer.h]"]
  node_client["TcpClient<br/>[TcpClient.h]"]
end

node_cmake_root -->|"builds"| node_cmake_lib
node_cmake_lib -->|"includes"| node_cmake_base
node_cmake_lib -->|"includes"| node_cmake_net
node_main -->|"uses"| node_server
node_main -->|"uses"| node_client
node_log -.->|"cross-cutting"| node_server
node_log -.->|"cross-cutting"| node_client
node_threadpool -.->|"supports"| node_loop_pool
node_queue -.->|"feeds"| node_threadpool
node_observer -.->|"callbacks"| node_server
node_singleton -.->|"shares"| node_log
node_inet -->|"configures"| node_socket
node_socket -->|"registered as"| node_channel
node_channel -->|"tracked by"| node_epoller
node_epoller -->|"driven by"| node_eventloop
node_eventloop -->|"dispatches"| node_channel
node_loop_pool -->|"creates"| node_eventloop
node_acceptor -->|"accepts for"| node_server
node_acceptor -->|"binds"| node_socket
node_server -->|"creates"| node_conn
node_client -->|"owns"| node_conn
node_conn -->|"wraps"| node_channel
node_conn -->|"runs on"| node_eventloop
node_server -->|"listens via"| node_acceptor
node_server -->|"scales with"| node_loop_pool
node_client -->|"connects on"| node_eventloop

click node_cmake_root "https://github.com/hoshimiaya/hoshimnet/blob/main/CMakeLists.txt"
click node_cmake_lib "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/CMakeLists.txt"
click node_cmake_base "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/CMakeLists.txt"
click node_cmake_net "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/CMakeLists.txt"
click node_main "https://github.com/hoshimiaya/hoshimnet/blob/main/main.cpp"
click node_log "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Log.h"
click node_queue "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/MpmcQueue.h"
click node_observer "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Observer.h"
click node_singleton "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Singleton.h"
click node_threadpool "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/ThreadPool.h"
click node_inet "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/InetAddress.h"
click node_socket "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Socket.h"
click node_channel "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Channel.h"
click node_epoller "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Epoller.h"
click node_eventloop "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/EventLoop.h"
click node_loop_pool "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/EventLoopThreadPool.h"
click node_acceptor "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Acceptor.h"
click node_conn "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpConnection.h"
click node_server "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpServer.h"
click node_client "https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpClient.h"

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_cmake_root,node_cmake_lib,node_cmake_base,node_cmake_net,node_main toneBlue
class node_log,node_queue,node_observer,node_singleton,node_threadpool toneAmber
class node_inet,node_socket,node_channel,node_epoller,node_eventloop,node_loop_pool,node_acceptor,node_conn,node_server,node_client toneMint
```

## Components

### Build & entry

Top-level build files and executable entry point.

- [CMake](https://github.com/hoshimiaya/hoshimnet/blob/main/CMakeLists.txt): build system · Top-level build configuration. · `CMakeLists.txt`
- [Library CMake](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/CMakeLists.txt): module build · Build rules for the reusable networking library. · `hoshiMNet/CMakeLists.txt`
- [Base CMake](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/CMakeLists.txt): module build · Build rules for the base utility layer. · `hoshiMNet/base/CMakeLists.txt`
- [Net CMake](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/CMakeLists.txt): module build · Build rules for the networking stack. · `hoshiMNet/net/CMakeLists.txt`
- [Main](https://github.com/hoshimiaya/hoshimnet/blob/main/main.cpp): entrypoint · Top-level executable or demo harness. · `main.cpp`

### Base layer

Cross-cutting utilities and concurrency helpers.

- [Log](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Log.h): diagnostics · Logging and diagnostics support. · `hoshiMNet/base/Log.h`
- [Queue](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/MpmcQueue.h): mpmc queue · Concurrent multi-producer multi-consumer queue. · `hoshiMNet/base/MpmcQueue.h`
- [Observer](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Observer.h): callback utility · Callback-style notification helper. · `hoshiMNet/base/Observer.h`
- [Singleton](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/Singleton.h): global helper · Shared-instance helper for global services. · `hoshiMNet/base/Singleton.h`
- [ThreadPool](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/base/ThreadPool.h): worker pool · General-purpose background worker pool. · `hoshiMNet/base/ThreadPool.h`

### Networking stack

Reactor-based TCP networking components.

- [InetAddress](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/InetAddress.h): endpoint · TCP endpoint and address wrapper. · `hoshiMNet/net/InetAddress.h`
- [Socket](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Socket.h): tcp socket · Thin wrapper around TCP socket operations. · `hoshiMNet/net/Socket.h`
- [Channel](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Channel.h): fd event · File descriptor, interested events, and callbacks. · `hoshiMNet/net/Channel.h`
- [Epoller](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Epoller.h): epoll wrapper · Linux epoll polling and readiness demultiplexing. · `hoshiMNet/net/Epoller.h`
- [EventLoop](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/EventLoop.h): reactor loop · Per-thread event dispatch loop. · `hoshiMNet/net/EventLoop.h`
- [Loop Pool](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/EventLoopThreadPool.h): loop threads · Distributes event loops across threads. · `hoshiMNet/net/EventLoopThreadPool.h`
- [Acceptor](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/Acceptor.h): listener · Accepts inbound TCP connections. · `hoshiMNet/net/Acceptor.h`
- [TcpConnection](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpConnection.h): connection · Per-connection state and I/O callback boundary. · `hoshiMNet/net/TcpConnection.h`
- [TcpServer](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpServer.h): server · Owns listening lifecycle and server-side connections. · `hoshiMNet/net/TcpServer.h`
- [TcpClient](https://github.com/hoshimiaya/hoshimnet/blob/main/hoshiMNet/net/TcpClient.h): client · Outbound TCP connection manager. · `hoshiMNet/net/TcpClient.h`

## Connections

- CMake → Library CMake: builds · Top-level build includes the library module.
- Library CMake → Base CMake: includes · Library build pulls in base utilities.
- Library CMake → Net CMake: includes · Library build pulls in networking stack.
- Main → TcpServer: uses · Application entry point likely instantiates server logic.
- Main → TcpClient: uses · Application entry point may drive client logic.
- Log → TcpServer: cross-cutting · Logging supports server operations.
- Log → TcpClient: cross-cutting · Logging supports client operations.
- ThreadPool → Loop Pool: supports · General worker threads complement reactor threads.
- Queue → ThreadPool: feeds · Concurrent queue underpins worker dispatch patterns.
- Observer → TcpServer: callbacks · Notification/callback utilities support connection events.
- Singleton → Log: shares · Global helper pattern can back shared logging state.
- InetAddress → Socket: configures · Endpoint data is used to create and bind sockets.
- Socket → Channel: registered as · Socket file descriptor is monitored through a channel.
- Channel → Epoller: tracked by · Channels are registered with the epoll wrapper.
- Epoller → EventLoop: driven by · Event loop owns the poll/dispatch cycle.
- EventLoop → Channel: dispatches · Loop invokes channel callbacks on readiness events.
- Loop Pool → EventLoop: creates · Thread pool manages multiple event loops.
- Acceptor → TcpServer: accepts for · Acceptor hands inbound connections to the server.
- Acceptor → Socket: binds · Listener uses socket primitives to accept connections.
- TcpServer → TcpConnection: creates · Server creates and manages per-connection objects.
- TcpClient → TcpConnection: owns · Client side uses the same connection abstraction.
- TcpConnection → Channel: wraps · Connection couples socket state to event notifications.
- TcpConnection → EventLoop: runs on · Connection callbacks execute on an event loop.
- TcpServer → Acceptor: listens via · Server controls the listening lifecycle through the acceptor.
- TcpServer → Loop Pool: scales with · Server can distribute work across loop threads.
- TcpClient → EventLoop: connects on · Outbound connection activity is driven by the loop.
