# WorkflowUI - Visual Workflow Editor Modern, production-grade visual workflow editor inspired by n8n, built for MetaBuilder's DAG executor system. ## ๐ŸŽฏ Overview WorkflowUI is a full-featured workflow editor with: - **Visual DAG Editor**: Drag-and-drop node-based workflow construction with React Flow - **Real-Time Collaboration**: Live updates via Redux and WebSockets - **Offline-First**: IndexedDB for local workflow storage and sync - **Plugin Ecosystem**: Support for custom node types and extensions - **Type-Safe**: Full TypeScript with strict mode enabled ## ๐Ÿ—๏ธ Architecture ``` Frontend (Next.js + React) โ”œโ”€ UI Components (FakeMUI) โ”œโ”€ Redux Store (state management) โ”œโ”€ React Flow (DAG visualization) โ””โ”€ IndexedDB (offline storage) โ”‚ โ–ผ Backend (Flask + Python) โ”œโ”€ Workflow execution โ”œโ”€ Plugin management โ”œโ”€ Database persistence โ””โ”€ WebSocket server โ”‚ โ–ผ MetaBuilder DAG Executor โ”œโ”€ Node execution โ”œโ”€ Error recovery โ”œโ”€ Multi-tenant support โ””โ”€ Plugin registry ``` ## ๐Ÿ“ฆ Tech Stack | Layer | Technology | Purpose | |-------|-----------|---------| | **Frontend** | Next.js 14 | Server-side rendering, API routes | | **UI Framework** | FakeMUI | Material UI compatible components | | **State** | Redux + Redux Toolkit | Centralized state management | | **Flow Editor** | React Flow | DAG visualization and manipulation | | **Styling** | SCSS | Component scoped styles | | **Storage** | IndexedDB (Dexie) | Offline workflow persistence | | **HTTP** | Axios | API client with interceptors | | **Backend** | Flask | Python workflow execution | | **Database** | SQLAlchemy + PostgreSQL/SQLite | Persistent workflow storage | | **Validation** | n8n JSON Schema | Workflow and node validation | ## ๐Ÿš€ Quick Start ### Prerequisites ```bash Node.js 18+ Python 3.11+ npm or yarn ``` ### Installation ```bash # Install frontend dependencies npm install # Install backend dependencies pip install -r backend/requirements.txt # Initialize IndexedDB npm run db:init ``` ### Development ```bash # Start both frontend and backend npm run dev:all # Or separately: npm run dev # Frontend on http://localhost:3000 npm run backend # Backend on http://localhost:5000 ``` ### Database Setup The backend uses SQLAlchemy for database persistence: ```bash # Default: SQLite (development) # The database file is created automatically at backend/workflows.db # PostgreSQL (production) export DATABASE_URL=postgresql://user:password@localhost/workflows npm run backend # Create tables python -c "from server_sqlalchemy import app, db; app.app_context().push(); db.create_all()" ``` ### Build ```bash npm run build npm start ``` ## ๐Ÿ“‚ Folder Structure ``` workflowui/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ app/ # Next.js app directory โ”‚ โ”‚ โ”œโ”€โ”€ layout.tsx # Root layout โ”‚ โ”‚ โ”œโ”€โ”€ page.tsx # Dashboard page โ”‚ โ”‚ โ”œโ”€โ”€ editor/[id].tsx # Workflow editor โ”‚ โ”‚ โ””โ”€โ”€ api/ # Next.js API routes โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ components/ # React components โ”‚ โ”‚ โ”œโ”€โ”€ Editor/ # Workflow editor components โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Canvas.tsx # React Flow canvas โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Toolbar.tsx # Editor toolbar โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ NodePanel.tsx # Node configuration panel โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Properties.tsx # Node properties panel โ”‚ โ”‚ โ”œโ”€โ”€ Nodes/ # Custom node types โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ BaseNode.tsx # Base node wrapper โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ PlaywrightNode.tsx โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ StorybookNode.tsx โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ CustomNode.tsx โ”‚ โ”‚ โ”œโ”€โ”€ UI/ # Shared UI components โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Button.tsx โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Modal.tsx โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Sidebar.tsx โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Toolbar.tsx โ”‚ โ”‚ โ””โ”€โ”€ Layout/ # Layout components โ”‚ โ”‚ โ”œโ”€โ”€ Header.tsx โ”‚ โ”‚ โ””โ”€โ”€ MainLayout.tsx โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ store/ # Redux store โ”‚ โ”‚ โ”œโ”€โ”€ store.ts # Store configuration โ”‚ โ”‚ โ”œโ”€โ”€ slices/ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ workflowSlice.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ editorSlice.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ nodesSlice.ts โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ connectionSlice.ts โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ uiSlice.ts โ”‚ โ”‚ โ””โ”€โ”€ types.ts # Store type definitions โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ services/ # API/backend services โ”‚ โ”‚ โ”œโ”€โ”€ workflowService.ts # Workflow API calls โ”‚ โ”‚ โ”œโ”€โ”€ nodeService.ts # Node registry API โ”‚ โ”‚ โ”œโ”€โ”€ executionService.ts # Workflow execution โ”‚ โ”‚ โ””โ”€โ”€ storageService.ts # IndexedDB persistence โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ db/ # IndexedDB schema & operations โ”‚ โ”‚ โ”œโ”€โ”€ schema.ts # Dexie schema โ”‚ โ”‚ โ”œโ”€โ”€ workflows.ts # Workflow queries โ”‚ โ”‚ โ”œโ”€โ”€ nodes.ts # Node cache โ”‚ โ”‚ โ””โ”€โ”€ cache.ts # Cache operations โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ hooks/ # React hooks โ”‚ โ”‚ โ”œโ”€โ”€ useWorkflow.ts # Workflow state hook โ”‚ โ”‚ โ”œโ”€โ”€ useEditor.ts # Editor state hook โ”‚ โ”‚ โ”œโ”€โ”€ useNodes.ts # Node operations hook โ”‚ โ”‚ โ”œโ”€โ”€ useConnection.ts # Connection hook โ”‚ โ”‚ โ””โ”€โ”€ useStorage.ts # IndexedDB hook โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ types/ # TypeScript types โ”‚ โ”‚ โ”œโ”€โ”€ workflow.ts # Workflow types โ”‚ โ”‚ โ”œโ”€โ”€ node.ts # Node types โ”‚ โ”‚ โ”œโ”€โ”€ connection.ts # Connection types โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Export all types โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ utils/ # Utility functions โ”‚ โ”‚ โ”œโ”€โ”€ dagValidation.ts # DAG validation โ”‚ โ”‚ โ”œโ”€โ”€ nodeFactory.ts # Node creation factory โ”‚ โ”‚ โ”œโ”€โ”€ layoutEngine.ts # Auto-layout algorithm โ”‚ โ”‚ โ”œโ”€โ”€ jsonValidator.ts # JSON Schema validation โ”‚ โ”‚ โ””โ”€โ”€ transformers.ts # n8n format converters โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ styles/ # Global styles โ”‚ โ”œโ”€โ”€ globals.scss # Global styles โ”‚ โ”œโ”€โ”€ variables.scss # Design tokens โ”‚ โ””โ”€โ”€ mixins.scss # SCSS mixins โ”‚ โ”œโ”€โ”€ backend/ # Flask backend โ”‚ โ”œโ”€โ”€ server.py # Flask app โ”‚ โ”œโ”€โ”€ requirements.txt # Python dependencies โ”‚ โ”œโ”€โ”€ routes/ โ”‚ โ”‚ โ”œโ”€โ”€ workflows.py # Workflow endpoints โ”‚ โ”‚ โ”œโ”€โ”€ execution.py # Execution endpoints โ”‚ โ”‚ โ””โ”€โ”€ nodes.py # Node registry โ”‚ โ”œโ”€โ”€ models/ โ”‚ โ”‚ โ”œโ”€โ”€ workflow.py # Workflow model โ”‚ โ”‚ โ””โ”€โ”€ execution.py # Execution model โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”‚ โ”œโ”€โ”€ executor.py # Workflow execution โ”‚ โ”‚ โ””โ”€โ”€ storage.py # Persistence โ”‚ โ””โ”€โ”€ utils/ โ”‚ โ”œโ”€โ”€ validation.py # Workflow validation โ”‚ โ””โ”€โ”€ converters.py # Format converters โ”‚ โ”œโ”€โ”€ workflows/ # Sample workflows โ”‚ โ”œโ”€โ”€ e2e-testing.json โ”‚ โ”œโ”€โ”€ documentation.json โ”‚ โ””โ”€โ”€ complex-pipeline.json โ”‚ โ”œโ”€โ”€ stories/ # Storybook stories โ”‚ โ”œโ”€โ”€ Editor.stories.tsx โ”‚ โ”œโ”€โ”€ Nodes.stories.tsx โ”‚ โ””โ”€โ”€ UI.stories.tsx โ”‚ โ”œโ”€โ”€ scripts/ # Build/setup scripts โ”‚ โ”œโ”€โ”€ init-db.js # Initialize IndexedDB โ”‚ โ””โ”€โ”€ migrate-db.js # Database migrations โ”‚ โ”œโ”€โ”€ public/ # Static assets โ”‚ โ””โ”€โ”€ icons/ โ”‚ โ”œโ”€โ”€ tsconfig.json # TypeScript config โ”œโ”€โ”€ next.config.js # Next.js config โ”œโ”€โ”€ jest.config.js # Jest config โ”œโ”€โ”€ .storybook/ # Storybook config โ””โ”€โ”€ README.md ``` ## ๐ŸŽจ Key Components ### 1. Canvas (React Flow) ```tsx // Drag-and-drop DAG editor with zoom, pan, selection ``` ### 2. Node Types ```tsx // Playwright node example ``` ### 3. Redux Store ```typescript // Central state management store/slices: - workflowSlice: Current workflow, metadata - editorSlice: Canvas zoom, pan, selection - nodesSlice: Node registry, templates - connectionSlice: Edge creation state - uiSlice: Modals, panels, notifications ``` ### 4. IndexedDB Storage ```typescript // Offline-first storage with Dexie db.workflows.put(workflow) db.workflows.get(id) db.workflows.toArray() db.syncWithServer() // Auto-sync when online ``` ### 5. Backend API ```python # Flask endpoints POST /api/workflows # Create workflow GET /api/workflows/ # Get workflow PUT /api/workflows/ # Update workflow DELETE /api/workflows/ # Delete workflow POST /api/workflows//execute # Execute workflow GET /api/nodes # Get node registry ``` ## ๐Ÿ”Œ Plugin System Custom node types can be added: ```typescript // Define custom node const CustomNode: NodeType = { id: 'my.custom', name: 'My Custom Node', category: 'custom', parameters: { field1: { type: 'string', required: true }, field2: { type: 'number', required: false } } }; // Register in node registry registerNodeType(CustomNode); ``` ## ๐Ÿ“Š Features ### Visual Editing - โœ… Drag-and-drop node creation - โœ… Connection drawing with validation - โœ… Node selection and multi-select - โœ… Undo/redo support - โœ… Auto-layout (horizontal, vertical, hierarchical) - โœ… Zoom and pan controls - โœ… Minimap navigation ### Workflow Management - โœ… Create/edit/delete workflows - โœ… Version control integration - โœ… Workflow templates - โœ… Import/export (JSON, n8n format) - โœ… Workflow validation (DAG constraints) - โœ… Multi-tenant support ### Execution - โœ… Dry-run execution - โœ… Execution history - โœ… Result visualization - โœ… Error reporting - โœ… Step-by-step debugging - โœ… Performance metrics ### Developer Experience - โœ… Hot reload - โœ… Redux DevTools integration - โœ… Storybook for component development - โœ… TypeScript strict mode - โœ… Comprehensive error messages - โœ… Debug mode ## ๐Ÿงช Testing ```bash # Run tests npm test # Watch mode npm test:watch # Component development npm run storybook ``` ## ๐Ÿ“š Documentation - [Architecture Guide](./docs/ARCHITECTURE.md) - [Component API](./docs/COMPONENTS.md) - [Redux Store Design](./docs/REDUX.md) - [IndexedDB Schema](./docs/DATABASE.md) - [Node Type Reference](./docs/NODE_TYPES.md) - [API Reference](./docs/API.md) ## ๐Ÿš€ Deployment ```bash # Build for production npm run build # Start production server npm start ``` Deployed with: - Vercel (Next.js frontend) - Heroku/Railway (Flask backend) - MongoDB Atlas (persistent storage) ## ๐Ÿค Contributing 1. Create feature branch: `git checkout -b feature/name` 2. Make changes with tests 3. Submit PR with description ## ๐Ÿ“„ License Part of MetaBuilder project ## ๐Ÿ”— Related - [MetaBuilder](../README.md) - [DAG Executor](../workflow/executor/ts) - [Workflow Plugins](../docs/WORKFLOW_PLUGINS_ARCHITECTURE.md) - [n8n Format](https://docs.n8n.io)