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 metrics;
44pub mod report;
45pub mod volatility;
46pub mod web;
47pub mod workspace;
48
49pub use analyzer::{
50    AnalyzedFileResult, AnalyzerError, CouplingAnalyzer, Dependency, DependencyKind, ItemDepType,
51    ItemDependency, ItemKind, analyze_project, analyze_rust_file, analyze_rust_file_full,
52    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    AnalysisConfig, CompiledConfig, ConfigError, CouplingConfig, ThresholdsConfig,
61    VolatilityConfig, load_compiled_config, load_config,
62};
63pub use metrics::{
64    BalanceClassification, BalanceCounts, CircularDependencySummary, CouplingMetrics,
65    DimensionStats, Distance, DistanceCounts, FunctionDefinition, IntegrationStrength,
66    ModuleMetrics, ProjectMetrics, StrengthCounts, TypeDefinition, Visibility, Volatility,
67    VolatilityCounts,
68};
69pub use report::{
70    generate_ai_output, generate_ai_output_with_thresholds, generate_report,
71    generate_report_with_thresholds, generate_summary, generate_summary_with_thresholds,
72};
73pub use volatility::{VolatilityAnalyzer, VolatilityError, VolatilityStats};
74pub use workspace::{CrateInfo, WorkspaceError, WorkspaceInfo};