Skip to main content

driven/context/
analyzer.rs

1//! Pattern analyzer
2
3use super::scanner::ScanResult;
4use crate::Result;
5
6/// Analyzes code patterns in a project
7#[derive(Debug, Default)]
8pub struct PatternAnalyzer;
9
10impl PatternAnalyzer {
11    /// Create a new pattern analyzer
12    pub fn new() -> Self {
13        Self
14    }
15
16    /// Analyze patterns from scan results
17    pub fn analyze(&self, scan_result: &ScanResult) -> Result<Vec<String>> {
18        let mut patterns = Vec::new();
19
20        // Detect patterns based on file counts
21        if let Some(&count) = scan_result.file_counts.get("rs") {
22            if count > 0 {
23                patterns.push("Rust codebase".to_string());
24            }
25        }
26
27        if let Some(&count) = scan_result.file_counts.get("ts") {
28            if count > 0 {
29                patterns.push("TypeScript codebase".to_string());
30            }
31        }
32
33        // Detect architecture patterns
34        if scan_result.key_directories.contains(&"src".to_string()) {
35            patterns.push("Standard src directory structure".to_string());
36        }
37
38        if scan_result.key_directories.contains(&"crates".to_string()) {
39            patterns.push("Cargo workspace structure".to_string());
40        }
41
42        if scan_result
43            .key_directories
44            .contains(&"packages".to_string())
45        {
46            patterns.push("Monorepo structure".to_string());
47        }
48
49        // Detect development practices
50        if scan_result.has_tests {
51            patterns.push("Has testing infrastructure".to_string());
52        }
53
54        if scan_result.has_ci {
55            patterns.push("Has CI/CD pipeline".to_string());
56        }
57
58        if scan_result.has_docs {
59            patterns.push("Has documentation".to_string());
60        }
61
62        Ok(patterns)
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_analyzer_new() {
72        let _analyzer = PatternAnalyzer::new();
73    }
74
75    #[test]
76    fn test_analyze_empty() {
77        let analyzer = PatternAnalyzer::new();
78        let scan_result = ScanResult::default();
79        let patterns = analyzer.analyze(&scan_result).unwrap();
80        assert!(patterns.is_empty());
81    }
82}