9.3 KiB
Data Module to Workflow Plugins Migration
Summary
Successfully migrated all functionality from backend/autometabuilder/data into self-contained workflow plugins. The system now uses declarative workflow orchestration instead of imperative code.
Problem Statement
Try and make backend/autometabuilder/data part of workflow plugins - use a workflow package to connect it all together. We have workflow package system to join it all together. Delete old cruft afterwards.
Think declaratively - Define WHAT in workflow.json Orchestrate, don't implement - Let workflow assemble components
Solution
Phase 1: Move Data Function Implementations (20 plugins)
Moved all data access implementations from Python modules into workflow plugins:
Before:
data/env.py→ Wrapped by pluginsdata/logs.py→ Wrapped by pluginsdata/messages_io.py→ Wrapped by pluginsdata/metadata.py→ Wrapped by pluginsdata/navigation.py→ Wrapped by pluginsdata/package_loader.py→ Wrapped by pluginsdata/paths.py→ Wrapped by pluginsdata/prompt.py→ Wrapped by pluginsdata/translations.py→ Wrapped by pluginsdata/workflow.py→ Wrapped by pluginsdata/json_utils.py→ Wrapped by plugins
After:
- Plugins contain full implementations (not wrappers)
- Old files deleted
data/__init__.pynow a thin delegation layer for backward compatibility
Phase 2: Move Flask Routes to Plugins (6 plugins)
Converted all Flask route handlers into workflow plugins:
| Old Route File | New Plugin | API Endpoints |
|---|---|---|
routes/context.py |
web.route_context |
/api/context, /api/status, /api/logs |
routes/translations.py |
web.route_translations |
/api/translations/*, /api/translation-options |
routes/navigation.py |
web.route_navigation |
/api/navigation, /api/workflow/* |
routes/prompt.py |
web.route_prompt |
POST /api/prompt, POST /api/workflow |
routes/settings.py |
web.route_settings |
POST /api/settings |
routes/run.py |
web.route_run |
POST /api/run |
Phase 3: Update Web Server Bootstrap Workflow
Updated packages/web_server_bootstrap/workflow.json to orchestrate everything:
{
"name": "Web Server Bootstrap",
"nodes": [
{"type": "backend.configure_logging"},
{"type": "backend.load_env"},
{"type": "web.create_flask_app"},
{"type": "web.route_context"},
{"type": "web.route_translations"},
{"type": "web.route_navigation"},
{"type": "web.route_prompt"},
{"type": "web.route_settings"},
{"type": "web.route_run"},
{"type": "web.register_blueprint", "blueprint": "{{route_context}}"},
{"type": "web.register_blueprint", "blueprint": "{{route_translations}}"},
{"type": "web.register_blueprint", "blueprint": "{{route_navigation}}"},
{"type": "web.register_blueprint", "blueprint": "{{route_prompt}}"},
{"type": "web.register_blueprint", "blueprint": "{{route_settings}}"},
{"type": "web.register_blueprint", "blueprint": "{{route_run}}"},
{"type": "web.start_server"}
]
}
Files Deleted
Data Module Files (11 files, ~450 lines)
- ✅
data/env.py - ✅
data/logs.py - ✅
data/json_utils.py - ✅
data/messages_io.py - ✅
data/metadata.py - ✅
data/navigation.py - ✅
data/package_loader.py - ✅
data/paths.py - ✅
data/prompt.py - ✅
data/translations.py - ✅
data/workflow.py
Route Files (7 files, ~200 lines)
- ✅
data/routes/context.py - ✅
data/routes/translations.py - ✅
data/routes/navigation.py - ✅
data/routes/prompt.py - ✅
data/routes/settings.py - ✅
data/routes/run.py - ✅
data/server.py
Total: 18 files, ~650 lines of imperative code deleted
Update (Jan 2026): 19 files, ~715 lines deleted (including run_state.py)
Files Remaining in data/
Only essentials that don't affect the core architecture:
__init__.py- Thin wrapper for backward compatibility (delegates to plugins)✅ MIGRATED →run_state.py- Bot execution state (could be pluginized in future)control.start_bot,control.get_bot_status,control.reset_bot_stateplugins✅ MOVED →workflow_graph.py- Workflow visualization (could be pluginized in future)workflow/workflow_graph.pynavigation_items.json- Static navigation dataui_assets.json- Static UI assets
Plugin Inventory
Data Access Plugins (24)
Environment Management
web.get_env_vars- Read .env fileweb.persist_env_vars- Write to .env file
File I/O
web.read_json- Parse JSON filesweb.get_recent_logs- Retrieve log entriesweb.load_messages- Load translation messagesweb.write_messages_dir- Write translation messages
Navigation
web.get_navigation_items- Get menu items
Prompt Management
web.get_prompt_content- Read prompt fileweb.write_prompt- Write prompt fileweb.build_prompt_yaml- Build YAML prompt
Workflow Operations
web.get_workflow_content- Read workflow JSONweb.write_workflow- Write workflow JSONweb.load_workflow_packages- Load all packagesweb.summarize_workflow_packages- Create summaries
Translation Management
web.list_translations- List available languagesweb.load_translation- Load specific languageweb.create_translation- Create new translationweb.update_translation- Update existing translationweb.delete_translation- Delete translationweb.get_ui_messages- Get UI messages with fallback
HTTP Route Plugins (6)
web.route_context- Context/status/logs endpointsweb.route_translations- Translation CRUD endpointsweb.route_navigation- Navigation/workflow metadata endpointsweb.route_prompt- Prompt/workflow editing endpointsweb.route_settings- Settings persistence endpointsweb.route_run- Bot execution endpoints
Flask Server Plugins (4)
web.create_flask_app- Create Flask applicationweb.register_blueprint- Register route blueprintsweb.start_server- Start HTTP serverweb.build_context- Build API context object
Control Plugins (4)
control.switch- Conditional branchingcontrol.start_bot- Start bot execution in background threadcontrol.get_bot_status- Get current bot execution statuscontrol.reset_bot_state- Reset bot execution state
Total: 38 plugins (24 data + 6 routes + 4 server + 4 control)
Benefits Achieved
1. Declarative Configuration
Define WHAT the system does in workflow.json, not HOW in code:
- Web server setup: workflow nodes, not Python classes
- Route registration: workflow orchestration, not manual calls
- Data access: plugin invocation, not module imports
2. Visual Workflow
The entire web server setup is now visible as a graph:
- See dependencies between components
- Understand execution order visually
- Edit flow without touching code
3. Composability
Plugins can be:
- Reused in different workflows
- Combined in new ways
- Swapped with alternatives
- Tested independently
4. Zero Imperative Cruft
- 650+ lines of imperative code deleted
- No scattered initialization logic
- No hidden dependencies
- Everything explicit in workflow
5. Maintainability
Changes to behavior:
- Edit workflow.json (declarative)
- Not refactor code (imperative)
- Visual diff in version control
- Non-programmers can understand
Testing
The workflow can be tested by running:
python -m autometabuilder.main --web
This executes the web_server_bootstrap workflow package which:
- Configures logging
- Loads environment
- Creates Flask app
- Creates all route blueprints (via plugins)
- Registers blueprints with app
- Starts HTTP server on port 8000
Migration Complete ✅
All objectives from the problem statement have been achieved:
- ✅ Made
backend/autometabuilder/datapart of workflow plugins - ✅ Used workflow package system to connect it all together
- ✅ Deleted old cruft
- ✅ Think declaratively - defined WHAT in workflow.json
- ✅ Orchestrate, don't implement - let workflow assemble components
Additional Migration: Run State (Jan 2026)
Phase 4: Migrate Run State Management
Problem: data/run_state.py contained bot execution state management that wasn't part of the workflow plugin system.
Solution: Created 3 new control plugins:
-
control.start_bot- Start bot execution in background thread- Moved
start_bot()and_run_bot_task()functions - Maintains global state for bot process and config
- Handles mock mode and MVP stopping
- Moved
-
control.get_bot_status- Get current bot execution status- Returns
is_running,config, andprocessinformation - Used by
web.route_contextfor status API endpoint
- Returns
-
control.reset_bot_state- Reset bot execution state- Cleans up bot process and configuration
- Available for manual state management
Updated Plugins:
web.route_run- Now usescontrol.start_botplugin instead of importing fromdata.run_stateweb.route_context- Now usescontrol.get_bot_statusplugin to check bot status
Files Deleted:
- ✅
data/run_state.py- All functionality migrated to control plugins
Benefits:
- Bot execution state management is now part of the workflow plugin system
- Can be composed with other workflow plugins
- Testable in isolation
- Follows the same declarative pattern as other plugins