Skip to main content

haystack_server/
state.rs

1//! Application state shared across all request handlers.
2
3use std::sync::Arc;
4
5use haystack_core::graph::SharedGraph;
6use haystack_core::ontology::DefNamespace;
7
8use crate::actions::ActionRegistry;
9use crate::auth::AuthManager;
10use crate::his_provider::HistoryProvider;
11use crate::ws::WatchManager;
12
13/// Type alias for the shared state used by Axum extractors.
14pub type SharedState = Arc<AppState>;
15
16/// Shared application state injected into every Axum handler via `State`.
17pub struct AppState {
18    /// Thread-safe entity graph.
19    pub graph: SharedGraph,
20    /// Haystack 4 ontology namespace for def/spec operations.
21    pub namespace: parking_lot::RwLock<DefNamespace>,
22    /// SCRAM authentication manager.
23    pub auth: AuthManager,
24    /// Watch subscription manager for change polling.
25    pub watches: WatchManager,
26    /// Action dispatch registry for the `invokeAction` op.
27    pub actions: ActionRegistry,
28    /// Pluggable time-series history store for hisRead/hisWrite.
29    pub his: Box<dyn HistoryProvider>,
30    /// Instant when the server was started, used for uptime calculation.
31    pub started_at: std::time::Instant,
32}