Expand description
§cargo-coupling - Coupling Analysis Tool
A tool for measuring and analyzing coupling in Rust projects, based on Vlad Khononov’s “Balancing Coupling in Software Design”.
§Overview
cargo-coupling measures coupling across three dimensions:
- Integration Strength - How much knowledge is shared between components
- Distance - How far apart components are in the module hierarchy
- Volatility - How frequently components change
§Usage
# Analyze current project (as cargo subcommand)
cargo coupling ./src
# Generate detailed report
cargo coupling -o report.md ./src
# Show summary only
cargo coupling --summary ./src§Balance Equation
The balance score is calculated as:
BALANCE = (STRENGTH XOR DISTANCE) OR NOT VOLATILITY- Strong coupling + close distance = Good (locality)
- Weak coupling + far distance = Good (loose coupling)
- Strong coupling + far distance = Bad (global complexity)
- High volatility + strong coupling = Bad (cascading changes)
Re-exports§
pub use analyzer::AnalyzedFileResult;pub use analyzer::AnalyzerError;pub use analyzer::CouplingAnalyzer;pub use analyzer::Dependency;pub use analyzer::DependencyKind;pub use analyzer::ItemDepType;pub use analyzer::ItemDependency;pub use analyzer::ItemKind;pub use analyzer::analyze_project;pub use analyzer::analyze_project_parallel_with_config;pub use analyzer::analyze_rust_file;pub use analyzer::analyze_rust_file_full;pub use analyzer::analyze_workspace;pub use analyzer::analyze_workspace_with_config;pub use balance::action::RefactoringAction;pub use balance::grade::HealthGrade;pub use balance::grade::ProjectBalanceReport;pub use balance::issue::CouplingIssue;pub use balance::issue_type::IssueType;pub use balance::project::analyze_project_balance;pub use balance::project::analyze_project_balance_with_thresholds;pub use balance::project::calculate_project_score;pub use balance::rationale::GradeDimension;pub use balance::rationale::GradeRationale;pub use balance::rationale::IssueTypeContribution;pub use balance::score::BalanceInterpretation;pub use balance::score::BalanceScore;pub use balance::score::IssueThresholds;pub use balance::severity::Severity;pub use config::AnalysisConfig;pub use config::CompiledConfig;pub use config::ConfigError;pub use config::CouplingConfig;pub use config::DeadConfigPattern;pub use config::ThresholdsConfig;pub use config::VolatilityConfig;pub use config::load_compiled_config;pub use config::load_config;pub use diff::BaselineDiff;pub use diff::IssueKey;pub use diff::diff_ref_analysis;pub use diff::diff_reports;pub use external::ExternalDependencyReport;pub use external::ExternalDependencyUsage;pub use external::SCATTERED_EXTERNAL_BREADTH_THRESHOLD;pub use external::analyze_external_dependencies;pub use external::detect_scattered_external_coupling;pub use external::load_lock_versions_near;pub use history::HistoryError;pub use history::HistoryPoint;pub use history::HistoryReport;pub use history::RefAnalysis;pub use history::SkippedRevision;pub use history::analyze_history;pub use history::analyze_ref;pub use manifest::AnalysisManifest;pub use manifest::BlindSpot;pub use manifest::ManifestContext;pub use manifest::build_manifest;pub use metrics::coupling::CouplingLocation;pub use metrics::coupling::CouplingMetrics;pub use metrics::dimensions::Distance;pub use metrics::dimensions::IntegrationStrength;pub use metrics::dimensions::MetricsConfig;pub use metrics::dimensions::Subdomain;pub use metrics::dimensions::Visibility;pub use metrics::module::BalanceClassification;pub use metrics::module::BalanceCounts;pub use metrics::module::DimensionStats;pub use metrics::module::DistanceCounts;pub use metrics::module::FunctionDefinition;pub use metrics::module::ModuleMetrics;pub use metrics::module::StrengthCounts;pub use metrics::module::TypeDefinition;pub use metrics::module::VolatilityCounts;pub use metrics::project::CircularDependencySummary;pub use metrics::project::ProjectMetrics;pub use report::TextReportOptions;pub use report::generate_ai_output;pub use report::generate_ai_output_with_thresholds;pub use report::generate_report;pub use report::generate_report_with_options;pub use report::generate_report_with_thresholds;pub use report::generate_summary;pub use report::generate_summary_with_options;pub use report::generate_summary_with_thresholds;pub use volatility::Volatility;pub use volatility::VolatilityAnalyzer;pub use volatility::VolatilityError;pub use volatility::VolatilityStats;pub use workspace::CrateInfo;pub use workspace::WorkspaceError;pub use workspace::WorkspaceInfo;
Modules§
- analyzer
- Rust AST analysis for coupling detection.
- balance
- Balance scoring and issue classification for coupling analysis.
- cli_
output - CLI output functions for job-focused commands
- config
- Configuration file support for cargo-coupling
- diff
- Baseline diffing for coupling reports.
- external
- External dependency coupling analysis.
- history
- Time-series coupling analysis.
- manifest
- Analysis blind-spot manifest.
- metrics
- Core metric types shared by analysis, balance scoring, and reporting.
- report
- Text and Markdown report rendering for coupling analysis.
- volatility
- Git history analysis for volatility measurement
- web
- Web visualization module for cargo-coupling
- workspace
- Workspace analysis using cargo metadata