Skip to content

Commit eaa84b1

Browse files
committed
feat(grid+grid-state+gridpoints): split out endpoints and state crates from grid
1 parent b403774 commit eaa84b1

28 files changed

+116
-18
lines changed

Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/grid-state/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "grid-state"
3+
version = "0.1.0"
4+
5+
edition = "2024"
6+
license-file.workspace = true
7+
8+
[dependencies]
9+
auth-domain = { path = "../auth-domain" }
10+
domain = { path = "../domain" }
11+
metrics-domain = { path = "../metrics-domain" }
12+
tower-sessions-db-store = { path = "../tower-sessions-db-store" }
13+
14+
db = { workspace = true }
15+
16+
axum.workspace = true
17+
leptos = { workspace = true, features = [ "ssr", "tracing" ] }
18+
19+
gethostname = { version = "1.1" }
20+
miette.workspace = true
21+
22+
[lints]
23+
workspace = true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! App state for the grid service.
2+
13
use std::sync::Arc;
24

35
use auth_domain::AuthDomainService;
@@ -11,13 +13,17 @@ use metrics_domain::MetricsService;
1113
use miette::{Context, IntoDiagnostic, Result};
1214
use tower_sessions_db_store::DatabaseStore as DatabaseSessionStore;
1315

16+
/// Metadata for a node serving the grid service.
1417
#[derive(Debug)]
1518
pub struct NodeMeta {
19+
/// A string descriptor of the node's environment (dev, staging, prod, etc.).
1620
pub environment: String,
21+
/// The name of the node host.
1722
pub host_name: String,
1823
}
1924

2025
impl NodeMeta {
26+
/// Collect [`NodeMeta`] from the runtime environment.
2127
pub fn from_env() -> miette::Result<Self> {
2228
let env = std::env::var("GRID_ENV")
2329
.into_diagnostic()
@@ -34,17 +40,25 @@ impl NodeMeta {
3440
}
3541
}
3642

43+
/// The state of a running grid service.
3744
#[derive(Clone, Debug, FromRef)]
3845
pub struct AppState {
46+
/// The auth domain service.
3947
pub auth_domain: AuthDomainService,
48+
/// The prime domain service.
4049
pub domain: DomainService,
50+
/// The metrics domain service.
4151
pub metrics_domain: MetricsService,
52+
/// The user session store.
4253
pub session_store: DatabaseSessionStore,
54+
/// Options for leptos.
4355
pub leptos_options: LeptosOptions,
56+
/// The node metadata.
4457
pub node_meta: Arc<NodeMeta>,
4558
}
4659

4760
impl AppState {
61+
/// Builds the [`AppState`].
4862
pub async fn build() -> Result<Self> {
4963
let (org_db, user_db, store_db, entry_db, cache_db, session_db) = {
5064
let url = std::env::var("POSTGRES_URL")

crates/grid/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ publish = false
1010
auth-domain = { path = "../auth-domain" }
1111
domain = { path = "../domain" }
1212
drop-stream = { path = "../drop-stream" }
13+
grid-state = { path = "../grid-state" }
14+
gridpoints = { path = "../gridpoints" }
1315
metrics-domain = { path = "../metrics-domain" }
1416
site-app = { path = "../site-app", default-features = false, features = [ "ssr" ] }
1517
tower-sessions-db-store = { path = "../tower-sessions-db-store" }

crates/grid/src/handlers.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use axum::{
55
http::Uri,
66
response::IntoResponse,
77
};
8+
use grid_state::AppState;
89
use leptos::prelude::provide_context;
910

10-
use crate::app_state::AppState;
11-
1211
#[axum::debug_handler]
1312
pub async fn leptos_routes_handler(
1413
auth_session: AuthSession,

crates/grid/src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
//! The server-side entrypoint for Rambit.
44
5-
mod app_state;
65
mod args;
7-
mod endpoints;
86
mod handlers;
97
mod middleware;
108
mod tracing_subscribers;
11-
mod util_traits;
129

1310
use axum::{Router, handler::Handler, routing::post};
1411
use axum_login::AuthManagerLayerBuilder;
1512
use clap::Parser;
13+
use grid_state::AppState;
1614
use leptos_axum::LeptosRoutes;
1715
use miette::{Context, IntoDiagnostic, Result};
1816
use tower_http::{
@@ -25,7 +23,6 @@ use tower_sessions::{
2523
};
2624

2725
use self::{
28-
app_state::AppState,
2926
args::CliArgs,
3027
handlers::{
3128
leptos_fallback_handler, leptos_routes_handler, server_fn_handler,
@@ -60,7 +57,7 @@ async fn main() -> Result<()> {
6057

6158
// build router
6259
let router = Router::new()
63-
.nest("/api/v1", self::endpoints::router())
60+
.nest("/api/v1", gridpoints::router())
6461
.leptos_routes_with_handler(routes, leptos_routes_handler)
6562
.route("/api/sfn/{*fn_name}", post(server_fn_handler))
6663
.fallback(

crates/grid/src/middleware/on_request_metric_reporter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use grid_state::NodeMeta;
34
use http::header::{ORIGIN, USER_AGENT};
45
use metrics_domain::{
56
MetricsService,
@@ -10,8 +11,6 @@ use metrics_domain::{
1011
};
1112
use tower_http::trace::{DefaultOnRequest, OnRequest};
1213

13-
use crate::app_state::NodeMeta;
14-
1514
#[derive(Clone, Debug)]
1615
pub struct MetricReporterOnRequest {
1716
inner: DefaultOnRequest,

crates/grid/src/middleware/on_response_metric_reporter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use grid_state::NodeMeta;
34
use http::header::CONTENT_LENGTH;
45
use metrics_domain::{
56
MetricsService,
@@ -10,8 +11,6 @@ use metrics_domain::{
1011
};
1112
use tower_http::trace::{DefaultOnResponse, OnResponse};
1213

13-
use crate::app_state::NodeMeta;
14-
1514
#[derive(Clone, Debug)]
1615
pub struct MetricReporterOnResponse {
1716
inner: DefaultOnResponse,

crates/gridpoints/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "gridpoints"
3+
version = "0.1.0"
4+
5+
edition = "2024"
6+
license-file.workspace = true
7+
8+
[dependencies]
9+
auth-domain = { path = "../auth-domain" }
10+
domain = { path = "../domain" }
11+
drop-stream = { path = "../drop-stream" }
12+
grid-state = { path = "../grid-state" }
13+
14+
axum.workspace = true
15+
http = { version = "1" }
16+
serde.workspace = true
17+
serde_json.workspace = true
18+
tracing.workspace = true
19+
20+
http-body-util = { version = "0.1.3" }
21+
22+
[lints]
23+
workspace = true

0 commit comments

Comments
 (0)