Skip to main content

communitas_core/
services.rs

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