Skip to content

Latest commit

 

History

History
482 lines (394 loc) · 16.8 KB

File metadata and controls

482 lines (394 loc) · 16.8 KB

UI Prototype Proposal: Structured CRUD Application Framework

Executive Summary

This proposal outlines the design and implementation of a disciplined, structure-first UI framework for CRUD applications with complex business processes. The goal is to eliminate UI clutter by enforcing a consistent three-pane layout that scales across all business use cases while maintaining simplicity and developer productivity.

Problem Statement

Modern web applications suffer from:

  • UI Clutter: Undisciplined placement of UI elements creates cognitive overload
  • Inconsistent Patterns: Each feature introduces new layouts and interaction patterns
  • Poor Scalability: Complex workflows become unwieldy without structure
  • Developer Friction: Lack of conventions leads to reinvention and technical debt

Proposed Solution

A structured three-pane layout with disciplined separation of concerns:

┌─────────────────────────────────────────────────────────┐
│              Application Header / Title Bar             │
├───────┬─────────────────────────────────────┬───────────┤
│       │                                     │           │
│  L    │          Middle Pane                │    R      │
│  E    │                                     │    I      │
│  F    │  ┌─────────────────────────────┐   │    G      │
│  T    │  │  Input Tab  │  Output Tab   │   │    H      │
│       │  ├─────────────────────────────┤   │    T      │
│  S    │  │                             │   │           │
│  I    │  │   Form / CRUD Operations    │   │    S      │
│  D    │  │   or                        │   │    I      │
│  E    │  │   Markdown Rendered View    │   │    D      │
│  B    │  │                             │   │    E      │
│  A    │  │                             │   │    B      │
│  R    │  └─────────────────────────────┘   │    A      │
│       │                                     │    R      │
│       │                                     │           │
└───────┴─────────────────────────────────────┴───────────┘

Layout Responsibilities

  1. Left Sidebar (Navigation)

    • Menu links only
    • Application navigation
    • Context switching
    • Workflow state indicators
  2. Middle Pane (Primary Workspace)

    • Input Tab: CRUD operations, form inputs, data entry
    • Output Tab: Read-only markdown-rendered results
    • Tab switching for input vs output modes
    • Structured data flow from input → processing → output
  3. Right Sidebar (Metadata & Notifications)

    • Real-time notifications
    • Activity logs
    • Contextual metadata
    • Status indicators
    • Process/workflow state

Technical Architecture

Frontend Stack

Core Technologies:

  • HTML5: Semantic structure
  • CSS3: Modern styling with CSS Grid and Flexbox
  • Vanilla JavaScript: No framework bloat
  • Datastar.dev: Hypermedia-driven, 2-way SSE streaming

Why Datastar.dev?

  • Lightweight (~9KB minified)
  • Native SSE support for real-time updates
  • Declarative attribute-based reactivity
  • Server-driven UI updates
  • No build step required
  • Plays well with Go backends

Backend Stack

Components:

Architecture Pattern:

HTTP Request (Datastar SSE)
    ↓
Chi Router (HTTP Handler)
    ↓
Rea Framework (Business Logic Layer)
    ↓
Restate SDK (Durable Execution)
    ↓
HTTP Response (SSE Stream)

Implementation Plan

Phase 1: Frontend Foundation (Estimated: 2-3 hours)

1.1 HTML Structure

Create a semantic three-pane layout:

  • Header with app title and global actions
  • Left sidebar with navigation menu
  • Middle pane with tab system (Input/Output)
  • Right sidebar with notification panel
  • Responsive grid layout

1.2 CSS Design System

  • CSS custom properties for theming
  • Responsive grid system
  • Component-level styles
  • Dark mode support
  • Accessibility considerations

1.3 JavaScript Core

  • Tab switching logic
  • Datastar.dev initialization
  • SSE connection management
  • Form serialization utilities
  • Markdown renderer (e.g., marked.js)

Phase 2: Backend Foundation (Estimated: 3-4 hours)

2.1 Chi Server Setup

package main

import (
    "github.com/go-chi/chi/v5"
    "github.com/go-chi/chi/v5/middleware"
)

func main() {
    r := chi.NewRouter()
    r.Use(middleware.Logger)
    r.Use(middleware.Recoverer)
    
    // Static files
    r.Get("/", serveIndex)
    r.Get("/static/*", serveStatic)
    
    // SSE endpoints
    r.Get("/stream/notifications", streamNotifications)
    r.Post("/api/crud/*", handleCRUD)
    
    http.ListenAndServe(":8080", r)
}

2.2 Restate Integration

import (
    restate "github.com/restatedev/sdk-go"
    "github.com/pithomlabs/rea"
)

// Define Restate services
type CRUDService struct{}

func (s *CRUDService) Create(ctx restate.ObjectContext, entity Entity) (string, error) {
    // Durable CRUD operation
    id := restate.UUID(ctx).String()
    restate.Set(ctx, id, entity)
    return id, nil
}

func (s *CRUDService) Read(ctx restate.ObjectSharedContext, id string) (Entity, error) {
    return restate.Get[Entity](ctx, id)
}

