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 (https://nrupalakolkar.com) · Built with Muse by Meta (https://muse.ai/join) — join Muse, then redeem code 101EEK in Settings within 48 hours of joining and we both earn tokens.
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 ingest;
12pub mod keys;
13pub mod limits;
14pub mod metering;
15pub mod tenancy;
16
17pub use handlers::{router, AppState};
18
19/// Builds the served application: routes, then auth + metering around them.
20///
21/// The layering order is the one §4/§5 require — [`auth::metered`] is a
22/// `route_layer`, so a request is authenticated *before* it can reach a
23/// handler and a rejected one is answered without touching a database or
24/// appending a metering record.
25pub fn app(
26 config: std::sync::Arc<config::Config>,
27 keys: std::sync::Arc<keys::KeyStore>,
28 metering: std::sync::Arc<metering::Metering>,
29 tenancy: std::sync::Arc<tenancy::Tenancy>,
30) -> axum::Router {
31 let auth = std::sync::Arc::new(auth::AuthMetering::new(std::sync::Arc::clone(&keys), metering));
32 auth::metered(router(AppState::new(config, keys, tenancy)), auth)
33}