Building MarkdownFlows
Open Source AI-Powered Mermaid Diagram Editor for Desktop
The Problem: Diagramming Shouldn't Require a PhD
Technical documentation needs diagrams. But creating them has always been painful:
- Drag-and-drop tools like Lucidchart are expensive and export poorly
- Mermaid syntax is powerful but has a steep learning curve—who remembers the difference between
-->and---? - Online editors require accounts and store your diagrams on someone else's server
- Converting ideas to diagram syntax requires mental translation overhead
- Most tools can't help you when you're stuck—you're on your own with the docs
I wanted a tool that lets me describe diagrams in plain English and have AI generate the Mermaid code. No syntax memorization. No cloud accounts. Just describe what you need.
The result: MarkdownFlows—an AI-powered desktop app that makes diagramming as simple as conversation.

MarkdownFlows: Write Mermaid or describe in natural language—AI handles the rest
The Vision: Local-First AI Diagramming
I set out to build MarkdownFlows: a desktop app that combines the power of Mermaid.js with OpenAI's language understanding. The core principles:
Natural Language Input
Describe your diagram in plain English. "Create a flowchart for user authentication with email and social login" becomes valid Mermaid code instantly.
Local-First Storage
All diagrams stored on your machine. No cloud sync, no accounts, no privacy concerns. Your technical documentation stays yours.
Real-Time Preview
See diagrams render as you type. Instant visual feedback makes iteration fast. Syntax errors highlight immediately.
Secure API Key Storage
OpenAI keys encrypted using OS keychain (macOS Keychain, Windows Credential Vault). Never touches the filesystem in plaintext.
100% Open Source (MIT License)
MarkdownFlows is completely free and open source under the MIT license. View the code, contribute improvements, or fork it for your own needs. No vendor lock-in, no subscription fees, no hidden costs. Your diagrams, your data, your control.
The Tech Stack: Modern Desktop Development
Electron + React 19 + TypeScript
Desktop apps deserve modern tooling. React 19's improved rendering handles real-time Mermaid preview without flicker. TypeScript catches errors before runtime. Electron provides cross-platform distribution with native OS integrations.
Electron Forge + Vite
Vite's lightning-fast HMR makes development enjoyable—changes appear instantly. Electron Forge handles the complexity of building, packaging, and distributing desktop apps. Three Vite configs manage main process, renderer process, and preload script compilation.
Mermaid.js for Rendering
Mermaid is the gold standard for code-based diagrams. It supports flowcharts, sequence diagrams, class diagrams, state machines, ER diagrams, Gantt charts, pie charts, and mind maps. The rendering engine is battle-tested across millions of GitHub READMEs.
OpenAI SDK (GPT-5)
AI generation uses OpenAI's GPT-5 model with intelligent prompt engineering. The service handles model differences—GPT-5 uses max_completion_tokens instead of max_tokens and doesn't support temperature parameter. These nuances are abstracted away.
shadcn/ui + Tailwind CSS
Beautiful, accessible components without the framework lock-in. shadcn/ui provides the building blocks (dialogs, buttons, inputs, scroll areas), Tailwind handles styling. The result: a native-feeling app with minimal custom CSS.
Key Features: From Idea to Export
AI-Powered Generation
Describe what you need in natural language. The AI understands context:
- Create new diagrams: "Create a flowchart for user authentication with email and OAuth"
- Modify existing diagrams: "Add error handling to the payment process"
- Convert between types: "Convert this flowchart to a sequence diagram"
- Add elements: "Add a decision node after the validation step"
8 Diagram Types Supported
Flowcharts
Process flows, decision trees, workflows
Sequence Diagrams
API interactions, message flows
Class Diagrams
Object-oriented structures
State Diagrams
State machines, transitions
ER Diagrams
Database relationships
Gantt Charts
Project timelines
Pie Charts
Data visualization
Mind Maps
Brainstorming, organization
Export Options
Export diagrams as SVG (scalable for any size) or PNG (universal compatibility). The print-friendly theme uses neutral colors optimized for both screen and paper—no more unreadable diagrams in printed docs.
Print-Ready Theme
Custom Mermaid theme with carefully chosen colors: slate tones for borders, soft backgrounds, high-contrast text. Diagrams look professional in presentations, documentation, and printed materials without manual styling.
The Architecture: Electron Security Model
Electron's multi-process architecture requires discipline. MarkdownFlows follows security best practices:
Process Isolation
- Main Process: Node.js environment handling file operations, secure storage, and OpenAI API calls
- Renderer Process: React UI running in browser sandbox, no direct Node.js access
- Preload Script: Secure IPC bridge exposing only safe operations to the renderer
Service Layer
Three focused services handle core functionality:
- DiagramStorageService: File-based diagram persistence with JSON format
- OpenAIService: AI generation with model-aware parameter handling
- SettingsService: Encrypted credential storage via OS keychain
Security: API Keys Done Right
OpenAI API keys are sensitive. Storing them in plaintext config files is asking for trouble. MarkdownFlows uses Electron's safeStorage API:
How it works: When you enter your API key, it's encrypted using your operating system's credential storage—macOS Keychain on Mac, Credential Vault on Windows, Secret Service on Linux. The encrypted blob is stored locally, but only your user account can decrypt it. Even if someone copies your config files, they can't extract the key.
This is the same security model used by professional password managers. Your API key never touches the filesystem in readable form.
Keyboard Shortcuts
Power users don't want to reach for the mouse. Essential shortcuts:
| Shortcut | Action |
|---|---|
⌘/Ctrl + Enter | Generate diagram from AI prompt |
⌘/Ctrl + S | Save diagram |
⌘/Ctrl + + | Zoom in preview |
⌘/Ctrl + - | Zoom out preview |
⌘/Ctrl + 0 | Reset zoom |
The Technical Challenges
1. Real-Time Rendering Without Flicker
Mermaid.js re-renders the entire SVG on every change. Naive implementation causes visible flicker during typing. Solution: debounced rendering with minimum 300ms delay, plus React's batched state updates to minimize reflows.
2. GPT-5 API Differences
OpenAI's GPT-5 uses different parameters than GPT-4. The OpenAIService detects model variants and adjusts—max_completion_tokens instead of max_tokens, no temperature parameter. Users can switch models without breaking generation.
3. Prompt Engineering for Diagram Quality
Getting AI to output clean Mermaid syntax required iteration. The system prompt specifies all supported diagram types, explains syntax rules, and enforces "output only the diagram code" behavior. Markdown code blocks are stripped automatically if the model includes them.
4. Resizable Panel Layout
The three-panel layout (sidebar, editor, preview) needed to be resizable with persisted widths. Custom drag handlers track mouse position, calculate percentages, and store preferences in localStorage. Panel widths survive app restarts.
The Results: Diagramming in Seconds
Before MarkdownFlows
- • Learn Mermaid syntax: 30+ minutes
- • Look up syntax for each diagram type: 5 minutes
- • Debug syntax errors: 10 minutes
- • Style for readability: 10 minutes
- Total: 55+ minutes per diagram
After MarkdownFlows
- • Describe diagram in English: 30 seconds
- • Review AI output: 10 seconds
- • Minor tweaks if needed: 30 seconds
- • Export: 5 seconds
- Total: ~1 minute per diagram
That's a 98% time reduction. Create dozens of diagrams in the time it used to take to make one.
Lessons Learned
1. Desktop Apps Are Not Dead
Local-first applications have real advantages: no accounts, no latency, no privacy concerns, works offline. For productivity tools that handle sensitive data, desktop distribution makes sense.
2. AI as Collaborator, Not Replacement
The AI generates initial diagrams, but users still review and refine. The tool amplifies human capability rather than replacing it. This balance keeps users in control while eliminating tedious syntax lookup.
3. Security Must Be Built In
Using Electron's safeStorage from day one meant zero security debt. Retrofitting credential encryption is harder than doing it right initially.
4. Simple Tools Can Be Powerful
MarkdownFlows does one thing well: AI-powered Mermaid diagrams. No feature bloat, no unnecessary complexity. Focused tools that solve specific problems are often more valuable than Swiss Army knife applications.
Technical Highlights
Tech Stack Summary
Frontend: React 19, TypeScript, Tailwind CSS, shadcn/ui
Desktop: Electron, Electron Forge, Vite
Diagrams: Mermaid.js with custom print-friendly theme
AI: OpenAI SDK with GPT-5 support
Security: Electron safeStorage for encrypted API keys
Storage: Local JSON files, localStorage for preferences
Want to Build Developer Tools?
If you're looking for an engineer who can build polished desktop applications, integrate AI capabilities, and ship tools developers actually want to use, let's talk.