DrawGen is a real-time, conversational diagramming tool. Describe your architecture, flowchart, or network topology in plain language, and watch it come to life instantly. It uses a powerful Large Language Model (LLM) backend to generate and modify draw.io diagrams through a simple chat interface.
- Conversational Interface: Build and refine diagrams through a simple chat. No drag-and-drop required.
- Real-Time Updates: See your changes reflected instantly in the live draw.io editor.
- Stateful Conversations: The AI remembers the context of your diagram, allowing for complex, iterative modifications.
- Advanced XML Processing: Robust parsing with automatic correction of malformed XML, missing closing tags, and attribute value escaping.
- Smart Error Recovery: Graceful handling of AI response variations with automatic fallback to error diagrams when XML parsing fails.
- Attribute Value Escaping: Automatic escaping of HTML characters (
<,>,&, quotes) inside XML attribute values for compliance with XML standards. - Error Logging: Automatically captures both client-side and server-side errors into a
feedback.mdfile for easy debugging. - Simple & Lightweight: A single-page application with a clean Python/FastAPI backend. No database required.
- User Prompt: The user enters a prompt in the chat interface (e.g., "Create a simple web server architecture").
- WebSocket Communication: The prompt is sent to the FastAPI backend via a WebSocket connection.
- AI-Powered Generation: The backend sends the entire conversation history to an LLM API (like DeepSeek), instructing it to return a
mxGraphModelXML string. - Response Handling:
- XML Responses: If the AI returns valid XML, it's sent back to the client. The system includes advanced parsing with automatic correction of malformed XML, missing closing tags, and escaped attribute values.
- Text Responses: If the AI returns a text message (e.g., clarifications or questions), it's sent as a chat message.
- Error Handling: If XML parsing fails despite corrections, an error diagram is generated and displayed with diagnostic information.
- Live Update: The frontend receives the message and uses the
postMessageAPI to load the XML into the embedded draw.io iframe, instantly updating the diagram.
- Backend: Python, FastAPI, Uvicorn
- AI Integration:
httpxfor asynchronous API calls - Real-time: WebSockets
- Frontend: Vanilla HTML, CSS, and JavaScript
- Diagramming: draw.io (diagrams.net) Embedded API
- Python 3.9+
- An API Key from an LLM provider (e.g., DeepSeek, OpenAI) or a running local Ollama instance.
-
Clone the repository:
git clone https://github.com/your-username/drawgen.git cd drawgen -
Create and activate a virtual environment:
# Windows python -m venv venv .\venv\Scripts\Activate.ps1 # macOS / Linux python3 -m venv venv source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
The application is configured via a .env file.
-
Create your
.envfile by copying the example file:cp .env.example .env
-
Edit the
.envfile to choose your provider and add the necessary credentials.-
Set the Provider: Choose between
deepseek,openai, orollama.LLM_PROVIDER=deepseek -
Add Keys & Models: Fill in the details for your chosen provider (e.g.,
DEEPSEEK_API_KEYfor DeepSeek,OLLAMA_MODELfor Ollama, etc.). Refer to the comments in the.env.examplefile for guidance.
-
-
Start the server:
# Using the provided script (port 8050) python run_server.py # Or directly with uvicorn uvicorn app:app --reload --host 0.0.0.0 --port 8050
-
Open your browser: Navigate to
http://localhost:8050. You should see the DrawGen interface ready to go!
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Designed by Eiji
This error usually occurs when:
-
Virtual environment is not activated - Make sure to activate the virtual environment:
source venv/bin/activate # Linux/macOS # or .\venv\Scripts\Activate.ps1 # Windows PowerShell
-
Dependencies are not installed - Install required packages:
pip install -r requirements.txt
-
Corrupted virtual environment - Try recreating it:
rm -rf venv python -m venv venv source venv/bin/activate # or the Windows equivalent pip install -r requirements.txt
Check if port 8050 is already in use:
lsof -i:8050 # Linux/macOS
# or
netstat -ano | findstr :8050 # WindowsIf the port is busy, you can:
- Stop the existing process
- Use a different port by modifying
run_server.pyandapp.py
This project is licensed under the MIT License. See the LICENSE file for details.
