Return to Codex Home
PROJECT ARTIFACTREGISTERED SECURE NODE

Toxi

Toxi

Architectural Intent

A web framework for Rust (previously Oxidite). Build APIs, microservices, serverless functions, and full-stack apps.

Codex Specification Details

Toxi


A web framework for Rust (previously Oxidite). Build APIs, microservices, serverless functions, and full-stack apps.

What is Toxi?

Toxi is a Rust web framework for building APIs, microservices, serverless functions, and full-stack applications. It provides routing, extractors, middleware, an ORM with auto-diff migrations, authentication, server-side templates, real-time communication, background job queues, caching, file storage, email delivery, and OpenAPI documentation. Each component is a separate crate. Use toxi-core alone for a minimal API server, or enable the full stack through the toxi facade.

Quick Start

[dependencies]
toxi = "3.1.0"
tokio = { version = "1", features = ["full"] }
use toxi::prelude::*;

async fn hello(_req: Request) -> Result<Response> {
    Ok(json_response!({ "message": "Hello from Toxi!" }))
}

#[tokio::main]
async fn main() -> Result<()> {
    let mut app = Application::new(Config::load().unwrap());
    app.router_mut().get("/", hello);
    app.run().await
}

Core Concepts

Extractors

Handler parameters are automatically extracted from the request:

use toxi::prelude::*;

#[derive(Deserialize)]
struct CreateUser {
    name: String,
    email: String,
}

async fn create_user(
    State(db): State<Arc<DbPool>>,
    Json(body): Json<CreateUser>,
) -> Result<Response> {
    let user = User::create(&db, &body.name, &body.email).await?;
    Ok(json_response!({ "id": user.id }))
}

Built-in extractors: Json<T>, Path<T>, Query<T>, State<T>, Form<T>, Cookies, Body<T>, WebSocketUpgrade.

Routing

Regex-based routing with path parameters, wildcards, and middleware:

let mut router = Router::new();
router.get("/users/:id", get_user);
router.post("/users", create_user);
router.delete("/users/:id", delete_user);

HTTP/2 Support

Toxi supports HTTP/1.1 and HTTP/2 out of the box:

Server::new(router)
    .with_http_version(HttpVersion::Http2)
    .listen(addr)
    .await

When behind a TLS-terminating proxy, use HttpVersion::Http::Auto for ALPN negotiation.

WebSocket Support

Native WebSocket upgrade with authenticated context:

async fn ws_handler(ws: WebSocketUpgrade) -> Result<Response> {
    Ok(ws.on_upgrade(|socket, extensions| async move {
        // Handle the WebSocket connection
    }))
}

Modular by Design

Each crate in the Toxi ecosystem is independent. Pick only what you need:

CratePurpose
toxiUnified facade — re-exports everything
toxi-coreHTTP kernel, routing, extractors, server
toxi-macros#[derive(Model)] and other proc macros
toxi-dbORM with relationships, migrations, eager loading
toxi-authJWT, OAuth2, RBAC, 2FA, API keys
toxi-realtimeWebSocket, SSE, event broadcasting
toxi-middlewareCORS, logging, compression, rate limiting, CSRF
toxi-configTOML config with env variable overrides
toxi-cacheIn-memory and Redis caching
toxi-queueBackground jobs with Postgres and Redis backends
toxi-templateServer-side rendering engine
toxi-mailSMTP email delivery
toxi-storageLocal and S3 file storage
toxi-securityCrypto primitives, hashing, sanitization
toxi-utilsString, date, validation helpers
toxi-openapiOpenAPI 3.0 schema generation
toxi-graphqlGraphQL integration
toxi-testingTest utilities and mock servers
toxi-pluginPlugin lifecycle hooks
toxi-cliScaffolding, tinker REPL, dev server

Minimal Setup

# Just routing — nothing else
[dependencies]
toxi-core = "3.1.0"

With Database

[dependencies]
toxi-core = "3.1.0"
toxi-db = "3.1.0"

Full Stack

[dependencies]
toxi = { version = "3.1.0", features = ["full"] }

Feature Flags

FeatureEnables
databaseORM, migrations, relationships
authJWT, OAuth2, RBAC, 2FA
queueBackground job processing
cacheResponse and data caching
realtimeWebSocket and SSE
templatesServer-side rendering
mailEmail delivery
storageFile storage (local + S3)
securityCrypto and hashing
utilsString and date helpers
graphqlGraphQL API
pluginPlugin system
fullEverything above

ORM

Toxi includes a custom ORM built on sqlx with #[derive(Model)]:

use toxi_db::Model;

#[derive(Model)]
#[model(table = "users")]
struct User {
    id: i64,
    name: String,
    email: String,
}

// Generated methods:
// User::find_by_id(&db, 1).await?
// User::create(&db, "Alice", "alice@example.com").await?
// User::query().filter_eq("name", "Alice").fetch_all(&db).await?
// user.posts().get(&db).await?  (relationship)

Features: async validation, soft deletes, eager loading (N+1 prevention), auto-diff migrations, savepoint transactions.

CLI

Install the CLI for scaffolding and development:

cargo install --path toxi-cli

Commands:

  • toxi new <project> — scaffold a new project
  • toxi dev — hot-reload development server
  • toxi migrate — run database migrations
  • toxi tinker — interactive REPL
  • toxi generate — code generation

Architecture

┌─────────────┐     ┌──────────────┐     ┌──────────────┐
│   Client     │────▶│    Server     │────▶│   Router     │
│  (HTTP/WS)   │     │  (hyper)      │     │  (routes)    │
└─────────────┘     └──────────────┘     └──────┬───────┘
                                                  │
                                          ┌───────▼───────┐
                                          │   Handler     │
                                          │  (extractors) │
                                          └───────────────┘

Built on:

  • hyper — HTTP/1.1 and HTTP/2
  • tokio — async runtime
  • tower — middleware composition
  • sqlx — database access

Contributing

Contributions welcome. See CONTRIBUTING.md.

License

MIT OR Apache-2.0 — see LICENSE.

System Specifications

Category Tags
rustasynchttpwebhigh-performanceframework
Target Architecturesx86_64, aarch64, Bare Metal
Compiler / ToolchainRust stable / LLVM 17
Verification Metrics
• Memory Overhead: < 2.4MB
• Execution Speed: Fastpath < 15μs
• Safe Abstractions: 100% verified
Toxi - Artifact Codex