Skip to content

YunaBraska/nano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧬 Project Nano

Issues Commit License Central Tag Javadoc Size Label Label

Introduction | Core Concept | Mechanics | Components | Getting Started | Build Nano | Benefits

πŸ–ΌοΈ Introduction

Back to basics and forget about frameworks!

Nano is a lightweight concept which makes it easier for developer to write microservices in functional, fluent, chaining, plain, modern java with a nano footprint. Nano is also designed to be fully compilable with GraalVM to create native executables. To enhance efficiency and performance, Nano utilizes non-blocking virtual threads from Project Loom.

πŸ“ Core Concept

Nano handles threads for you and provides a basic construct for event driven architecture. It's providing a simple way to write microservices in a functional fluent and chaining style. Objects are less needed thanks to the underlying TypeMap. Nano provides full access to all internal components, resulting in very few private methods or fields.

Read more...

πŸ“š Components

All you need to know are few classes: Context, Events, Logger, Schedulers, Services

flowchart LR
    nano(((Nano))) --> context[Context]
    context --> logger[Logger]
    logger --> events[Events]
    events --> services[Services]
    services --> schedulers[Schedulers]
    
    style nano fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
    style context fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
    style logger fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
    style events fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
    style services fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
    style schedulers fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
Loading

βš™οΈ Mechanics

πŸ“š Getting Started

Maven example

<dependency>
    <groupId>berlin.yuna</groupId>
    <artifactId>nano</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle example

dependencies {
    implementation 'berlin.yuna:nano:1.0.0'
}

Simple Nano example with HttpService (a default service)

public static void main(final String[] args) {
    // Start Nano with HttpService
    final Nano app = new Nano(args, new HttpService());

    // listen to /hello
    app.subscribeEvent(EVENT_HTTP_REQUEST, event -> event.payloadOpt(HttpObject.class)
        .filter(HttpObject::isMethodGet)
        .filter(request -> request.pathMatch("/hello"))
        .ifPresent(request -> request.response().body(Map.of("Hello", System.getProperty("user.name"))).respond(event)));

    // Override error handling for HTTP requests
    app.subscribeEvent(EVENT_APP_UNHANDLED, event -> event.payloadOpt(HttpObject.class).ifPresent(request ->
        request.response().body("Internal Server Error [" + event.error().getMessage() + "]").statusCode(500).respond(event)));
}

πŸ”¨ Build Nano

add the native-image profile to your pom.xml and run mvn package -Pnative-image

<profiles>
    <!-- NATIVE COMPILATION -->
    <plugin>
        <groupId>org.graalvm.nativeimage</groupId>
        <artifactId>native-image-maven-plugin</artifactId>
        <version>21.2.0</version>
        <configuration>
            <imageName>ExampleApp</imageName>
            <mainClass>de.yuna.berlin.nativeapp.helper.ExampleApp</mainClass>
            <buildArgs>
                <!-- Reduces the image size - Ensures the native image doesn't include the JVM as a fallback option -->
                <buildArg>--no-fallback</buildArg>
                <!-- Disables the use of the GraalVM compilation server -->
                <buildArg>--no-server</buildArg>
                <!-- Improve startup time - Initialize classes at build time rather than at runtime -->
                <buildArg>--initialize-at-build-time</buildArg>
                <!-- Include all files under /resources -->
                <buildArg>-H:IncludeResources=resources/config/.*</buildArg>
            </buildArgs>
        </configuration>
        <executions>
            <execution>
                <goals>
                    <goal>native-image</goal>
                </goals>
                <phase>package</phase>
            </execution>
        </executions>
    </plugin>
</profiles>

✨ Benefits of Nano:

  • 🧩 Modular Design: Nano's architecture is modular, making it easy to understand, extend, and maintain.
  • 🧡 Concurrency Management: Efficiently handle asynchronous tasks using advanced thread management.
  • πŸ“‘ Event-Driven Architecture: Robust event handling that simplifies communication between different parts of your application.
  • βš™οΈ Flexible Configuration: Configure your application using environment variables, system properties, or command-line arguments.
  • πŸ“Š Robust Logging and Error Handling: Integrated logging and comprehensive error handling mechanisms for reliable operation.
  • πŸš€ Scalable and Performant: Designed with scalability and performance in mind to handle high-concurrency scenarios.
  • πŸͺΆ Lightweight & Fast: Starts in milliseconds, uses ~10MB memory.
  • 🌿 Pure Java, Pure Simplicity: No reflections, no regex, no unnecessary magic.
  • ⚑ GraalVM Ready: For ahead-of-time compilation and faster startup.
  • πŸ”’ Minimal Dependencies: Reduces CVE risks and simplifies updates.
  • 🌊 Fluent & Stateless: Intuitive API design for easy readability and maintenance.
  • πŸ› οΈ Rapid Service Development: Build real services in minutes.

🀝 Contributing

Contributions to Nano are welcome! Please refer to our Contribution Guidelines for more information.

πŸ“œ License

Nano is open-source software licensed under the Apache license.

πŸ™‹β€ Support

If you encounter any issues or have questions, please file an issue here.

🌐 Stay Connected

tiny_java_logo