# lucienlsa/cppserver architecture

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

- Interactive diagram: https://gitdiagram.com/lucienlsa/cppserver
- Repository: https://github.com/lucienlsa/cppserver

## Overview

##### Project type and purpose
- From the file tree (“src/Channel.cpp”, “src/Epoll.cpp”, “src/EventLoop.cpp”, “src/Server.cpp”, etc.) and the README (“30dayMakeCppServer”), we see this is a small C++ network‐server library / framework.
- It implements an event‐driven Reactor pattern on Linux (epoll under the hood), exposing classes such as Server, EventLoop, Channel, Epoll, Socket and InetAddress.

##### File structure
- Top‐level:
- Makefile – build script
- client03.cpp / server06.cpp – example clients/servers
- src/ – core library code
· Channel.*          – wraps a single file‐descriptor + callback registration
· Epoll.*            – epoll wrapping & polling
· EventLoop.*        – main loop, dispatches events via Channels
· Server.*           – high‐level TCP server, accepts connections, ties together EventLoop + Channels
· Socket.*, InetAddress.* – low-level socket address & helper wrappers
· util.*             – small utility functions
· tmp/               – older/experimental server versions
- No thread pool is present: this is a single‐threaded Reactor.

##### Elements
- Client → Server.listenSocket (for TCP connect)
- Server.listenSocket → EventLoop.register(Channel)
- EventLoop → Epoll.poll() → Kernel / OS
- Kernel → ready-FDs → Epoll → EventLoop
- EventLoop → Channel.handleEvent() → Server or user callback
- Green for higher-level Server.
- Orange for low-level Socket/InetAddress.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client (external)"]:::external

    %% Server Layer
    Server["Server"]:::server

    %% Reactor Core
    EventLoop["EventLoop"]:::core
    Epoll["Epoll"]:::core
    Channel["Channel"]:::core

    %% Low-level wrappers
    Socket["Socket"]:::low
    InetAddress["InetAddress"]:::low
    Util["util"]:::low

    %% OS Kernel
    Kernel["OS Kernel"]:::external

    %% Connections and Flow
    Client -->|"1. connect()"| Server
    Server -->|"instantiates"| EventLoop
    Server -->|"uses"| Socket
    Server -->|"uses"| InetAddress

    EventLoop -->|"registers"| Channel
    EventLoop -->|"uses"| Epoll
    EventLoop -->|"invokes callbacks on"| Channel

    Epoll -->|"syscall epoll_wait"| Kernel
    Kernel -->|"ready FDs"| Epoll
    Epoll -->|"returns events"| EventLoop

    Socket -->|"helpers from"| Util
    InetAddress -->|"helpers from"| Util

    %% Click Events
    click Server "https://github.com/lucienlsa/cppserver/blob/master/src/Server.cpp"
    click EventLoop "https://github.com/lucienlsa/cppserver/blob/master/src/EventLoop.cpp"
    click Epoll "https://github.com/lucienlsa/cppserver/blob/master/src/Epoll.cpp"
    click Channel "https://github.com/lucienlsa/cppserver/blob/master/src/Channel.cpp"
    click Socket "https://github.com/lucienlsa/cppserver/blob/master/src/Socket.cpp"
    click InetAddress "https://github.com/lucienlsa/cppserver/blob/master/src/InetAddress.cpp"
    click Util "https://github.com/lucienlsa/cppserver/blob/master/src/util.cpp"
    click Client "https://github.com/lucienlsa/cppserver/blob/master/client03.cpp"
    click Server "https://github.com/lucienlsa/cppserver/blob/master/server06.cpp"
    click tmp1 "https://github.com/lucienlsa/cppserver/blob/master/src/tmp/server03.cpp"
    click tmp2 "https://github.com/lucienlsa/cppserver/blob/master/src/tmp/server04.cpp"
    click tmp3 "https://github.com/lucienlsa/cppserver/blob/master/src/tmp/server05.cpp"

    %% Styles
    classDef server fill:#9f6,stroke:#393,stroke-width:2px;
    classDef core fill:#6cf,stroke:#069,stroke-width:2px;
    classDef low fill:#fc9,stroke:#c60,stroke-width:2px;
    classDef external fill:#fff,stroke-dasharray: 5 5,stroke:#999,stroke-width:2px;
```
