1use anyhow::Result;
7use serde::{Deserialize, Serialize};
8use std::path::Path;
9
10pub trait Analyzer: Send + Sync {
12 type Input;
14 type Output;
16
17 fn analyze(&self, input: Self::Input) -> Result<Self::Output>;
19
20 fn name(&self) -> &str;
22}
23
24pub trait Scorer: Send + Sync {
26 type Item;
28
29 fn score(&self, item: &Self::Item) -> f64;
31
32 fn methodology(&self) -> &str;
34}
35
36pub trait FileSystem: Send + Sync {
38 fn read_file(&self, path: &Path) -> Result<String>;
40
41 fn write_file(&self, path: &Path, contents: &str) -> Result<()>;
43
44 fn exists(&self, path: &Path) -> bool;
46
47 fn glob(&self, pattern: &str) -> Result<Vec<std::path::PathBuf>>;
49}
50
51pub trait Parser: Send + Sync {
53 type Ast;
55
56 fn parse(&self, source: &str, path: &Path) -> Result<Self::Ast>;
58
59 fn language(&self) -> &str;
61}
62
63pub trait ComplexityCalculator: Send + Sync {
65 type Input;
67
68 fn cyclomatic_complexity(&self, input: &Self::Input) -> u32;
70
71 fn cognitive_complexity(&self, input: &Self::Input) -> u32;
73
74 fn halstead_metrics(&self, input: &Self::Input) -> HalsteadMetrics;
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80pub struct HalsteadMetrics {
81 pub volume: f64,
82 pub difficulty: f64,
83 pub effort: f64,
84 pub time: f64,
85 pub bugs: f64,
86}
87
88pub trait Formatter: Send + Sync {
90 type Report;
92
93 fn format(&self, report: &Self::Report) -> Result<String>;
95
96 fn format_name(&self) -> &str;
98}
99
100pub trait ConfigProvider: Send + Sync {
102 fn get(&self, key: &str) -> Option<String>;
104
105 fn set(&mut self, key: String, value: String);
107
108 fn load_from_file(&self, path: &Path) -> Result<()>;
110}
111
112pub trait Detector: Send + Sync {
114 type Context;
116 type Detection;
118
119 fn detect(&self, context: &Self::Context) -> Vec<Self::Detection>;
121
122 fn confidence(&self) -> f64;
124}
125
126pub trait PriorityCalculator: Send + Sync {
128 type Item;
130
131 fn calculate_priority(&self, item: &Self::Item) -> f64;
133
134 fn get_factors(&self, item: &Self::Item) -> Vec<PriorityFactor>;
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct PriorityFactor {
141 pub name: String,
142 pub weight: f64,
143 pub value: f64,
144 pub description: String,
145}
146
147pub trait RefactoringDetector: Send + Sync {
149 type Context;
151 type Opportunity;
153
154 fn detect_opportunities(&self, context: &Self::Context) -> Vec<Self::Opportunity>;
156
157 fn estimate_effort(&self, opportunity: &Self::Opportunity) -> EffortEstimate;
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct EffortEstimate {
164 pub hours: f64,
165 pub complexity: String,
166 pub risk_level: String,
167 pub confidence: f64,
168}
169
170pub trait TestAnalyzer: Send + Sync {
172 type TestSuite;
174
175 fn analyze_coverage(&self, suite: &Self::TestSuite) -> CoverageReport;
177
178 fn detect_test_smells(&self, suite: &Self::TestSuite) -> Vec<TestSmell>;
180}
181
182#[derive(Debug, Clone, Serialize, Deserialize)]
184pub struct CoverageReport {
185 pub line_coverage: f64,
186 pub branch_coverage: f64,
187 pub function_coverage: f64,
188 pub uncovered_lines: Vec<usize>,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct TestSmell {
194 pub smell_type: String,
195 pub location: String,
196 pub severity: String,
197 pub suggestion: String,
198}
199
200pub trait Repository<T>: Send + Sync {
202 fn save(&mut self, entity: T) -> Result<()>;
204
205 fn find_by_id(&self, id: &str) -> Option<T>;
207
208 fn find_all(&self) -> Vec<T>;
210
211 fn delete(&mut self, id: &str) -> Result<()>;
213}
214
215pub trait EventPublisher: Send + Sync {
217 type Event;
219
220 fn publish(&self, event: Self::Event) -> Result<()>;
222}
223
224pub trait EventSubscriber: Send + Sync {
226 type Event;
228
229 fn handle(&mut self, event: Self::Event) -> Result<()>;
231}