Sign in
Topics
Instantly generate production ready code with AI
This guide shows how to generate architecture diagrams automatically from code using tools like Swark and GitHub Copilot. It walks through setup, prompt handling, Mermaid preview rendering and version‑controlled diagram-as‑code workflows for web app projects.
Ever opened a new codebase and thought—Where do I even start? Manually sketching architecture diagrams wastes time and rarely stays updated. What if you could generate them instantly, straight from your code?
This guide shows how to generate architecture diagrams automatically from code using tools like Swark. You’ll see how source files turn into visual structures through a hands-on workflow powered by VS Code, AI, and diagram-as-code.
Software architecture documentation often lags behind code changes. Manual architecture diagram upkeep becomes burdensome and error‑prone. Teams need to create architecture diagrams that stay current, especially for web applications and complex systems.
Traditional tools—UML editors, static analyzers—fall into what the industry calls classic code visualization solutions. They often require manual configuration per language or project, and struggle to adapt to AI-generated code or new code bases.
These solutions require incremental updates to support new languages or frameworks. They don’t scale when architectures evolve.
By contrast, tools that treat diagrams as code and integrate with large language models bring:
Universal language support
Seamless updates
Better version control
Code‑driven diagrams
Swark is an open‑source VS Code extension that allows for instant generation of architecture diagrams. Within seconds, Swark transforms your source code into a visual architecture: it retrieves code files, builds prompts for LLMs, and presents a Mermaid diagram in VS Code.
Swark is a free and open source VS Code extension that allows creating architecture diagrams from code automatically using large language models (LLMs). — LinkedIn Post
File retrieval: Swark retrieves code files in your chosen folder. It automatically adjusts the number of retrieved files to respect the LLM max token limit.
Prompt building: From retrieved files, Swark builds a prompt including source code, asking GitHub Copilot for architectural structure.
LLM request: Swark invokes Copilot (no api keys required) through the VS Code LLM interface.
Diagram preview: On a successful response, Swark creates a markdown file with Mermaid syntax and renders a diagram preview.
Swark integrates directly with GitHub Copilot. With Copilot's free tier, you no longer need extra API keys or external providers. You can review Swark’s code on GitHub to audit or modify behavior.
Follow these steps when onboarding Swark:
Install the GitHub Copilot extension in VS Code.
Add the Swark extension from Visual Studio Marketplace.
Optional: install Markdown Preview Mermaid Support to preview diagrams in the editor.
Open Command Palette, choose Swark: Create Architecture Diagram, or press Ctrl+Shift+r.
Swark asks you to select a chosen folder. It retrieves files from that folder, builds its prompt, and sends the LLM request. Soon, a mermaid-based diagram preview appears in a markdown file.
Under the hood, Swark executes a workflow to enable architecture generation:
Swark only pulls files up to token limits. It may skip test files unless you include them, but if you do include them, it surfaces test coverage insights in the diagram. This helps you spot unwanted dependencies or coverage gaps.
You can enable test files in the configuration to see metrics visually.
Helps in identifying the repo’s dependency graph and areas for refactoring.
Once files are gathered, Swark builds a merge prompt that includes part of the source code, instructions to produce a high-level architecture diagram, and limits the prompt under the LLM max token limit.
Swark invokes the LLM request via Copilot’s API. It supports diagram as code output in Mermaid syntax.
The resulting diagram is generated in Mermaid.js syntax. Mermaid is a popular diagram‑as‑code framework, supported widely across Markdown environments. You can further edit the output markdown file to tweak components.
Swark helps in scenarios such as:
Onboarding a new team member: instantly generate architecture diagrams for complex repositories.
Reviewing AI-generated code: spot structure mismatches or missing dependencies.
Keeping documentation fresh: auto‑regenerate diagrams when code changes.
Dealing with unfamiliar repositories or legacy systems helps create a high-level understanding fast.
You can spot unwanted dependencies, assess test coverage, or visualize the repo’s dependency graph automatically.
Several modern tools aim to simplify architecture visualization through code. While each offers value, their capabilities and automation levels vary widely.
Diagrams (Python): Create cloud system architecture diagrams using Python code. Good for AWS, Azure, and GCP.
PlantUML: Write UML or C4 model diagrams using a DSL. Requires manual structure definition.
Mermaid: Integrates into Markdown docs. Popular for basic flowcharts, class diagrams, and sequence diagrams.
Graphviz: Visualize complex relationships with DOT language, often used for graph-based structures.
Structurizr DSL: Implements the C4 model. Requires code-like configuration to define systems, containers, and components.
D2 Studio: A modern diagram-as-code solution with automatic layout and real-time rendering.
Code2Flow: Focused on generating flowcharts from Python functions or pseudocode.
Architexa: Designed for Java projects, supports team collaboration with layered diagrams.
These tools offer diagram as code, but most require manual configuration and do not interpret your actual source code. Swark, by contrast, analyzes your codebase and builds diagrams automatically using large language models.
Feature | Diagrams / PlantUML / Graphviz / Structurizr | Swark |
---|---|---|
Source-code input | Requires manual DSL or scripting | Directly from code files |
Language support | Language- or domain-specific | Universal language support via LLMs |
Diagram creation | Requires manual design or templates | Swark generates diagrams automatically |
Setup | Needs config, DSL knowledge, or templates | No additional setup—just install and run |
Version control | Depends on external diagram files | Diagrams created as Markdown, version controlled |
AI integration | No LLM or AI understanding | Uses GitHub Copilot to build architecture context |
Best for | Structured documentation | Fast insights from real code, onboarding, audits |
Swark stands out for its ability to quickly visualize unfamiliar projects and AI-generated code, helping identify unwanted dependencies or incomplete test coverage directly from the working system.
If Copilot fails to process all files due to the LLM max token limit, try limiting analysis to headers, interfaces, or main modules. Swark automatically adjusts retrieved files to fit. You may further filter certain extensions via configuration settings.
Enable test files in Swark’s input to include test coverage in the generated architecture diagram. You will see both functional structure and test relationships—helping identify gaps.
Because Swark outputs Mermaid syntax, you can refine and expand diagrams manually inside the markdown file. Diagram preview updates instantly. This approach ensures your architecture stays in sync with code over time.
Treat the Mermaid markdown file as part of your repo. Commit and review changes via pull requests. This supports version control tracking and helps documentation stay fresh as code evolves.
Clone a repository, e.g., a web application project.
Open VS Code, install GitHub Copilot and Swark.
Open Command Palette → Swark: Create Architecture Diagram.
Select root folder: Swark retrieves files, adjusts to token limits.
Swark builds its prompt and invokes the LLM request.
Mermaid markdown file opens with a diagram preview.
Examine the diagram, which shows modules, classes, dependencies, and test coverage.
Modify the Mermaid code if necessary, then commit the markdown file for documentation.
Run weekly or integrate in CI to regenerate diagrams. This keeps your documentation fresh, helps teams understand structure, and spot unwanted dependencies as code changes.
Commit the Mermaid diagram file and treat diagrams as code for review. You can store definitions in version control alongside your code. Set up CI jobs to regenerate diagrams automatically and compare diffs.
Swark relies only on GitHub Copilot and no other external APIs or providers. That simplifies privacy compliance. No extra API keys required. You may adapt Swark’s prompt if you want to address specific architectural layers or include sequence flows.
A LinkedIn post by Rohit Doshi demonstrates Swark in action, showing how to quickly generate architecture diagrams from code: a credible peer‑shared example. Another post by Donald Lutz introduces Swark to his network.
You now see how software architecture can be visualized directly from source code using AI-powered workflows. Swark is a concrete example of how to generate architecture diagrams automatically from code. Classic manual or template-based approaches are being replaced by diagram-as-code methods paired with LLM‑enabled automation.
Install Swark and GitHub Copilot in VS Code, and try it on one of your repositories.
Compare Swark output with diagrams created manually or with traditional tools.
Commit auto‑generated Mermaid markdown diagrams into your documentation.
Optionally integrate regeneration into CI pipelines for ongoing updates.
Applying Swark helps you maintain accurate architecture diagrams, support onboarding, and improve documentation workflows.