# buger/goreplay architecture

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

- Interactive diagram: https://gitdiagram.com/buger/goreplay
- Repository: https://github.com/buger/goreplay

## Overview

##### Main Components Identification

a) Traffic Capture Layer
- Raw packet capture (input_raw.go)
- HTTP listener (input_http.go)
- TCP listener (input_tcp.go)
- File input (input_file.go)
- Kafka input (input_kafka.go)

b) Processing Layer
- Protocol parsing (proto/proto.go)
- HTTP modification (http_modifier.go)
- Traffic limiting (limiter.go)
- Middleware processing (middleware.go)

c) Output Layer
- HTTP output (output_http.go)
- File output (output_file.go)
- TCP output (output_tcp.go)
- Kafka output (output_kafka.go)
- S3 output (output_s3.go)
- WebSocket output (output_ws.go)

##### Flow Representation

Use these conventions:
- Thick lines for main data paths
- Thin lines for control/metadata flow

##### Component Relationships

Interactions:
- How traffic is captured non-intrusively
- How middleware can modify traffic
- How different outputs can be combined
- How rate limiting affects flow

##### Technical Details

Annotations for:
- Network protocols supported
- Methods (AF_PACKET, libpcap)
- Buffer mechanisms
- Scaling capabilities
- Security considerations

Remember to show both the open-source and PRO features (marked differently) to represent the full capability spectrum of the tool.

- Traffic recording and replay
- Load testing
- Traffic analysis
- Shadow testing

Keep the abstraction level high enough to be understandable but detailed enough to show the sophisticated nature of the tool's architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef input fill:#3498db,stroke:#2980b9,color:white
    classDef processing fill:#2ecc71,stroke:#27ae60,color:white
    classDef output fill:#e67e22,stroke:#d35400,color:white
    classDef middleware fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Input Layer
    subgraph InputLayer["Input Layer"]
        RawCapture["Raw Packet Capture"]:::input
        HTTPListener["HTTP Listener"]:::input
        TCPListener["TCP Listener"]:::input
        FileInput["File Input"]:::input
        KafkaInput["Kafka Input"]:::input
    end

    %% Processing Layer
    subgraph ProcessingLayer["Processing Layer"]
        TrafficInterceptor["Traffic Interceptor"]:::processing
        ProtocolParser["Protocol Parser"]:::processing
        HTTPMod["HTTP Modifier"]:::processing
        TrafficLimiter["Traffic Limiter"]:::processing
        MiddlewareProc["Middleware Processor"]:::processing
    end

    %% Core Components
    subgraph CoreComponents["Core Components"]
        RingBuffer["Ring Buffer"]:::processing
        TCPHandler["TCP Handler"]:::processing
        EmitterSystem["Emitter System"]:::processing
        PluginSystem["Plugin System"]:::processing
    end

    %% Output Layer
    subgraph OutputLayer["Output Layer"]
        HTTPOutput["HTTP Output"]:::output
        FileOutput["File Output"]:::output
        TCPOutput["TCP Output"]:::output
        KafkaOutput["Kafka Output"]:::output
        S3Output["S3 Output"]:::output
        WSOutput["WebSocket Output"]:::output
    end

    %% External Systems
    subgraph ExternalSystems["External Systems"]
        ES["ElasticSearch"]:::external
        S3["Amazon S3"]:::external
        Kafka["Kafka"]:::external
    end

    %% Relationships
    RawCapture --> TrafficInterceptor
    HTTPListener --> TrafficInterceptor
    TCPListener --> TrafficInterceptor
    FileInput --> TrafficInterceptor
    KafkaInput --> TrafficInterceptor

    TrafficInterceptor --> RingBuffer
    RingBuffer --> ProtocolParser
    ProtocolParser --> HTTPMod
    HTTPMod --> TrafficLimiter
    TrafficLimiter --> MiddlewareProc

    MiddlewareProc --> EmitterSystem
    EmitterSystem --> PluginSystem
    TCPHandler --> EmitterSystem

    PluginSystem --> HTTPOutput
    PluginSystem --> FileOutput
    PluginSystem --> TCPOutput
    PluginSystem --> KafkaOutput
    PluginSystem --> S3Output
    PluginSystem --> WSOutput

    KafkaOutput --> Kafka
    S3Output --> S3
    HTTPOutput --> ES

    %% Click Events
    click RawCapture "https://github.com/buger/goreplay/blob/master/input_raw.go"
    click HTTPListener "https://github.com/buger/goreplay/blob/master/input_http.go"
    click TCPListener "https://github.com/buger/goreplay/blob/master/input_tcp.go"
    click FileInput "https://github.com/buger/goreplay/blob/master/input_file.go"
    click KafkaInput "https://github.com/buger/goreplay/blob/master/input_kafka.go"
    click ProtocolParser "https://github.com/buger/goreplay/blob/master/proto/proto.go"
    click HTTPMod "https://github.com/buger/goreplay/blob/master/http_modifier.go"
    click TrafficLimiter "https://github.com/buger/goreplay/blob/master/limiter.go"
    click MiddlewareProc "https://github.com/buger/goreplay/blob/master/middleware.go"
    click HTTPOutput "https://github.com/buger/goreplay/blob/master/output_http.go"
    click FileOutput "https://github.com/buger/goreplay/blob/master/output_file.go"
    click TCPOutput "https://github.com/buger/goreplay/blob/master/output_tcp.go"
    click KafkaOutput "https://github.com/buger/goreplay/blob/master/output_kafka.go"
    click S3Output "https://github.com/buger/goreplay/blob/master/output_s3.go"
    click WSOutput "https://github.com/buger/goreplay/blob/master/output_ws.go"
    click TrafficInterceptor "https://github.com/buger/goreplay/blob/master/internal/capture/capture.go"
    click RingBuffer "https://github.com/buger/goreplay/blob/master/internal/ring/ring.go"
    click TCPHandler "https://github.com/buger/goreplay/tree/master/internal/tcp"
    click EmitterSystem "https://github.com/buger/goreplay/blob/master/emitter.go"
    click PluginSystem "https://github.com/buger/goreplay/blob/master/plugins.go"
    click ES "https://github.com/buger/goreplay/blob/master/elasticsearch.go"
    click Kafka "https://github.com/buger/goreplay/blob/master/kafka.go"
    click S3 "https://github.com/buger/goreplay/blob/master/s3_reader.go"

    %% Legend
    subgraph Legend
        InputLegend["Input Components"]:::input
        ProcessingLegend["Processing Components"]:::processing
        OutputLegend["Output Components"]:::output
        MiddlewareLegend["Middleware Components"]:::middleware
        ExternalLegend["External Systems"]:::external
    end
```
