arXiv:2610.36894cs.SEOct 2026

Manuscript Offprint

arXiv:2610.36894

ASNER: Software Architecture Recovery with Adaptive Semantic Neighborhoods and Evidence-Grounded Refinement

Wenhao Wang, Zhi Jin, Jia Li, Dongming Jin, Heng Tian, Yingtao Fang, Wenguang Ye, Tiankuo Zhao

ABSTRACT

Automated software architecture recovery is important for software engineering, especially as large language model (LLM) agents increasingly perform repository-level tasks that require architectural context to understand and modify large codebases. Existing methods combine structural and semantic signals, but the resulting relations do not necessarily reflect architectural responsibility. Files that co-implement one component may appear dissimilar, while related files may merely cooperate across component boundaries. Fixed thresholds or Top-K neighborhoods also ignore repository scale and local similarity distributions, causing missing within-component links or noisy cross-component edges. These errors propagate to community detection, while unconstrained LLM refinement may alter correct assignments without sufficient evidence. Our key insight is that accurate recovery requires responsibility-aware semantic relations that adapt to each repository, followed by evidence-grounded verification of uncertain boundaries. We therefore propose ASNER (Adaptive Semantic Neighborhoods and Evidence-Grounded Refinement for Software Architecture Recovery). ASNER uses an LLM to derive structured file responsibilities, constructs adaptive semantic neighborhoods, and augments a static dependency graph with selected semantic relations and weak directory cues. Community detection recovers the component backbone, after which a Responsibility-Ownership-Aware (ROA) Agent revisits uncertain boundary files using project-level responsibilities and traceable code evidence, changing assignments only when supported. We evaluate ASNER on 12 open-source projects spanning C, C++, Java, and Python. ASNER achieves the best macro-average on all five metrics on the common benchmark, improving ARI and c2c@66 over GAER-GAT by 19.5% and 32.9%, respectively. A downstream evaluation further shows that ASNER-guided LocAgent improves file-, module-, and function-level code localization. These results demonstrate the value of ASNER's architectural context for repository-level software engineering tasks.

1 INTRODUCTION

Repository-level software engineering tasks, including code generation, defect repair, and code evolution, are increasingly important applications for large language model (LLM) agents (Tao et al., 2025; Zhang et al., 2026; Wang et al., 2025). Agents performing these tasks must understand individual functions and files together with the system's module boundaries, functional responsibilities, and dependencies to reason about and modify code across files. As systems evolve, however, their implementations tend to diverge from the initial design, a phenomenon commonly described as architectural drift or erosion (Bass et al., 2012; de Silva & Balasubramaniam, 2012; Medvidovic et al., 2003), while architectural documentation that accurately reflects the current implementation is often missing or outdated (van Deursen et al., 2004). Recovering the architecture of a large codebase remains time-consuming even for experienced architects (Garcia et al., 2013). Automated architecture

*First-author email: wenhaowang@whu.edu.cn.

†^{\dagger}Corresponding authors.

recovery has therefore long been an important software engineering problem (Perry & Wolf, 1992; Medvidovic et al., 1999).

Automated architecture recovery has progressed from structural dependency analysis to multi-source semantic modeling. Early methods, such as ACDC (Tzerpos & Holt, 2000), Bunch (Mancoridis et al., 1999), and FCA (Teymourian et al., 2022), organize code entities using calls, references, inheritance, and other structural relations. ARC (Garcia et al., 2011) further introduces software concerns extracted from identifiers and comments, while SADE (Papachristou, 2019) and SARIF (Zhang et al., 2023) combine dependencies, directory structure, and textual semantics. More recently, SemArc (Zhao et al., 2026) uses an LLM to generate file-level functional summaries, whereas GAER (Jabeen et al., 2026) uses graph auto-encoders to jointly model typed dependencies, directory hierarchies, and code semantics. Although these methods incorporate increasingly rich information, their recovery quality still depends critically on whether the semantic relations constructed between files truly reflect the architectural responsibilities that determine component boundaries.