2.3 SSE Streaming Handler

func streamNotifications(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "text/event-stream")
    w.Header().Set("Cache-Control", "no-cache")
    w.Header().Set("Connection", "keep-alive")
    
    flusher, _ := w.(http.Flusher)
    
    for {
        select {
        case notification := <-notificationChan:
            fmt.Fprintf(w, "data: %s\n\n", notification)
            flusher.Flush()
        case <-r.Context().Done():
            return
        }
    }
}

Phase 3: Datastar Integration (Estimated: 2-3 hours)

3.1 Bidirectional SSE Setup

<div data-on-load="$get('/stream/notifications')">
    <div data-text="$notification.message"></div>
</div>

<form data-on-submit="$post('/api/crud/create')">
    <input name="name" data-model="name" />
    <button type="submit">Create</button>
</form>

3.2 Backend SSE Response

func handleCreate(w http.ResponseWriter, r *http.Request) {
    // Process CRUD operation
    result := processCreate(r)
    
    // Send SSE update
    w.Header().Set("Content-Type", "text/event-stream")
    fmt.Fprintf(w, "event: datastar-merge\n")
    fmt.Fprintf(w, "data: {\"fragments\": [{\"selector\": \"#output\", \"html\": \"%s\"}]}\n\n", result)
}

Phase 4: Generic CRUD Structure (Estimated: 3-4 hours)

4.1 Input Tab Structure

Create a flexible form system supporting:

  • Text inputs, textareas, selects
  • File uploads
  • Validation rules
  • Dynamic field addition
  • Form state persistence

4.2 Output Tab Structure

Markdown-based rendering supporting:

  • Tables for list views
  • Code blocks for technical data
  • Headings for structure
  • Links for navigation
  • Custom rendering hooks

4.3 Schema-Driven Forms

{
  "entity": "Product",
  "fields": [
    {"name": "name", "type": "text", "required": true},
    {"name": "price", "type": "number", "min": 0},
    {"name": "description", "type": "textarea"}
  ],
  "actions": ["create", "update", "delete"]
}

Backend renders forms and output based on schema.

Phase 5: Workflow Support (Estimated: 4-5 hours)

5.1 State Machine Integration

Use Restate workflows for complex processes:

type OrderWorkflow struct{}

func (w *OrderWorkflow) Run(ctx restate.WorkflowContext, order Order) (string, error) {
    // Step 1: Validate
    err := restate.Run(ctx, func(ctx restate.RunContext) (any, error) {
        return nil, validateOrder(order)
    })
    
    // Step 2: Process payment
    promise := restate.Promise[PaymentResult](ctx, "payment")
    paymentResult, err := promise.Result()
    
    // Step 3: Fulfill
    // ... more steps
    
    return "completed", nil
}

5.2 Visual Workflow Indicators

  • Left sidebar shows current step
  • Right sidebar shows step history
  • Middle pane shows current step form
  • Output tab shows workflow progress

Key Benefits

For Developers

  • Reduced Decision Fatigue: One layout for all features
  • Faster Development: Reusable patterns and components
  • Type Safety: Go backend with strong typing
  • Resilience: Restate provides durable execution
  • Real-time Updates: SSE streaming without polling

For Users

  • Consistency: Same layout everywhere
  • Predictability: Always know where to find things
  • Clear Workflow: Input → Process → Output is explicit
  • Live Updates: No manual refresh needed

For Business

  • Maintainability: Conventions reduce bugs
  • Scalability: Structure handles complexity
  • Extensibility: Add features without layout changes
  • Training: Easier onboarding with consistent patterns

Technology Justification

Why Datastar.dev?

  • SSE-First: Built for server-driven real-time updates
  • Lightweight: Minimal JavaScript footprint
  • Hypermedia: Server controls UI state
  • Progressive Enhancement: Works without JS (graceful degradation)
  • Go-Friendly: Natural fit with Chi router patterns

Why Chi Framework?

  • Idiomatic Go: Leverages standard library patterns
  • Middleware Composition: Clean request pipeline
  • Lightweight: No magic, no overhead
  • Testable: Easy to unit test handlers

Why Restate + Rea?

  • Durable Execution: Automatic retry and recovery
  • State Management: Built-in persistence
  • Workflow Primitives: Complex processes made simple
  • Type Safety: Go's strong typing throughout
  • Observability: Built-in tracing and logging

Proposed Directory Structure

zeroapp/prototype/
├── PROPOSAL.md                 (this file)
├── README.md                   (setup and usage instructions)
├── frontend/
│   ├── index.html              (main layout)
│   ├── css/
│   │   ├── reset.css           (CSS reset)
│   │   ├── variables.css       (design tokens)
│   │   ├── layout.css          (grid system)
│   │   ├── components.css      (reusable components)
│   │   └── themes.css          (light/dark modes)
│   ├── js/
│   │   ├── main.js             (initialization)
│   │   ├── tabs.js             (tab switching)
│   │   ├── forms.js            (form handling)
│   │   └── markdown.js         (output rendering)
│   └── vendor/
│       ├── datastar.min.js     (datastar.dev library)
│       └── marked.min.js       (markdown parser)
├── backend/
│   ├── main.go                 (server entry point)
│   ├── go.mod
│   ├── handlers/
│   │   ├── static.go           (serve frontend)
│   │   ├── sse.go              (SSE streaming)
│   │   └── crud.go             (CRUD operations)
│   ├── services/
│   │   ├── crud_service.go     (Restate CRUD service)
│   │   └── workflow_service.go (Restate workflows)
│   └── models/
│       ├── entity.go           (data models)
│       └── schema.go           (form schema)
└── examples/
    ├── simple-crud/            (basic CRUD example)
    ├── multi-step-workflow/    (complex workflow)
    └── real-time-dashboard/    (live updates)

