惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Vercel News
Vercel News
月光博客
月光博客
S
SegmentFault 最新的问题
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
小众软件
小众软件
WordPress大学
WordPress大学
G
Google Developers Blog
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
博客园 - 【当耐特】
I
InfoQ

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Mermaid.js - Sketching diagrams using code
Mirza Leka · 2026-05-11 · via DEV Community

Mermaid.js is a text-based diagramming language that lets technical writers create and modify complex diagrams with simple code.

Example

Let's say you're making a family tree and want to visualize it with Mermaid.js:

:::mermaid
flowchart TD
A["Grandad"]
B["Dad"]
C["Me"]
:::

Enter fullscreen mode Exit fullscreen mode

What this does is:

  • tells Mermaid.js that you want to use a flowchart diagram
  • to create three separate entities (boxes) with labels on them

family-tree

Then add arrows to create a relationship between entities.

:::mermaid
flowchart TD
A["Grandad"]
--> B["Dad"]
B --> C["Me"]
:::

Enter fullscreen mode Exit fullscreen mode

family-tree-relationship

And there you go. But you can also apply different conditions (A => B or A => C):

:::mermaid
flowchart TD
A["Raining outside?"]
A --> |Yes| B["Take umbrella"]
A --> |No| C["Take sunglasses"]
:::

Enter fullscreen mode Exit fullscreen mode

flow-conditions

Mermaid supports a wide range of diagram types, including flowcharts, pie charts, sequence diagrams, UML diagrams, mind maps, etc, as well as colors and style kits for each.

I'm not going to go through each one of these because the official documentation is pretty detailed. I'm going to teach you how to use these diagrams today.

Where can I render the diagram?

You can preview Mermaid diagrams in any markdown file - GitHub repository, code editor of choice, or Notion.

GitHub markdown file

Create a markdown file in your GitHub repository and paste the snippet inside the code block:

:::mermaid
<YOUR-DIAGRAM-CODE>
:::

Enter fullscreen mode Exit fullscreen mode

Surround the code block with three backticks or three colons, followed by the text "mermaid".

Here is a GitHub gist snippet I created for this demonstration.

Visual Studio Code

Just like on GitHub, create a markdown file inside the project and write your Mermaid.js script. To preview the diagram, the VSC has a markdown preview extension you can install in your editor.

Then, right-click on the markdown file (you wish to preview), choose Open With, and then choose the Markdown preview extension you've installed. The markdown should appear in the preview window.

vsc-markdown-preview

Can I use AI?

It's actually one of my favorite things to do when I need to document a feature or when I'm getting started on a new project.

Just for reference, this is the original code that I gave to Claude Code:

[Route("api/[controller]")]
[ApiController]
public class GamesController(IGamesService _gamesService) : ControllerBase
{

    [Route("NewGameMode")]
    [HttpPost]
    public async Task<ActionResult<GetGameModeDTO>> NewGameMode([FromBody] CreateGameModeDTO dto)
    {
        try
        {
            return await _gamesService.CreateGameMode(dto);
        }
        catch (Exception ex)
        {
            return BadRequest(ex.Message);
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

    public async Task<GetGameModeDTO> CreateGameMode(CreateGameModeDTO gameMode)
    {
        var newGameMode = new GameModes
        {
            Title = gameMode.Title,
            ShortTitle = gameMode.ShortTitle,
            GameType = gameMode.GameType
        };

        _gamesContext.GameModes.Add(newGameMode);
        await _gamesContext.SaveChangesAsync();

        var mappedGameMode = GetGameModeDTO.ToResponse(newGameMode);
        return mappedGameMode;
    }

Enter fullscreen mode Exit fullscreen mode

public class GetGameModeDTO
{
    public int ID { get; set; }
    public string Title { get; set; }
    public string ShortTitle { get; set; }

    public static GetGameModeDTO ToResponse(GameModes gameMode)
    {
        return new GetGameModeDTO()
        {
            ID = gameMode.ID,
            Title = gameMode.Title,
            ShortTitle = gameMode.ShortTitle
        };
    }

}

Enter fullscreen mode Exit fullscreen mode

Now, Open Claude (or your LLM agent of choice) and ask it to analyze the project:

Hey Claude, analyze this project for me and summarize the language used, classes and core functionalities.

Enter fullscreen mode Exit fullscreen mode

Then ask it to draw you a map:

Claude, can you describe what's going on from the games controller to the database using a Mermaid.js sequence diagram in the README.md?

Enter fullscreen mode Exit fullscreen mode

And the output is a Mermaid.js diagram

:::mermaid
sequenceDiagram
    participant Client
    participant GamesController
    participant GamesService
    participant GamesContext
    participant SQL as SQL Server (Game_Modes)

    Client->>GamesController: POST /api/games/NewGameMode — { title, shortTitle, gameType }
    GamesController->>GamesService: CreateGameMode(CreateGameModeDTO)
    GamesService->>GamesService: new GameModes { Title, ShortTitle, GameType }
    GamesService->>GamesContext: GameModes.Add(newGameMode)
    GamesService->>GamesContext: SaveChangesAsync()
    GamesContext->>SQL: INSERT INTO Game_Modes (Title, Short_Title, Game_Type) VALUES (...)
    SQL-->>GamesContext: auto-generated ID
    GamesContext-->>GamesService: entity with new ID populated
    GamesService->>GamesService: GetGameModeDTO.ToResponse(entity)
    GamesService-->>GamesController: GetGameModeDTO
    GamesController-->>Client: 200 OK — { id, title, shortTitle }
:::

Enter fullscreen mode Exit fullscreen mode

That you can preview in the markdown file.

mermaid-sequence-diagram

Pretty neat, right? Much faster than drawing manually.
Here's another example of asking Claude to do my homework.

mermaidjs-flow-chart

Summary

Mermaid.js is a pretty powerful tool when you need to sketch out functionalities to analyze or demonstrate. For more on Mermaid.js, feel free to visit the official documentation.

Until next time 👋