Skip to content

Universal Contract Generator (UniConGen) — generate REST, gRPC, GraphQL APIs and Kafka producers/consumers from annotated Java services

License

Notifications You must be signed in to change notification settings

Lewickiy/unicongen

Repository files navigation

UniConGen (Universal Contract Generator)

MIT License

UniConGen is a Java library for generating REST, gRPC, GraphQL APIs and Kafka producers/consumers from annotated services.
Its goal is to simplify microservice contract creation by automatically generating code for inter-service communication.

Note: The project is currently in Prototype / MVP state.
REST and gRPC modules contain placeholders, Kafka and GraphQL are under development.


Features

  • Generate API contracts for multiple technologies from a single annotated service.
  • Modular architecture:
    • core — library core
    • api-restREST API generation (MVP)
    • api-grpcgRPC API generation (MVP)
    • api-graphqlGraphQL generation (under development)
    • api-kafkaKafka producers/consumers generation (under development)
  • Annotations for generation configuration:
    • @ExposedService, @ExposeAs
    • @RestApiRoot, @GrpcApiRoot
  • Compatible with Java 21 and Gradle

Architecture and Modules

unicongen/
│
├─ core/           # Core: annotation scanning, models, generation logic
├─ api-rest/       # REST generation (MVP)
├─ api-grpc/       # gRPC generation (MVP)
├─ api-graphql/    # GraphQL generation (under development)
└─ api-kafka/      # Kafka generation (under development)

Example of an Annotated Service (current implementation)

@ExposedService(
        restApiRoot = @RestApiRoot(basePath = "/greeting"),
        grpcApiRoot = @GrpcApiRoot(serviceName = "GreetingService", packageName = "ru.levitsky.grpc")
)
public class GreetingService {

    @ExposeAs(rest = @RestType(RestOperationType.GET))
    public String hello(String name) {
        return "Hello, " + name;
    }

    @ExposeAs(rest = @RestType(RestOperationType.POST))
    public String helloPost(String name) {
        return "Hello, " + name + " posted";
    }

    @ExposeAs(graphql = @GraphQLType(GraphQLOperationType.QUERY))
    public String greet(String name) {
        return "Greetings, " + name;
    }

    @ExposeAs(kafka = @KafkaType(KafkaOperatorType.PRODUCER))
    public String sendMessage(String message) {
        return "Message sent: " + message;
    }
}

Demo Usage Example

package ru.levitsky.unicongen.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.levitsky.unicongen.core.model.ExposedClass;
import ru.levitsky.unicongen.core.scanner.ExposeScanner;

import java.util.Set;

public class Demo {

    private static final Logger log = LoggerFactory.getLogger(Demo.class);

    public static void main(String[] args) {
        log.info("Starting UniConGen Demo...");

        Set<ExposedClass> exposedMethods = ExposeScanner.scan("ru.levitsky.unicongen.core.demo");

        if (exposedMethods.isEmpty()) {
            log.warn("No exposed methods found");
        } else {
            log.info("Exposed methods found:");
            exposedMethods.forEach(exposed -> log.info(exposed.toString()));
        }

        log.info("Demo finished");
    }
}

Example Console Output

11:32:30 [main] INFO ru.levitsky.unicongen.core.demo.Demo - Starting UniConGen Demo...
11:32:30 [main] INFO ru.levitsky.unicongen.core.demo.Demo - Exposed methods found:
ExposedClass(technology=REST, operationType=POST, clazz=class GreetingService, method=helloPost)
ExposedClass(technology=KAFKA, operationType=PRODUCER, clazz=class GreetingService, method=sendMessage)
...
11:32:30 [main] INFO ru.levitsky.unicongen.core.demo.Demo - Demo finished.

Setup and Installation

dependencies {
    implementation project(':core')
}

Other modules (api-rest, api-grpc, api-graphql, api-kafka) will be included as they become ready

License

The project is licensed under the MIT License – see LICENSE

Contribution

  • Contributions are welcome: bug fixes, enhancements, or documentation improvements.
  • Open issues or submit pull requests.
  • Always follow the documentation standards described here.

Please note that this project is released with a Code of Conduct.
By participating in this project you agree to abide by its terms.

Roadmap

  • Full REST API generation (api-rest)
  • Full gRPC API generation (api-grpc)
  • Kafka producers/consumers (api-kafka)
  • GraphQL generation (api-graphql)
  • Transition from runtime Scanner to Annotation Processor
  • Structured logging across all modules
  • Unit tests and CI/CD integration

About

Universal Contract Generator (UniConGen) — generate REST, gRPC, GraphQL APIs and Kafka producers/consumers from annotated Java services

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages