# svadithya/kafkastudy architecture

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

- Interactive diagram: https://gitdiagram.com/svadithya/kafkastudy
- Repository: https://github.com/svadithya/kafkastudy

## Overview

##### Project Type & Purpose
- The project is a Spring Boot application (as indicated by the Maven structure and main Java class) that focuses on learning/investing Kafka – specifically, it appears to handle Kafka “kraft” (the new Kafka consensus mode) functionalities.
- The README describes various deployment aspects using Podman, Docker Compose, and Kubernetes, along with Kafka command examples for producing and consuming messages. This tells us that the application is designed for both local and containerized/cloud deployments, with integrations for monitoring (Prometheus, Grafana), logging (MongoDB interceptor and repository), and messaging via Kafka.

##### Key Components (as inferred from the file structure)
- Application (Spring Boot) Server:
- Main entry point: KafkaStudyApplication.
- Configuration components – e.g., KafkaConsumerConfiguration.
- Controllers (like the HealthController) exposing REST endpoints.
- Kafka listeners (both reactive and regular listeners) that subscribe to topics and process messages.
- Support modules such as interceptors (MongoLogInterceptor), health indicators (AppHealthIndicator), exception handling (GlobalExceptionHandler), and utility classes.
- A Repository layer (SuccessMessageRepository and corresponding DTO) for persisting or tracking successful processed messages.

- Messaging Infrastructure:
- Apache Kafka Broker (running with the Kraft configuration). It is responsible for managing topics (e.g., “my-topic”) and facilitating the publish/subscribe interactions between external producers and the application’s listeners.

- Data Persistence & Logging:
- MongoDB appears to be integrated (as seen by the MongoLogInterceptor and connection scripts in the README) to log messages or application events.

- Monitoring & CI/CD Tools:
- Prometheus and Grafana deployments (their YAML configurations exist in the deploy/k8s folder), which are used for collecting and visualizing metrics.
- GitHub Actions workflows (under .github/workflows) indicate CI/CD automation, including notifications (Slack integration).

- Deployment & Orchestration:
- Several deployment strategies are supported: Docker Compose, Podman, and Kubernetes (with deployment YAML files, kustomization, and conversion scripts for Kompose).
- The deploy folder shows dedicated scripts and configuration for deploying the application and its associated resources.

##### Relationships and Interactions
- External producers or command-line Kafka clients produce messages to the Kafka topic.
- The Kafka broker receives these messages and the application’s Kafka listeners (both reactive and regular) subscribe to the topic.
- After processing, the application may persist/record successful outcomes through its repository layer (interacting with MongoDB) and expose health information via controllers and health indicators.
- Monitoring tools (Prometheus and Grafana) scrape metrics from the application, while GitHub workflows manage CI/CD and deployment, sending notifications through Slack.
- The whole system is designed to be containerized and managed through Docker/Podman/Kubernetes.

##### Architectural Patterns & Design Principles
- Layered Architecture: Separates concerns across controllers, services/configuration, exception handling, listeners, repositories, and utilities.
- Event-Driven Messaging: Uses Kafka for decoupled message-passing between producers and consumers.
- Containerization & Orchestration: Emphasizes deployment flexibility through Docker, Podman, and Kubernetes configurations.
- Observability: Integrates monitoring and logging (Prometheus, Grafana, MongoDB logs) to ensure visibility in production.

##### Elements

