Skip to main content

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 balance;
41pub mod cli_output;
42pub mod config;
43pub mod diff;
44pub mod external;
45pub mod history;
46pub mod manifest;
47pub mod metrics;
48pub mod report;
49pub mod volatility;
50pub mod web;
51pub mod workspace;
52
53pub use analyzer::{
54    AnalyzedFileResult, AnalyzerError, CouplingAnalyzer, Dependency, DependencyKind, ItemDepType,
55    ItemDependency, ItemKind, analyze_project, analyze_project_parallel_with_config,
56    analyze_rust_file, analyze_rust_file_full, analyze_workspace, analyze_workspace_with_config,
57};
58pub use balance::action::RefactoringAction;
59pub use balance::grade::{HealthGrade, ProjectBalanceReport};
60pub use balance::issue::CouplingIssue;
61pub use balance::issue_type::IssueType;
62pub use balance::project::{
63    analyze_project_balance, analyze_project_balance_with_thresholds, calculate_project_score,
64};
65pub use balance::rationale::{GradeDimension, GradeRationale, IssueTypeContribution};
66pub use balance::score::{BalanceInterpretation, BalanceScore, IssueThresholds};
67pub use balance::severity::Severity;
68pub use config::{
69    AnalysisConfig, CompiledConfig, ConfigError, CouplingConfig, ThresholdsConfig,
70    VolatilityConfig, load_compiled_config, load_config,
71};
72pub use diff::{BaselineDiff, IssueKey, diff_ref_analysis, diff_reports};
73pub use external::{
74    ExternalDependencyReport, ExternalDependencyUsage, SCATTERED_EXTERNAL_BREADTH_THRESHOLD,
75    analyze_external_dependencies, detect_scattered_external_coupling, load_lock_versions_near,
76};
77pub use history::{
78    HistoryError, HistoryPoint, HistoryReport, RefAnalysis, SkippedRevision, analyze_history,
79    analyze_ref,
80};
81pub use manifest::{AnalysisManifest, BlindSpot, ManifestContext, build_manifest};
82pub use metrics::coupling::{CouplingLocation, CouplingMetrics};
83pub use metrics::dimensions::{
84    Distance, IntegrationStrength, MetricsConfig, Subdomain, Visibility,
85};
86pub use metrics::module::{
87    BalanceClassification, BalanceCounts, DimensionStats, DistanceCounts, FunctionDefinition,
88    ModuleMetrics, StrengthCounts, TypeDefinition, VolatilityCounts,
89};
90pub use metrics::project::{CircularDependencySummary, ProjectMetrics};
91pub use report::{
92    TextReportOptions, generate_ai_output, generate_ai_output_with_thresholds, generate_report,
93    generate_report_with_options, generate_report_with_thresholds, generate_summary,
94    generate_summary_with_options, generate_summary_with_thresholds,
95};
96pub use volatility::Volatility;
97pub use volatility::{VolatilityAnalyzer, VolatilityError, VolatilityStats};
98pub use workspace::{CrateInfo, WorkspaceError, WorkspaceInfo};