This document outlines the enhancement of Synapse's biological metaphor by:
- Renaming the UI layer to "Skin" - the organism's interface with the external world
- Integrating WebNN - actual neural network inference for intelligent UI responses
The skin is the body's largest organ and primary interface with the external environment. It:
- Detects external stimuli (touch, temperature, pressure)
- Protects internal systems
- Regulates what enters and exits
- Provides visible representation of internal state
- Adapts to environmental conditions
Skin (Integumentary System)
├── Epidermis (Visual Layer)
│ ├── Keratinocytes (Visual Components)
│ ├── Melanocytes (Theming/Styling)
│ └── Langerhans Cells (Event Detection)
├── Dermis (Structural Layer)
│ ├── Fibroblasts (Layout/Structure)
│ ├── Blood Vessels (Data Flow)
│ └── Nerve Endings (Sensory Receptors)
└── Hypodermis (Foundation Layer)
├── Adipocytes (State Storage)
└── Connective Tissue (Glial Support)
| Current | New Skin Term | Biological Role |
|---|---|---|
VisualNeuron |
SkinCell |
Base UI component |
SensoryNeuron |
Receptor |
Input detection |
MotorNeuron |
Effector |
Action execution |
InterneuronUI |
DermalLayer |
Container/layout |
VisualAstrocyte |
Adipocyte |
State management |
VisualOligodendrocyte |
Melanocyte |
Rendering optimization |
// Mechanoreceptors - Physical interaction
- TouchReceptor (Button, TouchArea)
- PressureReceptor (Slider, Pressure-sensitive input)
- VibrationReceptor (Haptic feedback components)
// Thermoreceptors - State indication
- WarmReceptor (Success/positive states)
- ColdReceptor (Error/negative states)
// Nociceptors - Error/warning detection
- AlertReceptor (Error messages)
- WarningReceptor (Warning messages)
// Proprioceptors - Position/layout awareness
- PositionReceptor (Drag & drop)
- OrientationReceptor (Rotation/orientation controls)
// Chemoreceptors - Data input
- TextReceptor (Text input)
- DataReceptor (Form inputs)src/skin/
├── cells/ # Base skin cell components
│ ├── SkinCell.ts # Base class (was VisualNeuron)
│ ├── Keratinocyte.ts # Visual components
│ └── Melanocyte.ts # Styling/theming
├── receptors/ # Input components (was SensoryNeuron)
│ ├── Receptor.ts # Base receptor class
│ ├── TouchReceptor.ts
│ ├── TextReceptor.ts
│ ├── DataReceptor.ts
│ └── AlertReceptor.ts
├── effectors/ # Action components (was MotorNeuron)
│ ├── Effector.ts # Base effector class
│ ├── GlandEffector.ts # State-changing actions
│ └── MuscleEffector.ts # Motion/animation actions
├── dermis/ # Structural layer (was InterneuronUI)
│ ├── DermalLayer.ts
│ ├── Fibroblast.ts # Layout structures
│ └── BloodVessel.ts # Data flow pipes
├── support/ # Support cells (glial equivalent)
│ ├── Adipocyte.ts # State storage (was VisualAstrocyte)
│ ├── Melanocyte.ts # Render optimization (was VisualOligodendrocyte)
│ └── LangerhansCell.ts # Event handling/immunity
└── components/ # Concrete implementations
├── Button.ts # TouchReceptor implementation
├── Input.ts # TextReceptor implementation
├── Form.ts # DermalLayer implementation
└── ...
WebNN allows us to implement actual neural network inference within our framework, creating "intelligent neurons" that can:
- Learn from user interactions
- Predict user intent
- Optimize UI responsiveness
- Personalize experiences
- Detect anomalies
// ML-Powered Neurons using WebNN
├── PerceptronNeuron # Single-layer inference
├── ConvolutionalNeuron # Image/pattern processing
├── RecurrentNeuron # Sequential/temporal data
├── TransformerNeuron # Attention-based processing
└── GAN_Neuron # Generative capabilities┌─────────────────────────────────────────────────┐
│ Synapse Application Layer │
├─────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌─────────────────┐ │
│ │ Skin Layer │◄────────┤ WebNN Neurons │ │
│ │ (UI/UX) │ │ (ML Inference) │ │
│ └──────────────┘ └─────────────────┘ │
│ ▲ ▲ │
│ │ │ │
│ ┌──────┴───────┐ ┌──────┴──────────┐ │
│ │ Receptors │────────►│ MLGraphBuilder │ │
│ │ (Inputs) │ │ (Build Graph) │ │
│ └──────────────┘ └─────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────┐ ┌─────────────────┐ │
│ │ Effectors │◄────────┤ MLContext │ │
│ │ (Actions) │ │ (Execute AI) │ │
│ └──────────────┘ └─────────────────┘ │
│ │ │ │
├─────────┴─────────────────────────┴─────────────┤
│ Core Neural Network (Synapse) │
│ ┌──────────────────────────────────────────┐ │
│ │ EventBus • Plasticity • Health Monitoring│ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
/**
* Base class for WebNN-powered neurons
* Combines Synapse's neural abstraction with WebNN inference
*/
export abstract class WebNNNeuron extends CorticalNeuron {
protected mlContext?: MLContext;
protected mlGraph?: MLGraph;
protected graphBuilder?: MLGraphBuilder;
protected isModelLoaded = false;
constructor(id: string) {
super(id, 'webnn-neuron');
}
/**
* Initialize WebNN context
*/
async activate(): Promise<void> {
await super.activate();
// Create ML context with device preferences
this.mlContext = await navigator.ml.createContext({
powerPreference: 'high-performance' // or 'low-power', 'default'
});
this.graphBuilder = new MLGraphBuilder(this.mlContext);
await this.loadModel();
}
/**
* Load and compile the neural network model
* Override in subclasses to define network architecture
*/
protected abstract loadModel(): Promise<void>;
/**
* Execute inference using WebNN
*/
protected async infer(inputs: MLNamedTensors): Promise<MLNamedTensors> {
if (!this.mlGraph || !this.mlContext) {
throw new Error('WebNN model not initialized');
}
const outputs: MLNamedTensors = {};
await this.mlContext.dispatch(this.mlGraph, inputs, outputs);
return outputs;
}
/**
* Process signal with ML inference
*/
protected async executeProcessing(input: Signal): Promise<Signal> {
// Convert signal to tensor
const tensor = this.signalToTensor(input);
// Run inference
const result = await this.infer({ input: tensor });
// Convert result back to signal
return this.tensorToSignal(result.output);
}
protected abstract signalToTensor(signal: Signal): MLTensor;
protected abstract tensorToSignal(tensor: MLTensor): Signal;
}/**
* Smart text input that predicts next words
*/
export class PredictiveTextReceptor extends WebNNNeuron {
protected async loadModel(): Promise<void> {
// Build LSTM network for text prediction
const input = this.graphBuilder!.input('input', {
dataType: 'float32',
dimensions: [1, 100, 128] // [batch, sequence, embedding]
});
const lstm = this.graphBuilder!.lstm(input, /*weight, recurrentWeight, bias*/);
const output = this.graphBuilder!.reshape(lstm.output, [1, 100, vocab_size]);
this.mlGraph = await this.graphBuilder!.build({ output });
}
// Predicts next word as user types
async predictNext(text: string): Promise<string[]> {
const embedding = await this.embedText(text);
const result = await this.infer({ input: embedding });
return this.decodeTokens(result.output);
}
}/**
* Recognizes touch gestures and patterns
*/
export class GestureReceptor extends WebNNNeuron {
protected async loadModel(): Promise<void> {
const input = this.graphBuilder!.input('input', {
dataType: 'float32',
dimensions: [1, 28, 28, 1] // Touch heatmap
});
// Build CNN for gesture recognition
let conv1 = this.graphBuilder!.conv2d(input, filter1);
let relu1 = this.graphBuilder!.relu(conv1);
let pool1 = this.graphBuilder!.maxPool2d(relu1);
let conv2 = this.graphBuilder!.conv2d(pool1, filter2);
let relu2 = this.graphBuilder!.relu(conv2);
let pool2 = this.graphBuilder!.maxPool2d(relu2);
let flatten = this.graphBuilder!.reshape(pool2, [1, -1]);
let output = this.graphBuilder!.gemm(flatten, weights);
this.mlGraph = await this.graphBuilder!.build({ output });
}
// Recognizes swipe, pinch, rotate gestures
async recognizeGesture(touchPoints: TouchPoint[]): Promise<Gesture> {
const heatmap = this.touchToHeatmap(touchPoints);
const result = await this.infer({ input: heatmap });
return this.decodeGesture(result.output);
}
}/**
* Detects unusual user interactions or system states
*/
export class AnomalyDetectorNeuron extends WebNNNeuron {
protected async loadModel(): Promise<void> {
// Autoencoder for anomaly detection
const input = this.graphBuilder!.input('input', {
dataType: 'float32',
dimensions: [1, 50] // Feature vector
});
// Encoder
let encoded = this.graphBuilder!.gemm(input, encoderWeights1);
encoded = this.graphBuilder!.relu(encoded);
encoded = this.graphBuilder!.gemm(encoded, encoderWeights2);
// Decoder
let decoded = this.graphBuilder!.gemm(encoded, decoderWeights1);
decoded = this.graphBuilder!.relu(decoded);
decoded = this.graphBuilder!.gemm(decoded, decoderWeights2);
this.mlGraph = await this.graphBuilder!.build({
encoded,
reconstructed: decoded
});
}
// Returns anomaly score (0-1)
async detectAnomaly(metrics: SystemMetrics): Promise<number> {
const features = this.metricsToFeatures(metrics);
const result = await this.infer({ input: features });
return this.calculateReconstructionError(features, result.reconstructed);
}
}/**
* Learns user preferences and personalizes UI
*/
export class PersonalizationNeuron extends WebNNNeuron {
protected async loadModel(): Promise<void> {
// Transformer for preference learning
const input = this.graphBuilder!.input('input', {
dataType: 'float32',
dimensions: [1, 512, 768] // [batch, sequence, embedding]
});
// Multi-head attention
const attention = await this.buildMultiHeadAttention(input);
const feedForward = await this.buildFeedForward(attention);
this.mlGraph = await this.graphBuilder!.build({ output: feedForward });
}
// Predicts user preferences based on interaction history
async predictPreference(history: UserInteraction[]): Promise<Preferences> {
const embedding = this.encodeHistory(history);
const result = await this.infer({ input: embedding });
return this.decodePreferences(result.output);
}
}-
Create new file structure
- Set up
src/skin/directory - Create base classes:
SkinCell,Receptor,Effector,DermalLayer
- Set up
-
Refactor existing UI components
- Migrate
VisualNeuron→SkinCell - Migrate
SensoryNeuron→Receptor - Migrate
MotorNeuron→Effector - Update all imports across codebase
- Migrate
-
Implement new receptor types
TouchReceptor(Button, ClickArea)TextReceptor(Text input)DataReceptor(Form inputs)AlertReceptor(Notifications)
-
Update support cells
Adipocyte(state storage)Melanocyte(render optimization)LangerhansCell(event handling)
-
Update Storybook stories
- Rename stories to use new terminology
- Update documentation strings
-
Create WebNN neuron base class
WebNNNeuronabstract class- Context management
- Tensor conversion utilities
- Model loading infrastructure
-
Implement simple WebNN neurons
PerceptronNeuron- basic classificationSimpleRegressionNeuron- value prediction
-
Add WebNN detection and fallback
- Check for WebNN support:
navigator.ml - Graceful degradation for unsupported browsers
- Feature detection utilities
- Check for WebNN support:
-
Create model loading infrastructure
- Model file loaders (ONNX, TFLite support)
- Weight initialization
- Model caching
-
Implement ML-powered receptors
PredictiveTextReceptorwith LSTMGestureReceptorwith CNNVoiceReceptorwith RNN (if WebAudio integration)
-
Add system intelligence
AnomalyDetectorNeuronfor error detectionPersonalizationNeuronfor UX adaptationPerformancePredictorfor optimization
-
Create training infrastructure
- Online learning support (if WebNN supports it)
- User feedback collection
- Model fine-tuning
-
Integrate Skin + WebNN
- Connect receptors to WebNN inference
- Intelligent effector responses
- Adaptive UI behavior
-
Performance optimization
- Model quantization
- Caching strategies
- Lazy loading of models
-
Testing & documentation
- Unit tests for WebNN neurons
- Integration tests for intelligent components
- API documentation
- Example applications
// Create a touch receptor (button)
const submitButton = new TouchReceptor('submit-btn', {
label: 'Submit',
sensitivity: 'high', // How sensitive to touch
hapticFeedback: true
});
// Create a text receptor (input)
const emailInput = new TextReceptor('email', {
placeholder: 'Enter email',
validation: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
receptorType: 'chemoreceptor' // Receives chemical/data input
});
// Create a dermal layer (container)
const formLayer = new DermalLayer('login-form', {
layout: 'vertical',
bloodSupply: true, // Enable data flow
nerveSupply: true // Enable event propagation
});
// Add receptors to dermal layer
formLayer.addCell(emailInput);
formLayer.addCell(submitButton);
// Connect to effector
const submitEffector = new GlandEffector('submit-action', {
secretion: 'api-call', // What action to perform
reactionTime: 100 // ms
});
submitButton.connect(submitEffector);// Create intelligent text input with prediction
const smartInput = new PredictiveTextReceptor('smart-input', {
modelPath: '/models/text-prediction.onnx',
predictionCount: 3,
minConfidence: 0.7
});
await smartInput.activate();
// Listen for predictions
smartInput.on('prediction', (predictions: string[]) => {
console.log('Next word predictions:', predictions);
});
// Create gesture-aware touch area
const gestureArea = new GestureReceptor('gesture-area', {
modelPath: '/models/gesture-recognition.onnx',
supportedGestures: ['swipe', 'pinch', 'rotate']
});
await gestureArea.activate();
gestureArea.on('gesture-detected', (gesture: Gesture) => {
console.log(`Detected ${gesture.type} with confidence ${gesture.confidence}`);
});
// Create anomaly detection for health monitoring
const anomalyDetector = new AnomalyDetectorNeuron('anomaly-detector');
await anomalyDetector.activate();
setInterval(async () => {
const metrics = collectSystemMetrics();
const anomalyScore = await anomalyDetector.detectAnomaly(metrics);
if (anomalyScore > 0.8) {
console.warn('Anomaly detected! Score:', anomalyScore);
}
}, 1000);- Consistent biological metaphor throughout the framework
- Clearer separation of concerns (UI is truly the "skin" of the application)
- More intuitive API for developers familiar with biology
- Better organization with receptor types matching real sensory receptors
- True neural network capabilities in a neural-inspired framework
- On-device ML inference without server round-trips
- Hardware acceleration via GPU/NPU when available
- Privacy-preserving - data stays on device
- Offline-capable AI features
- Cost-effective - no server ML infrastructure needed
- Intelligent UI that learns and adapts
- W3C standard with growing browser support
- Chrome/Edge: Preview support (behind flag)
- Safari: Under consideration
- Firefox: No public signals yet
// Feature detection
const hasWebNN = 'ml' in navigator && 'createContext' in navigator.ml;
if (hasWebNN) {
// Use WebNN-powered neurons
const smartComponent = new PredictiveTextReceptor('input');
} else {
// Fall back to traditional component
const basicComponent = new TextReceptor('input');
}
// Or use progressive enhancement
export class SmartTextReceptor extends TextReceptor {
private mlEnhancement?: PredictiveEngine;
async activate(): Promise<void> {
await super.activate();
if ('ml' in navigator) {
this.mlEnhancement = new PredictiveEngine();
await this.mlEnhancement.activate();
}
}
// Enhanced behavior when ML available, basic behavior otherwise
}- Get user approval for this architectural direction
- Choose implementation approach:
- Option A: Refactor Skin first, then add WebNN
- Option B: Add WebNN first to prove concept, then refactor Skin
- Option C: Do both in parallel (more complex)
- Start with Phase 1 (Skin Layer Refactoring) or proof-of-concept WebNN neuron
- Update test suite to cover new components
- Create migration guide for existing users
- Should we maintain backward compatibility with
VisualNeuronnames, or breaking change? - Which WebNN use case should we implement first as proof-of-concept?
- Should we bundle pre-trained models or require users to provide them?
- What's the minimum WebNN browser support we want to target?
- Should Storybook showcase WebNN features (may require polyfill)?