# cloudflare/goflow architecture

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

- Interactive diagram: https://gitdiagram.com/cloudflare/goflow
- Repository: https://github.com/cloudflare/goflow

## Overview

GoFlow is a UDP collector for NetFlow v5, NetFlow v9/IPFIX, and sFlow v5. Its principal workflow receives packets, decodes protocol-specific records (including NetFlow templates and options), converts samples into a shared protobuf flow message, then publishes through Kafka or console transports. The multi-protocol CLI starts collector states and exposes metrics and NetFlow template information. README capabilities are represented where source details were not sampled; links without direct evidence are omitted.

Main entry points: [`utils/netflow.go`](https://github.com/cloudflare/goflow/blob/master/utils/netflow.go) (NetFlow state), [`utils/sflow.go`](https://github.com/cloudflare/goflow/blob/master/utils/sflow.go) (sFlow state), [`utils/nflegacy.go`](https://github.com/cloudflare/goflow/blob/master/utils/nflegacy.go) (v5 state), [`utils/utils.go`](https://github.com/cloudflare/goflow/blob/master/utils/utils.go) (Transport selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Collector entrypoints"]
  node_multicli["Multi-protocol CLI<br/>[goflow.go]"]
  node_nfclic["NetFlow CLI<br/>[cnetflow.go]"]
  node_legacycli["NetFlow v5 CLI<br/>[cnflegacy.go]"]
  node_sfcli["sFlow CLI<br/>[csflow.go]"]
  node_nfstate["NetFlow state<br/>[netflow.go]"]
  node_legacy_state["v5 state<br/>[nflegacy.go]"]
  node_sfstate["sFlow state<br/>[sflow.go]"]
end

subgraph group_protocol["Protocol decoding"]
  node_nfdecode["NetFlow v9/IPFIX decoder<br/>[netflow.go]"]
  node_legacydecode["NetFlow v5 decoder<br/>[netflow.go]"]
  node_sfdecode["sFlow v5 decoder<br/>[sflow.go]"]
  node_template[("Template handling<br/>[netflow.go]")]
end

subgraph group_flows["Flow production"]
  node_nfproduce["NetFlow producer<br/>[producer_nf.go]"]
  node_legacyproduce["v5 producer"]
  node_sfproduce["sFlow producer<br/>[producer_sf.go]"]
  node_protobuf["Flow protobuf<br/>[flow.proto]"]
end

subgraph group_output["Output and monitoring"]
  node_transport["Transport selection<br/>[utils.go]"]
  node_kafka["Kafka publisher<br/>[kafka.go]"]
  node_console["Console output<br/>[utils.go]"]
  node_metrics["Prometheus metrics<br/>[metrics.go]"]
  node_monitor_http["Metrics and templates HTTP<br/>[goflow.go]"]
end

node_devices(("Flow exporters"))
node_kafkasvc[("Kafka brokers")]
node_prometheus(("Prometheus scraper"))

node_devices -->|"send UDP"| node_multicli
node_multicli -->|"starts collectors"| node_nfstate
node_multicli -->|"starts collectors"| node_sfstate
node_multicli -->|"starts collectors"| node_legacy_state
node_nfclic -->|"starts collector"| node_nfstate
node_legacycli -->|"starts collector"| node_legacy_state
node_sfcli -->|"starts collector"| node_sfstate
node_nfstate -->|"decodes packet"| node_nfdecode
node_nfstate -->|"maintains templates"| node_template
node_nfstate -->|"converts records"| node_nfproduce
node_legacy_state -->|"decodes packet"| node_legacydecode
node_legacy_state -->|"converts records"| node_legacyproduce
node_sfstate -->|"decodes packet"| node_sfdecode
node_sfstate -->|"processes samples"| node_sfproduce
node_nfproduce -->|"builds messages"| node_protobuf
node_legacyproduce -->|"builds messages"| node_protobuf
node_sfproduce -->|"builds messages"| node_protobuf
node_nfstate -->|"publishes flows"| node_transport
node_legacy_state -->|"publishes flows"| node_transport
node_sfstate -->|"publishes flows"| node_transport
node_transport -->|"selects publisher"| node_kafka
node_transport -->|"selects fallback"| node_console
node_kafka -->|"serializes messages"| node_protobuf
node_kafka -->|"sends records"| node_kafkasvc
node_monitor_http -->|"serves metrics"| node_metrics
node_monitor_http -->|"serves template view"| node_template
node_prometheus -.->|"scrapes metrics"| node_monitor_http
node_nfstate -->|"records decode stats"| node_metrics
node_sfstate -->|"records decode stats"| node_metrics

click node_multicli "https://github.com/cloudflare/goflow/blob/master/cmd/goflow/goflow.go"
click node_nfclic "https://github.com/cloudflare/goflow/blob/master/cmd/cnetflow/cnetflow.go"
click node_legacycli "https://github.com/cloudflare/goflow/blob/master/cmd/cnflegacy/cnflegacy.go"
click node_sfcli "https://github.com/cloudflare/goflow/blob/master/cmd/csflow/csflow.go"
click node_nfstate "https://github.com/cloudflare/goflow/blob/master/utils/netflow.go"
click node_legacy_state "https://github.com/cloudflare/goflow/blob/master/utils/nflegacy.go"
click node_sfstate "https://github.com/cloudflare/goflow/blob/master/utils/sflow.go"
click node_nfdecode "https://github.com/cloudflare/goflow/blob/master/decoders/netflow/netflow.go"
click node_legacydecode "https://github.com/cloudflare/goflow/blob/master/decoders/netflowlegacy/netflow.go"
click node_sfdecode "https://github.com/cloudflare/goflow/blob/master/decoders/sflow/sflow.go"
click node_template "https://github.com/cloudflare/goflow/blob/master/decoders/netflow/netflow.go"
click node_nfproduce "https://github.com/cloudflare/goflow/blob/master/producer/producer_nf.go"
click node_legacyproduce "https://github.com/cloudflare/goflow/blob/master/producer/producer_nflegacy.go"
click node_sfproduce "https://github.com/cloudflare/goflow/blob/master/producer/producer_sf.go"
click node_protobuf "https://github.com/cloudflare/goflow/blob/master/pb/flow.proto"
click node_transport "https://github.com/cloudflare/goflow/blob/master/utils/utils.go"
click node_kafka "https://github.com/cloudflare/goflow/blob/master/transport/kafka.go"
click node_console "https://github.com/cloudflare/goflow/blob/master/utils/utils.go"
click node_metrics "https://github.com/cloudflare/goflow/blob/master/utils/metrics.go"
click node_monitor_http "https://github.com/cloudflare/goflow/blob/master/cmd/goflow/goflow.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_multicli,node_nfclic,node_legacycli,node_sfcli,node_nfstate,node_legacy_state,node_sfstate toneBlue
class node_nfdecode,node_legacydecode,node_sfdecode,node_template,node_kafkasvc toneAmber
class node_nfproduce,node_legacyproduce,node_sfproduce,node_protobuf toneMint
class node_transport,node_kafka,node_console,node_metrics,node_monitor_http toneRose
class node_devices,node_prometheus toneIndigo
```

## Components

### Collector entrypoints

- [Multi-protocol CLI](https://github.com/cloudflare/goflow/blob/master/cmd/goflow/goflow.go): `cmd/goflow/goflow.go`
- [NetFlow CLI](https://github.com/cloudflare/goflow/blob/master/cmd/cnetflow/cnetflow.go): `cmd/cnetflow/cnetflow.go`
- [NetFlow v5 CLI](https://github.com/cloudflare/goflow/blob/master/cmd/cnflegacy/cnflegacy.go): `cmd/cnflegacy/cnflegacy.go`
- [sFlow CLI](https://github.com/cloudflare/goflow/blob/master/cmd/csflow/csflow.go): `cmd/csflow/csflow.go`
- [NetFlow state](https://github.com/cloudflare/goflow/blob/master/utils/netflow.go): `utils/netflow.go`
- [v5 state](https://github.com/cloudflare/goflow/blob/master/utils/nflegacy.go): `utils/nflegacy.go`
- [sFlow state](https://github.com/cloudflare/goflow/blob/master/utils/sflow.go): `utils/sflow.go`

### Protocol decoding

- [NetFlow v9/IPFIX decoder](https://github.com/cloudflare/goflow/blob/master/decoders/netflow/netflow.go): `decoders/netflow/netflow.go`
- [NetFlow v5 decoder](https://github.com/cloudflare/goflow/blob/master/decoders/netflowlegacy/netflow.go): `decoders/netflowlegacy/netflow.go`
- [sFlow v5 decoder](https://github.com/cloudflare/goflow/blob/master/decoders/sflow/sflow.go): `decoders/sflow/sflow.go`
- [Template handling](https://github.com/cloudflare/goflow/blob/master/decoders/netflow/netflow.go): `decoders/netflow/netflow.go`

### Flow production

- [NetFlow producer](https://github.com/cloudflare/goflow/blob/master/producer/producer_nf.go): `producer/producer_nf.go`
- [v5 producer](https://github.com/cloudflare/goflow/blob/master/producer/producer_nflegacy.go): `producer/producer_nflegacy.go`
- [sFlow producer](https://github.com/cloudflare/goflow/blob/master/producer/producer_sf.go): `producer/producer_sf.go`
- [Flow protobuf](https://github.com/cloudflare/goflow/blob/master/pb/flow.proto): `pb/flow.proto`

### Output and monitoring

- [Transport selection](https://github.com/cloudflare/goflow/blob/master/utils/utils.go): `utils/utils.go`
- [Kafka publisher](https://github.com/cloudflare/goflow/blob/master/transport/kafka.go): `transport/kafka.go`
- [Console output](https://github.com/cloudflare/goflow/blob/master/utils/utils.go): `utils/utils.go`
- [Prometheus metrics](https://github.com/cloudflare/goflow/blob/master/utils/metrics.go): `utils/metrics.go`
- [Metrics and templates HTTP](https://github.com/cloudflare/goflow/blob/master/cmd/goflow/goflow.go): `cmd/goflow/goflow.go`

### Other components

- **Flow exporters**
- **Kafka brokers**
- **Prometheus scraper**

## Connections

- Flow exporters → Multi-protocol CLI: send UDP (evidence: `README.md`)
- Multi-protocol CLI → NetFlow state: starts collectors (evidence: `cmd/goflow/goflow.go`)
- Multi-protocol CLI → sFlow state: starts collectors (evidence: `cmd/goflow/goflow.go`)
- Multi-protocol CLI → v5 state: starts collectors (evidence: `cmd/goflow/goflow.go`)
- NetFlow CLI → NetFlow state: starts collector (evidence: `cmd/cnetflow/cnetflow.go`)
- NetFlow v5 CLI → v5 state: starts collector (evidence: `cmd/cnflegacy/cnflegacy.go`)
- sFlow CLI → sFlow state: starts collector (evidence: `cmd/csflow/csflow.go`)
- NetFlow state → NetFlow v9/IPFIX decoder: decodes packet (evidence: `utils/netflow.go`)
- NetFlow state → Template handling: maintains templates (evidence: `utils/netflow.go`)
- NetFlow state → NetFlow producer: converts records (evidence: `producer/producer_nf.go`)
- v5 state → NetFlow v5 decoder: decodes packet (evidence: `utils/nflegacy.go`)
- v5 state → v5 producer: converts records (evidence: `utils/nflegacy.go`)
- sFlow state → sFlow v5 decoder: decodes packet (evidence: `utils/sflow.go`)
- sFlow state → sFlow producer: processes samples (evidence: `utils/sflow.go`)
- NetFlow producer → Flow protobuf: builds messages (evidence: `producer/producer_nf.go`)
- v5 producer → Flow protobuf: builds messages (evidence: `producer/producer_nflegacy.go`)
- sFlow producer → Flow protobuf: builds messages (evidence: `producer/producer_sf.go`)
- NetFlow state → Transport selection: publishes flows (evidence: `utils/netflow.go`)
- v5 state → Transport selection: publishes flows (evidence: `utils/nflegacy.go`)
- sFlow state → Transport selection: publishes flows (evidence: `utils/sflow.go`)
- Transport selection → Kafka publisher: selects publisher
- Transport selection → Console output: selects fallback (evidence: `utils/utils.go`)
- Kafka publisher → Flow protobuf: serializes messages (evidence: `transport/kafka.go`)
- Kafka publisher → Kafka brokers: sends records (evidence: `transport/kafka.go`)
- Metrics and templates HTTP → Prometheus metrics: serves metrics (evidence: `cmd/goflow/goflow.go`)
- Metrics and templates HTTP → Template handling: serves template view (evidence: `cmd/goflow/goflow.go`)
- Prometheus scraper → Metrics and templates HTTP: scrapes metrics (evidence: `README.md`)
- NetFlow state → Prometheus metrics: records decode stats (evidence: `utils/netflow.go`)
- sFlow state → Prometheus metrics: records decode stats (evidence: `utils/sflow.go`)
