1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/// Summary statistics for TDG across a codebase
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGSummary {
/// Total number of files analyzed
pub total_files: usize,
/// Number of files with critical TDG scores
pub critical_files: usize,
/// Number of files with warning TDG scores
pub warning_files: usize,
/// Average TDG score across all files
pub average_tdg: f64,
/// 95th percentile TDG score
pub p95_tdg: f64,
/// 99th percentile TDG score
pub p99_tdg: f64,
/// Estimated technical debt in hours
pub estimated_debt_hours: f64,
/// Files with highest TDG scores
pub hotspots: Vec<TDGHotspot>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGHotspot {
/// File path
pub path: String,
/// TDG score
pub tdg_score: f64,
/// Primary contributor to high TDG
pub primary_factor: String,
/// Estimated hours to refactor
pub estimated_hours: f64,
}
/// TDG calculation result with detailed breakdown
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGAnalysis {
/// The calculated TDG score
pub score: TDGScore,
/// Detailed explanation of the calculation
pub explanation: String,
/// Specific recommendations for reducing TDG
pub recommendations: Vec<TDGRecommendation>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGRecommendation {
/// Type of recommendation
pub recommendation_type: RecommendationType,
/// Specific action to take
pub action: String,
/// Expected TDG reduction
pub expected_reduction: f64,
/// Estimated effort in hours
pub estimated_hours: f64,
/// Priority level (1-5, 5 being highest)
pub priority: u8,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum RecommendationType {
/// Reduce function complexity
ReduceComplexity,
/// Stabilize frequently changing code
StabilizeChurn,
/// Reduce coupling between modules
ReduceCoupling,
/// Address domain-specific risks
AddressDomainRisk,
/// Remove duplicate code
RemoveDuplication,
/// Split large files
SplitFile,
/// Add test coverage
AddTests,
}
/// TDG distribution for visualization
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGDistribution {
/// Histogram buckets
pub buckets: Vec<TDGBucket>,
/// Total number of files
pub total_files: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TDGBucket {
/// Lower bound of the bucket (inclusive)
pub min: f64,
/// Upper bound of the bucket (exclusive)
pub max: f64,
/// Number of files in this bucket
pub count: usize,
/// Percentage of total files
pub percentage: f64,
}
// Additional types for SATD analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SatdItem {
pub file_path: PathBuf,
pub line_number: usize,
pub comment_text: String,
pub debt_type: String,
pub severity: SatdSeverity,
pub confidence: f64,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub enum SatdSeverity {
Low,
Medium,
High,
Critical,
}