Table of Contents
Fetching ...

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

Ahmad Hatahet, Christoph Knieke, Andreas Rausch

TL;DR

The paper tackles the problem of missing or outdated software architecture documentation by proposing a hybrid pipeline that combines reverse engineering with large language models to automatically generate both static (component) and behavioral (state machine) views from source code. The approach starts with a detailed class diagram obtained via reverse engineering, abstracts it to a component diagram using an LLM, and then generates state machines for core components with domain-informed few-shot prompts. Key contributions include a practical end-to-end workflow, a method for core component extraction, and an evaluation framework comparing generated diagrams to ground-truth references in C++ examples, showing domain-specific prompts improve behavioral fidelity. The work demonstrates the potential to reduce manual architectural documentation effort while improving comprehension and maintainability, though it also highlights limitations related to context size, complex hierarchies, and the need for domain-aware prompting.

Abstract

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.

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

TL;DR

The paper tackles the problem of missing or outdated software architecture documentation by proposing a hybrid pipeline that combines reverse engineering with large language models to automatically generate both static (component) and behavioral (state machine) views from source code. The approach starts with a detailed class diagram obtained via reverse engineering, abstracts it to a component diagram using an LLM, and then generates state machines for core components with domain-informed few-shot prompts. Key contributions include a practical end-to-end workflow, a method for core component extraction, and an evaluation framework comparing generated diagrams to ground-truth references in C++ examples, showing domain-specific prompts improve behavioral fidelity. The work demonstrates the potential to reduce manual architectural documentation effort while improving comprehension and maintainability, though it also highlights limitations related to context size, complex hierarchies, and the need for domain-aware prompting.

Abstract

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.

Paper Structure

This paper contains 14 sections, 13 figures, 2 tables.

Figures (13)

  • Figure 1: Proposed approach: the source code is used as an input then after RE, a detailed class diagram generated, after using LLM to abstract it to a component diagram, the LLM also generate multiple state machine diagrams for each component. Component and stat machine diagrams are the output forming the final SAD.
  • Figure 2: Ground truth component diagram from Rhapsody showing the core components of the Coffee Machine
  • Figure 3: Ground truth component diagram from Rhapsody showing the core components of the Dishwasher
  • Figure 4: Overview of the complexity of all Coffee Machine's classes after RE the source code via EA (full resolution available in our repository: diagrams/CofeeMachine/class_diagram/class-diagram.png)
  • Figure 5: Static View - Component Diagram of the Coffee Machine core components after abstraction using LLM
  • ...and 8 more figures