Skip to content

A production-ready TypeScript/React framework for AI-assisted runtime UI modification with multi-layered security boundaries.

License

Notifications You must be signed in to change notification settings

KikiSpace/RuntimeUI-Framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RuntimeUI Framework

A production-ready TypeScript/React framework for AI-assisted runtime UI modification with multi-layered security boundaries.

TypeScript React License


🎯 Problem

When building AI-powered applications where coding agents modify UI at runtime, you need to:

  1. Protect critical components (auth, payments, core logic) from AI changes
  2. Secure data flows and API access from AI-generated code
  3. Control AI code generation with configurable size/scope limits
  4. Ensure runtime safety with validation and rollback

RuntimeUI solves all of these with a reusable, extensible framework.


πŸš€ Quick Start

Installation

npm install
npm run build

Basic Usage

import { RuntimeEngine, Locked, AIModifiable } from 'runtime-ui-framework';

// 1. Protect your components
@Locked
class PaymentForm extends React.Component {
  // AI cannot touch this
}

@AIModifiable({ maxSize: 300 })
class Dashboard extends React.Component {
  // AI can modify this
}

// 2. Initialize runtime engine
const engine = new RuntimeEngine({
  maxTokens: 4000,
  maxComponents: 10,
  maxLinesPerComponent: 200
});

// 3. Process AI modifications
const result = await engine.processModification({
  userQuery: "Make the dashboard cards bigger",
  generatedCode: aiGeneratedCode
});

if (result.success) {
  // Code validated and applied!
} else {
  // Show validation errors
  console.log(result.validation.errors);
}

Read the 5-minute Quick Start Guide β†’


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    USER QUERY                           β”‚
β”‚              "Make the grid 4 columns"                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  AI CODE ENGINE                         β”‚
β”‚         (GPT-4, Claude, or custom model)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              RUNTIME ENGINE                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Layer 1: Constraint Validation                  β”‚   β”‚
β”‚  β”‚  - Token limits, size limits, patterns           β”‚   β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚
β”‚  β”‚  Layer 2: Component Protection                   β”‚   β”‚
β”‚  β”‚  - Check locked/protected components             β”‚   β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚
β”‚  β”‚  Layer 3: Security Analysis                      β”‚   β”‚
β”‚  β”‚  - XSS, injection, unsafe patterns               β”‚   β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”‚
β”‚  β”‚  Layer 4: Sandbox Testing                        β”‚   β”‚
β”‚  β”‚  - Parse and validate in isolation               β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     ↓
              APPLY or REJECT

Read the Full Architecture Guide β†’


✨ Key Features

πŸ”’ Component Protection

Three-tier protection system with decorators:

@Locked                    // AI cannot touch at all
@Protected({              // AI can only update styles/props
  allowedOperations: ['update-style', 'update-props']
})
@AIModifiable({           // AI has full control
  maxSize: 300,
  dataAccess: { canReadData: true, canWriteData: false }
})

πŸ›‘οΈ API & Data Security

Proxy-based access control:

// Secure API access
const secureFetch = APIGuard.createSecureFetch({
  canReadData: true,
  canWriteData: false,
  allowedEndpoints: ['/api/products'],
  forbiddenEndpoints: ['/api/admin']
});

// Protected data stores
DataStoreGuard.protect('authToken');
const secureStore = DataStoreGuard.createSecureStore(store, policy);

πŸ“ Code Generation Limits

Configurable constraints:

