Beerust is a Production-Grade Web Framework for Rust

Beerust

English

Beerust is a production-grade web framework for Rust. Its design philosophy comes from Go’s Beego framework, re-expressed with idiomatic Rust traits, macros, and type system.

Design Goals

Goal Target
Developer experience From Beerust new to first request in < 30 seconds
Performance Controller-layer overhead < 5% (vs. bare axum), P99 route latency < 100µs
Compile speed Full build of the meta crate < 60s (release), incremental build < 5s
Binary size Smallest app (router only) < 5MB (strip + LTO)
Safety 0 unsafe in business code; all FFI wrapped in dedicated *-sys crates
Compatibility Rust 1.80+ MSRV, tracking stable

Design Principles

  1. Beego philosophy, Rust expression — MVC, namespaces, and filter chains implemented with trait + macro
  2. Progressive enhancement — the minimal core depends only on axum + tokio; everything else is feature-gated
  3. Explicit over implicit — route registration, model mapping, and middleware order are all declared explicitly in code
  4. Zero-cost abstractions — static trait dispatch, compile-time macro expansion, no virtual function overhead
  5. Storage engine independence — each engine trait’s implementation can be swapped out on its own without affecting the business layer above
  6. Built-in observability — tracing + metrics instrumentation covers the whole framework, structured logging is on by default

Architecture Design

Crate Topology

1
2
3
4
5
6
7
8
9
10
11
12
13
bee_rust/           # meta crate, re-export + feature flags
bee_router/ # routing + controllers + Context + filter chain
bee_orm/ # ORM — Model trait + QuerySet + Migration + relation mapping
bee_kv/ # unified KV/Cache abstraction — Redis + Memcached
bee_search/ # search/analytics engines — Elasticsearch + OpenSearch + ClickHouse
bee_graph/ # graph databases — Neo4j + NebulaGraph + ArangoDB
bee_tsdb/ # time series databases — InfluxDB + Apache IoTDB + QuestDB
bee_config/ # configuration management — INI/YAML/ENV + hot reload
bee_cache/ # cache abstraction — Memory/Redis/Memcache
bee_session/ # Session — Memory/Redis/Cookie/Database backends
bee_logs/ # logging — multi-level logs + tracing integration
bee_template/ # template rendering — based on tera
bee_cli/ # CLI — scaffolding/code generation/hot reload/migrations

Architecture Diagram

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
                        ┌───────────────────────┐
│ bee_rust (meta) │
│ re-export + features │
└───────────┬───────────┘

┌───────────────────────┼───────────────────────┐
│ │ │
┌────────▼────────┐ ┌────────▼────────┐ ┌────────▼────────┐
│ Web Layer │ │ Data Layer │ │ Tool Layer │
└────────┬────────┘ └────────┬────────┘ └────────┬────────┘
│ │ │
┌───────────┼───────────┐ ┌───────┼───────┐ ┌───────────┼───────────┐
│ bee_router │ │ bee_orm │ │ bee_cli │
│ - route register │ │ - Model/Query │ │ - scaffolding │
│ - controller trait │ │ - Migration │ │ - hot reload │
│ - filter chain │ │ - Connection │ │ - code generation │
│ - param extract │ │ │ │ │
├────────────────────────┤ ├────────────────┤ ├───────────────────────┤
│ bee_template │ │ bee_config │ │ bee_logs │
│ - template render │ │ - INI/YAML/ENV│ │ - multi-level log │
│ - HTML/JSON │ │ - hot reload │ │ - tracing integrate │
├────────────────────────┤ ├────────────────┤ └───────────────────────┘
│ bee_session │ │ bee_cache │
│ - session management │ │ - cache trait │
│ - multi-backend │ │ - Mem/Redis │
└────────────────────────┘ └────────────────┘

┌─────────────────────────────────────────────────────────┐
│ Storage Engine Layer │
├──────────────────┬──────────────────────────────────────┤
│ bee_kv │ Redis + Memcached │
│ bee_search │ Elasticsearch + OpenSearch + ClickHouse │
│ bee_graph │ Neo4j + NebulaGraph + ArangoDB │
│ bee_tsdb │ InfluxDB + Apache IoTDB + QuestDB │
└──────────────────┴──────────────────────────────────────┘

Crate Dependencies

1
2
3
4
5
6
7
8
9
10
11
12
13
bee_config (no dependencies)
bee_logs (no dependencies)
bee_cache → bee_config
bee_kv → bee_config
bee_session → bee_cache, bee_config
bee_template (no dependencies)
bee_orm → bee_config, bee_cache
bee_search → bee_config
bee_graph → bee_config
bee_tsdb → bee_config
bee_router → bee_session, bee_template, bee_config, bee_logs
bee_cli → bee_router, bee_orm
bee_rust → all of the crates above (re-export)

Supported Databases

Category Database Crate Feature Flag
Relational SQLite bee_orm sqlite
PostgreSQL bee_orm postgres
MySQL bee_orm mysql
TiDB bee_orm mysql
KV / Cache Redis bee_kv / bee_cache redis
Memcached bee_kv / bee_cache memcache
Search / Analytics Elasticsearch bee_search elasticsearch
OpenSearch bee_search opensearch
ClickHouse bee_search clickhouse
Graph databases Neo4j bee_graph neo4j
NebulaGraph bee_graph nebulagraph
ArangoDB bee_graph arangodb
Time series databases InfluxDB bee_tsdb influxdb
Apache IoTDB bee_tsdb iotdb
QuestDB bee_tsdb questdb

Request Filter Chain

