Skip to main content

nova_boot/
traits.rs

1use axum::Router;
2
3#[async_trait::async_trait]
4/// A plugin provides optional features to a Nova application.
5///
6/// Plugins should implement lifecycle hooks and may extend the application's
7/// router to register additional routes or middleware. Plugins are loaded and
8/// initialized by `NovaApp` during startup.
9pub trait NovaPlugin: Send + Sync {
10    /// Human-readable plugin name used in logs.
11    fn name(&self) -> &'static str;
12
13    /// Initialization hook called during application startup.
14    async fn on_init(&self);
15
16    /// Shutdown hook called during application shutdown. Default is noop.
17    async fn on_shutdown(&self) {}
18
19    /// Extend the provided `Router<()>` with plugin routes or layers.
20    fn extend_router(&self, router: Router<()>) -> Router<()>;
21}
22
23/// Represents a logical module within the framework.
24pub trait NovaModule {
25    fn module_name(&self) -> &'static str;
26}
27
28/// Marker trait for request models. Implementations can override
29/// `request_model_name` to provide a readable type name for docs and telemetry.
30pub trait NovaRequestModel {
31    fn request_model_name() -> &'static str
32    where
33        Self: Sized,
34    {
35        std::any::type_name::<Self>()
36    }
37}
38
39/// Marker trait for response models. Implementations can override
40/// `response_model_name` to provide a readable type name for docs and telemetry.
41pub trait NovaResponseModel {
42    fn response_model_name() -> &'static str
43    where
44        Self: Sized,
45    {
46        std::any::type_name::<Self>()
47    }
48}
49
50#[async_trait::async_trait]
51pub trait NovaLifecycle: Send + Sync {
52    async fn on_start(&self) {}
53
54    async fn on_stop(&self) {}
55}
56
57pub trait NovaRouterExtender {
58    fn extend_router(&self, router: Router) -> Router;
59}