cargo_coupling/
lib.rs

1//! # cargo-coupling - Coupling Analysis Tool
2//!
3//! A tool for measuring and analyzing coupling in Rust projects,
4//! based on Vlad Khononov's "Balancing Coupling in Software Design".
5//!
6//! ## Overview
7//!
8//! cargo-coupling measures coupling across three dimensions:
9//!
10//! 1. **Integration Strength** - How much knowledge is shared between components
11//! 2. **Distance** - How far apart components are in the module hierarchy
12//! 3. **Volatility** - How frequently components change
13//!
14//! ## Usage
15//!
16//! ```bash
17//! # Analyze current project (as cargo subcommand)
18//! cargo coupling ./src
19//!
20//! # Generate detailed report
21//! cargo coupling -o report.md ./src
22//!
23//! # Show summary only
24//! cargo coupling --summary ./src
25//! ```
26//!
27//! ## Balance Equation
28//!
29//! The balance score is calculated as:
30//! ```text
31//! BALANCE = (STRENGTH XOR DISTANCE) OR NOT VOLATILITY
32//! ```
33//!
34//! - Strong coupling + close distance = Good (locality)
35//! - Weak coupling + far distance = Good (loose coupling)
36//! - Strong coupling + far distance = Bad (global complexity)
37//! - High volatility + strong coupling = Bad (cascading changes)
38
39pub mod analyzer;
40pub mod aposd;
41pub mod balance;
42pub mod config;
43pub mod connascence;
44pub mod metrics;
45pub mod report;
46pub mod temporal;
47pub mod volatility;
48pub mod workspace;
49
50pub use analyzer::{
51    AnalyzedFileResult, AnalyzerError, CouplingAnalyzer, Dependency, DependencyKind,
52    analyze_project, analyze_rust_file, analyze_rust_file_full, analyze_workspace,
53};
54pub use balance::{
55    BalanceInterpretation, BalanceScore, CouplingIssue, HealthGrade, IssueThresholds, IssueType,
56    ProjectBalanceReport, RefactoringAction, Severity, analyze_project_balance,
57    analyze_project_balance_with_thresholds, calculate_project_score,
58};
59pub use config::{
60    AposdConfig, CompiledConfig, ConfigError, CouplingConfig, ThresholdsConfig, VolatilityConfig,
61    load_compiled_config, load_config,
62};
63pub use connascence::{
64    ConnascenceAnalyzer, ConnascenceInstance, ConnascenceStats, ConnascenceType,
65    detect_algorithm_patterns,
66};
67pub use metrics::{
68    CircularDependencySummary, CouplingMetrics, Distance, IntegrationStrength, ModuleMetrics,
69    ProjectMetrics, TypeDefinition, Visibility, Volatility,
70};
71pub use report::{
72    generate_ai_output, generate_ai_output_with_thresholds, generate_report,
73    generate_report_with_thresholds, generate_summary, generate_summary_with_thresholds,
74};
75pub use temporal::{
76    LifecyclePhase, TemporalAnalyzer, TemporalCouplingInstance, TemporalCouplingStats,
77    TemporalPattern,
78};
79pub use volatility::{VolatilityAnalyzer, VolatilityError, VolatilityStats};
80pub use workspace::{CrateInfo, WorkspaceError, WorkspaceInfo};
81
82// APOSD (A Philosophy of Software Design) metrics
83pub use aposd::{
84    analyze_aposd, AposdAnalysis, AposdIssueCounts, CognitiveLoadLevel, CognitiveLoadMetrics,
85    ModuleDepthClass, ModuleDepthMetrics, PassThroughMethodInfo,
86};