A real-time collaborative web application for creating and visualizing sequence diagrams. The application features a split-panel interface with a code editor on the left and a rendered diagram on the right.
This application allows multiple users to collaboratively edit sequence diagram code in real-time. As users type in the editor, the diagram updates automatically, providing immediate visual feedback.
- Split-panel interface with resizable panels
- Real-time sequence diagram rendering
- Collaborative text editing
- Syntax highlighting for sequence diagram code
- URL-based session sharing
- SVG/PNG export options
- Automatic error highlighting
- React: UI framework
- CodeMirror 6: Text editor component with syntax highlighting
- Mermaid.js: Sequence diagram renderer
- Y.js: CRDT implementation for collaborative editing
- TailwindCSS: Styling framework
- y-websocket: WebSocket provider for Y.js
- Firebase/Supabase: Backend services (authentication, persistence)
- Express.js: (Optional) For custom WebSocket server
The application follows a client-heavy architecture with minimal backend requirements:
-
Client-side:
- React SPA with split-panel layout
- CodeMirror editor bound to Y.js for collaborative editing
- Mermaid.js for diagram rendering from text input
- WebSocket connection for real-time collaboration
-
Server-side:
- WebSocket server for Y.js synchronization
- Document/room management
- User authentication (optional)
- Diagram persistence (optional)
-
Project Initialization
- Create React app
- Install dependencies
- Set up development environment
-
Split Panel UI
- Implement resizable split panel layout
- Create basic responsive design
-
Editor Implementation
- Integrate CodeMirror 6
- Configure syntax highlighting
- Implement basic editor functionality
-
Diagram Renderer
- Integrate Mermaid.js
- Create component that renders diagrams from editor content
- Implement error handling for invalid syntax
-
Y.js Integration
- Set up Y.js document structure
- Bind CodeMirror to Y.js shared document
- Implement awareness features (cursor positions, user presence)
-
WebSocket Provider
- Set up y-websocket provider
- Configure connection management
- Implement reconnection logic
-
Session Management
- Generate unique document IDs
- Implement URL-based session sharing
- Add session joining/leaving logic
-
User Interface Enhancements
- Implement theming options
- Add editor preferences
- Create user presence indicators
-
Export Functionality
- Add SVG/PNG export options
- Implement copy-to-clipboard feature
- Create diagram sharing options
-
Error Handling & Validation
- Improve error messages
- Add syntax validation
- Implement real-time error highlighting
-
Persistence Layer
- Add diagram saving functionality
- Implement version history (optional)
- Create user accounts (optional)
# Clone the repository
git clone [repository-url]
cd sequence-diagram-editor
# Install dependencies
npm install
# Start development server
npm start
# For production build
npm run build
import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
import { EditorView, basicSetup } from 'codemirror';
import { EditorState } from '@codemirror/state';
import { yCollab } from 'y-codemirror.next';
const Editor = ({ documentId }) => {
const editorRef = useRef(null);
const viewRef = useRef(null);
useEffect(() => {
// Create a Yjs document
const ydoc = new Y.Doc();
// Connect to WebSocket server
const provider = new WebsocketProvider(
'wss://your-websocket-server.com',
documentId,
ydoc
);
// Get shared text from Yjs document
const ytext = ydoc.getText('codemirror');
// Set up CodeMirror with collaborative extension
const view = new EditorView({
state: EditorState.create({
extensions: [
basicSetup,
yCollab(ytext, provider.awareness)
]
}),
parent: editorRef.current
});
viewRef.current = view;
return () => {
// Clean up
view.destroy();
provider.disconnect();
ydoc.destroy();
};
}, [documentId]);
return <div ref={editorRef} className="editor-container" />;
};
import mermaid from 'mermaid';
import { useEffect, useRef } from 'react';
const DiagramRenderer = ({ code }) => {
const diagramRef = useRef(null);
useEffect(() => {
// Initialize Mermaid
mermaid.initialize({
startOnLoad: true,
theme: 'default',
securityLevel: 'loose',
logLevel: 'error',
fontFamily: 'monospace'
});
if (diagramRef.current && code) {
try {
// Clear previous diagram
diagramRef.current.innerHTML = '';
// Render new diagram
mermaid.render('diagram', code, (svgCode) => {
diagramRef.current.innerHTML = svgCode;
});
} catch (error) {
console.error('Failed to render diagram:', error);
diagramRef.current.innerHTML = `<div class="error">Diagram rendering error: ${error.message}</div>`;
}
}
}, [code]);
return <div ref={diagramRef} className="diagram-container" />;
};
- Mobile-responsive design
- Custom diagram templates
- Offline support
- Integration with design tools
- Commenting and annotation features
- Template gallery
MIT