# michaelik/kafka-example-lastest architecture

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

- Interactive diagram: https://gitdiagram.com/michaelik/kafka-example-lastest
- Repository: https://github.com/michaelik/kafka-example-lastest

## Overview

##### Main Components

a. Application Components:
- Spring Boot Application Container
- Kafka Message Broker
- Database (likely a relational database based on the Repository pattern usage)
- Email Service System

##### Key Architectural Layers (organize vertically from top to bottom)

Layer 1 - API Layer:
- MessageController (REST API endpoint)

Layer 2 - Service Layer:
- EmailMessageKafkaProducer
- EmailMessageKafkaConsumer
- EmailMessageSenderService

Layer 3 - Configuration Layer:
- KafkaProducerConfig
- KafkaConsumerConfig
- KafkaTopicConfig

Layer 4 - Data Layer:
- EmailMessageRepository
- Entity: EmailMessage

##### Additional Elements

Supporting components:
- DTOs (EmailDTO, BookDTO)
- Mappers (EmailMessageMapper)
- Utility classes (CustomJsonSerializer, CustomJsonTypeResolver)

##### Specific Implementation Details

Annotations for:
- Kafka Topics (from KafkaTopicConfig)
- Data transformation flows (DTOs ↔ Entities)
- Configuration properties
- Service implementation details

##### Notes Section

A notes section explaining:
- The async nature of Kafka messaging
- The purpose of custom JSON handling (CustomJsonSerializer)
- The role of type resolution (CustomTypeIdResolver)
- Any important configuration details

Remember to emphasize:
- The separation between producer and consumer components
- The central role of Kafka in message handling
- The email processing pipeline
- The data persistence layer
- Configuration management
- Error handling and message flow control

This will provide a comprehensive view of the system while maintaining clarity and usefulness for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "API Layer"
        MC["MessageController"]:::api
    end

    subgraph "Service Layer"
        KP["EmailMessageKafkaProducer"]:::service
        KC["EmailMessageKafkaConsumer"]:::service
        ES["EmailMessageSenderService"]:::service
    end

    subgraph "Configuration Layer"
        PC["KafkaProducerConfig"]:::config
        CC["KafkaConsumerConfig"]:::config
        TC["KafkaTopicConfig"]:::config
    end

    subgraph "Data Layer"
        EM["EmailMessage"]:::entity
        EMR["EmailMessageRepository"]:::repo
        MAP["EmailMessageMapper"]:::util
    end

    subgraph "Storage"
        KB[(Kafka Broker)]:::storage
        DB[(Database)]:::storage
    end

    subgraph "External Systems"
        EMS[Email Service]:::external
    end

    subgraph "DTOs"
        ED["EmailDTO"]:::dto
        BD["BookDTO"]:::dto
    end

    subgraph "Utils"
        CJS["CustomJsonSerializer"]:::util
        CJT["CustomJsonTypeResolver"]:::util
        CTI["CustomTypeIdResolver"]:::util
    end

    MC --> KP
    KP --> KB
    KB --> KC
    KC --> ES
    ES --> EMS
    EMR --> DB
    ES --> EMR
    MAP --> EM
    MAP --> ED
    
    PC -.-> KP
    CC -.-> KC
    TC -.-> KB
    
    %% Click Events
    click MC "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/controller/MessageController.java"
    click ED "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/dtos/EmailDTO.java"
    click BD "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/dtos/BookDTO.java"
    click PC "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/config/KafkaProducerConfig.java"
    click CC "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/config/KafkaConsumerConfig.java"
    click TC "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/config/KafkaTopicConfig.java"
    click KP "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/service/impl/EmailMessageKafkaProducerImpl.java"
    click KC "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/service/impl/EmailMessageKafkaConsumerImpl.java"
    click ES "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/service/impl/EmailMessageSenderServiceImpl.java"
    click EM "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/entity/EmailMessage.java"
    click EMR "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/repository/EmailMessageRepository.java"
    click MAP "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/mappers/EmailMessageMapper.java"
    click CJS "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/utils/CustomJsonSerializer.java"
    click CJT "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/utils/CustomJsonTypeResolver.java"
    click CTI "https://github.com/michaelik/kafka-example-lastest/blob/master/src/main/java/com/kafka/utils/CustomTypeIdResolver.java"

    classDef api fill:#2196F3,stroke:#000,stroke-width:2px
    classDef service fill:#4CAF50,stroke:#000,stroke-width:2px
    classDef config fill:#FFC107,stroke:#000,stroke-width:2px
    classDef entity fill:#9C27B0,stroke:#000,stroke-width:2px
    classDef storage fill:#673AB7,stroke:#000,stroke-width:2px
    classDef external fill:#F44336,stroke:#000,stroke-width:2px
    classDef util fill:#795548,stroke:#000,stroke-width:2px
    classDef repo fill:#607D8B,stroke:#000,stroke-width:2px
    classDef dto fill:#FF9800,stroke:#000,stroke-width:2px

    subgraph "Legend"
        L1[API]:::api
        L2[Service]:::service
        L3[Config]:::config
        L4[Entity]:::entity
        L5[(Storage)]:::storage
        L6[External]:::external
        L7[Utility]:::util
        L8[Repository]:::repo
        L9[DTO]:::dto
    end
```
