BoltR
A standalone, pure Rust implementation of the Bolt v5.x wire protocol - the binary protocol used by Neo4j and other graph databases for client-server communication.
Any Bolt-compatible database engine can plug in via the BoltBackend trait. BoltR handles transport (TCP, WebSocket, TLS), PackStream encoding, session management, transactions, and the full Bolt type system over the wire.
Features
- Spec-faithful: Full Bolt v5.x protocol (5.1-5.4), all PackStream types, all message types
- Pure Rust: No C/C++ dependencies
- Lightweight: Minimal deps: tokio, bytes, thiserror, tracing
- Fast: Efficient PackStream encoding, chunked streaming
- Embeddable: Library-first design, usable by any Rust project
- WebSocket: Optional Bolt-over-WebSocket via
wsfeature flag (tokio-tungstenite) - TLS: Optional TLS via
tlsfeature flag (tokio-rustls), works with both TCP and WebSocket (WSS) - Auth: Pluggable authentication via
AuthValidatortrait - Observability: Structured tracing via
tracingcrate - Graceful shutdown: Drain connections on signal
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Implementing a Backend
Implement the BoltBackend trait to connect your database:
use ;
use BoltError;
use BoltDict;
Starting the Server
use BoltServer;
use Duration;
async
Using the Client
Enable the client feature:
[]
= { = "0.1", = ["client"] }
use BoltSession;
async
WebSocket Transport
Enable the ws feature for Bolt-over-WebSocket:
[]
= { = "0.1", = ["client", "ws"] }
Client:
use BoltSession;
async
Server (standalone):
use BoltServer;
async
Server (pre-upgraded, e.g. Axum):
use accept_ws;
// Inside an Axum WebSocket handler:
async
Architecture
Application (Cypher statements, parameters, results)
|
v
Bolt Messages
- Client: HELLO, LOGON, RUN, PULL, BEGIN, COMMIT, ROLLBACK, GOODBYE
- Server: SUCCESS, RECORD, FAILURE, IGNORED
|
v
PackStream Encoding
- Full Bolt type system: scalars, graph elements, temporal, spatial
|
v
Chunk Framing (2-byte length-prefixed)
|
v
Transport (TCP | WebSocket | TLS/WSS)
|
v
BoltBackend trait (your database plugs in here)
Bolt Type Support
| Bolt Type | Wire Encoding |
|---|---|
NULL, BOOLEAN, INTEGER, FLOAT, STRING, BYTES |
PackStream native markers |
DATE, TIME, DATETIME, DURATION |
PackStream structures |
POINT2D, POINT3D |
PackStream structures with SRID |
LIST, DICT |
Recursive PackStream containers |
NODE |
ID + labels + properties + element_id |
RELATIONSHIP |
ID + type + start/end + properties + element_id |
PATH |
Alternating nodes and relationships |
Modules
| Module | Description |
|---|---|
packstream |
Binary encoding format (markers, encode, decode) |
types |
BoltValue enum and graph/temporal/spatial types |
chunk |
Message framing (length-prefixed chunks) |
message |
Client and server message types, encode/decode |
server |
BoltBackend trait, session/transaction management, TCP server |
client |
BoltConnection, BoltSession (feature-gated with client) |
ws |
WebSocket adapter and server (feature-gated with ws) |
error |
BoltError enum with Neo4j-compatible codes |
Feature Flags
| Feature | Default | Description |
|---|---|---|
client |
off | Client library (BoltConnection, BoltSession) |
ws |
off | WebSocket transport (WsStream, ws_serve) |
tls |
off | TLS support via tokio-rustls |
Enable all:
= { = "0.1", = ["client", "ws", "tls"] }
Requirements
- Rust 1.85.0+ (edition 2024)
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.