acton_service/
lib.rs

1//! # acton-service
2//!
3//! Production-ready Rust microservice framework with dual-protocol support (HTTP + gRPC).
4//!
5//! ## Features
6//!
7//! - **Dual-protocol**: HTTP (axum) + gRPC (tonic) on single port
8//! - **Middleware stack**: JWT auth, rate limiting, request tracking, panic recovery, body size limits
9//! - **Resilience**: Circuit breaker, retry with backoff, bulkhead (concurrency limiting)
10//! - **Observability**: OpenTelemetry tracing, HTTP metrics, request ID propagation
11//! - **Connection pooling**: Database (YSQL), Redis, NATS JetStream
12//! - **Health checks**: Liveness and readiness probes
13//! - **Graceful shutdown**: Proper signal handling (SIGTERM, SIGINT)
14//!
15//! ## Example
16//!
17//! ```rust,no_run
18//! use acton_service::prelude::*;
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<()> {
22//!     // Load configuration
23//!     let config = Config::load()?;
24//!
25//!     // Initialize tracing
26//!     init_tracing(&config)?;
27//!
28//!     // Build application state
29//!     let state = AppState::builder()
30//!         .config(config.clone())
31//!         .build()
32//!         .await?;
33//!
34//!     // Create router
35//!     let app = Router::new()
36//!         .route("/health", get(health))
37//!         .route("/ready", get(readiness))
38//!         .with_state(state);
39//!
40//!     // Run server
41//!     Server::new(config)
42//!         .serve(app)
43//!         .await?;
44//!
45//!     Ok(())
46//! }
47//! ```
48
49pub mod config;
50pub mod error;
51pub mod middleware;
52pub mod health;
53pub mod pool_health;
54pub mod responses;
55pub mod server;
56pub mod service_builder;
57pub mod state;
58pub mod versioning;
59
60#[cfg(feature = "database")]
61pub mod database;
62
63#[cfg(feature = "cache")]
64pub mod cache;
65
66#[cfg(feature = "events")]
67pub mod events;
68
69#[cfg(feature = "observability")]
70pub mod observability;
71
72#[cfg(feature = "openapi")]
73pub mod openapi;
74
75#[cfg(feature = "grpc")]
76pub mod grpc;
77
78/// Build-time utilities for compiling protocol buffers
79///
80/// These are used in `build.rs` scripts, not at runtime.
81pub mod build_utils;
82
83/// Prelude module for convenient imports
84pub mod prelude {
85    pub use crate::config::Config;
86
87    #[cfg(feature = "cedar-authz")]
88    pub use crate::config::CedarConfig;
89
90    pub use crate::error::{Error, Result};
91    pub use crate::health::{health, readiness, pool_metrics};
92    pub use crate::pool_health::PoolHealthSummary;
93
94    #[cfg(feature = "database")]
95    pub use crate::pool_health::DatabasePoolHealth;
96
97    #[cfg(feature = "cache")]
98    pub use crate::pool_health::RedisPoolHealth;
99
100    #[cfg(feature = "events")]
101    pub use crate::pool_health::NatsClientHealth;
102    pub use crate::middleware::{
103        Claims, JwtAuth, RateLimit, RequestTrackingConfig, PROPAGATE_HEADERS, SENSITIVE_HEADERS,
104        request_id_layer, request_id_propagation_layer, sensitive_headers_layer,
105    };
106
107    #[cfg(feature = "cache")]
108    pub use crate::middleware::{JwtRevocation, RedisJwtRevocation};
109    pub use crate::server::Server;
110    pub use crate::service_builder::{ActonService, ServiceBuilder, VersionedRoutes};
111    pub use crate::state::{AppState, AppStateBuilder};
112    pub use crate::versioning::{
113        ApiVersion, DeprecationInfo, VersionedApiBuilder, VersionedResponse,
114        extract_version_from_path, versioned_router,
115    };
116    pub use crate::responses::{
117        Accepted, Conflict, Created, FieldError, NoContent, Success, ValidationError,
118    };
119
120    #[cfg(feature = "resilience")]
121    pub use crate::middleware::ResilienceConfig;
122
123    #[cfg(feature = "otel-metrics")]
124    pub use crate::middleware::{MetricsConfig, metric_labels, metric_names};
125
126    #[cfg(feature = "governor")]
127    pub use crate::middleware::{GovernorConfig, RateLimitExceeded};
128
129    #[cfg(feature = "cedar-authz")]
130    pub use crate::middleware::CedarAuthz;
131
132    #[cfg(all(feature = "cedar-authz", feature = "cache"))]
133    pub use crate::middleware::{PolicyCache, RedisPolicyCache};
134
135    #[cfg(all(feature = "cedar-authz", feature = "grpc"))]
136    pub use crate::middleware::{CedarAuthzLayer, CedarAuthzService};
137
138    #[cfg(feature = "observability")]
139    pub use crate::observability::init_tracing;
140
141    #[cfg(feature = "openapi")]
142    pub use crate::openapi::{OpenApiBuilder, RapiDoc, ReDoc, SwaggerUI};
143
144    #[cfg(feature = "grpc")]
145    pub use crate::grpc::{
146        GrpcServer, HealthService, Request,
147        Response as GrpcResponse,
148        Status, Code,
149        request_id_interceptor, jwt_auth_interceptor, RequestIdExtension,
150        add_request_id_to_response, GrpcTracingLayer, LoggingLayer,
151    };
152
153    #[cfg(all(feature = "grpc", feature = "governor"))]
154    pub use crate::grpc::GrpcRateLimitLayer;
155
156    pub use axum::{
157        extract::{Path, Query, State},
158        http::{HeaderMap, HeaderValue, StatusCode},
159        response::{IntoResponse, Json, Response},
160        routing::{delete, get, patch, post, put},
161        Extension, Router,
162    };
163
164    pub use serde::{Deserialize, Serialize};
165    pub use tracing::{debug, error, info, warn};
166}