Add Avro/Kafka code generation with typed producers, consumers, and RPC#184
Merged
oyvindberg merged 3 commits intomainfrom Feb 1, 2026
Merged
Add Avro/Kafka code generation with typed producers, consumers, and RPC#184oyvindberg merged 3 commits intomainfrom
oyvindberg merged 3 commits intomainfrom
Conversation
Typr now generates type-safe JVM code from Apache Avro schemas (.avsc) and protocols (.avpr), with full support for Kafka producers, consumers, and request-reply RPC patterns. - **Records** - Immutable data classes (Java records, Kotlin data classes, Scala case classes) - **Enums** - Type-safe enumerations with JSON serialization - **Complex Unions** - Sealed interfaces for multi-type unions like `["string", "int", "boolean"]` - **Recursive Types** - Self-referential schemas (trees, linked lists) - **Logical Types** - UUID, date, time, timestamp-millis, decimal with precision - **$ref Support** - Reference schemas from other files - **Precise Types** - Compile-time validated wrappers like `Decimal10_2` - **AvroEncoded** - Binary Avro with Confluent Schema Registry - **JsonEncoded** - JSON serialization (Jackson, Circe, ZIO JSON) - **Typed Producers** - `orderEventsProducer.send(new OrderPlaced(...))` - **Typed Consumers** - Abstract handlers with methods per event type - **Multi-Event Topics** - Sealed interfaces for topics with multiple event types - **Serializers/Deserializers** - Kafka Serde implementations - **Topic Bindings** - Type-safe `TypedTopic<K, V>` definitions - **Spring Boot** - `@Service`, `KafkaTemplate`, `@KafkaListener`, `@SendTo` - **Quarkus** - `@ApplicationScoped`, `Emitter`, `@Incoming`, `@Outgoing` - **Service Interfaces** - Clean async interfaces from Avro protocol definitions - **Result ADT** - `Result<User, UserNotFoundError>` for explicit error handling - **Client/Server** - Generated Kafka request-reply implementations - **Effect Types** - Blocking, CompletableFuture, Uni (Mutiny), IO (Cats), ZIO | Project | Language | Framework | Wire Format | |---------|----------|-----------|-------------| | java | Java | - | Avro Binary | | java-vanilla | Java | - | Avro Binary | | java-async | Java | - | CompletableFuture | | java-json | Java | - | JSON | | java-spring | Java | Spring Boot | Avro + RPC | | java-quarkus | Java | Quarkus | Avro + RPC | | kotlin | Kotlin | - | Avro Binary | | kotlin-json | Kotlin | - | JSON | | kotlin-quarkus-mutiny | Kotlin | Quarkus | Uni effect | | scala | Scala 3 | - | Avro Binary | | scala-cats | Scala 3 | Cats Effect | IO effect | | scala-json | Scala 3 | - | JSON | Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change relative link ../readme.md to absolute /db/ path. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Typr now generates type-safe JVM code from Apache Avro schemas (
.avsc) and protocols (.avpr), with full support for Kafka producers, consumers, and request-reply RPC patterns.Core Features
["string", "int", "boolean"]Decimal10_2x-typr-wrapperto generate type-safe ID wrappersWire Formats
Typed Kafka Producers
Generated producers are fully typed and handle serialization automatically:
Usage:
Multi-Event Topics (Sealed Interfaces)
When multiple event types share a topic, Typr generates a sealed interface:
Typed Kafka Consumers
Generated consumers dispatch to typed handler methods:
Handler interface you implement:
Typed Kafka Headers
Define header schemas and get type-safe header classes:
Custom Wrapper Types (
x-typr-wrapper)Add
x-typr-wrapperto any field to generate a type-safe wrapper:{ "type": "record", "name": "CustomerOrder", "fields": [ {"name": "orderId", "type": "string", "x-typr-wrapper": "OrderId"}, {"name": "customerId", "type": "long", "x-typr-wrapper": "CustomerId"}, {"name": "email", "type": ["null", "string"], "x-typr-wrapper": "Email"} ] }Generated record uses wrappers:
Effect Types (Higher-Kinded)
BlockingTCompletableFutureCompletableFuture<T>MutinyUni<T>CatsIOIO[T]ZIOZIO[Any, Throwable, T]Kotlin with Mutiny (Quarkus):
Scala with Cats IO:
Kafka RPC (from .avpr protocols)
For request/reply patterns, define an Avro protocol and get generated client/server:
Test Projects
javajava-vanillajava-asyncjava-jsonjava-springjava-quarkuskotlinkotlin-jsonkotlin-quarkus-mutinyscalascala-catsscala-json🤖 Generated with Claude Code