Automated C4 Diagram Generation from Source Code: Static-Analysis Grounding and the Consistency of Large Language Model Output
2026 (English)Independent thesis Advanced level (degree of Master (One Year)), 10 credits / 15 HE credits
Student thesis
Abstract [en]
Software architectural documentation is frequently missing or outdated, and large language models (LLMs) are increasingly proposed as a way to recover architectural views from source code. A practical obstacle is that LLM output is not deterministic: repeated generation from the same input can yield different diagrams, even at temperature 0. This thesis studies this problem for the Container (C2) and Component (C3) levels of the C4 model, and investigates whether providing structural evidence extracted by static analysis changes how consistent LLM-generated diagrams are across repeated runs. The study measures consistency only; it does not assess whether the diagrams are architecturally correct. A five-stage pipeline (static-analysis extraction with Spoon, transformation into LLM input, prompt construction, LLM invocation, and output processing) was implemented and applied to three open-source Java projects of increasing size (jhipster ≈4,500 LOC, spring-boot-admin ≈15,300 LOC, apache-maven-3.9.15 ≈84,000 LOC). Three models (GPT-4.1 mini, GPT-4.1 nano, Gemini 2.5 Flash) were each given three input conditions: source code only, static analysis output only, and both combined. Every condition was run ten times, yielding 810 PlantUML diagrams. Consistency was measured as node and edge Jaccard similarity over all pairs of runs, after an automated, deterministic label-alignment procedure. Differences between conditions were tested with Wilcoxon signed-rank tests over model × project × target cells, with Holm correction. All 810 diagrams were syntactically valid PlantUML. Repeated generation was not deterministic: only 4 of 27 C2 conditions produced the same diagram in all ten runs. The combined condition had the highest mean C2 consistency (node Jaccard 0.83 versus 0.78 for source code only; edge Jaccard 0.71 versus 0.60), but none of the differences was statistically significant after Holm correction for multiple comparisons, and the effect of adding static analysis was positive for one model, negative for another and negligible for the third. At C3, consistency was high in all conditions (node Jaccard 0.92–0.97); however, for two of the three projects every run of every model produced an identical set of components, so the C3 differences stem almost entirely from the largest project. Gemini 2.5 Flash produced the most stable output overall and GPT-4.1 nano the least. Label normalisation changed the measured consistency by at most 0.032, which indicates that run-to-run variation is structural rather than terminological. The lowest consistency values were concentrated in outputs with large numbers of repeated declarations. Overall, adding static analysis did not reliably make LLM-generated architectural views more stable.
Place, publisher, year, edition, pages
2026. , p. 43
Keywords [en]
software architecture recovery, C4 model, static analysis, large language models, LLM non-determinism, output consistency, architectural views, PlantUML, Spoon, empirical evaluation
National Category
Software Engineering
Identifiers
URN: urn:nbn:se:mdh:diva-79405OAI: oai:DiVA.org:mdh-79405DiVA, id: diva2:2115043
Supervisors
Examiners
2026-11-042026-11-032026-11-04Bibliographically approved