1
2
Request → [SecurityFilter attack detection] → [Session restore] → [param validation] → [prepare hook] → [handle] → [finish hook] → Response
↓ any stage can abort (similar to Beego's Abort)

Feature Overview

Web Core (bee_router)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use bee_rust::prelude::*;

// define a controller
struct UserController;

#[bee_router::async_trait]
impl Controller for UserController {
async fn handle(&self, ctx: &mut Context) -> Result<(), RouterError> {
ctx.json(&serde_json::json!({"users": []}))
}
}

// route registration
let router = Router::new()
.ns("/api/v1", |ns| {
ns.get("/users")
.post("/users");
});

Context provides:

  • ctx.json() / ctx.text() / ctx.html() — response output
  • ctx.redirect() — redirects
  • ctx.abort() — abort the request
  • ctx.session — session access
  • ctx.params — path parameters

Security Detection (security feature)

An attack detection filter built on security-rust, covering 27 attack types including XSS, SQL injection, command injection, and SSRF:

1
2
3
use bee_rust::prelude::*;

let security = SecurityFilter::new(); // all 27 detectors enabled

Enable it in Cargo.toml:

1
bee_rust = { features = ["security"] }

ORM (bee_orm)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#[derive(Model)]
#[bee(table = "users")]
struct User {
id: i64,
name: String,
age: i32,
}

// chained query
let users = User::query()
.filter("age > 18")
.order_by("created_at DESC")
.limit(20)
.to_sql();
// → SELECT * FROM users WHERE age > 18 ORDER BY created_at DESC LIMIT 20

Configuration Management (bee_config)

1
2
3
4
5
6
7
8
9
#[derive(Config)]
#[config(file = "conf/app.conf")]
struct AppConfig {
app_name: String,
http_port: u16,
run_mode: String,
}

let cfg = AppConfig::load("conf/app.conf")?;

Storage Engines

KV/Cache:

1
2
3
let kv = RedisStore::new("redis://localhost:6379").await?;
kv.set("key", b"value", Some(Duration::from_secs(60))).await?;
let val = kv.get("key").await?;

Search engine:

1
2
3
4
let engine = ElasticsearchEngine::new("http://localhost:9200")?;
let result = engine.search("my_index", &SearchQuery {
q: Some("keyword".into()), ..Default::default()
}).await?;

Graph database:

1
2
let db = Neo4jDB::new("bolt://localhost:7687").await?;
let vid = db.add_vertex("Person", &[("name", "Alice")]).await?;

Time series database:

1
2
let tsdb = InfluxDB::new("http://localhost:8086").await?;
tsdb.write_point("cpu", &[("host", "srv1")], &[("value", 0.85)], Utc::now()).await?;

Session

1
2
3
4
let cache = Arc::new(MemoryCache::new());
let mut session = Session::new(cache, Duration::from_secs(3600));
session.set("user_id", &"123")?;
let uid: String = session.get("user_id")?.unwrap();

Logging

1
2
3
4
5
Logger::new()
.level(Level::INFO)
.output(Output::MultiFile("logs/"))
.async_()
.init()?;

Templates

1
2
3
let engine = TemplateEngine::new("views/")?;
let result = engine.render("hello.html", &context! { name: &"World" })?;
// → "Hello, World!"

CLI Tool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# create a project
bee-rust new my-app

# generate code
bee-rust generate controller user
bee-rust generate model user --fields "name:string,age:int"

# run in dev mode
bee-rust run --watch

# database migrations
bee-rust migrate up
bee-rust migrate down

# package and deploy
bee-rust pack --target linux/x86_64

Usage Steps

Requirements

  • Rust 1.80+
  • Cargo

Installation

1
2
3
4
5
6
7
8
9
# clone the project
git clone https://github.com/erikwang2013/bee-rust.git
cd bee-rust

# build
cargo build --workspace

# run tests
cargo test --workspace

Quick Start

1
2
3
4
5
6
# create a new project with the CLI
cargo run -p bee_cli -- new hello
cd hello

# run the dev server
cargo run

Using It in Your Project

1
2
[dependencies]
bee_rust = { git = "https://github.com/erikwang2013/bee-rust", features = ["full"] }

Technical Notes

Tech Stack

Layer Technology
HTTP foundation axum 0.8 + tower 0.5
Async runtime tokio 1.x
Serialization serde + serde_json
Template engine tera 1.x
Logging backend tracing + tracing-subscriber
CLI clap 4
Config parsing toml / serde_yaml / hand-rolled INI
Error handling thiserror
Procedural macros syn + quote + proc-macro2

Design Patterns

Pattern Usage
Builder Logger, Router, QuerySet
Trait abstraction Cache, KvStore, SearchEngine, GraphDB, TimeSeriesDB
Derive macros #[derive(Model)], #[derive(Config)]
Feature gates Driver implementations compiled on demand (redis, memcached, elasticsearch, etc.)
Filter chain Request filter chain, modeled on Beego Filter

Crate List

Crate Feature Beego equivalent
bee_rust Meta crate, unified entry point
bee_router Routing + controllers + Context + filters server/web, context
bee_orm ORM + QuerySet + Migration client/orm
bee_kv Unified KV/Cache abstraction client/cache (extended)
bee_search Search/analytics engines — (new)
bee_graph Graph databases — (new)
bee_tsdb Time series databases — (new)
bee_config Configuration management + hot reload client/config
bee_cache Cache abstraction client/cache
bee_session Session management server/web/session
bee_logs Logging logs
bee_template Template rendering — (enhanced)
bee_cli CLI tool the bee tool

Test Coverage

All 63 tests across the workspace pass:

Crate Tests
bee_config 4
bee_cache 4
bee_template 2
bee_logs 3
bee_kv 4
bee_search 6
bee_graph 5
bee_tsdb 5
bee_orm 7
bee_session 2
bee_router 9
bee_cli 9

License

Apache-2.0