Visualizing with Mermaid Charts
Transform your ideas into stunning visual diagrams using GitHub Copilot and the powerful Mermaid Chart extension.
What is Mermaid?โ
Mermaid is a text-based diagramming tool that creates beautiful charts from simple markdown-like syntax. With GitHub Copilot integration, you can generate complex diagrams using natural language prompts! โจ
Quick Setupโ
Installationโ
- Go to VS Code Marketplace
- Install Mermaid Chart extension
- Ensure you have active GitHub Copilot license
- Restart VS Code
Basic Usageโ
- Open Copilot Chat in VS Code
- Start prompts with
@mermaid-chart - Describe your diagram naturally
- Get instant live preview!
Diagram Types & Examplesโ
1. Flowchartsโ
Perfect for process flows and decision trees.
Prompt:
@mermaid-chart create a flowchart for user authentication process
Generated Code:
```mermaid
flowchart TD
A[User Login Request] --> B{Valid Credentials?}
B -->|Yes| C[Generate JWT Token]
B -->|No| D[Return Error Message]
C --> E[Set Session Cookie]
E --> F[Redirect to Dashboard]
D --> G[Show Login Form]
```
Rendered Output:
2. Class Diagramsโ
Visualize object-oriented design and relationships.
Prompt:
@mermaid-chart create a class diagram for an e-commerce system
Generated Code:
```mermaid
classDiagram
class User {
+String email
+String password
+String name
+login()
+logout()
}
class Product {
+String id
+String name
+Float price
+Integer stock
+updateStock()
}
class Order {
+String id
+Date createdAt
+Float total
+addItem()
+calculateTotal()
}
User "1" --o Order : places
Order "1" --o Product : contains
```
Rendered Output:
3. Sequence Diagramsโ
Show interactions over time between different components.
Prompt:
@mermaid-chart create a sequence diagram for API authentication
Generated Code:
```mermaid
sequenceDiagram
participant Client
participant API Gateway
participant Auth Service
participant Database
Client->>API Gateway: POST /login
API Gateway->>Auth Service: validate credentials
Auth Service->>Database: query user
Database-->>Auth Service: user data
Auth Service-->>API Gateway: JWT token
API Gateway-->>Client: 200 OK + token
```
Rendered Output:
4. Entity Relationship Diagramsโ
Design database schemas and relationships.
Prompt:
@mermaid-chart create an ER diagram for a blog system
Generated Code:
```mermaid
erDiagram
USER ||--o{ POST : writes
USER {
int id PK
string email
string name
datetime created_at
}
POST ||--o{ COMMENT : has
POST {
int id PK
string title
text content
int author_id FK
datetime published_at
}
COMMENT {
int id PK
text content
int post_id FK
int user_id FK
datetime created_at
}
```
Rendered Output:
5. Gantt Chartsโ
Project timelines and task management.
Prompt:
@mermaid-chart create a Gantt chart for app development project
Generated Code:
```mermaid
gantt
title App Development Timeline
dateFormat YYYY-MM-DD
section Planning
Requirements Analysis :a1, 2024-01-01, 7d
UI/UX Design :a2, after a1, 10d
section Development
Backend API :b1, after a2, 14d
Frontend Development :b2, after a2, 21d
Database Setup :b3, after a2, 7d
section Testing
Unit Testing :c1, after b1, 7d
Integration Testing :c2, after b2, 5d
section Deployment
Production Setup :d1, after c2, 3d
```
Rendered Output:
Advanced Featuresโ
Generate from Codeโ
Automatically create diagrams from your existing codebase!
Prompt:
@mermaid-chart analyze my TypeScript classes and create a class diagram
Mermaid Chart extension scans your code and generates accurate representations of your class structures, inheritance, and relationships.
Cloud Architecture Visualizationโ
Visualize your infrastructure and cloud resources.
Command:
@mermaid-chart /generate_cloud_architecture_diagram
Or use Command Palette:
MermaidChart: Generate Cloud Diagram
Features:
- Scans configuration files (Docker, Kubernetes, Terraform)
- Detects cloud services and dependencies
- Creates comprehensive architecture diagrams
- Allows file selection for focused diagrams
Database Schema Visualizationโ
Transform your database schemas into clear ER diagrams.
Command:
@mermaid-chart /generate_er_diagram
Capabilities:
- Analyzes database migration files
- Detects model relationships in code
- Creates comprehensive entity relationship diagrams
- Supports multiple database formats
Practical Examplesโ
1. API Documentationโ
@mermaid-chart create a sequence diagram showing:
- Client requests product list
- API validates JWT token
- Fetches data from database
- Returns paginated results
2. Microservices Architectureโ
@mermaid-chart design a microservices diagram with:
- User Service (authentication)
- Product Service (catalog)
- Order Service (transactions)
- API Gateway (routing)
- Message Queue (communication)
3. Git Workflowโ
@mermaid-chart create a Git flow diagram showing:
- Feature branch creation
- Pull request process
- Code review steps
- Merge to main branch
4. CI/CD Pipelineโ
@mermaid-chart visualize a CI/CD pipeline with:
- Code commit triggers
- Automated testing phases
- Security scanning
- Deployment stages
- Rollback procedures
Interactive Featuresโ
Live Previewโ
- Real-time rendering as you type
- Zoom and pan capabilities
- Export options (PNG, SVG, PDF)
- Theme customization (light/dark modes)
Collaborative Editingโ
- Share diagrams with team members
- Version control integration
- Comment and review capabilities
- Export to various formats
Auto-Updateโ
When your code changes, Mermaid Chart can:
- Detect changes in source files
- Offer to update related diagrams
- Maintain consistency between code and documentation
- Suggest improvements to existing diagrams
Pro Tips & Tricksโ
1. Be Specific with Contextโ
โ Generic: "Create a flowchart"
โ
Specific: "Create a flowchart for password reset process including email verification"
2. Combine Multiple Diagram Typesโ
@mermaid-chart create both a sequence diagram and flowchart for the checkout process
3. Iterate and Refineโ
# First: Generate basic diagram
@mermaid-chart create user registration flow
# Then: Add details
Add error handling and validation steps to the registration diagram
# Finally: Enhance
Add loading states and success/failure paths
4. Use Consistent Stylingโ
@mermaid-chart create an architecture diagram using consistent colors:
- Blue for services
- Green for databases
- Orange for external APIs
Quick Referenceโ
Essential Commands:
@mermaid-chartโ Start diagram generation/generate_cloud_architecture_diagramโ Cloud infrastructure/generate_er_diagramโ Database schemasMermaidChart: Generateโ Command palette options
Common Diagram Types:
- Flowchart โ Process flows, decision trees
- Sequence โ API interactions, user flows
- Class โ Object-oriented design
- ER โ Database relationships
- Gantt โ Project timelines
- Describe your diagram in natural language ๐ฃ๏ธ
- Review generated code for accuracy โ
- Iterate with specific requests for improvements ๐
- Export in desired format for documentation ๐ค
- Keep diagrams updated with code changes ๐
Marketplace Link: Mermaid Chart Extension
Ready to explore all Copilot features? Check out our Complete Reference guide! ๐