# dilipsundarraj1/kafka-for-developers-using-spring-boot architecture

> Architecture diagram of the GitHub repository dilipsundarraj1/kafka-for-developers-using-spring-boot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dilipsundarraj1/kafka-for-developers-using-spring-boot
- Repository: https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot

## Overview

##### Project type and purpose
- This is an event-driven, two-microservice demo built with Spring Boot and Apache Kafka.
- “library-events-producer” exposes a REST API to publish “LibraryEvent” messages to Kafka topics.
- “library-events-consumer” consumes those messages, processes them (with manual-offset control, retry scheduler, error handling) and persists into an H2 database via JPA.

##### File structure
- Top-level folders:
- library-events-producer (a Spring Boot producer service)
- library-events-consumer (a Spring Boot consumer service)
- Each service contains:
- src/main/java/com/learnkafka – code packages (config, controller/producer/consumer/service/jpa/entity)
- application.yml – environment & Kafka settings
- CI: .github/workflows/gradle.yml
- Docs: SetUpKafka*.md, Kafka_Security.md

##### README for insights
- Confirms core use-case: Kafka producers/consumers demo
- Mentions SSL security, H2 console (http://localhost:8081/h2-console)

##### Main components and interactions
a. Components
- Client (e.g., curl, Postman)
- Producer Service (“library-events-producer”):
- REST Controller
- Kafka Producer component
- Auto-topic creation config
- Kafka Cluster (secured via SSL/TLS)
- Consumer Service (“library-events-consumer”):
- KafkaListener implementations (auto/manual offset, retry consumer)
- RetryScheduler
- Business services
- JPA repositories (LibraryEvents, FailureRecord)
- H2 Database (in-memory)
b. Relationships & data flow
1. Client → HTTP POST/PUT → Producer Controller
2. Controller → LibraryEventProducer → Kafka topic
3. Kafka Broker → delivers messages to consumer group
4. Consumer → onMessage → Service → JPA Repo → H2 DB (LibraryEvents table)
5. On processing failures → FailureRecord table + RetryScheduler triggers re-processing
c. Architectural patterns/design principles
- Asynchronous, event-driven pub/sub
- Spring Boot microservices
- Manual offset management for at-least-once semantics
- Retry with scheduler for transient errors
- Separation of concerns: controller, producer/consumer, service, repository
d. Key technologies
- Spring Boot, Spring Kafka
- Apache Kafka (SSL/TLS secured cluster)
- H2 database
- JPA/Hibernate
- Gradle, GitHub Actions CI

##### Detailed elements
- Service names (LibraryEventsProducerApplication, LibraryEventsConsumerApplication)
- Config components (AutoCreateConfig, LibraryEventsConsumerConfig)
- Kafka topics and security (SSL/TLS config)
- RetryScheduler and FailureRecord path
- H2 console endpoint

##### Final advice
- Call out key architectural patterns (pub/sub, manual offset, retry) in notes

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Postman, curl)"]:::external

    subgraph "Producer Service (library-events-producer)"
      direction TB
      ProducerApp["LibraryEventsProducerApplication"]:::producer
      LibraryEvController["LibraryEventsController"]:::producer
      ControllerAdvice["LibraryEventControllerAdvice"]:::producer
      EventProducer["LibraryEventProducer"]:::producer
      AutoConfig["AutoCreateConfig"]:::producer
      AppConfigProd["application.yml"]:::producer
      DomainModels["Domain Models"]:::producer
    end

    subgraph "Kafka Cluster (SSL/TLS secured)"
      Kafka["Kafka Cluster"]:::kafka
    end

    subgraph "Consumer Service (library-events-consumer)"
      direction TB
      ConsumerApp["LibraryEventsConsumerApplication"]:::consumer
      AppConfigCons["application.yml"]:::consumer
      subgraph "Consumer Configs"
        direction TB
        ConsConfig["LibraryEventsConsumerConfig"]:::consumer
        ConsConfigOld["LibraryEventsConsumerConfigLegacy"]:::consumer
      end
      subgraph "Consumers"
        direction TB
        AutoConsumer["LibraryEventsConsumer"]:::consumer
        ManualConsumer["LibraryEventsConsumerManualOffset"]:::consumer
        RetryConsumer["LibraryEventsRetryConsumer"]:::consumer
      end
      RetrySched["RetryScheduler"]:::consumer
      subgraph "Services"
        LibraryService["LibraryEventsService"]:::consumer
        FailureService["FailureService"]:::consumer
      end
      subgraph "Repositories (JPA)"
        LibraryRepo["LibraryEventsRepository"]:::consumer
        FailureRepo["FailureRecordRepository"]:::consumer
      end
    end

    DB[(H2 Database)]:::db

    Client -->|HTTP POST/PUT| LibraryEvController
    LibraryEvController -->|calls| EventProducer
    EventProducer -->|sends Kafka message| Kafka
    Kafka -->|delivers messages| AutoConsumer
    Kafka -->|delivers messages| ManualConsumer
    Kafka -->|delivers messages| RetryConsumer
    AutoConsumer -->|onMessage| LibraryService
    ManualConsumer -->|onMessage| LibraryService
    RetryConsumer -->|onMessage| LibraryService
    LibraryService -->|save| LibraryRepo
    LibraryService -->|on failure| FailureRepo
    RetrySched -->|schedules retry| ManualConsumer
    LibraryRepo --> DB
    FailureRepo --> DB

    click ProducerApp "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/java/com/learnkafka/LibraryEventsProducerApplication.java"
    click LibraryEvController "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/java/com/learnkafka/controller/LibraryEventsController.java"
    click ControllerAdvice "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/java/com/learnkafka/controller/LibraryEventControllerAdvice.java"
    click EventProducer "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/java/com/learnkafka/producer/LibraryEventProducer.java"
    click AutoConfig "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/java/com/learnkafka/config/AutoCreateConfig.java"
    click AppConfigProd "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-producer/src/main/resources/application.yml"
    click DomainModels "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/tree/main/library-events-producer/src/main/java/com/learnkafka/domain"
    
    click ConsumerApp "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/LibraryEventsConsumerApplication.java"
    click AppConfigCons "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/resources/application.yml"
    click ConsConfig "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/config/LibraryEventsConsumerConfig.java"
    click ConsConfigOld "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/config/LibraryEventsConsumerConfigLegacy.java"
    click AutoConsumer "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/consumer/LibraryEventsConsumer.java"
    click ManualConsumer "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/consumer/LibraryEventsConsumerManualOffset.java"
    click RetryConsumer "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/consumer/LibraryEventsRetryConsumer.java"
    click RetrySched "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/scheduler/RetryScheduler.java"
    click LibraryService "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/service/LibraryEventsService.java"
    click FailureService "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/service/FailureService.java"
    click LibraryRepo "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/jpa/LibraryEventsRepository.java"
    click FailureRepo "https://github.com/dilipsundarraj1/kafka-for-developers-using-spring-boot/blob/main/library-events-consumer/src/main/java/com/learnkafka/jpa/FailureRecordRepository.java"

    classDef producer fill:#D1E8FF,stroke:#333,stroke-width:1px
    classDef consumer fill:#DFF5D1,stroke:#333,stroke-width:1px
    classDef kafka fill:#FFE4B3,stroke:#333,stroke-width:1px
    classDef db fill:#E0B3FF,stroke:#333,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#333,stroke-width:1px
```
