# yukaz0/pocketkafka architecture

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

- Interactive diagram: https://gitdiagram.com/yukaz0/pocketkafka
- Repository: https://github.com/yukaz0/pocketkafka

## Overview

PocketKafka is a single-process Kafka-compatible broker with a Go client SDK, admin CLI, embedded control center, schema registry, and REST/MQTT gateways. The main workflow is a producer or gateway sending Kafka-protocol requests to the broker, which dispatches them to storage or group coordination; consumers fetch records and commit offsets. The graph also preserves documented monitoring, security, compaction, and tiered-storage capabilities. Source excerpts show key wiring; several branches are documented in the README or represented by their exact enclosing directory because their implementation was not sampled.

Main entry points: [`internal/storage/store.go`](https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/store.go) (Commit Log), [`internal/handler/handler.go`](https://github.com/yukaz0/pocketkafka/blob/master/internal/handler/handler.go) (Kafka API Handlers), [`internal/web`](https://github.com/yukaz0/pocketkafka/tree/master/internal/web) (Control Center), [`pkg/client/client.go`](https://github.com/yukaz0/pocketkafka/blob/master/pkg/client/client.go) (Go Client SDK)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_broker["Broker Runtime"]
  node_kafka_listener["Kafka Listener<br/>[server.go]"]
  node_request_dispatch["Request Dispatch<br/>[dispatch.go]"]
  node_api_handlers["Kafka API Handlers<br/>[handler.go]"]
  node_protocol_codec["Protocol Codec"]
end

subgraph group_state["Data And Coordination"]
  node_log_store[("Commit Log<br/>[store.go]")]
  node_partition_engine[("Partitions<br/>[partition.go]")]
  node_group_manager["Group Coordination<br/>[group.go]"]
  node_offset_store[("Committed Offsets<br/>[offset_store.go]")]
end

subgraph group_access["Clients And Gateways"]
  node_client_sdk["Go Client SDK<br/>[client.go]"]
  node_client_groups["Consumer Group SDK<br/>[consumer_group.go]"]
  node_admin_cli["Admin CLI<br/>[main.go]"]
  node_rest_gateway["REST Gateway<br/>[rest.go]"]
  node_mqtt_gateway["MQTT Bridge<br/>[mqtt.go]"]
end

subgraph group_operations["Operations And Security"]
  node_control_center["Control Center"]
  node_web_auth["Web Authentication<br/>[auth.go]"]
  node_acl[("Authorization<br/>[store.go]")]
  node_metrics["Prometheus Metrics<br/>[metrics.go]"]
end

subgraph group_extensions["Registry And Tiering"]
  node_schema_registry["Schema Registry<br/>[schema_registry.go]"]
  node_registry_storage[("Registry Persistence<br/>[storage.go]")]
  node_compaction["Log Compaction<br/>[compaction.go]"]
  node_tiered_storage["S3 Tiered Storage<br/>[s3.go]"]
end

node_producers(("Producers"))
node_consumers(("Consumers"))
node_mqtt_devices(("MQTT Devices"))
node_http_apps(("HTTP Applications"))
node_operator(("Operator"))
node_s3[("S3-Compatible Storage")]

node_producers -->|"send messages"| node_client_sdk
node_consumers -->|"consume messages"| node_client_groups
node_client_groups -->|"uses client"| node_client_sdk
node_admin_cli -->|"issues commands"| node_client_sdk
node_client_sdk -.->|"sends Kafka frames"| node_kafka_listener
node_kafka_listener -->|"dispatches requests"| node_request_dispatch
node_request_dispatch -->|"routes API calls"| node_api_handlers
node_api_handlers -->|"decodes and encodes"| node_protocol_codec
node_kafka_listener -->|"reads and writes frames"| node_protocol_codec
node_api_handlers -->|"reads and appends"| node_log_store
node_api_handlers -->|"coordinates groups"| node_group_manager
node_group_manager -->|"persists offsets"| node_offset_store
node_log_store -.->|"manages partitions"| node_partition_engine
node_http_apps -->|"publishes and consumes"| node_rest_gateway
node_rest_gateway -->|"reads and writes records"| node_log_store
node_mqtt_devices -->|"publishes and subscribes"| node_mqtt_gateway
node_mqtt_gateway -->|"bridges records"| node_log_store
node_mqtt_gateway -->|"checks permissions"| node_acl
node_operator -->|"operates broker"| node_control_center
node_control_center -->|"shows group state"| node_group_manager
node_control_center -->|"shows broker health"| node_log_store
node_control_center -->|"authenticates requests"| node_web_auth
node_web_auth -.->|"uses principals"| node_acl
node_control_center -.->|"exposes monitoring"| node_metrics
node_admin_cli -->|"manages schemas"| node_schema_registry
node_schema_registry -->|"loads and saves"| node_registry_storage
node_api_handlers -->|"configures compaction"| node_compaction
node_log_store -.->|"uses tiered storage"| node_tiered_storage
node_tiered_storage -.->|"stores segments"| node_s3

click node_kafka_listener "https://github.com/yukaz0/pocketkafka/blob/master/internal/server/server.go"
click node_request_dispatch "https://github.com/yukaz0/pocketkafka/blob/master/internal/handler/dispatch.go"
click node_api_handlers "https://github.com/yukaz0/pocketkafka/blob/master/internal/handler/handler.go"
click node_protocol_codec "https://github.com/yukaz0/pocketkafka/tree/master/pkg/protocol"
click node_log_store "https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/store.go"
click node_partition_engine "https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/partition.go"
click node_group_manager "https://github.com/yukaz0/pocketkafka/blob/master/internal/coordinator/group.go"
click node_offset_store "https://github.com/yukaz0/pocketkafka/blob/master/internal/coordinator/offset_store.go"
click node_client_sdk "https://github.com/yukaz0/pocketkafka/blob/master/pkg/client/client.go"
click node_client_groups "https://github.com/yukaz0/pocketkafka/blob/master/pkg/client/consumer_group.go"
click node_admin_cli "https://github.com/yukaz0/pocketkafka/blob/master/cmd/kctl/main.go"
click node_rest_gateway "https://github.com/yukaz0/pocketkafka/blob/master/internal/gateway/rest.go"
click node_mqtt_gateway "https://github.com/yukaz0/pocketkafka/blob/master/internal/gateway/mqtt.go"
click node_control_center "https://github.com/yukaz0/pocketkafka/tree/master/internal/web"
click node_web_auth "https://github.com/yukaz0/pocketkafka/blob/master/internal/web/auth.go"
click node_acl "https://github.com/yukaz0/pocketkafka/blob/master/internal/authz/store.go"
click node_metrics "https://github.com/yukaz0/pocketkafka/blob/master/internal/metrics/metrics.go"
click node_schema_registry "https://github.com/yukaz0/pocketkafka/blob/master/internal/schemaregistry/schema_registry.go"
click node_registry_storage "https://github.com/yukaz0/pocketkafka/blob/master/internal/schemaregistry/storage.go"
click node_compaction "https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/compaction.go"
click node_tiered_storage "https://github.com/yukaz0/pocketkafka/blob/master/internal/tier/s3.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_kafka_listener,node_request_dispatch,node_api_handlers,node_protocol_codec toneBlue
class node_log_store,node_partition_engine,node_group_manager,node_offset_store,node_s3 toneAmber
class node_client_sdk,node_client_groups,node_admin_cli,node_rest_gateway,node_mqtt_gateway toneMint
class node_control_center,node_web_auth,node_acl,node_metrics toneRose
class node_schema_registry,node_registry_storage,node_compaction,node_tiered_storage,node_producers,node_consumers,node_mqtt_devices,node_http_apps,node_operator toneIndigo
```

## Components

### Broker Runtime

- [Kafka Listener](https://github.com/yukaz0/pocketkafka/blob/master/internal/server/server.go): `internal/server/server.go`
- [Request Dispatch](https://github.com/yukaz0/pocketkafka/blob/master/internal/handler/dispatch.go): `internal/handler/dispatch.go`
- [Kafka API Handlers](https://github.com/yukaz0/pocketkafka/blob/master/internal/handler/handler.go): `internal/handler/handler.go`
- [Protocol Codec](https://github.com/yukaz0/pocketkafka/tree/master/pkg/protocol): `pkg/protocol`

### Data And Coordination

- [Commit Log](https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/store.go): `internal/storage/store.go`
- [Partitions](https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/partition.go): `internal/storage/partition.go`
- [Group Coordination](https://github.com/yukaz0/pocketkafka/blob/master/internal/coordinator/group.go): `internal/coordinator/group.go`
- [Committed Offsets](https://github.com/yukaz0/pocketkafka/blob/master/internal/coordinator/offset_store.go): `internal/coordinator/offset_store.go`

### Clients And Gateways

- [Go Client SDK](https://github.com/yukaz0/pocketkafka/blob/master/pkg/client/client.go): `pkg/client/client.go`
- [Consumer Group SDK](https://github.com/yukaz0/pocketkafka/blob/master/pkg/client/consumer_group.go): `pkg/client/consumer_group.go`
- [Admin CLI](https://github.com/yukaz0/pocketkafka/blob/master/cmd/kctl/main.go): `cmd/kctl/main.go`
- [REST Gateway](https://github.com/yukaz0/pocketkafka/blob/master/internal/gateway/rest.go): `internal/gateway/rest.go`
- [MQTT Bridge](https://github.com/yukaz0/pocketkafka/blob/master/internal/gateway/mqtt.go): `internal/gateway/mqtt.go`

### Operations And Security

- [Control Center](https://github.com/yukaz0/pocketkafka/tree/master/internal/web): `internal/web`
- [Web Authentication](https://github.com/yukaz0/pocketkafka/blob/master/internal/web/auth.go): `internal/web/auth.go`
- [Authorization](https://github.com/yukaz0/pocketkafka/blob/master/internal/authz/store.go): `internal/authz/store.go`
- [Prometheus Metrics](https://github.com/yukaz0/pocketkafka/blob/master/internal/metrics/metrics.go): `internal/metrics/metrics.go`

### Registry And Tiering

- [Schema Registry](https://github.com/yukaz0/pocketkafka/blob/master/internal/schemaregistry/schema_registry.go): `internal/schemaregistry/schema_registry.go`
- [Registry Persistence](https://github.com/yukaz0/pocketkafka/blob/master/internal/schemaregistry/storage.go): `internal/schemaregistry/storage.go`
- [Log Compaction](https://github.com/yukaz0/pocketkafka/blob/master/internal/storage/compaction.go): `internal/storage/compaction.go`
- [S3 Tiered Storage](https://github.com/yukaz0/pocketkafka/blob/master/internal/tier/s3.go): `internal/tier/s3.go`

### Other components

- **Producers**
- **Consumers**
- **MQTT Devices**
- **HTTP Applications**
- **Operator**
- **S3-Compatible Storage**

## Connections

- Producers → Go Client SDK: send messages (evidence: `README.md`)
- Consumers → Consumer Group SDK: consume messages (evidence: `README.md`)
- Consumer Group SDK → Go Client SDK: uses client (evidence: `pkg/client/consumer_group.go`)
- Admin CLI → Go Client SDK: issues commands (evidence: `cmd/kctl/main.go`)
- Go Client SDK → Kafka Listener: sends Kafka frames (evidence: `README.md`)
- Kafka Listener → Request Dispatch: dispatches requests (evidence: `internal/server/server.go`)
- Request Dispatch → Kafka API Handlers: routes API calls (evidence: `internal/handler/dispatch.go`)
- Kafka API Handlers → Protocol Codec: decodes and encodes (evidence: `internal/handler/handler.go`)
- Kafka Listener → Protocol Codec: reads and writes frames (evidence: `internal/server/server.go`)
- Kafka API Handlers → Commit Log: reads and appends (evidence: `internal/handler/handler.go`)
- Kafka API Handlers → Group Coordination: coordinates groups (evidence: `internal/handler/handler.go`)
- Group Coordination → Committed Offsets: persists offsets (evidence: `internal/coordinator/group.go`)
- Commit Log → Partitions: manages partitions
- HTTP Applications → REST Gateway: publishes and consumes (evidence: `README.md`)
- REST Gateway → Commit Log: reads and writes records (evidence: `internal/gateway/rest.go`)
- MQTT Devices → MQTT Bridge: publishes and subscribes (evidence: `README.md`)
- MQTT Bridge → Commit Log: bridges records (evidence: `internal/gateway/mqtt.go`)
- MQTT Bridge → Authorization: checks permissions (evidence: `internal/gateway/mqtt.go`)
- Operator → Control Center: operates broker (evidence: `README.md`)
- Control Center → Group Coordination: shows group state (evidence: `internal/web/monitor.go`)
- Control Center → Commit Log: shows broker health (evidence: `internal/web/monitor.go`)
- Control Center → Web Authentication: authenticates requests (evidence: `internal/web/auth.go`)
- Web Authentication → Authorization: uses principals
- Control Center → Prometheus Metrics: exposes monitoring (evidence: `README.md`)
- Admin CLI → Schema Registry: manages schemas (evidence: `README.md`)
- Schema Registry → Registry Persistence: loads and saves (evidence: `internal/schemaregistry/storage.go`)
- Kafka API Handlers → Log Compaction: configures compaction (evidence: `internal/handler/handler.go`)
- Commit Log → S3 Tiered Storage: uses tiered storage (evidence: `README.md`)
- S3 Tiered Storage → S3-Compatible Storage: stores segments (evidence: `README.md`)
