Skip to content

Bernardusz/levtus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Levtus (Levis Conatus) 🐧🚀

Maven Central License Maven Release Qodana

Levtus (Latin: Levis Conatus - "Light Effort") is a high-performance, zero-dependency HTTP/1.1 engine built from the ground up for the modern JVM. It is designed to be lightweight, secure, and incredibly fast by leveraging the power of Java 21+ Virtual Threads (Project Loom).

"Infrastructure should be simple, transparent, and built to last."


🏗 Why Levtus?

Most modern Java frameworks are built on top of complex abstractions like Netty or Jetty. Levtus was born from a desire to strip away the "magic" and build a protocol-compliant engine from raw sockets.

It is designed for developers who need a minimalist, ultra-fast web core for microservices, embedded systems, or high-performance APIs without the overhead of a massive framework.


⚡ Technical Highlights

  • Loom-Native Concurrency: Uses a newVirtualThreadPerTaskExecutor to handle thousands of concurrent connections with minimal memory footprint.
  • Trie-Based Routing: Features a high-performance Prefix Tree (Trie) router for $O(K)$ route matching (where $K$ is the path length).
  • Zero Dependencies: Pure Java. No external libraries, no "DLL hell," and ultra-small JAR size.
  • Hardened Security: Built-in protection against:
    • Path Traversal: Secure render() logic with path normalization.
    • Memory Exhaustion: Configurable limits for headers, body size, and line lengths.
    • Connection Overload: Semaphore-based throttling to protect system resources.
  • SSL/TLS Ready: Native support for HTTPS via PKCS12 keystores.
  • Fluent API: Express-inspired context handling for JSON, HTML, and binary data.

🚀 Quick Start

import io.github.bernardusz.levtus.Levtus;

public class Main {
    public static void main(String[] args) {
        Levtus app = Levtus.create();

        // Middleware support
        app.use((ctx, next) -> {
            System.out.println("Request received: " + ctx.req().path());
            next.run();
        });

        // Simple GET route
        app.get("/hello", ctx -> {
            ctx.text("Hello from the Levtus Engine!");
        });

        // Dynamic routing with path params
        app.get("/user/{id}", ctx -> {
            String userId = ctx.param("id");
            ctx.json("{\"id\": \"" + userId + "\"}");
        });

        // Secure static file rendering
        app.get("/", ctx -> {
            ctx.render("index.html");
        });

        app.listen(8080);
    }
}

🛠 Architecture & Internals

The Request Lifecycle

  1. Connection Throttling: A global Semaphore limits active connections to prevent the JVM from being overwhelmed.
  2. Virtual Thread Hand-off: Each socket is handed to a Virtual Thread, keeping the main loop free for new accepts.
  3. Protocol Parsing: Raw InputStream parsing for HTTP/1.1 compliance, including support for persistent connections and keep-alive.
  4. Trie Matching: The router traverses the Trie to find the correct handler while extracting path parameters on the fly.
  5. Middleware Execution: A recursive execution chain allows for powerful pre- and post-processing.

Security Configurations

Levtus gives you fine-grained control over your server's surface area:

app.setMaxBodySize(10 * 1024 * 1024); // 10MB limit
app.setMaxHeaderCount(100);
app.setMaxLineSize(8192); // Prevent Slowloris attacks

📈 Performance

By utilizing Project Loom, Levtus avoids the overhead of traditional thread-pooling and the complexity of reactive programming. It provides a simple, synchronous programming model that scales horizontally with hardware.


📜 License

MIT License. Feel free to use, modify, and distribute.


Built with 🐧 and raw sockets 🐧💀.

About

A lightweight, high-performance HTTP/1.1 engine for Java 25. Built from the ground up with zero external dependencies, leveraging Virtual Threads for massive scalability and modern TLS for native security.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages