Skip to main content

boundary_core/
analyzer.rs

1use std::path::{Path, PathBuf};
2
3use anyhow::Result;
4use tree_sitter::Tree;
5
6use crate::types::{Component, Dependency};
7
8/// A parsed source file with its tree-sitter AST and original content.
9pub struct ParsedFile {
10    pub path: PathBuf,
11    pub tree: Tree,
12    pub content: String,
13}
14
15/// Trait that each language analyzer must implement.
16pub trait LanguageAnalyzer: Send + Sync {
17    /// Language name (e.g., "go", "rust")
18    fn language(&self) -> &'static str;
19
20    /// File extensions this analyzer handles (e.g., &["go"])
21    fn file_extensions(&self) -> &[&str];
22
23    /// Parse a source file into a ParsedFile.
24    fn parse_file(&self, path: &Path, content: &str) -> Result<ParsedFile>;
25
26    /// Extract architectural components from a parsed file.
27    fn extract_components(&self, parsed: &ParsedFile) -> Vec<Component>;
28
29    /// Extract dependencies (imports, type references, etc.) from a parsed file.
30    fn extract_dependencies(&self, parsed: &ParsedFile) -> Vec<Dependency>;
31
32    /// Returns true if the given import path is a standard library import
33    /// that should be excluded from architectural analysis.
34    fn is_stdlib_import(&self, _import_path: &str) -> bool {
35        false
36    }
37}