PRD-38.0: Widget Architecture Master Plan

Version: 1.0 Status: 🟡 Design Phase Priority: HIGH - Platform Evolution Author: Automatos AI Platform Team Last Updated: 2026-01-27 Dependencies: PRD-31 (Chatbot UX), PRD-32 (Widget Integration System)


Executive Summary

This master document defines a unified widget architecture for Automatos AI that serves dual purposes:

  1. Internal: Power the Chatbot Workspace with a canvas-based artifact system

  2. External: Enable embeddable widgets for customer websites and applications

The architecture follows a "Build Once, Deploy Everywhere" philosophy where the same widget components work inside the Automatos workspace AND can be packaged for external embedding via script tags or npm packages.

The Vision: "Widgets as Universal Interface"

Today: Chatbot shows results in modal overlays, one at a time Tomorrow: Canvas workspace with persistent, arrangeable widgets Future: Same widgets embedded on customer sites, connected to their Automatos workspaces

Current State → Target State

Aspect
Current
Phase 1
Phase 4+

Artifact Display

Modal overlay

Canvas workspace

Canvas + External embed

Artifact Types

4 (code, text, sheet, image)

10 types

12+ types

Layout

Single artifact

Multi-artifact grid

Drag-drop + embeddable

Persistence

Session only

Workspace saved

Cross-platform sync

External Use

None

None

Script tag + SDK


Phase Overview


Core Architecture

Widget Component Model

All widgets share a common interface and lifecycle, enabling consistent behavior across internal and external use.

Widget Registry

Tool-to-Widget Mapping

The system automatically routes tool results to appropriate widgets:


State Management

Workspace Store (Zustand)


File Structure

Phase 1-3: Internal Widgets (in main repo)

Phase 4+: External SDK (separate repo)


Dependencies & Libraries

Phase
Library
Purpose
License

1

react-grid-layout

Draggable grid

MIT

1

@dnd-kit/core

Modern drag-drop

MIT

1

zustand

State management

MIT

1

@monaco-editor/react

Code editing

MIT

1

recharts

Charts

MIT

2

@tanstack/react-table

Advanced tables

MIT

2

react-resizable-panels

Panel resizing

MIT

3

html2canvas

Screenshot export

MIT

4

vite

Widget bundling

MIT

4

rollup

Library bundling

MIT

Already in Stack (Reuse)

Library
Current Use
Widget Use

shadcn/ui

UI components

Widget chrome

framer-motion

Animations

Widget transitions

react-markdown

Markdown render

Document widget

prismjs

Code highlight

Code widget

lucide-react

Icons

Widget icons

tailwindcss

Styling

All widgets


API Contracts

Widget Data Endpoint (Backend)

Streaming Events (Tool → Widget)


Success Metrics

Phase 1 Metrics

Phase 2 Metrics

Phase 3 Metrics

Phase 4 Metrics

Phase 5 Metrics


Risk Mitigation

Risk
Impact
Mitigation

Performance degradation with many widgets

High

Virtualization, lazy loading, web workers

Breaking existing chat UX

High

Feature flags, A/B testing, gradual rollout

SDK bundle size too large

Medium

Tree-shaking, code splitting, lazy loading

External widget security

High

CSP headers, sandboxing, API key scoping

State sync complexity

High

Documented sync strategy, conflict resolution

Risk Mitigation Details

R1: Performance Degradation with Many Widgets

Trigger Threshold: >20 widgets in canvas, or >100 widgets in workspace store

Implementation Approach:

Implemented In: PRD-38.1 Section 3.1 (Canvas Component), PRD-38.3 (Dashboard Builder)

R2: Breaking Existing Chat UX

Trigger Threshold: Any Phase 1 deployment

Implementation Approach:

  • Feature flag ENABLE_CANVAS_WORKSPACE defaults to false

  • A/B test with 10% of users before full rollout

  • Gradual rollout: 10% → 25% → 50% → 100% over 2 weeks

  • Rollback mechanism via feature flag toggle (< 5 minute recovery)

Implemented In: PRD-38.1 Section 9 (Rollout Plan)

R3: SDK Bundle Size Too Large

Trigger Threshold: Any widget bundle >50KB gzipped

Implementation Approach:

  • Tree-shaking via ES modules and sideEffects: false

  • Code splitting: each widget in separate chunk

  • Lazy loading: Automatos.widgets.chat() loads chat chunk on demand

  • Monitor with bundlesize CI check

Implemented In: PRD-38.4 Section 6 (CDN & Distribution)

R4: External Widget Security

Trigger Threshold: Any external widget (marketplace or embedded)

Implementation Approach:

Implemented In: PRD-38.4 Section 5 (Security), PRD-38.5 Section 3.1 (Widget Sandbox)

R5: State Sync Complexity (Elevated to High)

Rationale for High Impact: State synchronization affects every widget interaction, workspace persistence, and real-time collaboration. Bugs here cause data loss and poor UX.

Trigger Threshold: Any multi-widget or persistence scenario

Implementation Approach:

Implemented In: PRD-38.1 Section 3.3 (Zustand Store), PRD-38.3 Section 2.1 (Workspace Persistence)


  • PRD-31: Chatbot UX Upgrade (foundation for this work)

  • PRD-32: Widget Integration System (external embedding spec)

  • PRD-38.1: Phase 1 - Widget-Ready Chatbot Workspace

  • PRD-38.2: Phase 2 - Extended Widgets

  • PRD-38.3: Phase 3 - Dashboard Builder

  • PRD-38.4: Phase 4 - SDK Foundation

  • PRD-38.5: Phase 5 - Widget Marketplace


Appendix: Open Source Inspirations

Dashboard/Workspace

Embeddable Widgets

Component Libraries


Document Version: 1.0 Created: 2026-01-27 Next Review: After Phase 1 completion

Last updated