claviron 0.2.1

Build around your application. Run existing apps alongside Rust and move one route at a time.
Documentation

Claviron

Retire middlemen. Let the others go!

Claviron is an application-first toolkit for building and running services. Run Rust alongside your existing applications. Keep them together as a modular monolith or distribute them across independent processes.

Build your own Edge and serve public traffic directly. Terminate TLS, route requests, serve files, and dispatch to your applications at the Edge. Your application controls every layer, from listeners and access rules to handlers and response policies. Enable what you need. An omitted layer adds no work per request.

Fleet awareness

Taste the power of Orbit. Let your processes share memory, exchange requests, and publish events on the same host. Orbit's shared-memory waits use Linux futexes, FreeBSD umtx, and shared address waits on macOS 14.4 and later.

Fleet awareness · Orbit Link

Move to Rust without a full rewrite

Keep your application behind Claviron and add a Rust intercept for the first route you want to move. Claviron runs the Rust handler first. Requests it leaves unhandled continue to the existing application. You can move one API, a hot path, or a security check at a time while keeping the public URL and host policies.

Start with a route that benefits from Rust's type and memory safety, or one where you want to reduce latency or CPU use. Claviron can run the new Rust code alongside your PHP, Python, JavaScript, Go, Java, or C/C++ application. Each part can keep its existing runtime and move on its own schedule.

Design contracts

Build your own Edge

Add claviron with the edge and supervisor features and Tokio with macros and rt-multi-thread. Define your listeners and hosts in config/.

use claviron::{Result, Server, Workers};

#[tokio::main]
async fn main() -> Result<()> {
    Server::new()
        .config_dir("config")
        .workers(Workers::Available)
        .serve()
        .await
}

Start with the Edge example or the Edge configuration guide.

Add ACME certificate automation and gRPC administration with typed service registration. DNS plugs into the same lifecycle through its registration function. Use compatible releases of the three backend crates and enable their server features.

use claviron::{Result, Server, Workers};
use claviron_acme::AcmeProvider as AcmeService;
use claviron_grpc::server::provider::GrpcServiceProvider as GrpcAdmin;

#[tokio::main]
async fn main() -> Result<()> {
    Server::new()
        .config_dir("config")
        .workers(Workers::Available)
        .with_services::<(AcmeService, GrpcAdmin)>()
        .register(claviron_dns::register)
        .serve()
        .await
}

ACME · gRPC administration · DNS · Runnable examples

Bring your application

Put boundaries where they belong

Let your Edge apply CORS and verify CSRF before a request reaches PHP. Claviron includes CORS policy. Register a route extension for CSRF and give it the application's session and token verifier. The Edge can then enforce the check on the routes you select.

routes:
  /account:
    csrf: true

Register a route extension

Serve static files at the Edge

Mount asset directories, serve directory indexes, and configure try_files or an SPA fallback. Large files stream from disk with backpressure. Small files can be cached in memory and shared across workers when the fleet cache is enabled.

Capability HTTP specification
ETag and Last-Modified, conditional requests, and single byte ranges RFC 9110 §§8.8, 13–14
Browser freshness via Cache-Control and Expires, with opt-in immutable assets RFC 9111 §5, RFC 8246
Negotiated Brotli and Zstandard representations RFC 9110 §12.5, RFC 7932, RFC 8878

Static file configuration and caching

Performance

Plain HTTP. At the highest load all three configurations passed in the same Linux HTTP/1.1 run, Claviron with Axum delivered 3.27× Caddy's throughput with 68% less server CPU per response.

Server Responses/s CPU/response
Caddy 2.11.9 268,817 74.76 µs
Claviron + Axum, 32 workers 879,753 24.09 µs

A separate run reached 1,045,500 responses/s with Claviron and Warp. Matched Caddy comparison · Warp peak

Persistent PHP. With 128 PHP instances and 1,024 connections, both servers completed the five-minute runs without errors. Each cell shows responses per second and server CPU per response.

Workload Claviron FrankenPHP 1.13.5
Plain PHP 299,896 / 64.72 µs 90,015 / 227.23 µs
Symfony, with Skene on Claviron 88,139 / 312.43 µs 41,398 / 565.52 µs

FrankenPHP comparison · Laravel/Lumenize results

Near-native throughput with managed workers

On Linux with 1,024 HTTP/1.1 connections, Claviron Other delivered 93% of native Hyper's throughput at the highest load both passed. Its 40 supervised worker processes kept meeting the SLA up to 38,912 outstanding requests.

Server Responses/s at 16,384 outstanding Server CPU/response Last passing outstanding target
Native Hyper, 40 runtime threads 1,811,355 14.50 µs 16,384
Claviron Other, 40 worker processes 1,678,101 16.31 µs 38,912

HTTP/1.1 benchmark and methodology

With Claviron for Apple, see embedded and linked applications together and add workers from the same app.

Crates.io · API documentation · Contributing · Security

Examples · Bench HTTP · Break

Licensed under MIT or Apache 2.0.