Diagram-as-Code Architect
Paste code, get architecture diagrams — powered by Gemini and rendered with Mermaid.js.
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.
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.
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
Production Architecture
How a diagram request flows from browser to Mermaid output
Generation Pipeline
How source code becomes a Mermaid.js diagram in five steps
Tech Stack
Medium effortSpring Boot 3.5
Java 21 Backend
Spring AI 1.1
LLM Orchestration
Gemini 2.0 Flash
Diagram Generation
Mermaid.js 11.6
SVG Rendering (CDN)
Resilience4j 2.2
Circuit Breaker + Retry
Cloud Run
Scale-to-Zero Deploy
Astro 5
Static Frontend
Spring Security
API Key Auth + CORS