# 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)