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."
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.
-
Loom-Native Concurrency: Uses a
newVirtualThreadPerTaskExecutorto 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.
-
Path Traversal: Secure
- SSL/TLS Ready: Native support for HTTPS via PKCS12 keystores.
- Fluent API: Express-inspired context handling for JSON, HTML, and binary data.
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);
}
}- Connection Throttling: A global
Semaphorelimits active connections to prevent the JVM from being overwhelmed. - Virtual Thread Hand-off: Each socket is handed to a Virtual Thread, keeping the main loop free for new accepts.
- Protocol Parsing: Raw
InputStreamparsing for HTTP/1.1 compliance, including support for persistent connections and keep-alive. - Trie Matching: The router traverses the Trie to find the correct handler while extracting path parameters on the fly.
- Middleware Execution: A recursive execution chain allows for powerful pre- and post-processing.
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 attacksBy 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.
MIT License. Feel free to use, modify, and distribute.
Built with 🐧 and raw sockets 🐧💀.