RootIB: RB-20260505073904-E4C1B9D7

# Repo-Wide Automation Architecture Map

**Repository:** `barbrickdesign/barbrickdesign.github.io`  
**Author:** Ryan Barbrick — Barbrick Design  
**AI Assistant:** Merlin AI  
**Contact:** BarbrickDesign@gmail.com  
**Created:** 2026-05-05

---

## Overview

This document describes the **five-layer browser automation architecture** that has been
scaffolded across the entire `barbrickdesign.github.io` repository.
Every project in the repo can now activate all five layers by including a single script tag.

---

## Quick Start (any page)

```html
<!-- Add to <head> or before </body> -->
<script src="/js/unified-automation-engine.js"></script>

<script>
  UnifiedAutomationEngine.init({ sw: true, db: true }).then(engine => {
    // All five layers ready
    engine.python.run('print("Hello from Python")');
    engine.db.kv.set('lastVisit', new Date().toISOString());
    engine.web3.connectWallet();
  });
</script>
```

---

## Layer Descriptions

### Layer 1 — Python Runtime (Pyodide)

| Property | Value |
|----------|-------|
| File | `js/unified-automation-engine.js` → `PythonLayer` |
| CDN  | `https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js` |
| API  | `UAE.python.load()` · `UAE.python.run(code, globals?)` · `UAE.python.installPackage(pkg)` |
| Lazy | Yes — Pyodide only downloaded when `python.load()` or `python.run()` is called |

**Use cases by project type:**

- **AI tools / agents** — ML scoring, CSV/JSON export, PoHV scoring algorithms
- **Dashboards** — data processing pipelines, statistical analysis
- **Health tools** — referral verification, scoring
- **Grants portal** — application text generation, data validation

---

### Layer 2 — WebAssembly (WASM)

| Property | Value |
|----------|-------|
| File | `js/unified-automation-engine.js` → `WasmLayer` |
| API  | `UAE.wasm.load(url, importObject?)` · `UAE.wasm.isSupported()` · `UAE.wasm.unload(url)` |
| Cache | Modules cached in memory by URL — only compiled once per session |

**Use cases by project type:**

- **Games** — physics engines, collision detection, procedural generation
- **AI scanners** — ML inference (ONNX-runtime-web, TensorFlow Lite WASM)
- **Crypto tools** — Solana signature verification, Ed25519 operations
- **3D tools** — GPU fallback compute, asset decompression
- **Image processing** — real-time ultrasound / scanner image analysis

**Loading a module:**
```js
const { instance } = await UAE.wasm.load('/wasm/physics.wasm', {
  env: { memory: new WebAssembly.Memory({ initial: 16 }) }
});
instance.exports.simulate(60); // 60 fps tick
```

---

### Layer 3 — Service Worker + PWA Automation

| Property | Value |
|----------|-------|
| File | `sw.js` (root, full scope) |
| API  | `UAE.sw.register()` · `UAE.sw.requestSync(tag)` · `UAE.sw.postMessage(msg)` · `UAE.sw.unregisterAll()` |
| Manifest | `manifest.json` (already present and enhanced) |

**Caching strategies:**

| Request type | Strategy |
|---|---|
| `/api/*` | Virtual backend (existing RootIB relay) |
| Static assets (JS, CSS, HTML, images) | Cache-First → Dynamic cache |
| No network + no cache | Offline fallback (`/offline.html`) |

**Background sync tags:**

| Tag | Syncs to |
|---|---|
| `health-sync` | `/api/health/sync` |
| `referral-sync` | `/api/referrals/sync` |
| `revenue-sync` | `/api/revenue/sync` |

**Periodic sync tags:**

| Tag | Purpose |
|---|---|
| `daily-streak` | Updates `kv_store.last_streak_check` every 24 h |

**Client message types:**

| `{ type }` | Effect |
|---|---|
| `SKIP_WAITING` | Activate new SW immediately without refresh |
| `CACHE_URLS` | Pre-cache `{ urls: string[] }` on demand |
| `CLEAR_CACHE` | Purge all caches |

---

### Layer 4 — IndexedDB (Structured Local Database)

| Property | Value |
|----------|-------|
| File | `js/unified-automation-engine.js` → `IndexedDBLayer` |
| DB name | `BarbrickDesignDB` v1 |
| API  | `UAE.db.put(store, record)` · `UAE.db.get(store, key)` · `UAE.db.getAll(store, filter?)` · `UAE.db.remove(store, key)` · `UAE.db.kv.set/get/delete` |

**Object stores:**

