arXiv:2511.05165cs.SEcs.AI2025-11被引 7

用大模型从代码自动生成架构图,省去人工梳理的麻烦。

Generating Software Architecture Description from Source Code using Reverse Engineering and Large Language Model

  • 结合逆向工程与大模型,自动提取组件和行为视图。
  • 通过提示工程筛选核心组件,少样本提示生成状态机图。
  • 适合需要快速理解复杂系统的开发团队使用。

软件架构描述(SAD)对管理现代软件系统的复杂性至关重要,能支持高层架构推理、指导设计决策并促进各利益相关方沟通。然而实践中,SAD常缺失、过时或与实际实现不符。开发者不得不直接从源码中推导架构信息,耗时且增加认知负担,影响新成员上手效率,并导致系统长期可读性下降。为此,我们提出一种半自动化方法,结合逆向工程(RE)与大语言模型(LLM),从源码生成架构描述。该方法通过提取全面的组件图,利用提示工程筛选出有架构意义的元素(核心组件),并基于代码逻辑使用少样本提示生成状态机图以建模组件行为。所生成的视图提供了一种可扩展、易维护的替代传统手工文档的方案。在C++示例中的验证表明,大模型能有效:1)抽象组件图,减少对人工专家的依赖;2)准确表示复杂软件行为,尤其在融入领域知识的少样本提示下表现更优。这些发现为显著降低人工成本、提升系统理解力与长期可维护性提供了可行路径。

原文摘要 · Abstract (English)

Software Architecture Descriptions (SADs) are essential for managing the inherent complexity of modern software systems. They enable high-level architectural reasoning, guide design decisions, and facilitate effective communication among diverse stakeholders. However, in practice, SADs are often missing, outdated, or poorly aligned with the system's actual implementation. Consequently, developers are compelled to derive architectural insights directly from source code-a time-intensive process that increases cognitive load, slows new developer onboarding, and contributes to the gradual degradation of clarity over the system's lifetime. To address these issues, we propose a semi-automated generation of SADs from source code by integrating reverse engineering (RE) techniques with a Large Language Model (LLM). Our approach recovers both static and behavioral architectural views by extracting a comprehensive component diagram, filtering architecturally significant elements (core components) via prompt engineering, and generating state machine diagrams to model component behavior based on underlying code logic with few-shots prompting. This resulting views representation offer a scalable and maintainable alternative to traditional manual architectural documentation. This methodology, demonstrated using C++ examples, highlights the potent capability of LLMs to: 1) abstract the component diagram, thereby reducing the reliance on human expert involvement, and 2) accurately represent complex software behaviors, especially when enriched with domain-specific knowledge through few-shot prompting. These findings suggest a viable path toward significantly reducing manual effort while enhancing system understanding and long-term maintainability.

架构生成大模型逆向工程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。