Skip to main content

tuitbot_server/
state.rs

1//! Shared application state for the tuitbot server.
2
3use std::path::PathBuf;
4use std::sync::Arc;
5
6use tokio::sync::{broadcast, Mutex};
7use tuitbot_core::automation::Runtime;
8use tuitbot_core::content::ContentGenerator;
9use tuitbot_core::storage::DbPool;
10
11use crate::ws::WsEvent;
12
13/// Shared application state accessible by all route handlers.
14pub struct AppState {
15    /// SQLite connection pool.
16    pub db: DbPool,
17    /// Path to the configuration file.
18    pub config_path: PathBuf,
19    /// Data directory for media storage (parent of config file).
20    pub data_dir: PathBuf,
21    /// Broadcast channel sender for real-time WebSocket events.
22    pub event_tx: broadcast::Sender<WsEvent>,
23    /// Local bearer token for API authentication.
24    pub api_token: String,
25    /// Optional automation runtime handle for start/stop control.
26    pub runtime: Mutex<Option<Runtime>>,
27    /// Optional content generator for AI assist endpoints.
28    pub content_generator: Option<Arc<ContentGenerator>>,
29}