diff --git a/Cargo.lock b/Cargo.lock index 9b00388..df30e15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,8 @@ checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" name = "arch-api" version = "0.2.0" dependencies = [ - "arch-core", + "arch-domain-api", + "arch-utils", "axum", "hyper", "hyper-util", @@ -149,33 +150,44 @@ dependencies = [ ] [[package]] -name = "arch-core" +name = "arch-db" version = "0.2.0" dependencies = [ - "arch-db", - "arch-utils", - "async-trait", + "sea-orm", + "sea-orm-migration", + "serde", + "serde_json", "thiserror", "tracing", + "tracing-log", ] [[package]] -name = "arch-core-models" +name = "arch-domain-api" version = "0.2.0" +dependencies = [ + "arch-db", + "arch-utils", + "async-trait", + "thiserror", +] [[package]] -name = "arch-db" +name = "arch-domain-core" version = "0.2.0" dependencies = [ - "sea-orm", - "sea-orm-migration", - "serde", - "serde_json", + "arch-db", + "arch-domain-api", + "arch-utils", + "async-trait", "thiserror", "tracing", - "tracing-log", ] +[[package]] +name = "arch-domain-models" +version = "0.2.0" + [[package]] name = "arch-utils" version = "0.2.0" @@ -1933,8 +1945,8 @@ version = "0.2.0" dependencies = [ "anyhow", "arch-api", - "arch-core", "arch-db", + "arch-domain-core", "clap", "config", "log", diff --git a/Cargo.toml b/Cargo.toml index 6fd5b10..aaca5a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,9 +3,10 @@ resolver = "2" members = [ "crates/rust-arch", "crates/arch-api", - "crates/arch-core", - "crates/arch-core-models", "crates/arch-db", + "crates/arch-domain-api", + "crates/arch-domain-core", + "crates/arch-domain-models", "crates/arch-utils", ] @@ -21,8 +22,10 @@ rust-version = "1.80" [workspace.dependencies] arch-api = { path = "crates/arch-api" } -arch-core = { path = "crates/arch-core" } arch-db = { path = "crates/arch-db" } +arch-domain-api = { path = "crates/arch-domain-api" } +arch-domain-core = { path = "crates/arch-domain-core" } +arch-domain-models = { path = "crates/arch-domain-models" } arch-utils = { path = "crates/arch-utils" } async-trait = "0.1.81" diff --git a/crates/arch-api/Cargo.toml b/crates/arch-api/Cargo.toml index 44ce48a..6a0e4b0 100644 --- a/crates/arch-api/Cargo.toml +++ b/crates/arch-api/Cargo.toml @@ -11,7 +11,8 @@ rust-version.workspace = true publish = false [dependencies] -arch-core.workspace = true +arch-domain-api.workspace = true +arch-utils.workspace = true thiserror.workspace = true tokio.workspace = true diff --git a/crates/arch-api/src/http.rs b/crates/arch-api/src/http.rs index 4d5966a..19f9334 100644 --- a/crates/arch-api/src/http.rs +++ b/crates/arch-api/src/http.rs @@ -1,7 +1,6 @@ use std::{net::SocketAddr, sync::Arc}; -use arch_core::ArchService; - +use arch_domain_api::ArchApi; use axum::response::{IntoResponse, Response}; use hyper::StatusCode; use tokio::net::TcpListener; @@ -12,13 +11,13 @@ use crate::ApiError; pub(crate) mod handlers; pub(crate) mod health; -pub async fn start_server(port: u16, arch_service: Arc, subsys: SubsystemHandle) -> Result<(), ApiError> { +pub async fn start_server(port: u16, arch_api: Arc, subsys: SubsystemHandle) -> Result<(), ApiError> { tracing::trace!("Starting http service"); let addr: SocketAddr = format!("0.0.0.0:{}", port).parse().map_err(|_| ApiError::BadPort(port))?; let listener = TcpListener::bind(addr).await.unwrap(); - let routes = handlers::get_routes(arch_service.clone()); + let routes = handlers::get_routes(arch_api.clone()); tracing::info!("Listening on port {}", port); loop { diff --git a/crates/arch-api/src/http/handlers.rs b/crates/arch-api/src/http/handlers.rs index c27ed0a..1d90be8 100644 --- a/crates/arch-api/src/http/handlers.rs +++ b/crates/arch-api/src/http/handlers.rs @@ -1,7 +1,7 @@ use crate::ApiError; use std::{net::SocketAddr, sync::Arc, time::Duration}; -use arch_core::ArchService; +use arch_domain_api::ArchApi; use axum::{extract::Request, routing::get, Router}; use hyper::body::Incoming; use hyper_util::rt::TokioIo; @@ -12,10 +12,10 @@ use tower_http::timeout::TimeoutLayer; use super::health; -pub fn get_routes(arch_service: Arc) -> Router<()> { +pub fn get_routes(arch_api: Arc) -> Router<()> { axum::Router::new() .route("/api/v1/health", get(health::health)) - .with_state(arch_service.health_service.clone()) + .with_state(arch_api.health_api.clone()) .layer(TimeoutLayer::new(Duration::from_secs(2))) } diff --git a/crates/arch-api/src/http/health.rs b/crates/arch-api/src/http/health.rs index c619b39..b8139ae 100644 --- a/crates/arch-api/src/http/health.rs +++ b/crates/arch-api/src/http/health.rs @@ -1,12 +1,11 @@ -use std::sync::Arc; - -use arch_core::HealthService; +use arch_domain_api::HealthApi; +use arch_utils::arcbox::ArcBox; use axum::{extract::State, response::IntoResponse}; use hyper::StatusCode; -#[tracing::instrument(level = "trace", skip(health_service))] -pub(crate) async fn health(State(health_service): State>>) -> impl IntoResponse { - match health_service.is_healthy().await { +#[tracing::instrument(level = "trace", skip(health_api))] +pub(crate) async fn health(State(health_api): State>) -> impl IntoResponse { + match health_api.is_healthy().await { true => StatusCode::OK, false => StatusCode::BAD_REQUEST, } diff --git a/crates/arch-core/src/lib.rs b/crates/arch-core/src/lib.rs deleted file mode 100644 index 766fcd4..0000000 --- a/crates/arch-core/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::sync::Arc; - -use arch_db::DatabaseRepository; -use arch_utils::{arcbox, arcbox::ArcBox}; -use error::Error; -use health::HealthServiceImpl; - -pub mod error; - -mod health; -pub use health::HealthService; - -pub struct ArchService { - pub health_service: ArcBox, -} - -#[tracing::instrument(level = "trace", skip(database))] -pub async fn create_service(database: Arc) -> Result { - let health_service = HealthServiceImpl::new(database.clone()); - let health_service: ArcBox = arcbox!(health_service); - - Ok(ArchService { health_service }) -} diff --git a/crates/arch-core/Cargo.toml b/crates/arch-domain-api/Cargo.toml similarity index 89% rename from crates/arch-core/Cargo.toml rename to crates/arch-domain-api/Cargo.toml index f96ae07..daf8afb 100644 --- a/crates/arch-core/Cargo.toml +++ b/crates/arch-domain-api/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "arch-core" +name = "arch-domain-api" version.workspace = true edition.workspace = true authors.workspace = true @@ -16,4 +16,3 @@ arch-utils.workspace = true async-trait.workspace = true thiserror.workspace = true -tracing.workspace = true diff --git a/crates/arch-core/src/error.rs b/crates/arch-domain-api/src/error.rs similarity index 100% rename from crates/arch-core/src/error.rs rename to crates/arch-domain-api/src/error.rs diff --git a/crates/arch-domain-api/src/health.rs b/crates/arch-domain-api/src/health.rs new file mode 100644 index 0000000..856e547 --- /dev/null +++ b/crates/arch-domain-api/src/health.rs @@ -0,0 +1,6 @@ +use async_trait::async_trait; + +#[async_trait] +pub trait HealthApi: Send + Sync { + async fn is_healthy(&self) -> bool; +} diff --git a/crates/arch-domain-api/src/lib.rs b/crates/arch-domain-api/src/lib.rs new file mode 100644 index 0000000..15a2bb4 --- /dev/null +++ b/crates/arch-domain-api/src/lib.rs @@ -0,0 +1,11 @@ +mod health; + +pub mod error; +pub use error::Error; + +use arch_utils::arcbox::ArcBox; +pub use health::HealthApi; + +pub struct ArchApi { + pub health_api: ArcBox, +} diff --git a/crates/arch-domain-core/Cargo.toml b/crates/arch-domain-core/Cargo.toml new file mode 100644 index 0000000..1359ce7 --- /dev/null +++ b/crates/arch-domain-core/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "arch-domain-core" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +rust-version.workspace = true +publish = false + +[dependencies] +arch-db.workspace = true +arch-domain-api.workspace = true +arch-utils.workspace = true + +async-trait.workspace = true +thiserror.workspace = true +tracing.workspace = true diff --git a/crates/arch-core/src/health.rs b/crates/arch-domain-core/src/health.rs similarity index 70% rename from crates/arch-core/src/health.rs rename to crates/arch-domain-core/src/health.rs index 8794121..7922892 100644 --- a/crates/arch-core/src/health.rs +++ b/crates/arch-domain-core/src/health.rs @@ -1,25 +1,21 @@ use std::sync::Arc; use arch_db::DatabaseRepository; +use arch_domain_api::HealthApi; use async_trait::async_trait; -#[async_trait] -pub trait HealthService: Send + Sync { - async fn is_healthy(&self) -> bool; -} - #[derive(Clone)] -pub(crate) struct HealthServiceImpl { +pub(crate) struct HealthService { repository: Arc, } -impl HealthServiceImpl { +impl HealthService { pub(crate) fn new(repository: Arc) -> Self { Self { repository } } } #[async_trait] -impl HealthService for HealthServiceImpl { +impl HealthApi for HealthService { #[tracing::instrument(level = "trace", skip(self))] async fn is_healthy(&self) -> bool { let db_healthy = !self.repository.database.get_postgres_connection_pool().is_closed(); diff --git a/crates/arch-domain-core/src/lib.rs b/crates/arch-domain-core/src/lib.rs new file mode 100644 index 0000000..a3bf091 --- /dev/null +++ b/crates/arch-domain-core/src/lib.rs @@ -0,0 +1,16 @@ +use std::sync::Arc; + +use arch_db::DatabaseRepository; +use arch_domain_api::{ArchApi, Error, HealthApi}; +use arch_utils::{arcbox, arcbox::ArcBox}; +use health::HealthService; + +mod health; + +#[tracing::instrument(level = "trace", skip(database))] +pub async fn create_service(database: Arc) -> Result { + let health_service = HealthService::new(database.clone()); + let health_api: ArcBox = arcbox!(health_service); + + Ok(ArchApi { health_api }) +} diff --git a/crates/arch-core-models/Cargo.toml b/crates/arch-domain-models/Cargo.toml similarity index 84% rename from crates/arch-core-models/Cargo.toml rename to crates/arch-domain-models/Cargo.toml index 3f4ea23..5e61af9 100644 --- a/crates/arch-core-models/Cargo.toml +++ b/crates/arch-domain-models/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "arch-core-models" +name = "arch-domain-models" version.workspace = true edition.workspace = true authors.workspace = true @@ -8,5 +8,6 @@ homepage.workspace = true repository.workspace = true readme.workspace = true rust-version.workspace = true +publish = false [dependencies] diff --git a/crates/arch-core-models/src/lib.rs b/crates/arch-domain-models/src/lib.rs similarity index 100% rename from crates/arch-core-models/src/lib.rs rename to crates/arch-domain-models/src/lib.rs diff --git a/crates/rust-arch/Cargo.toml b/crates/rust-arch/Cargo.toml index d6c7e44..e8d0ce5 100644 --- a/crates/rust-arch/Cargo.toml +++ b/crates/rust-arch/Cargo.toml @@ -31,7 +31,7 @@ config = "0.14.0" log = "0.4.22" arch-api.workspace = true -arch-core.workspace = true +arch-domain-core.workspace = true arch-db.workspace = true serde.workspace = true diff --git a/crates/rust-arch/src/bin/rust-arch.rs b/crates/rust-arch/src/bin/rust-arch.rs index 4f632aa..6c66b88 100644 --- a/crates/rust-arch/src/bin/rust-arch.rs +++ b/crates/rust-arch/src/bin/rust-arch.rs @@ -1,10 +1,10 @@ use std::{sync::Arc, time::Duration}; use arch_api::http::start_server; -use arch_core::create_service; use anyhow::{Context, Result}; use arch_db::create_database_connection; +use arch_domain_core::create_service; use rust_arch::{ args::{self, Args}, config::RustArchConfig,