- You capture monitoring and CI/CD flows and any additional external integrations (e.g., Slack notifications).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Layer
    subgraph "External Layer"
        EP("External Producer (Kafka CLI)"):::kafka
    end

    %% Messaging Broker Layer
    subgraph "Messaging Broker Layer"
        KB("Kafka Broker (Apache Kafka - Kraft)"):::kafka
        click KB "https://github.com/svadithya/kafkastudy/blob/main/deploy/k8s/kafka-deployment.yaml"
    end

    %% Application Layer (Spring Boot Application)
    subgraph "Application Layer (Spring Boot)"
        SBA("KafkaStudyApplication (Main Entry)"):::springboot
        click SBA "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/KafkaStudyApplication.java"

        KCC("KafkaConsumerConfiguration"):::springboot
        click KCC "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/config/KafkaConsumerConfiguration.java"

        subgraph "REST Controllers"
            HC("HealthController"):::springboot
            click HC "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/controller/HealthController.java"
            AS("AppService"):::springboot
            click AS "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/controller/model/AppService.java"
        end

        subgraph "Kafka Listeners"
            RKL("ReactiveKafkaListener"):::springboot
            click RKL "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/listener/ReactiveKafkaListener.java"
            RGL("RegularKafkaListener"):::springboot
            click RGL "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/listener/RegularKafkaListener.java"
        end

        subgraph "Exception Handling"
            GEH("GlobalExceptionHandler"):::springboot
            click GEH "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/exception/handler/GlobalExceptionHandler.java"
            EC("ExceptionCode"):::springboot
            click EC "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/exception/ExceptionCode.java"
        end

        HI("AppHealthIndicator"):::springboot
        click HI "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/health/AppHealthIndicator.java"

        ML("MongoLogInterceptor"):::springboot
        click ML "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/interceptor/MongoLogInterceptor.java"

        subgraph "Repository Layer"
            SMR("SuccessMessageRepository"):::springboot
            click SMR "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/repository/SuccessMessageRepository.java"
            SM("SuccessMessage DTO"):::springboot
            click SM "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/repository/dto/SuccessMessage.java"
        end

        HU("HeaderUtil (Utility)"):::springboot
        click HU "https://github.com/svadithya/kafkastudy/blob/main/src/main/java/com/kafka/learn/kafkastudy/util/HeaderUtil.java"
    end

    %% Persistence & Logging Layer
    subgraph "Persistence & Logging Layer"
        MONGODB("MongoDB"):::mongodb
        click MONGODB "https://github.com/svadithya/kafkastudy/blob/main/deploy/k8s/mongodb-deployment.yaml"
    end

    %% Monitoring & Metrics
    subgraph "Monitoring & Metrics"
        PROM("Prometheus"):::monitoring
        click PROM "https://github.com/svadithya/kafkastudy/blob/main/deploy/k8s/prometheus-deployment.yaml"
        GRAF("Grafana"):::monitoring
        click GRAF "https://github.com/svadithya/kafkastudy/blob/main/deploy/k8s/grafana-deployment.yaml"
    end

    %% CI/CD & Deployment
    subgraph "CI/CD & Deployment"
        GHA("GitHub Actions CI/CD"):::deployment
        click GHA "https://github.com/svadithya/kafkastudy/blob/main/.github/workflows/main.yml"
        DC("Docker Compose & Kubernetes Deployments"):::deployment
        click DC "https://github.com/svadithya/kafkastudy/blob/main/deploy/docker-compose.yml"
    end

    %% Data & Control Flow Connections
    EP -->|"produces"| KB
    KB -->|"delivers messages"| RKL
    KB -->|"delivers messages"| RGL
    SBA -->|"uses"| KCC
    SBA -->|"exposes endpoints via"| HC
    SBA -->|"exposes endpoints via"| AS
    SBA -->|"initiates"| RKL
    SBA -->|"initiates"| RGL
    SBA -->|"manages"| GEH
    SBA -->|"reports health"| HI
    RKL -->|"logs via"| ML
    RGL -->|"logs via"| ML
    ML -->|"records"| SMR
    SMR -->|"stores events in"| SM
    ML -->|"writes logs to"| MONGODB
    SBA -->|"emits metrics to"| PROM
    PROM -->|"visualized in"| GRAF
    GHA -->|"deploys"| SBA
    GHA -->|"deploys"| KB
    GHA -->|"deploys"| MONGODB
    GHA -->|"deploys"| PROM
    GHA -->|"deploys"| GRAF
    DC -->|"orchestrates"| SBA

    %% Style Definitions
    classDef springboot fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef kafka fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef mongodb fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef monitoring fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef deployment fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
```
