rust_template_foundation/lib.rs
1//! Shared infrastructure for projects spawned from `rust-template`.
2//!
3//! This crate extracts the generic plumbing (config loading, logging,
4//! health checks, metrics, OpenAPI, OIDC auth, systemd integration) so
5//! downstream projects consume it as a git dependency and receive
6//! improvements via `cargo update`.
7//!
8//! # Feature flags
9//!
10//! - **`cli`** — `CommonConfigFile` (file side of the CLI/file merge),
11//! CLI logging, `CliApp` trait, the `MergeConfig` derive (which
12//! generates `CliRaw` with per-app-prefixed env vars), and
13//! `#[foundation_main]`.
14//! - **`server`** — Health registry, metrics endpoint, OpenAPI/Scalar
15//! helpers, SPA fallback, systemd notify/watchdog, server logging.
16//! - **`auth`** (implies `server` + `cli`) — OIDC login/callback/logout
17//! handlers, `require_auth` middleware, `Server` runner, `ServerApp`
18//! trait, and `BaseServerState`.
19
20pub mod config;
21pub mod logging;
22
23#[cfg(feature = "cli")]
24pub mod app;
25
26#[cfg(feature = "server")]
27pub mod server;
28
29#[cfg(feature = "auth")]
30pub mod auth;
31
32/// Convenience re-exports used by most downstream crates.
33pub mod prelude {
34 pub use crate::config::find_config_file;
35 pub use crate::config::load_toml;
36 pub use crate::logging::{LogFormat, LogLevel};
37}
38
39// Re-export proc macros so users write
40// `use rust_template_foundation::main` and
41// `use rust_template_foundation::MergeConfig`.
42#[cfg(feature = "cli")]
43pub use rust_template_foundation_derive::foundation_main as main;
44#[cfg(feature = "cli")]
45pub use rust_template_foundation_derive::MergeConfig;
46
47// Re-exported for the `MergeConfig` derive macro to reference without
48// requiring downstream crates to depend on `thiserror` directly. Not
49// part of the public API.
50#[doc(hidden)]
51pub use thiserror;
52
53// Re-export CliApp at crate root for CLI apps.
54#[cfg(feature = "cli")]
55pub use app::CliApp;
56
57// Re-export key runner types at crate root for server apps.
58#[cfg(feature = "auth")]
59pub use server::runner::{
60 BaseServerState, Server, ServerApp, ServerError, ServerRunConfig,
61};