# fgrosse/kafkactl architecture

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

- Interactive diagram: https://gitdiagram.com/fgrosse/kafkactl
- Repository: https://github.com/fgrosse/kafkactl

## Overview

##### Main Components

a. Core Components:
- Command Line Interface (CLI) Layer
- Configuration Management
- Kafka Interaction Layer
- Message Processing Layer
- Schema Support Layer

b. External Systems:
- Apache Kafka Cluster
- Schema Registry (for Avro support)

**┌─ CLI Layer (User Interface) ─────────────────────────┐**

- ┌─ Command Groups ──────────────────────────┐      │
- Config/Context Management               │      │
- Resource Operations (Create/Get/Delete) │      │
- Message Operations (Consume/Produce)    │      │

- ┬───────────────────────────────┘

**┌──────────────────────▼───────────────────────────────┐**
- Configuration Management Layer                       │
- Context handling                                  │
- Broker configurations                             │
- ┬───────────────────────────────┘

**┌──────────────────────▼───────────────────────────────┐**
- Core Processing Layer                               │
- ┌─ Message Processing ─┐  ┌─ Schema Handling ─┐    │
- Encoder           │  │ - Avro Support     │    │
- Decoder          │  │ - Protobuf Support │    │
- ┘  └──────────────────────    │
- ┬───────────────────────────────┘

**┌──────────────────────▼───────────────────────────────┐**
- Kafka Interaction Layer                             │
- Consumer Operations                               │
- Producer Operations                               │
- Admin Operations                                  │
- ┬───────────────────────────────┘

**┌──────────────────────▼───────────────────────────────┐**
- External Systems                                    │
- ┌─ Kafka Cluster ─┐  ┌─ Schema Registry ─┐         │

- ┘  └───────────────────┘         │
- ┘

##### Important Details to Highlight

a. Command Structure:
- Hierarchical command structure (root → command groups → specific commands)
- Main command categories: config, context, create, delete, get, update, consume, produce, replay

b. Data Flow:
- How commands flow from CLI through the processing layers
- How configuration context affects operations
- Demonstrate message flow for produce/consume operations

c. Integration Points:
- Connection points with Kafka brokers
- Schema Registry integration for Avro support
- Protobuf message handling

##### Implementation Details

- cmd/* files represent the CLI command structure
- internal/* contains the core processing logic
- How the configuration management (from internal/config.go) interfaces with the system
- Message encoding/decoding capabilities (internal/encoder.go, internal/decoder.go)
- Consumer group handling (internal/consumer_group.go)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI["CLI Layer"]
        direction TB
        Root["Root Command"]
        ConfigCmd["Config Commands"]
        ContextCmd["Context Commands"]
        CreateCmd["Create Commands"]
        DeleteCmd["Delete Commands"]
        GetCmd["Get Commands"]
        ProduceCmd["Produce Commands"]
        ConsumeCmd["Consume Commands"]
        ReplayCmd["Replay Commands"]
        
        Root --> ConfigCmd
        Root --> ContextCmd
        Root --> CreateCmd
        Root --> DeleteCmd
        Root --> GetCmd
        Root --> ProduceCmd
        Root --> ConsumeCmd
        Root --> ReplayCmd
    end

    subgraph Config["Configuration Management Layer"]
        ConfigHandler["Core Config Handler"]
        ConfigProcessor["Config Processor"]
    end

    subgraph Core["Core Processing Layer"]
        Encoder["Message Encoder"]
        Decoder["Message Decoder"]
        AvroHandler["Avro Support"]
        ProtoHandler["Protobuf Support"]
    end

    subgraph Kafka["Kafka Interaction Layer"]
        Consumer["Consumer Handler"]
        ConsumerGroup["Consumer Group Handler"]
        OffsetConsumer["Offset Consumer"]
        RangeConsumer["Range Consumer"]
        DataFetcher["Data Fetcher"]
    end

    subgraph External["External Systems"]
        KafkaCluster["Apache Kafka Cluster"]
        SchemaRegistry["Schema Registry"]
    end

    CLI --> Config
    Config --> Core
    Core --> Kafka
    Kafka --> External
    Core --> SchemaRegistry

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef cli fill:#b3d1ff,stroke:#333
    classDef config fill:#d9d9d9,stroke:#333
    classDef core fill:#90EE90,stroke:#333
    classDef kafka fill:#b3d1ff,stroke:#333
    classDef external fill:#ffb366,stroke:#333

    class Root,ConfigCmd,ContextCmd,CreateCmd,DeleteCmd,GetCmd,ProduceCmd,ConsumeCmd,ReplayCmd cli
    class ConfigHandler,ConfigProcessor config
    class Encoder,Decoder,AvroHandler,ProtoHandler core
    class Consumer,ConsumerGroup,OffsetConsumer,RangeConsumer,DataFetcher kafka
    class KafkaCluster,SchemaRegistry external

    click Root "https://github.com/fgrosse/kafkactl/blob/main/cmd/root.go"
    click ConfigCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/config"
    click ContextCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/context"
    click CreateCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/create"
    click DeleteCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/delete"
    click GetCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/get"
    click ProduceCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/produce"
    click ConsumeCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/consume"
    click ReplayCmd "https://github.com/fgrosse/kafkactl/tree/main/cmd/replay"
    click ConfigHandler "https://github.com/fgrosse/kafkactl/blob/main/internal/config.go"
    click Encoder "https://github.com/fgrosse/kafkactl/blob/main/internal/encoder.go"
    click Decoder "https://github.com/fgrosse/kafkactl/blob/main/internal/decoder.go"
    click AvroHandler "https://github.com/fgrosse/kafkactl/blob/main/internal/avro.go"
    click ProtoHandler "https://github.com/fgrosse/kafkactl/blob/main/internal/proto.go"
    click Consumer "https://github.com/fgrosse/kafkactl/blob/main/internal/consumer.go"
    click ConsumerGroup "https://github.com/fgrosse/kafkactl/blob/main/internal/consumer_group.go"
    click OffsetConsumer "https://github.com/fgrosse/kafkactl/blob/main/internal/offset_consumer.go"
    click RangeConsumer "https://github.com/fgrosse/kafkactl/blob/main/internal/range_consumer.go"
    click DataFetcher "https://github.com/fgrosse/kafkactl/blob/main/internal/fetch.go"
    click SchemaRegistry "https://github.com/fgrosse/kafkactl/blob/main/internal/schema_registry.go"
```
