1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2025 Saorsa Labs Limited
//
// Licensed under the AGPL-3.0 license
//! Domain services for Communitas
//!
//! This module provides high-level service abstractions that wrap CRDT operations
//! for specific business entities (channels, groups, issues, etc.).
use crate::{CrdtManager, CrdtResult};
use std::sync::Arc;
/// Consolidated service container for all domain services
pub struct CoreServices {
crdt_manager: Arc<CrdtManager>,
}
impl CoreServices {
/// Bootstrap services with a database path
pub async fn bootstrap(db_path: impl AsRef<std::path::Path>) -> CrdtResult<Self> {
let crdt_manager = Arc::new(CrdtManager::new(db_path).await?);
Ok(Self { crdt_manager })
}
/// Get a reference to the CRDT manager
pub fn crdt_manager(&self) -> &Arc<CrdtManager> {
&self.crdt_manager
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[tokio::test]
async fn test_bootstrap_services() {
let temp_dir = tempdir().unwrap();
let db_path = temp_dir.path().join("test.db");
let services = CoreServices::bootstrap(&db_path).await.unwrap();
assert!(Arc::strong_count(services.crdt_manager()) >= 1);
}
}