# tq-ngo/kafka-go architecture

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

- Interactive diagram: https://gitdiagram.com/tq-ngo/kafka-go
- Repository: https://github.com/tq-ngo/kafka-go

## Overview

This is a small Kafka-like message-broker prototype. The main workflow is to start a broker, register producers and consumers for topics (and consumer groups), route producer messages into queues, then deliver queued messages to consumers that signal readiness. Topics, groups, partitions, and queues are distinct domain stages; the wire protocol and file-backed queue are useful internal layers. The README is empty, so capabilities and relationships here are based on the shown source; unsampled files are not assumed to add behavior.

Main entry points: [`broker.go`](https://github.com/tq-ngo/kafka-go/blob/main/broker.go) (Broker server), [`main.go`](https://github.com/tq-ngo/kafka-go/blob/main/main.go) (Command entry), [`producer.go`](https://github.com/tq-ngo/kafka-go/blob/main/producer.go) (Producer client), [`consumer.go`](https://github.com/tq-ngo/kafka-go/blob/main/consumer.go) (Consumer client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and protocol"]
  node_entry["Command entry<br/>[main.go]"]
  node_broker["Broker server<br/>[broker.go]"]
  node_wire["Wire messages<br/>[message.go]"]
  node_producer["Producer client<br/>[producer.go]"]
  node_consumer["Consumer client<br/>[consumer.go]"]
end

subgraph group_routing["Message routing"]
  node_topic["Topic registry<br/>[topic.go]"]
  node_cgroup["Consumer groups<br/>[cgroup.go]"]
  node_partition["Partitions<br/>[partition.go]"]
  node_backlog["Topic backlog<br/>[topic.go]"]
end

subgraph group_storage["Persistent storage"]
  node_queue[("Persistent queue<br/>[queue.go]")]
end

node_operator(("Process operator"))
node_filesystem[("Local files")]

node_operator -->|"starts process"| node_entry
node_entry -->|"starts broker"| node_broker
node_entry -->|"starts producer"| node_producer
node_entry -->|"starts consumer"| node_consumer
node_producer -->|"registers and sends"| node_broker
node_consumer -->|"registers"| node_broker
node_broker -->|"connects for data"| node_producer
node_broker -->|"connects for delivery"| node_consumer
node_producer -->|"encodes messages"| node_wire
node_consumer -->|"encodes messages"| node_wire
node_broker -->|"reads and writes"| node_wire
node_broker -->|"initializes topics"| node_topic
node_broker -->|"creates groups"| node_cgroup
node_broker -->|"creates partitions"| node_partition
node_broker -->|"buffers messages"| node_backlog
node_broker -->|"enqueues and dequeues"| node_queue
node_topic -->|"initializes backlog"| node_queue
node_cgroup -->|"restores partitions"| node_partition
node_partition -->|"initializes queue"| node_queue
node_broker -->|"stores topic metadata"| node_filesystem
node_topic -->|"stores group metadata"| node_filesystem
node_cgroup -->|"stores partition metadata"| node_filesystem
node_queue -->|"maps queue files"| node_filesystem

click node_entry "https://github.com/tq-ngo/kafka-go/blob/main/main.go"
click node_broker "https://github.com/tq-ngo/kafka-go/blob/main/broker.go"
click node_wire "https://github.com/tq-ngo/kafka-go/blob/main/message.go"
click node_producer "https://github.com/tq-ngo/kafka-go/blob/main/producer.go"
click node_consumer "https://github.com/tq-ngo/kafka-go/blob/main/consumer.go"
click node_topic "https://github.com/tq-ngo/kafka-go/blob/main/topic.go"
click node_cgroup "https://github.com/tq-ngo/kafka-go/blob/main/cgroup.go"
click node_partition "https://github.com/tq-ngo/kafka-go/blob/main/partition.go"
click node_backlog "https://github.com/tq-ngo/kafka-go/blob/main/topic.go"
click node_queue "https://github.com/tq-ngo/kafka-go/blob/main/queue.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_entry,node_broker,node_wire,node_producer,node_consumer toneBlue
class node_topic,node_cgroup,node_partition,node_backlog,node_filesystem toneAmber
class node_queue toneMint
class node_operator toneIndigo
```

## Components

### Runtime and protocol

- [Command entry](https://github.com/tq-ngo/kafka-go/blob/main/main.go): `main.go`
- [Broker server](https://github.com/tq-ngo/kafka-go/blob/main/broker.go): `broker.go`
- [Wire messages](https://github.com/tq-ngo/kafka-go/blob/main/message.go): `message.go`
- [Producer client](https://github.com/tq-ngo/kafka-go/blob/main/producer.go): `producer.go`
- [Consumer client](https://github.com/tq-ngo/kafka-go/blob/main/consumer.go): `consumer.go`

### Message routing

- [Topic registry](https://github.com/tq-ngo/kafka-go/blob/main/topic.go): `topic.go`
- [Consumer groups](https://github.com/tq-ngo/kafka-go/blob/main/cgroup.go): `cgroup.go`
- [Partitions](https://github.com/tq-ngo/kafka-go/blob/main/partition.go): `partition.go`
- [Topic backlog](https://github.com/tq-ngo/kafka-go/blob/main/topic.go): `topic.go`

### Persistent storage

- [Persistent queue](https://github.com/tq-ngo/kafka-go/blob/main/queue.go): `queue.go`

### Other components

- **Process operator**
- **Local files**

## Connections

- Process operator → Command entry: starts process (evidence: `main.go`)
- Command entry → Broker server: starts broker (evidence: `main.go`)
- Command entry → Producer client: starts producer (evidence: `main.go`)
- Command entry → Consumer client: starts consumer (evidence: `main.go`)
- Producer client → Broker server: registers and sends (evidence: `producer.go`)
- Consumer client → Broker server: registers (evidence: `consumer.go`)
- Broker server → Producer client: connects for data (evidence: `broker.go`)
- Broker server → Consumer client: connects for delivery (evidence: `broker.go`)
- Producer client → Wire messages: encodes messages (evidence: `producer.go`)
- Consumer client → Wire messages: encodes messages (evidence: `consumer.go`)
- Broker server → Wire messages: reads and writes (evidence: `broker.go`)
- Broker server → Topic registry: initializes topics (evidence: `broker.go`)
- Broker server → Consumer groups: creates groups (evidence: `broker.go`)
- Broker server → Partitions: creates partitions (evidence: `broker.go`)
- Broker server → Topic backlog: buffers messages (evidence: `broker.go`)
- Broker server → Persistent queue: enqueues and dequeues (evidence: `broker.go`)
- Topic registry → Persistent queue: initializes backlog (evidence: `topic.go`)
- Consumer groups → Partitions: restores partitions (evidence: `cgroup.go`)
- Partitions → Persistent queue: initializes queue (evidence: `partition.go`)
- Broker server → Local files: stores topic metadata (evidence: `broker.go`)
- Topic registry → Local files: stores group metadata (evidence: `topic.go`)
- Consumer groups → Local files: stores partition metadata (evidence: `cgroup.go`)
- Persistent queue → Local files: maps queue files (evidence: `queue.go`)
