Skip to content

sametcn99/mermaid-viewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ§œβ€β™€οΈ Mermaid Live Editor & Viewer

Next.js React TypeScript Mermaid MUI

πŸš€ Create, edit, and share beautiful Mermaid diagrams in real-time!

A powerful, modern web application that transforms your ideas into stunning diagrams with live preview and instant sharing capabilities.

✨ Live Demo β€’ πŸ› Report Bug β€’ πŸ’‘ Request Feature


✨ Features

πŸ”₯ Core Features

  • ⚑ Live Preview: See your diagrams update instantly as you type
  • πŸ“± Responsive Split View: Adjustable panels that work perfectly on all devices
  • 🎨 Syntax Highlighting: Monaco Editor with intelligent code completion
  • πŸš€ Fast Rendering: Debounced updates for smooth performance
  • πŸ“€ Quick Sharing: Generate shareable links with URL encoding
  • πŸŒ™ Dark/Light Theme: Beautiful themes that adapt to your preference

πŸ’Ž Advanced Features

  • πŸ” Zoom & Pan: Interactive diagram navigation with mouse and touch
  • πŸ’Ύ Auto-Save: Your work is automatically saved in browser storage
  • πŸ“‹ One-Click Copy: Copy diagrams as SVG or share links instantly
  • πŸ”„ Real-time Validation: Immediate feedback on syntax errors
  • πŸ“± Mobile Optimized: Perfect experience on phones and tablets
  • ⌨️ Keyboard Shortcuts: Power user shortcuts for faster workflow

πŸš€ Quick Start

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18.17.0 or higher)
  • Bun (recommended) or npm/yarn/pnpm
  • Git for version control

⚑ Installation

  1. Clone the repository

    git clone https://github.com/sametcn99/mermaid-viewer.git
    cd mermaid-viewer
  2. Install dependencies

    # Using Bun (recommended for fastest installation)
    bun install
    
    # Or using npm
    npm install
    
    # Or using yarn
    yarn install
    
    # Or using pnpm
    pnpm install
  3. Start the development server

    # Using Bun
    bun dev
    
    # Or using npm
    npm run dev
    
    # Or using yarn
    yarn dev
    
    # Or using pnpm
    pnpm dev
  4. Open your browser

    Navigate to http://localhost:3000 and start creating diagrams! πŸŽ‰


πŸ“– Usage Examples

🎯 Basic Flowchart

graph TD
    A[Start] --> B{Is it working?}
    B -->|Yes| C[Great!]
    B -->|No| D[Debug]
    D --> B
    C --> E[End]
Loading

🏒 Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant API
    participant Database
    
    User->>Frontend: Create diagram
    Frontend->>API: Validate syntax
    API->>Database: Save diagram
    Database-->>API: Success
    API-->>Frontend: Confirmation
    Frontend-->>User: Show result
Loading

πŸ“Š Class Diagram

classDiagram
    class DiagramEditor {
        +String content
        +Boolean isValid
        +updateContent(content)
        +validateSyntax()
        +exportSVG()
    }
    
    class DiagramViewer {
        +Element svg
        +render(content)
        +zoom(level)
        +pan(x, y)
    }
    
    DiagramEditor --> DiagramViewer : renders
Loading

πŸ› οΈ Available Scripts

Command Description
bun dev πŸ”₯ Start development server with Turbopack
bun build πŸ—οΈ Build the application for production
bun start πŸš€ Start the production server
bun lint πŸ” Run ESLint to check code quality
bun format ✨ Format code with Prettier

βš™οΈ How It Works

πŸ—οΈ Architecture Overview

graph LR
    A[πŸ“ Monaco Editor] --> B[⚑ Debounced Updates]
    B --> C[πŸ§œβ€β™€οΈ Mermaid Parser]
    C --> D[πŸ“Š SVG Renderer]
    D --> E[πŸ” Zoom & Pan Viewer]
    
    F[πŸ’Ύ Local Storage] --> A
    A --> F
    
    G[πŸ”— URL Encoding] --> A
    E --> H[πŸ“€ Share Function]
    H --> G
Loading

πŸ”§ Key Components

  • πŸ“ Editor Panel: Monaco Editor with TypeScript and Mermaid syntax highlighting
  • πŸ“Š Diagram Panel: Real-time SVG rendering with interactive zoom and pan
  • πŸ”„ Debounced Updates: Optimized performance with 300ms debounce
  • πŸ“± Responsive Layout: react-split for adjustable panels on all devices
  • πŸ’Ύ Auto-Save: Browser localStorage for persistent diagram storage
  • πŸ”— URL Sharing: Compressed diagram data in shareable URLs

🧰 Technology Stack

Frontend Framework

Next.js React TypeScript

Core Libraries

Mermaid MUI Monaco Editor

Performance & Utilities

Lodash React Zoom Pan Pinch Pako

Development Tools

ESLint Prettier Husky


πŸ”§ Configuration & Customization

🎨 Theming

The application supports both light and dark themes using Material-UI's theming system. Themes automatically adapt to system preferences.

βš™οΈ Editor Configuration

Monaco Editor is configured with:

  • Mermaid syntax highlighting
  • Auto-completion
  • Error detection
  • Bracket matching
  • Code folding

πŸ“± Responsive Breakpoints

  • Mobile: < 768px (stacked layout)
  • Tablet: 768px - 1024px (adjustable split)
  • Desktop: > 1024px (side-by-side split)

πŸ“Š Performance Features

  • ⚑ Turbopack: Lightning-fast development builds
  • πŸ”„ Debounced Rendering: Optimized diagram updates
  • πŸ’Ύ Efficient Storage: Compressed URL encoding with Pako
  • πŸ“± Mobile Optimized: Touch-friendly interface
  • πŸš€ SSR Ready: Server-side rendering support

🀝 Contributing

We welcome contributions from the community! Here's how you can help:

πŸš€ Quick Contribution Guide

  1. 🍴 Fork the Project

    # Click the Fork button on GitHub
  2. 🌿 Create your Feature Branch

    git checkout -b feature/AmazingFeature
  3. πŸ’» Make your Changes

    # Make your awesome changes
    bun dev # Test locally
  4. βœ… Run Tests & Linting

    bun lint
    bun format
  5. πŸ“ Commit your Changes

    git commit -m 'Add some AmazingFeature'
  6. πŸš€ Push to the Branch

    git push origin feature/AmazingFeature
  7. πŸ”„ Open a Pull Request

🎯 Contribution Areas

  • πŸ› Bug Fixes: Help us squash bugs
  • ✨ New Features: Add exciting new functionality
  • πŸ“– Documentation: Improve our docs
  • 🎨 UI/UX: Enhance user experience
  • ⚑ Performance: Optimize for speed
  • πŸ§ͺ Testing: Add test coverage

πŸ“‹ Development Guidelines

  • Follow existing code style (Prettier + ESLint)
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed
  • Test on multiple browsers/devices

πŸ™ Acknowledgments

  • Mermaid.js - For the amazing diagram rendering engine
  • Monaco Editor - For the powerful code editor
  • Next.js - For the excellent React framework
  • Material-UI - For the beautiful component library
  • Vercel - For seamless deployment and hosting

πŸ“ˆ Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


⭐ Star this repo if you found it helpful! ⭐

πŸ” Back to top