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