Crate allframe_core

Crate allframe_core 

Source
Expand description

§AllFrame Core

Crates.io Documentation License

The Composable Rust API Framework - Protocol-agnostic routing, CQRS/ES, resilience patterns, and beautiful API documentation.

AllFrame is the first Rust web framework designed, built, and evolved exclusively through Test-Driven Development (TDD) with 450+ tests.

§Features at a Glance

FeatureDescription
🔀 Protocol-AgnosticWrite once, expose via REST, GraphQL, and gRPC
📖 Auto DocumentationScalar UI, GraphiQL, gRPC Explorer built-in
🔄 CQRS/Event Sourcing85% boilerplate reduction with CommandBus, Projections, Sagas
🛡️ Resilience PatternsRetry, Circuit Breaker, Rate Limiting
🔒 Security UtilitiesSafe logging, credential obfuscation
💉 Compile-time DIDependency injection resolved at compile time
📊 OpenTelemetryAutomatic tracing and metrics

§Quick Start

Add to your Cargo.toml:

[dependencies]
allframe = "0.1"
tokio = { version = "1", features = ["full"] }

§Basic Router Example

use allframe_core::router::{Router, RestAdapter, ProtocolAdapter};

#[tokio::main]
async fn main() {
    // Create a router
    let mut router = Router::new();

    // Register handlers - works with any protocol!
    router.register("get_users", || async {
        r#"[{"id": 1, "name": "Alice"}]"#.to_string()
    });

    router.register("create_user", || async {
        r#"{"id": 2, "name": "Bob"}"#.to_string()
    });

    // Expose via REST
    let mut rest = RestAdapter::new();
    rest.route("GET", "/users", "get_users");
    rest.route("POST", "/users", "create_user");

    println!("Router configured with {} handlers", 2);
}

§Protocol-Agnostic Handler

use allframe_core::router::{Router, RestAdapter, GraphQLAdapter, GrpcAdapter};

// Same handler, multiple protocols!
let mut router = Router::new();
router.register("get_user", || async {
    r#"{"id": 42, "name": "John"}"#.to_string()
});

// REST: GET /users/42
let mut rest = RestAdapter::new();
rest.route("GET", "/users/:id", "get_user");

// GraphQL: query { user(id: 42) { name } }
let mut graphql = GraphQLAdapter::new();
graphql.query("user", "get_user");

// gRPC: UserService.GetUser
let mut grpc = GrpcAdapter::new();
grpc.unary("UserService", "GetUser", "get_user");

§Feature Flags

AllFrame uses feature flags to minimize binary size. Only enable what you need:

FeatureDescriptionDefault
routerProtocol-agnostic routing
router-graphqlGraphQL adapter with async-graphql
router-grpcgRPC adapter with tonic
diCompile-time dependency injection
cqrsCQRS + Event Sourcing infrastructure
otelOpenTelemetry tracing
healthHealth check endpoints
resilienceRetry, Circuit Breaker, Rate Limiting
securitySafe logging, credential obfuscation

§Feature Examples

# Minimal REST API
allframe = { version = "0.1", default-features = false, features = ["router"] }

# Full-stack with resilience
allframe = { version = "0.1", features = ["resilience", "security"] }

# Multi-protocol gateway
allframe = { version = "0.1", features = ["router-graphql", "router-grpc"] }

§Module Overview

  • router - Protocol-agnostic request routing (REST, GraphQL, gRPC)
  • shutdown - Graceful shutdown utilities
  • cache - Caching infrastructure
  • cqrs - CQRS + Event Sourcing (requires cqrs feature)
  • resilience - Retry, Circuit Breaker, Rate Limiting (requires resilience feature)
  • security - Safe logging and credential obfuscation (requires security feature)
  • di - Compile-time dependency injection (requires di feature)
  • otel - OpenTelemetry instrumentation (requires otel feature)
  • health - Health check infrastructure (requires health feature)

§Examples

See the examples directory for complete working examples:

  • scalar_docs.rs - REST API with Scalar documentation
  • graphql_docs.rs - GraphQL API with GraphiQL playground
  • resilience.rs - Retry, Circuit Breaker, Rate Limiting
  • graceful_shutdown.rs - Production shutdown handling

§Learn More

Re-exports§

pub use async_graphql;router-graphql
pub use async_graphql_parser;router-graphql
pub use async_trait;
pub use backoff;resilience
pub use chrono;utils
pub use dashmap;cache-memory
pub use futures;router-grpc
pub use governor;rate-limit
pub use hyper;health
pub use moka;cache-memory
pub use opentelemetry;otel-otlp
pub use opentelemetry_otlp;otel-otlp
pub use opentelemetry_sdk;otel-otlp
pub use parking_lot;utils
pub use prometheus;metrics
pub use prost;router-grpc
pub use prost_types;router-grpc
pub use rand;utils
pub use redis;cache-redis
pub use reqwest;http-client
pub use serde;
pub use serde_json;
pub use tokio;
pub use tokio_stream;router-grpc
pub use tonic;router-grpc
pub use tonic_reflection;router-grpc
pub use tracing;otel
pub use tracing_opentelemetry;otel-otlp
pub use tracing_subscriber;otel-otlp
pub use url;utils

Modules§

archdi
Clean Architecture enforcement with compile-time dependency injection.
authauth
Authentication primitives with layered feature flags.
cache
Cache abstraction with in-memory and Redis backends.
cqrscqrs
CQRS + Event Sourcing infrastructure with 85% boilerplate reduction.
didi
Compile-time dependency injection infrastructure.
grpcrouter-grpc
gRPC server infrastructure with TLS support.
healthhealth
Health check infrastructure for Kubernetes-ready services.
otelotel
OpenTelemetry automatic instrumentation for distributed tracing.
prelude
Prelude module for convenient imports
resilienceresilience
Resilience patterns: Retry, Circuit Breaker, and Rate Limiting.
router
Protocol-agnostic request routing for REST, GraphQL, and gRPC.
securitysecurity
Security utilities for safe logging and credential obfuscation.
shutdown
Graceful shutdown utilities for production services.

Attribute Macros§

circuit_breakerresilience
Re-export circuit_breaker attribute macro Attribute macro for circuit breaker pattern
rate_limitedresilience
Re-export rate_limited attribute macro Attribute macro for rate limiting
retryresilience
Re-export retry attribute macro Attribute macro for automatic retry with exponential backoff

Derive Macros§

GrpcErrorrouter-grpc
Re-export GrpcError derive macro for automatic tonic::Status conversion Derive macro for automatic gRPC status conversion
HealthCheckdi
Re-export HealthCheck derive macro for automatic health check implementation Derive macro for automatic HealthCheck implementation
Obfuscatesecurity
Re-export Obfuscate derive macro for safe logging Derive macro for automatic Obfuscate implementation