Skip to main content

Crate bhtune_server

Crate bhtune_server 

Source
Expand description

bhtune-server — the Axum HTTP/REST adapter over bhtune-core/bhtune-db, and the host for the built React SPA (embedded via rust-embed, server-embed-spa). See AGENTS.md’s “Web app architecture” section for why this, rather than a desktop GUI, is the primary v1 GUI adapter.

Split into a lib (this crate, bhtune_server) and a thin main.rs binary shell so route handlers are directly testable via [tower::ServiceExt::oneshot] against build_router’s output, with no bound TCP socket needed – the same lib/bin split bhtune-cli already uses for the same reason.

Re-exports§

pub use state::AppState;

Modules§

active_run
ActiveRun: tracks every tune run currently executing in a background task, so crate::routes::runs can cancel one specific run and graceful shutdown can cancel and wait for all in-flight runs to be restored before the process actually exits.
cli
bhtune-server’s CLI surface (server-windows-service): a --config flag plus five subcommands (install/uninstall/start/stop/status) that manage this binary’s registration as a platform service.
error
ApiError: the one error type every route handler returns, and its mapping onto an HTTP status code plus a JSON {"error": "..."} body.
openapi
ApiDoc: the single [utoipa::OpenApi] aggregator listing every route and schema this crate serves. Kept as its own module (rather than folded into lib.rs) because this list is the one place that must be updated whenever a route or DTO is added – a dedicated file makes that omission easy to spot in a diff.
routes
HTTP route modules, one per resource. Each exposes a plain pub fn router() -> axum::Router<AppState>, merged together in crate::build_router.
run
The actual bhtune-server bootstrap-and-serve sequence, split out of main.rs so it can be driven two different ways (server-windows-service): directly, from an interactive console session or a systemd/launchd-managed foreground process, or from inside the Windows Service Control Manager’s own callback thread (crate::service’s #[cfg(windows)] glue), which needs its own shutdown trigger (an SCM Stop/Shutdown control event) instead of Ctrl+C/SIGTERM.
security
service
Platform service registration and lifecycle management (server-windows-service).
state
AppState: the shared state every route handler receives via axum::extract::State.

Functions§

build_router
Assembles every route module into one [axum::Router], ready to serve or to drive directly in a test via tower::ServiceExt::oneshot.