# nishisan-dev/n-udptee architecture

> Architecture diagram of the GitHub repository nishisan-dev/n-udptee, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nishisan-dev/n-udptee
- Repository: https://github.com/nishisan-dev/n-udptee

## Overview

n-udptee passively captures inbound UDP/IPv4 traffic and independently replicates matching datagrams to configured targets while leaving the original receiver undisturbed. The main workflow is CLI configuration loading, ingress capture, frame decoding, first-match rule selection, bounded per-target queuing, and sending through the selected forwarding mode. Metrics and health endpoints provide operational visibility. The README documents these capabilities; the graph’s implementation links rely on the shown source excerpts and SOURCE INDEX, so unsampled details are not expanded.

Main entry points: [`internal/app/app.go`](https://github.com/nishisan-dev/n-udptee/blob/main/internal/app/app.go) (Service runtime), [`internal/engine/engine.go`](https://github.com/nishisan-dev/n-udptee/blob/main/internal/engine/engine.go) (Fan-out engine), [`cmd/n-udptee/main.go`](https://github.com/nishisan-dev/n-udptee/blob/main/cmd/n-udptee/main.go) (CLI), [`internal/send/rawipv4/raw.go`](https://github.com/nishisan-dev/n-udptee/blob/main/internal/send/rawipv4/raw.go) (Raw IPv4 sender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Ingress capture"]
  node_bpf["BPF validation<br/>[compile.go]"]
  node_capture["Packet capture<br/>[pcap.go]"]
  node_decode["UDP decoder<br/>[decode.go]"]
end

subgraph group_routing["Rules and fan-out"]
  node_datagram["Datagram model<br/>[datagram.go]"]
  node_engine["Fan-out engine<br/>[engine.go]"]
  node_matcher["First-match rules<br/>[match.go]"]
end

subgraph group_forwarding["Forwarding"]
  node_raw["Raw IPv4 sender<br/>[raw.go]"]
  node_udp["UDP socket sender<br/>[udp.go]"]
end

subgraph group_operations["Operations"]
  node_cli["CLI<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_app["Service runtime<br/>[app.go]"]
  node_metrics["Metrics registry<br/>[metrics.go]"]
end

node_sender(("UDP sender"))
node_scraper(("Metrics scraper"))
node_receiver(("Configured receivers"))

node_sender -->|"starts"| node_cli
node_cli -->|"loads"| node_config
node_cli -->|"runs"| node_app
node_config -->|"validates filter"| node_bpf
node_app -->|"opens"| node_capture
node_capture -->|"provides packets"| node_app
node_app -->|"decodes frames"| node_decode
node_decode -->|"creates"| node_datagram
node_app -->|"submits datagrams"| node_engine
node_engine -->|"matches rules"| node_matcher
node_engine -->|"queues replicas"| node_datagram
node_app -->|"creates in raw mode"| node_raw
node_app -->|"creates in socket mode"| node_udp
node_engine -.->|"dispatches sends"| node_raw
node_engine -.->|"dispatches sends"| node_udp
node_raw -.->|"sends replicas"| node_receiver
node_udp -.->|"sends replicas"| node_receiver
node_app -->|"records capture"| node_metrics
node_engine -->|"records queue and sends"| node_metrics
node_scraper -->|"requests metrics"| node_app
node_app -->|"serves metrics"| node_metrics

click node_cli "https://github.com/nishisan-dev/n-udptee/blob/main/cmd/n-udptee/main.go"
click node_config "https://github.com/nishisan-dev/n-udptee/blob/main/internal/config/config.go"
click node_bpf "https://github.com/nishisan-dev/n-udptee/blob/main/internal/bpf/compile.go"
click node_app "https://github.com/nishisan-dev/n-udptee/blob/main/internal/app/app.go"
click node_capture "https://github.com/nishisan-dev/n-udptee/blob/main/internal/capture/pcap.go"
click node_decode "https://github.com/nishisan-dev/n-udptee/blob/main/internal/decode/decode.go"
click node_datagram "https://github.com/nishisan-dev/n-udptee/blob/main/internal/model/datagram.go"
click node_engine "https://github.com/nishisan-dev/n-udptee/blob/main/internal/engine/engine.go"
click node_matcher "https://github.com/nishisan-dev/n-udptee/blob/main/internal/match/match.go"
click node_raw "https://github.com/nishisan-dev/n-udptee/blob/main/internal/send/rawipv4/raw.go"
click node_udp "https://github.com/nishisan-dev/n-udptee/blob/main/internal/send/udpsocket/udp.go"
click node_metrics "https://github.com/nishisan-dev/n-udptee/blob/main/internal/metrics/metrics.go"

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_bpf,node_capture,node_decode toneBlue
class node_datagram,node_engine,node_matcher toneAmber
class node_raw,node_udp toneMint
class node_cli,node_config,node_app,node_metrics toneRose
class node_sender,node_scraper,node_receiver toneIndigo
```

## Components

### Ingress capture

- [BPF validation](https://github.com/nishisan-dev/n-udptee/blob/main/internal/bpf/compile.go): `internal/bpf/compile.go`
- [Packet capture](https://github.com/nishisan-dev/n-udptee/blob/main/internal/capture/pcap.go): `internal/capture/pcap.go`
- [UDP decoder](https://github.com/nishisan-dev/n-udptee/blob/main/internal/decode/decode.go): `internal/decode/decode.go`

### Rules and fan-out

- [Datagram model](https://github.com/nishisan-dev/n-udptee/blob/main/internal/model/datagram.go): `internal/model/datagram.go`
- [Fan-out engine](https://github.com/nishisan-dev/n-udptee/blob/main/internal/engine/engine.go): `internal/engine/engine.go`
- [First-match rules](https://github.com/nishisan-dev/n-udptee/blob/main/internal/match/match.go): `internal/match/match.go`

### Forwarding

- [Raw IPv4 sender](https://github.com/nishisan-dev/n-udptee/blob/main/internal/send/rawipv4/raw.go): `internal/send/rawipv4/raw.go`
- [UDP socket sender](https://github.com/nishisan-dev/n-udptee/blob/main/internal/send/udpsocket/udp.go): `internal/send/udpsocket/udp.go`

### Operations

- [CLI](https://github.com/nishisan-dev/n-udptee/blob/main/cmd/n-udptee/main.go): `cmd/n-udptee/main.go`
- [Configuration](https://github.com/nishisan-dev/n-udptee/blob/main/internal/config/config.go): `internal/config/config.go`
- [Service runtime](https://github.com/nishisan-dev/n-udptee/blob/main/internal/app/app.go): `internal/app/app.go`
- [Metrics registry](https://github.com/nishisan-dev/n-udptee/blob/main/internal/metrics/metrics.go): `internal/metrics/metrics.go`

### Other components

- **UDP sender**
- **Metrics scraper**
- **Configured receivers**

## Connections

- UDP sender → CLI: starts (evidence: `README.md`)
- CLI → Configuration: loads (evidence: `cmd/n-udptee/main.go`)
- CLI → Service runtime: runs (evidence: `cmd/n-udptee/main.go`)
- Configuration → BPF validation: validates filter (evidence: `internal/config/config.go`)
- Service runtime → Packet capture: opens (evidence: `internal/app/app.go`)
- Packet capture → Service runtime: provides packets (evidence: `internal/app/app.go`)
- Service runtime → UDP decoder: decodes frames (evidence: `internal/app/app.go`)
- UDP decoder → Datagram model: creates (evidence: `internal/decode/decode.go`)
- Service runtime → Fan-out engine: submits datagrams (evidence: `internal/app/app.go`)
- Fan-out engine → First-match rules: matches rules (evidence: `internal/engine/engine.go`)
- Fan-out engine → Datagram model: queues replicas (evidence: `internal/engine/engine.go`)
- Service runtime → Raw IPv4 sender: creates in raw mode (evidence: `internal/app/app.go`)
- Service runtime → UDP socket sender: creates in socket mode (evidence: `internal/app/app.go`)
- Fan-out engine → Raw IPv4 sender: dispatches sends
- Fan-out engine → UDP socket sender: dispatches sends
- Raw IPv4 sender → Configured receivers: sends replicas
- UDP socket sender → Configured receivers: sends replicas
- Service runtime → Metrics registry: records capture (evidence: `internal/app/app.go`)
- Fan-out engine → Metrics registry: records queue and sends (evidence: `internal/engine/engine.go`)
- Metrics scraper → Service runtime: requests metrics (evidence: `internal/app/app.go`)
- Service runtime → Metrics registry: serves metrics (evidence: `internal/app/app.go`)
