#![allow(dead_code)]
use anyhow::Result;
use std::path::Path;
use tracing::info;
use serde::{Serialize, Deserialize};
pub mod code_analyzer;
pub mod pattern_extractor;
pub mod git_analyzer;
pub use code_analyzer::CodeAnalyzer;
pub use pattern_extractor::PatternExtractor;
pub use git_analyzer::GitAnalyzer;
pub struct Analyzer {
code_analyzer: CodeAnalyzer,
pattern_extractor: PatternExtractor,
git_analyzer: GitAnalyzer,
}
impl Analyzer {
pub fn new() -> Self {
Self {
code_analyzer: CodeAnalyzer::new(),
pattern_extractor: PatternExtractor::new(),
git_analyzer: GitAnalyzer::new(),
}
}
pub async fn analyze_project(&self, path: &Path) -> Result<ProjectAnalysis> {
info!("Analyzing project at: {}", path.display());
let git_info = self.git_analyzer.analyze(path).await?;
let code_stats = self.code_analyzer.analyze_directory(path).await?;
let patterns = self.pattern_extractor.extract_patterns(path, &code_stats).await?;
Ok(ProjectAnalysis {
path: path.to_path_buf(),
git_info,
code_stats,
patterns,
})
}
pub async fn analyze_projects(&self, paths: &[&Path]) -> Result<Vec<ProjectAnalysis>> {
use futures::future::join_all;
let futures = paths.iter().map(|path| self.analyze_project(path));
let results = join_all(futures).await;
results.into_iter().collect::<Result<Vec<_>>>()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectAnalysis {
pub path: std::path::PathBuf,
pub git_info: GitInfo,
pub code_stats: CodeStatistics,
pub patterns: Vec<DetectedPattern>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GitInfo {
pub is_git_repo: bool,
pub current_branch: Option<String>,
pub recent_commits: Vec<CommitInfo>,
pub remote_url: Option<String>,
pub total_commits: i64,
pub contributors: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommitInfo {
pub hash: String,
pub message: String,
pub author: String,
pub date: chrono::DateTime<chrono::Utc>,
pub files_changed: Vec<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CodeStatistics {
pub total_files: usize,
pub total_lines: usize,
pub languages: std::collections::HashMap<String, LanguageStats>,
pub file_types: std::collections::HashMap<String, usize>,
pub average_file_size: usize,
pub largest_files: Vec<(String, usize)>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LanguageStats {
pub file_count: usize,
pub total_lines: usize,
pub code_lines: usize,
pub comment_lines: usize,
pub blank_lines: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DetectedPattern {
pub pattern_type: String,
pub confidence: f64,
pub evidence: String,
pub files: Vec<String>,
}