Skip to content

Minimact Client Architecture: Layered Reactive DOM Stack โ€‹

Minimact's client modules form a coherent hierarchy of reactive capabilities โ€” from predictive rendering to distributed DOM synchronization.

Each layer is a separate npm package. Install only what you need.

The Evolution Stack โ€‹

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-quantum         โ”‚  โ† 6๏ธโƒฃ Distributed Identity
โ”‚   Entanglement Protocol    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-trees           โ”‚  โ† 5๏ธโƒฃ Semantic Trees
โ”‚   Declarative State        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-spatial         โ”‚  โ† 4๏ธโƒฃ Layout & Flow Analysis
โ”‚   Viewport as 2D Database  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-dynamic         โ”‚  โ† 3๏ธโƒฃ Function-Based Binding
โ”‚   Structure/Logic Split    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-query           โ”‚  โ† 2๏ธโƒฃ SQL for Reactive DOM
โ”‚   Relational Queries       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact-punch           โ”‚  โ† 1๏ธโƒฃ DOM as Reactive State
โ”‚   80+ Observable Props     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ–ฒ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   minimact (core)          โ”‚  โ† 0๏ธโƒฃ Predictive Rendering
โ”‚   13.33 KB Runtime         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Journey:

React โ†’ Reactive DOM โ†’ Queryable DOM โ†’ Predictive Layout โ†’ Distributed DOM

0๏ธโƒฃ minimact (Core) โ€‹

Foundation: Predictive rendering, state hooks, and patch cache execution.

bash
npm install minimact

What It Includes โ€‹

  • Hooks: useState, useEffect, useRef, useContext, useComputed, useServerTask
  • Predictive patches via template cache
  • Server-rendered HTML with client patch application
  • 13.33 KB runtime (gzipped) โ€” 71% smaller than React
  • Alternative: minimact-r with full SignalR (25.03 KB)

Key Features โ€‹

tsx
// Server-managed state
const [count, setCount] = useState(0);

// Client-only state (no server round-trip)
const [isOpen, setIsOpen] = useClientState(false);

// Long-running server tasks with progress
const [task, startTask] = useServerTask(async (updateProgress) => {
  for (let i = 0; i <= 100; i += 10) {
    await delay(500);
    updateProgress(i);
  }
  return 'Complete!';
});

See: Core Hooks Documentation


1๏ธโƒฃ minimact-punch: DOM as Reactive Data Source โ€‹

Capability: Make the DOM observable โ€” structure, pseudo-state, styles, lifecycle.

bash
npm install minimact-punch

What It Adds โ€‹

  • useDomElementState(selector) - Makes DOM queryable like a database
  • 80+ reactive properties (isIntersecting, childrenCount, attributes, classList, etc.)
  • MutationObserver integration (automatic updates)
  • IntersectionObserver integration (viewport tracking)
  • Statistical aggregates (.vals.avg(), .vals.sum(), .vals.median())
  • Collection queries (count, map, filter, find)
  • MES Silver certified (Minimact Extension Standards)

Example โ€‹

tsx
import { useDomElementState } from 'minimact-punch';

function AdaptiveHeader() {
  const scrollContainer = useDomElementState('#main-content');

  return (
    <header className={scrollContainer.scrollTop > 100 ? 'compact' : 'full'}>
      {/* Header adapts based on scroll position */}
    </header>
  );
}

See: DOM as Data Source Use Cases


2๏ธโƒฃ minimact-query: SQL for the DOM โ€‹

Capability: Query reactive DOM state declaratively with SQL semantics.

bash
npm install minimact-query

What It Adds โ€‹

  • useDomQuery() - Query DOM like a relational database
  • Full SQL semantics (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT)
  • Aggregate functions (COUNT, SUM, AVG, MIN, MAX, STDDEV)
  • Set operations (UNION, INTERSECT, EXCEPT, DISTINCT)
  • Reactive by default (queries auto-update when DOM changes)
  • Type-safe with autocomplete for 80+ DOM properties
  • Performance optimized (throttling/debouncing built-in)

Example โ€‹

tsx
import { useDomQuery } from 'minimact-query';

function PerformanceMonitor() {
  const unstableComponents = useDomQuery()
    .from('.component')
    .where(c => c.history.changesPerSecond > 10)
    .orderBy(c => c.history.volatility, 'DESC')
    .limit(10);

  return (
    <div>
      <h3>Unstable Components ({unstableComponents.count})</h3>
      {unstableComponents.map(c => (
        <div>{c.id}: {c.history.changesPerSecond} changes/sec</div>
      ))}
    </div>
  );
}

Status: ๐Ÿงช Experimental (in development)


3๏ธโƒฃ minimact-dynamic: Function-Based Value Binding โ€‹

Capability: Separate structure from logic. JSX stays clean; logic lives in TypeScript functions.

bash
npm install minimact-dynamic

What It Adds โ€‹

  • useDynamicState(selector, fn) - Separate structure from content
  • Define DOM once, bind values with functions
  • Auto dependency tracking with Proxy
  • Direct DOM updates (< 1ms, no VDOM)
  • Server pre-compilation support
  • Minimal bundle (< 3KB gzipped)

Example โ€‹

tsx
import { dynamic } from 'minimact-dynamic';

function PricingCard({ product, user }) {
  // Structure ONCE
  return (
    <div className="card">
      <span className="price"></span>
    </div>
  );
}

