diff --git a/examples/compose-master.ds b/examples/compose-master.ds new file mode 100644 index 0000000..fd69d1d --- /dev/null +++ b/examples/compose-master.ds @@ -0,0 +1,42 @@ +-- DreamStack Chained Composition — Layer 2: Master Dashboard +-- Receives the aggregated metrics (from Layer 1) AND mood (from Layer 0). +-- +-- Architecture: +-- Counter ──┐ +-- Clock ───┤──► compose-metrics ──┐ +-- Stats ───┘ (Layer 1) │ +-- ├──► THIS APP (Layer 2) +-- Mood ────────────────────────────┘ +-- +-- This demonstrates: +-- 1. Chained composition (3 → 1 → final) +-- 2. Multiple layers of signal derivation +-- 3. Mixing independently-sourced streams +-- +-- Run with: +-- dreamstack build examples/compose-master.ds + +let metrics = stream from "ws://localhost:9100/stream/metrics" +let mood = stream from "ws://localhost:9100/stream/mood" + +view main = + column [ + text "🏗️ Master Dashboard (Layer 2)" + text "Chained: 3→1→here + mood" + row [ + column [ + text "── ⚡ Aggregated Metrics ──" + text "(from compose-metrics)" + text "Uptime: {metrics.uptime}s" + text "Total Events: {metrics.events}" + text "Status: {metrics.status}" + ] + column [ + text "── 😊 Mood (Direct) ──" + text "(from streaming-mood)" + text "Mood: {mood.mood}" + text "Energy: {mood.energy}%" + text "Color: {mood.color}" + ] + ] + ] diff --git a/examples/compose-metrics.ds b/examples/compose-metrics.ds new file mode 100644 index 0000000..8fa2b77 --- /dev/null +++ b/examples/compose-metrics.ds @@ -0,0 +1,39 @@ +-- DreamStack Chained Composition — Layer 1: Metrics Aggregator +-- Receives 3 signal streams, derives combined metrics, re-streams them. +-- +-- Architecture: +-- Counter ──┐ +-- Clock ───┤──► THIS APP ──► /peer/metrics +-- Stats ───┘ +-- +-- This app is BOTH a receiver AND a source: +-- - Receives: counter.count, counter.doubled, clock.seconds, stats.total, stats.max +-- - Derives: uptime (from clock), events (from stats+counter), status (combined) +-- - Streams: uptime, events, status on /peer/metrics +-- +-- Run with: +-- dreamstack stream examples/compose-metrics.ds --port 3006 + +let counter = stream from "ws://localhost:9100/stream/counter" +let clock = stream from "ws://localhost:9100/stream/clock" +let stats = stream from "ws://localhost:9100/stream/stats" + +-- Derived metrics from upstream streams +let uptime = clock.seconds +let events = counter.count + stats.total +let status = "nominal" + +-- Re-stream derived metrics downstream +stream metrics on "ws://localhost:9100/peer/metrics" { + mode: signal, + output: uptime, events, status +} + +view metrics = + column [ + text "⚡ Metrics Aggregator (Layer 1)" + text "Receives: counter + clock + stats" + text "Uptime: {uptime}s" + text "Total Events: {events}" + text "Status: {status}" + ]