| Store | Key | Purpose |
|---|---|---|
| `health_logs` | auto-increment `id` | Health check / PoHV log entries |
| `referral_logs` | auto-increment `id` | Referral events and codes |
| `agent_state` | `agentId` | Persistent agent configuration and state |
| `game_state` | `gameId` | Game save / progress data |
| `ai_scanner_results` | auto-increment `id` | AI scan results |
| `revenue_tracking` | auto-increment `id` | Revenue and contributor tracking |
| `kv_store` | `key` | General-purpose key-value store |

---

### Layer 5 — Crypto / Web3 (Solana Web3.js + Wallet Adapter)

| Property | Value |
|----------|-------|
| File | `js/unified-automation-engine.js` → `CryptoWeb3Layer` |
| CDN  | `https://cdn.jsdelivr.net/npm/@solana/web3.js@1.98.0/lib/index.iife.min.js` |
| API  | `UAE.web3.loadWeb3()` · `UAE.web3.detectWallet()` · `UAE.web3.connectWallet()` · `UAE.web3.disconnectWallet()` · `UAE.web3.getBalance(addr?)` · `UAE.web3.signMessage(msg)` · `UAE.web3.sendTransaction(to, sol)` |
| Vault | `6HTjfgWZYMbENnMAJJFhxWR2VZDxdze3qV7zznSAsfk` |

**Supported wallets:** Phantom (`window.phantom.solana` / `window.solana`) · Solflare (`window.solflare`)

**Use cases:**

- **Referral proof verification** — `signMessage()` for on-chain identity
- **VITA minting** — `sendTransaction()` to vault wallet
- **PoHV on-chain identity** — public key as persistent user ID
- **Revenue distribution** — transaction to contributors
- **Wallet-gated features** — check balance or ownership before enabling

---

## Project-Type Matrix

| Project Type | Python | WASM | SW/PWA | IndexedDB | Web3 |
|---|:---:|:---:|:---:|:---:|:---:|
| AI tools (scanners, agents) | ✅ | ✅ | ✅ | ✅ | — |
| Games (Casino AI, mmjJumper) | — | ✅ | ✅ | ✅ | — |
| Dashboards (LiveSafe, analytics) | ✅ | — | ✅ | ✅ | — |
| 3D tools (Babylon, Three.js) | — | ✅ | ✅ | — | — |
| Wallet / crypto tools | — | ✅ | ✅ | ✅ | ✅ |
| General utilities | ✅ | — | ✅ | ✅ | — |
| Grants / revenue portal | ✅ | — | ✅ | ✅ | ✅ |

---

## File Inventory

| File | Role |
|---|---|
| `js/unified-automation-engine.js` | Master five-layer engine (drop-in) |
| `sw.js` | Service Worker (cache, sync, push, virtual API) |
| `manifest.json` | PWA manifest (enhanced with automation metadata) |
| `offline.html` | Offline fallback page (pre-existing) |
| `automation-scaffold.html` | Interactive demo & control panel |
| `docs/AUTOMATION-ARCHITECTURE-MAP.md` | This document |

---

## Integration Checklist (per project)

- [ ] Add `<script src="/js/unified-automation-engine.js"></script>` to `<head>`
- [ ] Call `UnifiedAutomationEngine.init({ sw: true, db: true })` on page load
- [ ] Add `<link rel="manifest" href="/manifest.json">` to `<head>`
- [ ] Select the layers needed from the project-type matrix above
- [ ] For Python-heavy pages: call `UAE.python.load()` early (async, lazy)
- [ ] For WASM modules: place `.wasm` files under `/wasm/` and load via `UAE.wasm.load()`
- [ ] For Web3 pages: add wallet-detection UI using `UAE.web3.detectWallet()`

---

## Security Notes

- Python runs in Pyodide's sandboxed WASM environment — no native code execution
- WASM modules are fetched over HTTPS only
- IndexedDB data is origin-scoped — cannot be read cross-origin
- Wallet private keys are never exposed; only the public key is stored
- No secrets are committed to the repository — all sensitive values use environment variables or are read from `/backend/pat` at runtime

---

## Pump.fun Ecosystem

Every tool completed with the five-layer automation engine should have a corresponding
pump.fun coin created via `PumpFunCoinCreator` (see `src/systems/pumpfun-ecosystem-config.js`).

- Referral: <https://refer.pump.fun/DiamondBoi>
- Onboarding: <https://join.pump.fun/HSag/ko3gg0x0>
- Vault wallet: `6HTjfgWZYMbENnMAJJFhxWR2VZDxdze3qV7zznSAsfk`

---

*© 2008-2026 Ryan Barbrick (Barbrick Design). All Rights Reserved.*
