# mohamedshyzeghori/webserver architecture

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

- Interactive diagram: https://gitdiagram.com/mohamedshyzeghori/webserver
- Repository: https://github.com/mohamedshyzeghori/webserver

## Overview

##### Project Type and Purpose
- This is a Java‐based server application demonstrating three threading models (single‐threaded, multi‐threaded, thread‐pool) for handling TCP client connections.
- It’s a back-end service (no UI) with external load-generation via Apache JMeter or a custom Java Client.

##### Main Components
- Client(s) – can be the provided Client.java or JMeter acting as an external load generator.
- Server Core – three interchangeable modules under WEBSERVER/SingleThreaded, MultiThreaded, ThreadPool.
- Thread Manager – either the single main thread, per-connection thread factory, or fixed thread pool executor.
- Network Interface – TCP listener bound to port 8010, accepting Socket connections.
- Business Logic – simple greeting response written to the socket’s OutputStream.
- Build/Deployment – Java compiler (javac), Maven for dependencies, IDE project files (.iml), output directory (out/production).

##### Relationships and Interactions
- Client → TCP Socket → Server Listener
- Server Listener → hands off the socket to the Thread Manager
- Thread Manager → invokes a Worker Thread/Task → executes Business Logic → writes response back through the same socket
- JMeter (external) → simulates N concurrent clients → collects response times → feeds back into performance metrics

##### Architectural Patterns and Design Principles
- Single‐Threaded: request lifecycle all in one thread (no concurrency).
- Multi‐Threaded: “one thread per client” model, unlimited thread creation.
- Thread Pool: fixed-size java.util.concurrent.ExecutorService to cap concurrency and reuse threads.
- Separation of Concerns: network I/O, thread management, and business logic are distinct responsibilities.

– Left: Clients (Custom Java Client, JMeter Load Generator)
– Center: Server Listener & Thread Manager Module (choose one of the three models)
– Right: Worker Threads executing Business Logic
c. Alternatives:
d. Technologies:
– Label Java 21, Maven dependency management
– Note port 8010, TCP Sampler in JMeter, ThreadPool size (configurable)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Client_ST["Custom Java Client (SingleThreaded)"]:::external
        Client_MT["Custom Java Client (MultiThreaded)"]:::external
        JMeter["JMeter Load Generator"]:::external
    end

    %% Network Interface
    Listener["Server Listener\n(port 8010)"]:::network

    %% Thread Manager Layer
    subgraph "Server Core - Thread Manager Modules"
        direction TB
        ST_Module["Single-Threaded Module"]:::thread
        MT_Module["Multi-Threaded Module"]:::thread
        TP_Module["Thread-Pool Module\n(configurable size)"]:::thread
    end

    %% Worker Layer
    Worker["Worker Thread / Task\n(Business Logic)"]:::worker

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        direction TB
        IM_Single["SingleThreaded.iml"]:::build
        IM_Multi["MultiThreaded.iml"]:::build
        IM_Pool["ThreadPool.iml"]:::build
        Out_ST["out/production/SingleThreaded"]:::build
        Out_TP["out/production/ThreadPool"]:::build
        README["README.md"]:::build
    end

    %% Connections
    Client_ST -->|"TCP request"| Listener
    Client_MT -->|"TCP request"| Listener
    JMeter -->|"TCP request (TCP Sampler)"| Listener

    Listener -->|"hand off socket"| ST_Module
    Listener -->|"hand off socket"| MT_Module
    Listener -->|"hand off socket"| TP_Module

    ST_Module -->|"invoke worker"| Worker
    MT_Module -->|"invoke worker"| Worker
    TP_Module -->|"invoke worker"| Worker

    Worker -->|"TCP response"| Client_ST
    Worker -->|"TCP response"| Client_MT
    Worker -->|"TCP response"| JMeter

    %% Click Events
    click Client_ST "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/SingleThreaded/src/Client.java"
    click Client_MT "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/MultiThreaded/src/Client.java"
    click ST_Module "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/SingleThreaded/src/Server.java"
    click MT_Module "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/MultiThreaded/src/Server.java"
    click TP_Module "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/ThreadPool/src/Server.java"
    click IM_Single "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/SingleThreaded/SingleThreaded.iml"
    click IM_Multi "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/MultiThreaded/MultiThreaded.iml"
    click IM_Pool "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/ThreadPool/ThreadPool.iml"
    click README "https://github.com/mohamedshyzeghori/webserver/blob/main/README.md"
    click Out_ST "https://github.com/mohamedshyzeghori/webserver/tree/main/WEBSERVER/out/production/SingleThreaded"
    click Out_TP "https://github.com/mohamedshyzeghori/webserver/tree/main/WEBSERVER/out/production/ThreadPool"
    click JMeter "https://github.com/mohamedshyzeghori/webserver/blob/main/WEBSERVER/SingleThreaded/src/ThreadGroup.jmx"

    %% Styles
    classDef external fill:#eeeeee,stroke:#666,stroke-width:1px,shape:parallelogram;
    classDef network fill:#bbdefb,stroke:#333,stroke-width:1px;
    classDef thread fill:#c8e6c9,stroke:#333,stroke-width:1px;
    classDef worker fill:#ffcc80,stroke:#333,stroke-width:1px;
    classDef build fill:#e0e0e0,stroke:#333,stroke-width:1px;
```
