codebase-comprehension-algorithms

v2026.09.24

Mapping an unfamiliar codebase into feature/business domains — answering "what is this about", "which files implement feature X", "where is the architectural spine", or reviewing a refactor that crosses module boundaries. 47 algorithms across 9 categories — graph construction (omnipresent filter, multilayer, SCC), lexical preprocessing (Samurai, TF-IDF), community detection (Leiden, Infomap, SBM, MCL, Walktrap, spectral, HDBSCAN), architecture recovery (Bunch+MQ, ACDC, Limbo, Reflexion, DSM), topic modelling (LDA, LSI, NMF, HDP), evolutionary coupling (Gall, ROSE), information-theoretic (NCD, MI, MDL, naturalness), centrality (PageRank, HITS, betweenness, TextRank), validation (MoJoFM, ARI/NMI, resolution limit, consensus, co-change prediction, ablation). Trigger without explicit "clustering" mention — codebase grokking, dependency mapping, domain extraction, architecture-recovery validation all apply.

GitHub
安装命令
npx skhub add pproenca/codebase-comprehension-algorithms
Markdown
SKILL.md

Community Codebase Comprehension And Domain Mapping Algorithms Best Practices

A practitioner-oriented reference of the algorithms that work for mapping a codebase into understandable feature/business domains. Most of these techniques live in the Software Architecture Recovery and Mining Software Repositories literatures and are invisible to working engineers — yet they're the right tools for the job a coding agent is asked to do every day: "what does this codebase do, and where?"

The 47 rules are organized by execution-lifecycle impact: a wrong decision early in the pipeline (which graph to build, which identifiers to keep) propagates through everything downstream. The three CRITICAL categories (graph-, clust-, valid-) are the ones a wrong call cannot be recovered from later. Read them first.

Scope: proven algorithms with peer-reviewed citations or canonical books — Newman Networks, Leskovec-Rajaraman-Ullman Mining of Massive Datasets, Ganter-Wille Formal Concept Analysis, plus 40+ ICSE / FSE / TSE / PNAS / JMLR papers. No tutorial sites, no Stack Overflow, no marketing posts. Deliberately deferred to a future version: GNN/CodeBERT/code2vec (not "proven over decades" yet) and refactoring-recipe stuff (covered by sibling skills like react-refactor and typescript-refactor).

When to Apply

Use these rules when:

  • Onboarding an agent into an unfamiliar codebase: "explain what this codebase does, by domain"
  • Producing an architecture map: "what are the main subsystems and how do they connect?"
  • Locating a feature: "which files implement payments / authentication / search?"
  • Reviewing a refactor: "did this change respect the architectural boundaries?"
  • Detecting architectural debt: "what files have surprising coupling?"
  • Validating an existing decomposition: "does the README's architecture match the code?"
  • Picking algorithms for any of the above — the user wants something that's proven, not vibes

Rule Categories By Priority

#CategoryPrefixImpactWhat it does
1Graph Construction & Edge Weightinggraph-CRITICALWhich graph to build; omnipresent filter; cycle handling; multilayer
2Community Detection & Clusteringclust-CRITICALLeiden, Infomap, SBM, MCL, Walktrap, spectral, HDBSCAN
3Validation & Quality Metricsvalid-CRITICALMoJoFM, ARI/NMI, resolution limit, consensus, co-change prediction, ablation
4Identifier & Lexical Preprocessinglex-HIGHSamurai splitting, abbreviation expansion, TF-IDF/BM25, stemming, V-O parsing
5Software-Specific Architecture Recoveryarch-HIGHBunch + MQ, ACDC, Limbo, Reflexion, DSM
6Topic Modelling on Source Codetopic-HIGHLDA, LSI/SVD, NMF, HDP, coherence-based K selection
7Evolutionary Coupling & Co-Change Miningevol-HIGHLift / confidence / support, large-commit filter, temporal decay, logical coupling
8Information-Theoretic Methodsinfo-MEDIUM-HIGHNormalized Compression Distance, Mutual Information, MDL, code naturalness
9Centrality, Hierarchy & Labellingrank-MEDIUMPageRank, HITS, betweenness, TextRank/YAKE labels

Quick Reference

1. Graph Construction & Edge Weighting (CRITICAL)

2. Community Detection & Clustering (CRITICAL)

3. Validation & Quality Metrics (CRITICAL)

4. Identifier & Lexical Preprocessing (HIGH)

5. Software-Specific Architecture Recovery (HIGH)

6. Topic Modelling on Source Code (HIGH)

7. Evolutionary Coupling & Co-Change Mining (HIGH)

8. Information-Theoretic Methods (MEDIUM-HIGH)

9. Centrality, Hierarchy & Labelling (MEDIUM)

How to Use

Start with the question the agent is trying to answer:

  • "What are the main domains in this codebase?" → graph- (pick a graph) → clust- (Leiden / Infomap / SBM) → topic- (label them) → valid- (sanity-check stability and ablate)
  • "Which files implement feature X?" → topic-lda-on-source-code for theme location; rank-pagerank-for-module-importance with X's files as seed for personalized PageRank
  • "Where is the architectural spine?" → rank-pagerank-for-module-importance + rank-hits-hubs-and-authorities on the dependency graph
  • "Does the README's architecture match the code?" → arch-reflexion-model is purpose-built for this
  • "What's the real coupling here (beyond static dependencies)?" → evol-logical-coupling-as-architectural-signal and evol-mine-cochange-with-lift-and-confidence
  • "How do I cluster without designing features?" → info-normalized-compression-distance
  • "How big are the clusters supposed to be?" → valid-be-aware-of-resolution-limit and topic-hdp-for-nonparametric-topic-count
  • "How do I know my decomposition is right?" → the entire valid- category; multi-proxy evaluation is mandatory

The skill's worldview: build the right graph first (and filter omnipresent files), pick an algorithm matching the graph and the question, use a code-specific preprocessing pipeline (Samurai + stop-words + stemming + TF-IDF) where lexical signals matter, and always validate — MoJoFM if you have expert ground truth, consensus + co-change prediction + ablation if you don't.

Code examples are in Python because the reference implementations (networkx, igraph, leidenalg, scikit-learn, gensim, graph-tool, hdbscan) all live there. The reasoning generalises to any language.

Reference Files

FileDescription
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for new rules
metadata.jsonVersion and reference information
AGENTS.mdAuto-built TOC navigation

Related Skills

  • computer-science-algorithms — Algorithm-and-data-structure reference (this skill cross-references it for MinHash/LSH, Aho-Corasick, etc.)
  • complexity-optimizer — Static analysis for hot paths the rules here identify
  • design-to-react-algorithms — Companion skill for design-to-code structural recovery
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

Sep 24, 2026

分类

未分类

许可证

MIT

源路径

skills/.experimental/codebase-comprehension-algorithms

默认分支

master

最新提交

cf93c57

Tree SHA

afbb575