Validation Plan

Functional Testing

  1. CRUD Operations: Create, read, update, delete entities
  2. SSE Streaming: Verify real-time updates in right sidebar
  3. Tab Switching: Smooth transition between input and output
  4. Markdown Rendering: Proper display of formatted output
  5. Workflow Execution: Multi-step process completion

Non-Functional Testing

  1. Performance: <100ms response time for CRUD ops
  2. Concurrency: Handle 100+ simultaneous SSE connections
  3. Accessibility: WCAG 2.1 AA compliance
  4. Responsiveness: Mobile-friendly layout
  5. Browser Support: Chrome, Firefox, Safari, Edge (latest 2 versions)

Manual Testing Checklist

  • Left sidebar navigation works
  • Input tab form submission succeeds
  • Output tab displays markdown correctly
  • Right sidebar shows live notifications
  • SSE connection recovers from network interruption
  • Dark mode toggle works
  • Mobile layout is usable
  • Keyboard navigation is functional

Risks and Mitigations

Risk Impact Mitigation
SSE connection stability High Implement automatic reconnection logic
Browser compatibility Medium Polyfills for older browsers, progressive enhancement
Datastar.dev ecosystem maturity Medium Keep vanilla JS fallback, monitor library updates
Restate learning curve Medium Comprehensive examples, clear documentation
Schema rigidity Low Make schema optional, allow custom layouts

Open Questions for Discussion

  1. Schema Definition: Should we use JSON, YAML, or Go structs for defining form schemas?
  2. Authentication: Should we include auth in the prototype or keep it minimal?
  3. Multi-Tenancy: Does the prototype need tenant isolation?
  4. File Uploads: How should we handle file storage with Restate?
  5. Validation: Client-side, server-side, or both?
  6. Error Handling: How should errors display in the UI?

Suggestions for Improvement

Enhanced Features

  1. Command Palette: Keyboard-driven navigation (Cmd+K)
  2. Breadcrumbs: Show navigation path in header
  3. Quick Actions: Context menu for common tasks
  4. Search: Global search across all entities
  5. Undo/Redo: Leverage Restate's durable state for history

Advanced Workflows

  1. Approval Chains: Multi-step approval workflows
  2. Parallel Tasks: Fan-out/fan-in patterns
  3. Scheduled Actions: Delayed execution with Restate sleep
  4. Event-Driven: React to external events via awakeables

Developer Experience

  1. Code Generation: CLI to generate CRUD boilerplate
  2. Hot Reload: Auto-refresh on file changes (development mode)
  3. API Documentation: Auto-generated from schema
  4. Testing Utilities: Helpers for testing SSE endpoints

User Experience

  1. Keyboard Shortcuts: Power user efficiency
  2. Customizable Layout: Adjustable sidebar widths
  3. Saved Views: User-specific layouts and filters
  4. Export: Download output as PDF, CSV, JSON

Timeline

Phase Duration Deliverable
Phase 1: Frontend Foundation 2-3 hours Static HTML/CSS/JS prototype
Phase 2: Backend Foundation 3-4 hours Chi server with basic endpoints
Phase 3: Datastar Integration 2-3 hours Live SSE streaming
Phase 4: Generic CRUD 3-4 hours Schema-driven forms and output
Phase 5: Workflow Support 4-5 hours Complex process orchestration
Total 14-19 hours Fully functional prototype

Success Criteria

The prototype is considered successful if:

  1. ✅ All CRUD operations work end-to-end
  2. ✅ SSE streaming provides real-time updates
  3. ✅ Layout is consistent and responsive
  4. ✅ Markdown rendering displays correctly
  5. ✅ At least one complex workflow is demonstrated
  6. ✅ Code is documented and understandable
  7. ✅ Performance meets benchmarks (<100ms CRUD ops)

Conclusion

This proposal outlines a disciplined, structured approach to building CRUD applications with complex workflows. By enforcing a consistent three-pane layout and leveraging modern technologies (Datastar.dev, Chi, Restate, Rea), we can eliminate UI clutter while maintaining developer productivity and application resilience.

The prototype will serve as a foundational pattern for future business applications, providing:

  • Clear conventions that reduce decision fatigue
  • Proven patterns that scale with complexity
  • Resilient architecture that handles failures gracefully
  • Real-time capabilities without polling overhead

Next steps: Review this proposal, address open questions, and proceed with Phase 1 implementation.


Author: Claude (Gemini Agent)
Date: 2025-12-02
Version: 1.0