jammi_server/lib.rs
1//! Library surface for the OSS `jammi-server` binary.
2//!
3//! The binary's orchestration entry-point is [`runtime::OssServer`].
4//! The library also re-exports building blocks (`build_router`,
5//! `flight::*`, `grpc::*`) so test fixtures and downstream binaries
6//! (e.g. the `jammi` CLI's `serve` subcommand) can compose the same
7//! pieces without reimplementing them.
8//!
9//! For downstream *composition*, [`runtime::assemble_grpc_chain`] returns an
10//! [`runtime::AssembledChain`] with the engine's services pre-mounted; a
11//! downstream chains [`runtime::AssembledChain::mount`] to add its own services
12//! beside the engine's on one listener, then serves — or splits via
13//! [`runtime::AssembledChain::into_axum_router`] to compose a single axum
14//! listener of its own. `serve_grpc_chain` is the thin OSS-only path over the
15//! same seam.
16
17pub mod error;
18pub mod flight;
19pub mod grpc;
20pub mod grpc_web_trailers;
21pub mod metrics_layer;
22pub mod routes;
23pub mod runtime;
24pub mod telemetry;
25pub mod tenant_resolver_layer;
26pub mod tiers;
27
28use std::sync::Arc;
29
30use axum::routing::get;
31use axum::Router;
32
33use jammi_db::catalog::topic_repo::TopicRepo;
34use jammi_db::trigger::{Publisher, Subscriber};
35
36use crate::error::fallback_handler;
37use crate::routes::health::{self, MetricsRegistry};
38use crate::runtime::ReadinessProbe;
39
40/// Trigger-stream handles attached to the gRPC server. The caller
41/// constructs these once per deployment (sharing one broker, publisher,
42/// subscriber, and topic catalog repo across every connection).
43///
44/// Kept as a public struct because integration tests still wire trigger
45/// handles manually for fixtures that need to drive a stubbed broker.
46/// Production code goes through [`runtime::OssServer`] which derives
47/// the same handles from the engine session.
48pub struct TriggerHandles {
49 pub topic_repo: Arc<TopicRepo>,
50 pub publisher: Arc<Publisher>,
51 pub subscriber: Arc<Subscriber>,
52}
53
54/// Build the side-channel router with `/healthz` only — no readiness
55/// or metrics state attached. Callers that need the full surface
56/// construct the router through [`runtime::OssServer`].
57pub fn build_router() -> Router {
58 Router::new()
59 .route("/healthz", get(health::healthz))
60 .fallback(fallback_handler)
61}
62
63/// Build the full side-channel router exposing `/healthz`, `/readyz`,
64/// and `/metrics`. The readiness probe and metrics registry are passed
65/// in as `Arc`s so test fixtures can substitute stubs.
66pub fn build_health_router(
67 readiness: Arc<ReadinessProbe>,
68 metrics: Arc<MetricsRegistry>,
69) -> Router {
70 let readyz = Router::new()
71 .route("/readyz", get(health::readyz))
72 .with_state(readiness);
73 let metrics = Router::new()
74 .route("/metrics", get(health::metrics))
75 .with_state(metrics);
76 Router::new()
77 .route("/healthz", get(health::healthz))
78 .merge(readyz)
79 .merge(metrics)
80 .fallback(fallback_handler)
81}