web_server_abstraction/
lib.rs

1//! # Web Server Abstraction - Production-Ready Framework
2//!
3//! A comprehensive, production-ready web server abstraction layer providing
4//! a unified interface across multiple Rust web frameworks with enterprise-grade features.
5//!
6//! ## Key Features
7//!
8//! - **Framework Agnostic**: Unified API for Axum, Actix-Web, Warp, Rocket, Salvo, Poem
9//! - **Ultra-Low Latency**: Optimized for sub-millisecond response times
10//! - **Production Security**: CSRF, XSS protection, input sanitization, TLS/SSL
11//! - **Unified Configuration**: Centralized configuration with multiple sources (file, env, remote)
12//! - **Comprehensive Monitoring**: Metrics, distributed tracing, health checks, alerting
13//! - **Multi-Language Support**: FFI layer for Python, Node.js, Go, and C integration
14//! - **Performance Benchmarking**: Built-in latency and throughput validation
15//! - **Enhanced Middleware**: CORS, compression, rate limiting, security headers
16//! - **Type Safety**: Leverages Rust's type system for compile-time guarantees
17//! - **Async First**: Built for modern async Rust with Tower ecosystem integration
18//!
19//! ## Supported Frameworks
20//!
21//! - **Axum** - High-performance async web framework
22//! - **Actix-Web** - Actor-based web framework
23//! - **Warp** - Composable web framework
24//! - **Rocket** - Type-safe web framework
25//! - **Salvo** - Simple and powerful web framework
26//! - **Poem** - Fast and powerful web framework
27//! - **Mock** - For testing and development
28//!
29//! ## Quick Start
30//!
31//! ```rust,no_run
32//! use web_server_abstraction::{WebServer, HttpMethod, Response};
33//!
34//! #[tokio::main]
35//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
36//!     let server = WebServer::new()
37//!         .route("/hello", HttpMethod::GET, |_req| async {
38//!             Ok(Response::ok().body("Hello, Production World!"))
39//!         })
40//!         .route("/health", HttpMethod::GET, |_req| async {
41//!             Ok(Response::ok()
42//!                 .header("content-type", "application/json")
43//!                 .body(r#"{"status": "healthy"}"#))
44//!         })
45//!         .bind("127.0.0.1:3000")
46//!         .await?;
47//!
48//!     server.run().await?;
49//!     Ok(())
50//! }
51//! ```
52//!
53//! ## Production Configuration
54//!
55//! ```yaml
56//! # config/server.yaml
57//! server:
58//!   host: "0.0.0.0"
59//!   port: 8080
60//!   workers: 4
61//!
62//! security:
63//!   csrf_protection: true
64//!   tls:
65//!     enabled: true
66//!     cert_path: "/path/to/cert.pem"
67//!     key_path: "/path/to/key.pem"
68//!
69//! monitoring:
70//!   metrics_enabled: true
71//!   tracing_enabled: true
72//!   health_checks_enabled: true
73//! ```
74
75pub mod adapters;
76pub mod auth;
77pub mod benchmarks;
78pub mod config;
79pub mod content;
80pub mod core;
81pub mod cross_platform_testing;
82pub mod database;
83pub mod enhanced_middleware;
84pub mod error;
85pub mod ffi;
86pub mod middleware;
87pub mod monitoring;
88pub mod mountable;
89pub mod performance;
90pub mod routing;
91pub mod security;
92pub mod session;
93pub mod state;
94pub mod static_files;
95pub mod types;
96
97// Re-export core types and new production modules
98pub use auth::{
99    AuthContext, AuthContextConfig, AuthError, AuthMiddlewareResult, AuthRequirements,
100    RequestAuthExt, UserSession, auth_middleware, enhanced_auth_middleware,
101};
102pub use config::{ConfigManager, MonitoringConfig, SecurityConfig, WebServerConfig};
103pub use core::{Handler, HandlerFn, Route, WebServer};
104pub use enhanced_middleware::{
105    CompressionMiddleware, CorsMiddleware, EnhancedMiddleware, MiddlewareStack,
106    RateLimitMiddleware, SecurityHeadersMiddleware,
107};
108pub use error::{Result, WebServerError};
109pub use ffi::{FfiContext, ws_create_server as ffi_create_server};
110pub use monitoring::{
111    Alert, AlertSeverity, HealthStatus, MonitoringSystem, PerformanceStats, TraceContext,
112};
113pub use performance::{
114    AdapterBenchmark, BenchmarkConfig, BenchmarkResults, LatencyCollector, PerformanceMetrics,
115};
116pub use security::SecurityStats;
117pub use security::{
118    CspMiddleware, CsrfMiddleware, SecurityContext, SecurityIssue, SecurityMiddleware,
119    SecurityValidationResult, XssProtectionMiddleware, sanitize,
120};
121pub use types::{
122    Cookie, FileUpload, Headers, HttpMethod, MultipartForm, Request, Response, StatusCode,
123};
124
125// Re-export existing modules
126pub use content::{
127    CompressionMiddleware as LegacyCompressionMiddleware, ContentNegotiationMiddleware,
128};
129pub use database::{
130    ConnectionPool, DatabaseConfig, DatabaseConnection, DatabaseError, DatabaseValue,
131    FromDatabaseValue, MockDatabase, PoolStats, QueryBuilder, Row, Transaction,
132};
133pub use mountable::{
134    InterfaceBuilder, InterfaceRegistry, MountOptions, MountableInterface, OpenApiSpec,
135    RouteDefinition, RouteDoc,
136};
137pub use routing::{Route as RoutePattern, Router};
138pub use session::{MemorySessionStore, Session, SessionExt, SessionManager, SessionStore};
139pub use state::{AppState, Config, Environment, SharedState};
140pub use static_files::{
141    StaticFileConfig, StaticFileHandler, serve_static, serve_static_with_prefix, static_files,
142};
143
144// Re-export benchmarking utilities (legacy)
145pub use benchmarks::{
146    BenchmarkConfig as LegacyBenchmarkConfig, BenchmarkResults as LegacyBenchmarkResults,
147    PerformanceProfiler,
148};
149
150// Re-export framework adapters when features are enabled
151pub use adapters::mock::MockAdapter;
152
153#[cfg(feature = "axum")]
154pub use adapters::axum::AxumAdapter;
155
156#[cfg(feature = "actix-web")]
157pub use adapters::actix_web::ActixWebAdapter;
158
159#[cfg(feature = "warp")]
160pub use adapters::warp::WarpAdapter;
161
162#[cfg(feature = "rocket")]
163pub use adapters::rocket::RocketAdapter;
164
165#[cfg(feature = "salvo")]
166pub use adapters::salvo::SalvoAdapter;
167
168#[cfg(feature = "poem")]
169pub use adapters::poem::PoemAdapter;