Skip to main content

Module communities

Module communities 

Expand description

Leiden community detection on the behavioural coupling graph.

Auto-detects Conway’s-law communities from the coupling graph (Fisher-significant pairs from [coupling::run_coupling]) using the Leiden algorithm (Traag et al. 2019). Each file lands in exactly one community; the per-community modularity contribution and member list are exposed for downstream consumers.

§Algorithm choice

Leiden over Louvain (Blondel et al. 2008) — Leiden guarantees well-connected communities and converges to a partition that’s a local optimum under both the modularity and CPM quality functions, where Louvain can produce disconnected communities that survive iteration. The Traag 2019 paper documents the pathology Louvain has on real-world graphs. CodeLore’s coupling graph is exactly the shape (sparse, weighted, modular) where the Louvain pathology shows up most.

§Crate choice

leiden-rs (Apache-2.0/MIT). We use the no-default-features surface — the upstream default pulls in gryf (an alternative graph crate we don’t need) and cli (a binary we don’t ship). Opted back into rayon for parallel iteration; meaningful speedup on the linux-kernel-scale coupling graph.

§Modularity vs CPM

Default quality function: modularity (QualityType::Modularity, γ = 1.0). The Newman-Girvan modularity has a known resolution limit (small communities can be invisibly merged by the modularity-optimal partition) but it’s the most-cited interpretive reference in software-engineering literature, which makes the results comparable to other Conway’s-law analyses. CPM is available via the optional [CommunitiesOptions::cpm_resolution] knob for users who want resolution-limit-free output.

§Research basis

  • Traag, Waltman, van Eck 2019. “From Louvain to Leiden: guaranteeing well-connected communities.” Scientific Reports. https://doi.org/10.1038/s41598-019-41695-z
  • Newman & Girvan 2004. “Finding and evaluating community structure in networks.” Phys. Rev. E.

See docs/research-foundations.md entry “communities” for the full grounded write-up.

Structs§

CommunitiesResult
Aggregate output of run_communities.
CommunityRow
One row per file mapped to its Leiden community ID. Files with no Fisher-significant coupling partners are omitted (no node, no row). Rows are sorted by (community_id ASC, path ASC) so the output is deterministic across runs and friendly to a stable git diff.

Functions§

run_communities
Run Leiden community detection on the Fisher-significant coupling pairs.