// Bind SEPARATELY (logic outside JSX)
dynamic('.price', (state) =>
  state.user.isPremium
    ? state.product.factoryPrice
    : state.product.price
);

Key Benefit: Structure is static, logic is dynamic. Re-bind without re-rendering.


4๏ธโƒฃ minimact-spatial: Physical Layout Reasoning โ€‹

Capability: DOM spatial intelligence โ€” gaps, overlaps, flow, lookahead/lookbehind.

bash
npm install minimact-spatial

What It Adds โ€‹

  • useArea() - Query spatial regions of the viewport
  • Track coverage, density, element counts
  • Reactive spatial queries
  • Region-based event handling
  • Spatial collision detection

Example โ€‹

tsx
import { useArea } from 'minimact-spatial';

function AdaptiveLayout() {
  const header = useArea({ top: 0, height: 80 });
  const sidebar = useArea('#sidebar');

  return (
    <div>
      {header.isFull && <CompactMode />}
      {sidebar.elementsCount > 10 && <ScrollIndicator />}
    </div>
  );
}

Use Cases:

  • Sticky headers that adapt to content
  • Scroll indicators based on viewport coverage
  • Layout collision detection
  • Responsive design based on actual layout (not just viewport size)

5๏ธโƒฃ minimact-trees: Declarative State Machines โ€‹

Capability: Understand ancestry, depth, siblings, and tree relationships declaratively.

bash
npm install minimact-trees

What It Adds โ€‹

  • useDecisionTree() - XState but minimal and declarative
  • Universal value type support (any primitive or object)
  • Nested decision paths
  • Predictive transition pre-computation
  • Server-side rendering integration
  • TypeScript inference for tree structure

Example โ€‹

tsx
import { useDecisionTree } from 'minimact-trees';

function PricingEngine({ user, cartSize }) {
  const price = useDecisionTree({
    roleAdmin: 0,
    rolePremium: {
      count5: 0,
      count3: 5
    },
    roleBasic: 10
  }, { role: user.role, count: cartSize });

  return <div>Price: ${price}</div>;
}

Key Insight: Decision trees are predictable state machines. Server can pre-compute all transitions.


6๏ธโƒฃ minimact-quantum: The Entangled DOM โ€‹

Capability: DOM sync across clients & pages. Mutation vectors. Shared identity.

bash
npm install minimact-quantum

What It Adds โ€‹

  • Multi-client DOM synchronization across physical space
  • Identity sync (not data sync - same element in two places at once)
  • Mutation vectors for efficient transmission
  • Bidirectional entanglement
  • Operational Transform for conflict resolution
  • 100x bandwidth reduction vs full state sync
  • WebWormhole integration for P2P

Example โ€‹

tsx
import { quantum } from 'minimact-quantum';

async function CollaborativeSlider() {
  const slider = document.querySelector('#volume-slider');

  // User A in New York, User B in Tokyo
  const link = await quantum.entangle(slider, {
    clientId: 'user-b',
    selector: '#volume-slider'
  }, 'bidirectional');

  // User A drags โ†’ User B's slider moves instantly
  // SAME IDENTITY. DIFFERENT SPACETIME COORDINATES.
}

Key Concept:

Traditional: Sync data, reconstruct UI
Quantum: Sync DOM identity, mutations propagate

Status: ๐Ÿงช Experimental (proof-of-concept)


Layer Composition โ€‹

Each layer builds on the previous:

LayerAddsBuilds On
0: CorePredictive renderingServer HTML
1: PunchDOM observabilityCore state
2: QueryRelational queriesPunch properties
3: DynamicFunction bindingCore patches
4: SpatialLayout intelligencePunch spatial data
5: TreesState machinesCore prediction
6: QuantumMulti-client syncCore patches + Punch state

You can use any layer without the ones above it.

Example:

  • Use just minimact-dynamic with core (no Punch/Query needed)
  • Use minimact-spatial without Query
  • Use minimact-quantum directly with core

Philosophy: From React to Reactive โ€‹

Traditional React โ€‹

React Component โ†’ VDOM โ†’ Reconciliation โ†’ DOM

Minimact Core โ€‹

TSX Component โ†’ Server Render โ†’ Predictive Patches โ†’ DOM

Minimact + Extensions โ€‹

TSX Component โ†’ Server Render โ†’ Predictive Patches โ†’ DOM
                                                      โ†“
                                              Observable State
                                                      โ†“
                                              SQL Queries
                                                      โ†“
                                              Function Bindings
                                                      โ†“
                                              Spatial Reasoning
                                                      โ†“
                                              State Machines
                                                      โ†“
                                              Quantum Sync

The DOM becomes:

  1. Reactive (Punch) - Observable like state
  2. Queryable (Query) - Relational like a database
  3. Declarative (Dynamic) - Bindable like templates
  4. Spatial (Spatial) - Geometric like a canvas
  5. Structural (Trees) - Hierarchical like a filesystem
  6. Distributed (Quantum) - Synchronized like CRDT

Production Readiness โ€‹

โœ… Production-Ready โ€‹

  • minimact (core)
  • minimact-punch (MES Silver certified)
  • minimact-dynamic
  • minimact-spatial
  • minimact-trees

๐Ÿงช Experimental โ€‹

  • minimact-query (in development)
  • minimact-quantum (proof-of-concept)

Next Steps โ€‹


React gave us components.

Minimact gives us a reactive, queryable, distributed DOM.

๐ŸŒต The future is layered. ๐ŸŒต

Released under the MIT License.