Skip to main content

mnemo_admin/
lib.rs

1pub mod handlers;
2
3use std::sync::Arc;
4
5use axum::Router;
6use axum::routing::{get, post};
7use mnemo_core::query::MnemoEngine;
8
9/// Construct the Axum router for the Mnemo admin dashboard.
10///
11/// Mounts all admin API endpoints under `/admin/api/` and the HTML dashboard
12/// at `/admin/`. The router carries `Arc<MnemoEngine>` as shared state.
13///
14/// # Routes
15///
16/// | Method | Path                            | Description                    |
17/// |--------|---------------------------------|--------------------------------|
18/// | GET    | `/admin/`                       | HTML dashboard                 |
19/// | GET    | `/admin/api/health`             | Health check                   |
20/// | GET    | `/admin/api/stats`              | Aggregate statistics           |
21/// | GET    | `/admin/api/agents`             | List known agent IDs           |
22/// | GET    | `/admin/api/memories`           | Paginated memory browser       |
23/// | GET    | `/admin/api/events`             | Paginated event timeline       |
24/// | POST   | `/admin/api/quarantine/:id`     | Quarantine a memory            |
25/// | POST   | `/admin/api/unquarantine/:id`   | Release memory from quarantine |
26pub fn router(engine: Arc<MnemoEngine>) -> Router {
27    Router::new()
28        // Dashboard
29        .route("/admin/", get(handlers::dashboard_handler))
30        // API
31        .route("/admin/api/health", get(handlers::health_handler))
32        .route("/admin/api/stats", get(handlers::stats_handler))
33        .route("/admin/api/agents", get(handlers::agents_handler))
34        .route("/admin/api/memories", get(handlers::memories_handler))
35        .route("/admin/api/events", get(handlers::events_handler))
36        .route(
37            "/admin/api/quarantine/{id}",
38            post(handlers::quarantine_handler),
39        )
40        .route(
41            "/admin/api/unquarantine/{id}",
42            post(handlers::unquarantine_handler),
43        )
44        .layer(tower_http::cors::CorsLayer::permissive())
45        .layer(tower_http::trace::TraceLayer::new_for_http())
46        .with_state(engine)
47}