Java + Astro LIVE

Diagram-as-Code Architect

Paste code, get architecture diagrams — powered by Gemini and rendered with Mermaid.js.

info
description

Overview

Diagram-as-Code Architect is a developer productivity tool that converts Spring Boot (Java) or Terraform (HCL) source code into Mermaid.js diagrams using Vertex AI Gemini 2.0 Flash via Spring AI. Paste a controller class and get a flowchart, sequence diagram, class diagram, or ER diagram. Paste a Terraform file and get an infrastructure topology map. The backend is a Java 21 Spring Boot service with Spring AI 1.1, protected by API key authentication and a Resilience4j circuit breaker with exponential backoff retry. The frontend is an Astro 5 single-page app with Mermaid.js 11.6 rendering, hosted on Firebase with a Cloud Functions API proxy that injects the API key server-side. The entire stack is stateless — no database — and runs on Google Cloud with scale-to-zero Cloud Run.

psychology_alt
warning

The Problem

Architecture diagrams go stale almost immediately after they're created. A developer refactors a service, adds a dependency, or changes a data flow, and the diagram in the wiki is instantly wrong. Teams spend hours manually updating Lucidchart or Draw.io documents that drift from the actual code, leading to confusion during onboarding, incorrect assumptions during incident response, and wasted time in design reviews. The gap between code and documentation only grows as the codebase evolves.

auto_fix

The Approach

The system uses a prompt-template pipeline with six specialized templates — one per language-diagram combination (e.g., java-flowchart.txt, hcl-infrastructure.txt). Each template includes Mermaid syntax rules, a one-shot example of valid input and output, and placeholders for the user's code and optional context. At request time, the CodeAnalysisService validates the input (max 50K characters, valid language-diagram combination), the PromptTemplateEngine selects and fills the correct template, and the ResilientLlmClient sends it to Vertex AI Gemini 2.0 Flash at temperature 0.2 for deterministic structured output. The MermaidSyntaxExtractor strips any markdown fencing from the LLM response and validates the Mermaid directive. The result is returned with metadata (processing time, model name, input size) and rendered client-side by Mermaid.js with options to copy the raw syntax or export as PNG or SVG.

Architecture

account_tree

Production Architecture

How a diagram request flows from browser to Mermaid output

Production Architecture
zoom_in Tap to expand
account_tree

Generation Pipeline

How source code becomes a Mermaid.js diagram in five steps

Generation Pipeline
zoom_in Tap to expand

Tech Stack

Medium effort
code_blocks

Spring Boot 3.5

Java 21 Backend

psychology

Spring AI 1.1

LLM Orchestration

auto_awesome

Gemini 2.0 Flash

Diagram Generation

account_tree

Mermaid.js 11.6

SVG Rendering (CDN)

shield

Resilience4j 2.2

Circuit Breaker + Retry

cloud

Cloud Run

Scale-to-Zero Deploy

web

Astro 5

Static Frontend

lock

Spring Security

API Key Auth + CORS

Engineering Highlights

Code-to-Diagram5 Diagram TypesPrompt TemplatesCircuit BreakerScale-to-ZeroAPI Key AuthPNG/SVG ExportCloud-Native