# undertow-io/undertow architecture

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

- Interactive diagram: https://gitdiagram.com/undertow-io/undertow
- Repository: https://github.com/undertow-io/undertow

## Overview

##### Main Components Identification

The system should be divided into three main components as indicated in the README and file structure:
- Core HTTP Server (non-blocking IO)
- Servlet Implementation
- WebSocket Implementation

##### Detailed Architecture Breakdown

a. Core Layer:
- Following sub-components:
- Protocol handlers (HTTP/1.1, HTTP/2, AJP)
- Channel management
- Buffer pools
- Connection handling

b. Protocol Layer:
- Above the core layer
- Separate sections for:
- HTTP/1.1 implementation
- HTTP/2 implementation
- AJP protocol support
- WebSocket protocols

c. Handler Layer:
- Above the protocol layer
- Components for:
- Routing handlers
- Security handlers
- Session management
- Resource handlers
- Predicate handlers

d. Integration Layer:
- At the top
- Integration points for:
- Servlet container
- WebSocket endpoints
- External applications

##### Connection Flow Representation

- Incoming client requests
- Request processing flow through layers
- Response generation and return path
- WebSocket upgrade paths

##### Additional Details

Annotations for:
- Supported protocols (HTTP/1.1, HTTP/2, WebSocket, AJP)
- Servlet specification versions (4.0/5.0/6.0)
- WebSocket specification compliance (JSR-356/Jakarta 2.0)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Integration Layer"
        ServletContainer["Servlet Container"]:::integration
        WebSocketJSR["WebSocket JSR Implementation"]:::integration
        ServletCore["Servlet Core Integration"]:::integration
        WebSocketEndpoints["WebSocket Endpoints"]:::integration
    end

    subgraph "Handler Layer"
        Routing["Routing Handlers"]:::handler
        Security["Security Handlers"]:::handler
        Session["Session Management"]:::handler
        Resource["Resource Handlers"]:::handler
        Predicate["Predicate Handlers"]:::handler
    end

    subgraph "Protocol Layer"
        HTTP1["HTTP/1.1 Protocol"]:::protocol
        HTTP2["HTTP/2 Protocol"]:::protocol
        AJP["AJP Protocol"]:::protocol
        WebSocket["WebSocket Protocol"]:::protocol
    end

    subgraph "Core Layer"
        CoreServer["Core HTTP Server"]:::core
        ChannelMgmt["Channel Management"]:::core
        BufferPool["Buffer Pool Management"]:::core
        ConnHandler["Connection Handler"]:::core
        IOUtils["IO Utilities"]:::core
        Conduits["Connection Conduits"]:::core
        SSL["SSL/TLS Support"]:::core
    end

    %% Integration Layer Connections
    ServletContainer --> Routing
    WebSocketJSR --> WebSocket
    ServletCore --> CoreServer
    WebSocketEndpoints --> WebSocket

    %% Handler Layer Connections
    Routing --> HTTP1
    Routing --> HTTP2
    Security --> CoreServer
    Session --> CoreServer
    Resource --> CoreServer
    Predicate --> Routing

    %% Protocol Layer Connections
    HTTP1 --> CoreServer
    HTTP2 --> CoreServer
    AJP --> CoreServer
    WebSocket --> CoreServer

    %% Core Layer Connections
    CoreServer --> ChannelMgmt
    CoreServer --> BufferPool
    CoreServer --> ConnHandler
    CoreServer --> IOUtils
    CoreServer --> Conduits
    CoreServer --> SSL

    %% Styling
    classDef core fill:#2374ab
    classDef protocol fill:#39a9db
    classDef handler fill:#40bcd8
    classDef integration fill:#7d56f4

    %% Click Events
    click CoreServer "https://github.com/undertow-io/undertow/blob/main/core/src/main/java/io/undertow/Undertow.java"
    click ChannelMgmt "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/channels/"
    click BufferPool "https://github.com/undertow-io/undertow/blob/main/core/src/main/java/io/undertow/connector/ByteBufferPool.java"
    click ConnHandler "https://github.com/undertow-io/undertow/blob/main/core/src/main/java/io/undertow/server/ServerConnection.java"
    click HTTP1 "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/server/protocol/http/"
    click HTTP2 "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/server/protocol/http2/"
    click AJP "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/server/protocol/ajp/"
    click WebSocket "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/websockets/"
    click Routing "https://github.com/undertow-io/undertow/blob/main/core/src/main/java/io/undertow/server/handlers/RoutingHandler.java"
    click Security "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/security/"
    click Session "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/server/session/"
    click Resource "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/server/handlers/resource/"
    click Predicate "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/predicate/"
    click ServletContainer "https://github.com/undertow-io/undertow/tree/main/servlet/src/main/java/io/undertow/servlet/"
    click WebSocketJSR "https://github.com/undertow-io/undertow/tree/main/websockets-jsr/src/main/java/io/undertow/websockets/jsr/"
    click ServletCore "https://github.com/undertow-io/undertow/tree/main/servlet/src/main/java/io/undertow/servlet/core/"
    click WebSocketEndpoints "https://github.com/undertow-io/undertow/tree/main/websockets-jsr/src/main/java/io/undertow/websockets/jsr/annotated/"
    click IOUtils "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/io/"
    click Conduits "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/conduits/"
    click SSL "https://github.com/undertow-io/undertow/tree/main/core/src/main/java/io/undertow/protocols/ssl/"
```
