axum_realtime_kit/lib.rs
1//! # Axum Realtime Kit
2//!
3//! A toolkit for building scalable, real-time applications with Axum, WebSockets,
4//! and Redis Pub/Sub. This crate provides generic building blocks to help you focus
5//! on your application's business logic instead of the boilerplate for managing
6//! connections and state.
7//!
8//! ## Core Features
9//!
10//! - **Generic `WebsocketService`**: Manages the entire lifecycle of WebSocket connections.
11//! - **Redis Pub/Sub Integration**: Horizontally scale your service across multiple instances.
12//! - **Pluggable Logic**: Use the `MessageHandler` trait to define your application's behavior.
13//! - **Flexible Authentication**: A generic `WsAuth` extractor that works with headers or query params.
14//! - **Request Coalescing (Optional)**: A generic `CoalescingService` to prevent dogpiling on expensive operations.
15//!
16//! ## Getting Started
17//!
18//! See the documentation for the `ws` module for a full example of how to set up the `WebsocketService`.
19//!
20//! ---
21
22// The `ws` module contains all WebSocket-related logic.
23pub mod ws;
24
25// It will only be part of the crate if the "coalescing" feature is enabled.
26#[cfg(feature = "coalescing")]
27pub mod coalescing;
28
29// It will only be part of the crate if the "auth" feature is enabled.
30#[cfg(feature = "auth")]
31pub mod auth;
32
33/// Public prelude for convenience.
34///
35/// This allows users to import the most common types with a single `use` statement:
36/// `use axum_realtime_kit::prelude::*;`
37pub mod prelude {
38 // Re-export the main WebSocket service components.
39 pub use crate::ws::{
40 handler::{ConnectionContext, MessageHandler},
41 service::WebsocketService,
42 upgrade::upgrade_handler,
43 };
44
45 // Re-export the CoalescingService if the feature is enabled.
46 #[cfg(feature = "coalescing")]
47 pub use crate::coalescing::CoalescingService;
48
49 // Re-export the WsAuth extractor if the feature is enabled.
50 #[cfg(feature = "auth")]
51 pub use crate::auth::WsAuth;
52}