arXiv:2610.27634cs.SEOct 2026

Manuscript Offprint

arXiv:2610.27634

Standards-Guided and Dependency-Aware Code-Level Documentation Generation

Tingxu Han, Wei Song, Ziming Li, Yuchen Chen, Weisong Sun, Zhenpeng Chen, Chunrong Fang, Zhenyu Chen, Yang Liu

Tingxu Han*, Wei Song*, Ziming Li*, Yuchen Chen, Weisong Sun†, Zhenpeng Chen, Chunrong Fang†, Zhenyu Chen, and Yang Liu

Abstract—Automatically generating high-quality documentation for software repositories remains challenging because existing approaches largely treat documentation as an unconstrained text generation problem. As a result, they often lack explicit quality specifications, depend heavily on long-context prompts over raw code, and provide limited support for reproducible evaluation. We argue that code-level documentation generation should instead be formulated as a standards-guided software engineering task, in which documentation is generated and assessed against explicit, reusable quality requirements derived from authoritative documentation standards. In this paper, code documentation refers to natural-language descriptions of repository functions and classes, organized by source-code path.

We present CODEDOC, a standards-guided and dependency-aware framework for code-level documentation generation. CODEDOC identifies dependencies between code entities using static call-graph and AST analysis. It then constructs dependency-aware structured prompts that combine local code context, repository paths, and documentation criteria derived from authoritative standards and style guides. We further introduce an interactive LLM-as-a-judge protocol that provides criterion-aligned feedback to optimize generated documentation, enabling targeted refinement based on fine-grained dimensions derived from formal and practice-oriented documentation standards. Experiments on ten open-source Python repositories show that CODEDOC produces higher-quality documentation than both RepoAgent and a long-context baseline under standards-aligned evaluation, with relative improvements of 11.6%–17.0% and 21.4%–29.6%, respectively, while consuming roughly an order of magnitude fewer tokens per documentation entity than the long-context baseline. A human evaluation study confirms substantial alignment between LLM-based and human judgments (Spearman's ρ=0.72\rho = 0.72), and the relative findings are preserved across different judge LLMs. Code is available at https://github.com/ControllableModel/CodeDoc.

Index Terms—Code documentation generation, repository-level code understanding, documentation standards, large language models, static analysis, LLM-as-a-judge.

Tingxu Han, Ziming Li, Yuchen Chen, Chunrong Fang, and Zhenyu Chen are with the State Key Laboratory for Novel Software Technology, Nanjing University, Nanjing, Jiangsu, 210093, China (e-mail: txhan@smail.nju.edu.cn; dzycd53@gmail.com; fangchunrong@nju.edu.cn; zychen@nju.edu.cn).

Wei Song is with the School of Computer Science and Engineering, UNSW Sydney, NSW 2052, Australia (e-mail: wei.song1@unsw.edu.au).

Weisong Sun and Yang Liu are with the College of Computing and Data Science, Nanyang Technological University, 639798, Singapore (e-mail: weisong.sun@ntu.edu.sg; yangliu@ntu.edu.sg).

Zhenpeng Chen is with Tsinghua University, Beijing, China. E-mail: zpchen@tsinghua.edu.cn.

Tingxu Han, Wei Song, and Ziming Li contributed equally to this work. Weisong Sun and Chunrong Fang are corresponding authors.

1 INTRODUCTION

Throughout the software lifecycle, developers continuously interact with existing code artifacts [1]–[4], especially during tasks such as feature extension [5], bug fixing [6], code review [7], and system maintenance [8]. A growing body of empirical evidence shows that a substantial portion of developers' effort is devoted to understanding existing code rather than writing new functionality [9]–[11]. In this context, high-quality code documentation plays a critical role in facilitating code comprehension, supporting collaboration, and improving the maintainability and evolution of software systems. However, maintaining documentation manually is labor-intensive and error-prone [12], [13]. As software evolves, documentation often becomes incomplete, inconsistent, or outdated, reducing its usefulness and potentially harming overall software quality. These challenges have motivated increasing research interest in automatic code documentation generation, with the goal of reducing manual effort while improving the availability and quality of software documentation [14]–[16].

Figure

Fig. 1. An intuitive example for different documentation levels for a code repo. We focus on code-level documentation in this paper.

As shown in Figure 1, following [17], documentation in a code repository can be organized at different levels. Project-level documentation describes the repository as a whole, such as README, CONTRIBUTING, and LICENSE files. Architecture-level documentation explains higher-level design and interface information, such as architecture descriptions and API documents. In contrast, this work focuses on code-level documentation, which refers to natural-language descriptions attached to individual code entities, such as function and class descriptions and docstrings. Different from inline code comments, which are implementation-level annotations embedded in the code body that explain how or why particular statements work, code-level documentation describes an entity's purpose, behavior, interface, and role within the repository, forming a self-contained description. Repository-level documentation can be constructed by organizing these entity-level descriptions according to the source code structure, but our study specifically targets generating documentation for a single code entity at a time.

Existing research on automatic code documentation generation falls into three strains. Heuristic-based methods generate documentation through handcrafted templates, rules, or retrieval over similar fragments [18]–[25]. They are interpretable and controllable, but rely on manually designed heuristics or code-similarity assumptions and generalize poorly to large, evolving codebases, especially in repository-level settings with cross-file and cross-function dependencies. Neural model-based methods learn mappings from code to natural language using pretrained code models such as CodeNN [25], CodeBERT [26], and PLBART [27], substantially improving semantic modeling, but most focus on function-level summarisation rather than repository-wide coverage. LLM-based methods leverage in-context learning and long-context capabilities of general-purpose LLMs to produce more fluent and adaptable documentation, and recent repository-level systems such as RepoAgent [16] and RepoSummary [14] explicitly incorporate directory structures, code dependencies, and feature-level organization to improve global coherence beyond isolated method-level summaries. Despite these advances, existing approaches still face several fundamental challenges: ① They lack explicit and verifiable documentation criteria, leaving the notion of what constitutes high-quality documentation largely implicit and inconsistent across tools and usage scenarios; ② They often incur high token costs because they rely on deep recursive analysis and redundant dependency inputs, which limit scalability and hinder practical deployment on large repositories. ③ Their code understanding can become unstable when excessively long contexts are provided, as critical information may be diluted by irrelevant details, leading to inconsistent or inaccurate documentation generation. ④ Their evaluation methods still rely heavily on human judgments and subjective assessments, which makes results harder to reproduce and limits objective comparison across methods.

To address the above challenges, we formulate automatic code documentation generation as a standards-guided and verifiable generation task, in which the content, structure, and scope of the generated documentation are explicitly constrained by well-defined documentation requirements derived from documentation standards. In this work, we propose CODEDOC, a standards-guided and dependency-aware framework for code-level documentation generation. We first extract documentation standards from authoritative sources, including ISO/IEC/IEEE standards and widely used style guides, and convert them into explicit criteria that define what to document and how to structure it. Guided by these criteria, CODEDOC generates accurate and structured documentation by combining standards grounding with static program analysis. It further incorporates dependency-aware context construction to capture relationships between code entities across the repository, and closes the loop with a criterion-aligned LLM judge whose feedback iteratively refines the generated documentation against the same standards. The main contributions of this work are as follows:

• We present a standards-guided perspective on automatic code documentation generation, systematically deriving explicit and actionable documentation criteria from authoritative ISO/IEC/IEEE and GitHub documentation standards. The resulting criteria provide a reusable foundation for both defining and evaluating documentation quality.

• We propose CODEDOC, a standards-guided and dependency-aware framework for code-level documentation generation. CODEDOC couples standards-derived criteria with AST-based structural analysis and static call-graph dependency modeling, constructing dependency-aware structured prompts that improve repository-level code understanding while reducing redundant context and token consumption.

• We introduce a criterion-aligned LLM-as-a-judge protocol that plays a dual role: it provides dimension-level feedback to iteratively optimize the generated documentation in a closed loop, and it doubles as a reproducible, standards-grounded evaluation paradigm—so that a single explicit specification governs both generation and assessment.

• We conduct experiments on ten open-source Python repositories, showing that CODEDOC improves documentation quality by 11.6%–17.0% over RepoAgent and 21.4%–29.6% over a long-context baseline under standards-aligned evaluation, while consuming roughly an order of magnitude fewer tokens per documentation entity. The LLM-based evaluation aligns with human judgment (Spearman’s ρ=0.72\rho = 0.72), and the relative findings are preserved across different judge model families.

References (41)