Skip to main content

mentedb_server/
routes.rs

1//! Route definitions for the MenteDB REST API.
2
3use std::sync::Arc;
4
5use axum::Router;
6use axum::routing::{get, post};
7
8use crate::handlers;
9use crate::state::AppState;
10use crate::websocket;
11
12/// Build the complete axum router with all v1 API routes.
13pub fn build_router(state: Arc<AppState>) -> Router {
14    Router::new()
15        .route("/v1/health", get(handlers::health))
16        .route("/v1/memories", post(handlers::store_memory))
17        .route(
18            "/v1/memories/{id}",
19            get(handlers::get_memory).delete(handlers::forget_memory),
20        )
21        .route("/v1/recall", post(handlers::recall_memories))
22        .route("/v1/search", post(handlers::search_similar))
23        .route("/v1/edges", post(handlers::create_edge))
24        .route("/v1/stats", get(handlers::stats))
25        .route("/v1/ingest", post(handlers::ingest_conversation))
26        .route("/v1/process_turn", post(handlers::process_turn))
27        .route("/v1/auth/token", post(crate::auth::generate_token))
28        .route(
29            "/v1/spaces",
30            post(handlers::create_space).get(handlers::list_spaces),
31        )
32        .route("/v1/spaces/{id}/grant", post(handlers::grant_space_access))
33        .route("/v1/ws/stream", get(websocket::ws_handler))
34        .route(
35            crate::cluster::GOSSIP_PATH,
36            post(crate::cluster::gossip_handler),
37        )
38        .route("/metrics", get(crate::metrics::handler))
39        .route("/console", get(crate::console::handler))
40        .route("/v1/admin/memories", get(handlers::admin_list_memories))
41        .route(
42            "/v1/admin/memories/{id}",
43            axum::routing::delete(handlers::admin_delete_memory),
44        )
45        .route("/v1/admin/mql", post(handlers::admin_run_mql))
46        .with_state(state)
47}