Reliable semantic graph construction and boundary refinement face closely related challenges. Functional relatedness does not imply shared architectural responsibility: closely related files may cooperate across component boundaries, while files with different local functionality may jointly implement one component's responsibility. Functional summaries and generic embeddings do not always distinguish directly implemented responsibilities from invoked or supporting functionality, potentially omitting within-component links or introducing cross-component edges. Uniform edge-selection rules also overlook repository scale and local similarity distributions. Repositories differ in size and modular organization, and files within one repository may need different numbers of meaningful neighbors. Fixed thresholds can discard useful links or admit noisy ones, while fixed Top-K rules impose similarly sized neighborhoods on all files. Reliable semantic relations therefore require responsibility-aware representations and project-adaptive neighborhood selection. Even with improved relations, shared utilities, cross-component workflows, and sparse dependencies can still leave boundary files incorrectly assigned by community detection. Adding semantic edges alone cannot resolve these ambiguities, while unconstrained LLM post-processing may change correct assignments without sufficient evidence. Reliable boundary refinement requires project-level responsibility context to compare candidate assignments and traceable code evidence to justify changes, preserving the original assignment when the evidence is insufficient.

Figure 1 illustrates these two limitations. In Bash’s libglob component, a fixed threshold of 0.5 retains only one semantic link, whereas lowering it to 0.3 recovers the missing within-component relations and reconnects the five files. In distributed_camera, semantic similarity alone mixes Source and Sink implementations, while project-level responsibilities and code evidence distinguish their different endpoint roles and recover the reference boundary.

(a) Fixed thresholds can discard relevant links

Figure

(b) Shared semantics can cross component boundaries

Figure 1: Motivating cases for adaptive semantic neighborhoods and evidence-grounded refinement. Left: in Bash’s libglob component, lowering the threshold from 0.5 to 0.3 recovers missing within-component relations. Right: in distributed_camera, project-level responsibilities and code evidence help distinguish Source and Sink and recover the correct component boundary.

These observations identify a central requirement for architecture recovery: semantic relations should reflect shared implementation responsibilities and adapt to each repository's relationship distribution. Human architects similarly establish a repository-level understanding of system responsibilities before examining ambiguous local boundaries through interfaces, state ownership, component interactions, and concrete code evidence (van Deursen et al., 2004; Garcia et al., 2013). Guided by this intuition, we propose ASNER (Adaptive Semantic Neighborhoods and Evidence-Grounded Refinement for Software Architecture Recovery).

ASNER first uses an LLM to derive structured file responsibilities so that semantic comparison focuses on the responsibilities directly implemented by each file. We then propose the Scale-Gap Adaptive Semantic Neighborhood (SGASN) algorithm, which determines the candidate neighborhood according to repository scale and selects the final neighbors according to each file's local similarity distribution. The selected semantic relations augment the static dependency graph, while directory structure serves as a weak auxiliary cue, and community detection recovers the component backbone. Finally, a Responsibility-Ownership-Aware (ROA) Agent examines uncertain boundary files using project-level responsibility context and traceable static code evidence, changing their assignments only when the evidence supports the correction. ASNER therefore first recovers the global component structure through responsibility-aware, project-adaptive semantic relations and then refines residual boundaries under evidence constraints.

Contributions. Our main contributions are as follows:

• Responsibility-aware and Adaptive Semantic Neighborhood. We introduce structured responsibility representations that distinguish directly implemented responsibilities from invoked or supporting functionality. We further propose SGASN, which adapts the candidate range to repository scale and determines each file's final neighborhood from its local similarity distribution, producing semantic relations that better reflect component responsibilities.

• Evidence-grounded boundary refinement. We introduce a Responsibility-Ownership-Aware Agent that revisits uncertain component boundaries using project-level responsibility context and traceable code evidence, changing a file’s assignment only when both responsibility ownership and concrete code facts support the alternative.

• Cross-project evaluation and downstream validation. We evaluate ASNER on 12 projects spanning C, C++, Java, and Python. ASNER achieves the best macro-average across all five metrics on the common benchmark and improves ARI and c2c@66 over GAER-GAT by 19.5% and 32.9%, respectively. A downstream evaluation further shows that ASNER-guided LocAgent improves file-, module-, and function-level code localization. Case studies further show that ASNER can recover component boundaries that are difficult to identify from file-level semantic similarity or explicit dependencies alone, providing more reliable architectural context for repository-level software engineering tasks.

References (35)