Skip to main content

thread_services/
facade.rs

1// SPDX-FileCopyrightText: 2025 Knitli Inc. <knitli@knit.li>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! # Thread Service Facade
5//!
6//! This module provides a simplified high-level interface for consuming Thread services.
7//! It hides the complexity of underlying dataflow graphs and storage implementations,
8//! offering a clean API for CLI, LSP, and other tools.
9
10use crate::error::ServiceResult;
11use crate::traits::CodeAnalyzer;
12#[cfg(feature = "storage-traits")]
13use crate::traits::StorageService;
14use crate::types::ParsedDocument;
15use std::path::Path;
16use std::sync::Arc;
17
18/// Main entry point for Thread services.
19///
20/// The Facade pattern is used here to provide a simplified interface to a
21/// complex subsystem (the CocoIndex dataflow engine and storage backend).
22pub struct ThreadService<A: CodeAnalyzer<D>, D: crate::types::Doc + Send + Sync> {
23    #[allow(dead_code)]
24    analyzer: Arc<A>,
25    #[allow(dead_code)]
26    #[cfg(feature = "storage-traits")]
27    storage: Option<Arc<dyn StorageService>>,
28    _marker: std::marker::PhantomData<D>,
29}
30
31impl<A: CodeAnalyzer<D>, D: crate::types::Doc + Send + Sync> ThreadService<A, D> {
32    /// Create a new ThreadService with provided components
33    #[cfg(feature = "storage-traits")]
34    pub fn new(analyzer: Arc<A>, storage: Option<Arc<dyn StorageService>>) -> Self {
35        Self {
36            analyzer,
37            storage,
38            _marker: std::marker::PhantomData,
39        }
40    }
41
42    #[cfg(not(feature = "storage-traits"))]
43    pub fn new(analyzer: Arc<A>) -> Self {
44        Self {
45            analyzer,
46            _marker: std::marker::PhantomData,
47        }
48    }
49
50    /// Analyze a single file or directory path.
51    ///
52    /// This method orchestrates the analysis process:
53    /// 1. Discovers files (if path is directory)
54    /// 2. Parses and analyzes code
55    /// 3. Stores results (if storage is configured)
56    pub async fn analyze_path(&self, _path: &Path) -> ServiceResult<Vec<ParsedDocument<D>>> {
57        // Implementation would delegate to analyzer
58        // This is a placeholder for the facade interface
59
60        Ok(vec![])
61    }
62}