codetopo_server/lib.rs
1// Copyright (C) 2026 Nrupal Akolkar
2// SPDX-License-Identifier: AGPL-3.0-or-later
3// Part of codetopo — Owned by Nrupal Akolkar · Built with Muse by Meta.
4
5//! HTTP surface for codetopo (Phase 2 design §3, §4).
6
7pub mod auth;
8pub mod config;
9pub mod error;
10pub mod handlers;
11pub mod keys;
12pub mod metering;
13
14pub use handlers::{router, AppState};
15
16/// Builds the served application: routes, then auth + metering around them.
17///
18/// The layering order is the one §4/§5 require — [`auth::metered`] is a
19/// `route_layer`, so a request is authenticated *before* it can reach a
20/// handler and a rejected one is answered without touching a database or
21/// appending a metering record.
22pub fn app(
23 config: std::sync::Arc<config::Config>,
24 keys: std::sync::Arc<keys::KeyStore>,
25 metering: std::sync::Arc<metering::Metering>,
26) -> axum::Router {
27 let auth = std::sync::Arc::new(auth::AuthMetering::new(keys, metering));
28 auth::metered(router(AppState::new(config)), auth)
29}