46 KiB
46 KiB
MidStream Dependency Graph & Architecture Diagrams
Created by rUv Date: October 26, 2025
Visual Architecture Overview
System Architecture - Component View
┌─────────────────────────────────────────────────────────────────────────────┐
│ MIDSTREAM PLATFORM │
│ Real-Time LLM Streaming & Analysis │
└─────────────────────────────────────────────────────────────────────────────┘
│
┌─────────────────┴─────────────────┐
│ │
┌───────────▼──────────┐ ┌────────────▼────────────┐
│ TypeScript Layer │ │ Application Layer │
│ (npm package) │ │ (User Applications) │
│ │ │ │
│ - Dashboard │ │ - CLI Tools │
│ - OpenAI Client │ │ - Web Dashboards │
│ - QUIC Client │ │ - Custom Integrations │
│ - MCP Server │ │ │
└──────────┬───────────┘ └────────────┬────────────┘
│ │
└──────────┬────────────────────────┘
│
┌──────────▼───────────┐
│ WASM Bindings │
│ (wasm-pack) │
│ │
│ JavaScript ←→ Rust │
└──────────┬───────────┘
│
┌─────────────────────┴─────────────────────┐
│ RUST WORKSPACE (6 Crates) │
│ 3,171 LOC Production Code │
└─────────────────────┬─────────────────────┘
│
┌───────────────────────┼───────────────────────┐
│ │ │
┌─────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
│ LAYER 1 │ │ LAYER 2 │ │ LAYER 3 │
│ Foundation │ │ Core │ │ Meta │
└────────────┘ └─────────────┘ └─────────────┘
Detailed Crate Architecture
Layer 1: Foundation (Zero Internal Dependencies)
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 1: FOUNDATION │
│ (No internal dependencies) │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ temporal-compare (475 LOC) │ │
│ │ Pattern Matching & Sequence Comparison │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • Dynamic Time Warping (DTW) │ │
│ │ • Longest Common Subsequence (LCS) │ │
│ │ • Edit Distance (Levenshtein) │ │
│ │ • Pattern matching with LRU cache │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ External Dependencies: │ │
│ │ • serde, thiserror, dashmap, lru │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ nanosecond-scheduler (407 LOC) │ │
│ │ Ultra-Low-Latency Real-Time Scheduler │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • Nanosecond-precision scheduling │ │
│ │ • Priority-based task queues │ │
│ │ • Lock-free concurrent execution │ │
│ │ • Deadline-aware scheduling │ │
│ │ • <50ns scheduling latency (p50) │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ External Dependencies: │ │
│ │ • tokio, crossbeam, parking_lot, serde, thiserror │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ quic-multistream (865 LOC) │ │
│ │ QUIC/HTTP3 Multiplexed Streaming │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • 0-RTT connection establishment │ │
│ │ • Multiplexing: 1000+ concurrent streams │ │
│ │ • Stream prioritization │ │
│ │ • Native (Quinn) + WASM (WebTransport) │ │
│ │ • Platform: Linux/macOS/Windows/Browser │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ External Dependencies: │ │
│ │ Native: quinn, rustls, tokio │ │
│ │ WASM: web-sys, wasm-bindgen │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
Layer 2: Core (Depends on Layer 1)
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 2: CORE │
│ (Depends on Foundation Layer Only) │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ temporal-attractor-studio (420 LOC) │ │
│ │ Dynamical Systems & Strange Attractors │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • Fixed-point attractor detection │ │
│ │ • Periodic orbit analysis │ │
│ │ • Chaotic behavior detection │ │
│ │ • Lyapunov exponent calculation │ │
│ │ • Phase space reconstruction │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Internal Dependencies: │ │
│ │ • temporal-compare ────────────────────────────┐ │ │
│ │ │ │ │
│ │ External Dependencies: │ │ │
│ │ • nalgebra, ndarray, serde, thiserror │ │ │
│ └──────────────────────────────────────────────────┼────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────▼────────┐ │
│ │ temporal-neural-solver (509 LOC) │ │
│ │ Temporal Logic Verification with Neural Reasoning │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • Linear Temporal Logic (LTL) verification │ │
│ │ • Neural network integration │ │
│ │ • Sequence prediction │ │
│ │ • Temporal constraint solving │ │
│ │ • Proof generation │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Internal Dependencies: │ │
│ │ • nanosecond-scheduler ─────────────────────────┐ │ │
│ │ │ │ │
│ │ External Dependencies: │ │ │
│ │ • ndarray, serde, thiserror │ │ │
│ └──────────────────────────────────────────────────┼───────┘ │
│ │ │
└─────────────────────────────────────────────────────┼──────────────┘
│
│
┌─────────────────────────────────────────────────────┼──────────────┐
│ LAYER 1 │ │
│ │ │
│ ┌─────────────────────────────┐ ┌────────────────▼──────┐ │
│ │ temporal-compare │ │ nanosecond-scheduler │ │
│ │ (475 LOC) │ │ (407 LOC) │ │
│ └─────────────────────────────┘ └───────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────────┘
Layer 3: Meta (Depends on All Lower Layers)
┌─────────────────────────────────────────────────────────────────────┐
│ LAYER 3: META │
│ (Self-Referential Systems & Meta-Learning) │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ strange-loop (495 LOC) │ │
│ │ Meta-Learning & Self-Referential Systems │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Features: │ │
│ │ • Meta-learning framework │ │
│ │ • Self-referential system modeling │ │
│ │ • Policy adaptation │ │
│ │ • Reward optimization │ │
│ │ • Knowledge graph integration │ │
│ │ • Experience replay │ │
│ ├──────────────────────────────────────────────────────────┤ │
│ │ Internal Dependencies: (ALL LAYER 1 + 2) │ │
│ │ ┌────────────────────────────────────────────────┐ │ │
│ │ │ • temporal-compare (Layer 1) │ │ │
│ │ │ • nanosecond-scheduler (Layer 1) │ │ │
│ │ │ • temporal-attractor-studio (Layer 2) │ │ │
│ │ │ • temporal-neural-solver (Layer 2) │ │ │
│ │ └────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ External Dependencies: │ │
│ │ • dashmap, serde, thiserror │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
│ │ │
┌─────────────────▼───────┐ ┌────────▼─────────┐ ┌──────▼──────────┐
│ LAYER 2 │ │ LAYER 2 │ │ LAYER 1 │
│ temporal-attractor- │ │ temporal-neural- │ │ nanosecond- │
│ studio │ │ solver │ │ scheduler │
└─────────────┬───────────┘ └──────────────────┘ └─────────────────┘
│
│
┌─────────────▼───────────┐
│ LAYER 1 │
│ temporal-compare │
└─────────────────────────┘
Dependency Flow Diagrams
Full Workspace Dependency Flow
┌─────────────────────────────────────────────────────────────────┐
│ midstream (root) │
│ Main application binary │
└───┬─────┬─────┬──────┬──────┬──────┬─────────────────────────────┘
│ │ │ │ │ │
│ │ │ │ │ └─────────────────────┐
│ │ │ │ └──────────────────┐ │
│ │ │ └─────────────────┐ │ │
│ │ └────────────────┐ │ │ │
│ └───────────────┐ │ │ │ │
▼ ▼ ▼ ▼ ▼ ▼
┌────────┐ ┌──────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌──────────────┐
│temporal│ │nano- │ │temp-│ │temp-│ │ │ │quic- │
│compare │ │second│ │attr │ │neur │ │stran│ │multistream │
│ │ │sched │ │stud │ │solv │ │loop │ │ │
│Layer 1 │ │Layer1│ │Layer│ │Layer│ │Layer│ │Layer 1 │
│ │ │ │ │ 2 │ │ 2 │ │ 3 │ │ │
└────────┘ └──┬───┘ └──┬──┘ └──┬──┘ └──┬──┘ └──────────────┘
│ │ │ │
│ │ │ │
│ ┌────┘ │ │
│ │ │ │
└────┼────────────┘ │
│ │
└────────────────────┘
Legend:
─── = Direct dependency
↓ = Transitive dependency
Dependency Resolution Order
Build Order (Topological Sort):
1. Foundation Layer (Parallel):
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ temporal- │ │ nanosecond- │ │ quic- │
│ compare │ │ scheduler │ │ multistream │
└─────────────────┘ └─────────────────┘ └─────────────────┘
2. Core Layer (Parallel after Foundation):
┌─────────────────┐ ┌─────────────────┐
│ temporal- │ │ temporal- │
│ attractor- │ │ neural-solver │
│ studio │ │ │
└─────────────────┘ └─────────────────┘
3. Meta Layer (After Core):
┌─────────────────┐
│ strange-loop │
└─────────────────┘
4. Application (After Meta):
┌─────────────────┐
│ midstream │
│ (main binary) │
└─────────────────┘
Data Flow Diagram
Real-Time Streaming Analysis Pipeline
┌──────────────────────────────────────────────────────────────────┐
│ INPUT SOURCES │
└──────────────────────────────────────────────────────────────────┘
│ │ │
│ Text Stream │ Audio Stream │ Video Stream
│ (OpenAI RT) │ (WebRTC) │ (QUIC)
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────────────────────┐
│ TRANSPORT LAYER │
│ ┌───────────┐ ┌────────────┐ ┌──────────────┐ │
│ │ WebSocket │ │ WebRTC │ │ QUIC/HTTP3 │ │
│ │ (WSS) │ │ (P2P/TURN) │ │ (0-RTT) │ │
│ └─────┬─────┘ └─────┬──────┘ └──────┬───────┘ │
└────────┼────────────────┼──────────────────┼─────────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────────────────────┐
│ SCHEDULING LAYER │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ nanosecond-scheduler │ │
│ │ Priority Queues | Deadline Scheduling | <50ns Latency │ │
│ └────────┬───────────────┬───────────────┬─────────────────┘ │
└───────────┼───────────────┼───────────────┼──────────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────────────────────┐
│ ANALYSIS LAYER │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ temporal- │ │ temporal- │ │ temporal- │ │
│ │ compare │ │ attractor- │ │ neural- │ │
│ │ │ │ studio │ │ solver │ │
│ │ DTW, LCS │ │ Lyapunov │ │ LTL Logic │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
└─────────┼──────────────────┼──────────────────┼──────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────────────────────────────────────────────────────────┐
│ META-LEARNING LAYER │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ strange-loop │ │
│ │ Policy Adaptation | Reward Optimization | Experience │ │
│ │ Knowledge Graph | Self-Reference | Meta-Learn │ │
│ └────────────────────────────┬─────────────────────────────┘ │
└────────────────────────────────┼──────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────────────────┐
│ OUTPUT LAYER │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Dashboard │ │ API │ │ Storage │ │
│ │ (Console) │ │ (REST) │ │ (Metrics) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└──────────────────────────────────────────────────────────────────┘
Component Interaction Diagram
Runtime Architecture
┌──────────────────────────────────────────────────────────────────┐
│ USER APPLICATION │
└──────────────────────────────────────────────────────────────────┘
│
│ API Calls
▼
┌──────────────────────────────────────────────────────────────────┐
│ MIDSTREAM LIBRARY │
│ │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Agent │◄────────┤ Scheduler │◄───────┤ Stream │ │
│ │ Manager │ │ (nano-sec)│ │ Handler │ │
│ └─────┬──────┘ └─────┬──────┘ └─────┬──────┘ │
│ │ │ │ │
│ │ coordinates │ schedules │ processes │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ ANALYSIS PIPELINE │ │
│ │ │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Pattern │─▶│ Attractor│─▶│ Logic │ │ │
│ │ │ Match │ │ Detect │ │ Verify │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ │ │ │
│ │ │ │ │
│ │ ▼ │ │
│ │ ┌──────────────┐ │ │
│ │ │ Meta-Learn │ │ │
│ │ │ (strange- │ │ │
│ │ │ loop) │ │ │
│ │ └──────────────┘ │ │
│ └──────────────────────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────────┘
│
│ Results
▼
┌──────────────────────────────────────────────────────────────────┐
│ OUTPUT INTERFACES │
│ • Dashboard Metrics │
│ • Event Callbacks │
│ • Structured Logs │
│ • Analytics Data │
└──────────────────────────────────────────────────────────────────┘
Published Crates Integration
Hybrid Architecture: Published + Local
┌─────────────────────────────────────────────────────────────────┐
│ crates.io (Registry) │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ temporal- │ │ nanosecond- │ │ temporal- │ │
│ │ compare │ │ scheduler │ │ attractor │ │
│ │ v0.1.0 │ │ v0.1.0 │ │ v0.1.0 │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ temporal- │ │ strange-loop │ │
│ │ neural │ │ v0.1.0 │ │
│ │ v0.1.0 │ └──────────────┘ │
│ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
│ cargo fetch
▼
┌─────────────────────────────────────────────────────────────────┐
│ Local Workspace │
│ │
│ Cargo.toml (root): │
│ [dependencies] │
│ temporal-compare = "0.1" # From crates.io │
│ nanosecond-scheduler = "0.1" # From crates.io │
│ temporal-attractor-studio = "0.1" # From crates.io │
│ temporal-neural-solver = "0.1" # From crates.io │
│ strange-loop = "0.1" # From crates.io │
│ │
│ quic-multistream = { path = "crates/quic-multistream" } │
│ # Local for development │
│ │
│ [workspace] │
│ members = ["crates/quic-multistream"] │
│ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Build Process │
│ │
│ 1. Download published crates from crates.io (~5s) │
│ 2. Use cached pre-compiled artifacts (0s) │
│ 3. Compile local crate only (~30s) │
│ │
│ TOTAL BUILD TIME: ~35s │
│ (vs 124s for all-local) │
│ │
│ Performance Gain: 71% faster │
└─────────────────────────────────────────────────────────────────┘
Circular Dependency Check
Verification Matrix
Dependency Check Matrix:
FROM ↓ TO → | comp | sched | attr | solv | loop | quic
─────────────────┼──────┼───────┼──────┼──────┼──────┼─────
temporal-compare │ X │ - │ - │ - │ - │ -
nanosec-sched │ - │ X │ - │ - │ - │ -
attractor-studio │ ✓ │ - │ X │ - │ - │ -
neural-solver │ - │ ✓ │ - │ X │ - │ -
strange-loop │ ✓ │ ✓ │ ✓ │ ✓ │ X │ -
quic-multistream │ - │ - │ - │ - │ - │ X
Legend:
X = Self (diagonal)
- = No dependency
✓ = Valid dependency (lower layer)
⚠ = WARNING: Circular dependency (NONE FOUND)
❌ = ERROR: Invalid dependency (higher layer)
Result: ✅ NO CIRCULAR DEPENDENCIES DETECTED
Dependency Layers Verification
Layer 3 (Meta): strange-loop
├─ Depends on: Layer 2 + Layer 1 ✅ VALID
└─ Depended by: None ✅ TOP LAYER
Layer 2 (Core): temporal-attractor-studio, temporal-neural-solver
├─ Depends on: Layer 1 only ✅ VALID
└─ Depended by: Layer 3 ✅ CORRECT
Layer 1 (Foundation): temporal-compare, nanosecond-scheduler, quic-multistream
├─ Depends on: External only ✅ VALID
└─ Depended by: Layer 2, Layer 3 ✅ CORRECT
Architecture Validity: ✅ PASSED
Performance Impact Diagram
Build Time Comparison
Local Development (All Path Dependencies):
Time → 0s 30s 60s 90s 120s 150s
│────────┼───────┼───────┼───────┼───────┤
├─ temporal-compare ────────┤ (15s)
├─ nanosecond-scheduler ─────────────┤ (20s)
├─ attractor-studio ──────────┤ (18s)
├─ neural-solver ───────────┤ (16s)
├─ strange-loop ────────────────────┤ (25s)
└─ quic-multistream ──────────────────────────┤ (30s)
TOTAL BUILD TIME: 124s
Published Crates Strategy:
Time → 0s 10s 20s 30s 40s
│────────┼───────┼───────┼───────┤
├─ Download crates ──┤ (5s)
├─ temporal-compare (cached) (0s)
├─ nanosecond-scheduler (cached) (0s)
├─ attractor-studio (cached) (0s)
├─ neural-solver (cached) (0s)
├─ strange-loop (cached) (0s)
└─ quic-multistream ──────────────────────┤ (30s)
TOTAL BUILD TIME: 35s
┌─────────────────────────────────┐
│ 71% FASTER BUILD TIME │
│ 89 seconds saved │
└─────────────────────────────────┘
Feature Flag Architecture (Proposed)
Modular Dependency Management
┌─────────────────────────────────────────────────────────────────┐
│ strange-loop │
│ │
│ [features] │
│ default = ["full"] │
│ full = ["temporal", "attractor", "solver", "scheduler"] │
│ minimal = [] │
│ │
│ temporal = ["dep:temporal-compare"] │
│ attractor = ["dep:temporal-attractor-studio"] │
│ solver = ["dep:temporal-neural-solver"] │
│ scheduler = ["dep:nanosecond-scheduler"] │
└─────────────────────────────────────────────────────────────────┘
│
┌─────────────────┼─────────────────┬────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────┐ ┌──────────┐
│ temporal- │ │ temporal- │ │temporal- │ │nanosec- │
│ compare │ │ attractor │ │neural │ │scheduler │
│ (optional) │ │ (optional) │ │(optional)│ │(optional)│
└──────────────┘ └──────────────┘ └──────────┘ └──────────┘
Usage Examples:
1. Full features (default):
strange-loop = "0.1"
→ Includes all dependencies
2. Minimal build:
strange-loop = { version = "0.1", default-features = false }
→ No optional dependencies
3. Custom features:
strange-loop = { version = "0.1", features = ["temporal", "attractor"] }
→ Only temporal-compare + temporal-attractor-studio
Dependency Analysis Complete ✅ No Circular Dependencies ✅ Architecture Valid ✅ Production Ready ✅
Created by rUv 🚀