{
  maxTokens: 4000,              // Max tokens per generation
  maxComponents: 10,            // Max components modified
  maxLinesPerComponent: 200,    // Max lines per component
  allowedLibraries: ['react'],  // Import whitelist
  forbiddenPatterns: [/eval\(/, /fetch\(/]  // Pattern blocklist
}

βœ… Multi-Stage Validation

Every AI modification goes through:

  1. Constraint validation (size, tokens, patterns)
  2. Protection check (locked components)
  3. Security analysis (XSS, injection)
  4. Sandbox testing (safe execution)
  5. Rollback support (undo mechanism)

πŸ“Š Monitoring & Logging

// View request logs
const log = APIGuard.getRequestLog();

// View modification history
const history = engine.getHistory();

// Rollback to previous state
engine.rollback(rollbackToken);

πŸ“¦ What's Included

RuntimeUI/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/               # Core framework
β”‚   β”‚   β”œβ”€β”€ types.ts
β”‚   β”‚   β”œβ”€β”€ decorators.ts   # @Locked, @Protected, @AIModifiable
β”‚   β”‚   β”œβ”€β”€ registry.ts     # Component registry
β”‚   β”‚   β”œβ”€β”€ constraints.ts  # Generation limits
β”‚   β”‚   β”œβ”€β”€ api-guard.ts    # API security
β”‚   β”‚   β”œβ”€β”€ validator.ts    # Code validation
β”‚   β”‚   └── runtime-engine.ts
β”‚   β”œβ”€β”€ react/              # React integration
β”‚   └── utils/              # Helper utilities
β”œβ”€β”€ examples/               # Complete examples
β”œβ”€β”€ README.md
β”œβ”€β”€ ARCHITECTURE.md         # Detailed architecture
β”œβ”€β”€ QUICKSTART.md          # 5-minute guide
└── SOLUTION_SUMMARY.md    # Solution overview

πŸ“š Documentation


πŸŽ“ Examples

Example 1: Component Protection

See examples/basic-usage.tsx

Example 2: Runtime Modification

See examples/runtime-modification.ts

Example 3: API Security

See examples/api-protection.tsx

Example 4: Complete Application

See examples/complete-app-example.tsx


πŸ” Security Features

  • βœ… Multi-layered protection (4 validation stages)
  • βœ… Component-level access control
  • βœ… API endpoint allowlist/denylist
  • βœ… Forbidden pattern detection (eval, XSS, injection)
  • βœ… Token and size limits
  • βœ… Sandbox execution testing
  • βœ… Request logging and monitoring
  • βœ… Rollback mechanism

🎯 Use Cases

  1. AI-Powered Dashboards - Let users customize layouts via natural language
  2. Dynamic Forms - AI generates form fields based on user requirements
  3. Theme Customization - AI applies styling based on user preferences
  4. Content Layouts - AI arranges content based on viewport/device
  5. A/B Testing - AI generates UI variations for testing

πŸ› οΈ Advanced Usage

Custom Constraints

engine.updateConstraints({
  maxTokens: 8000,
  allowedLibraries: ['react', 'styled-components', 'lodash']
});

Validation Result Analysis

import { formatValidationResult, getCodeStats } from 'runtime-ui-framework';

const result = await engine.processModification({...});

console.log(formatValidationResult(result.validation));
console.log(getCodeStats(generatedCode));

Component Wrapper

import { withProtection } from 'runtime-ui-framework';

const SecureButton = withProtection(Button, 'Button', {
  canReadData: true,
  canWriteData: false
});

🀝 Integration

Works with any AI provider:

  • OpenAI (GPT-4, GPT-3.5)
  • Anthropic (Claude)
  • Google (Gemini)
  • Custom models

Simply pass the AI-generated code to engine.processModification().


πŸ“ˆ Benefits

Feature RuntimeUI Manual Implementation
Component Protection βœ“ Built-in 3-tier βœ— Custom per-app
API Security βœ“ Proxy + policies ~ Basic blocking
Size Limits βœ“ Configurable βœ— Manual checks
Validation βœ“ 4-stage pipeline ~ Basic
Rollback βœ“ Automatic βœ— Manual
Monitoring βœ“ Built-in βœ— Custom logging
Reusability βœ“ Framework βœ— Copy-paste
Type Safety βœ“ Full TypeScript ~ Partial

🚦 Getting Started

  1. Read QUICKSTART.md for a 5-minute tutorial
  2. Explore examples/ for real-world patterns
  3. Review ARCHITECTURE.md for deep dive
  4. Customize constraints for your use case
  5. Integrate with your AI provider
  6. Deploy with confidence

πŸ“ License

MIT License - see LICENSE file for details


πŸ™ Contributing

Contributions welcome! Please read our contributing guidelines.


πŸ“§ Support

  • GitHub Issues for bug reports
  • Discussions for questions
  • Examples for common patterns

Built with ❀️ for safe AI-assisted development

About

A production-ready TypeScript/React framework for AI-assisted runtime UI modification with multi-layered security boundaries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •