A modern, static-first, modular web application with serverless P2P communication capabilities built entirely with browser-native WebRTC APIs. Features rich markdown documentation viewing, LaTeX math rendering, Mermaid diagrams, interactive games, and zero-dependency peer-to-peer networking.
- Zero Dependencies: Pure WebRTC APIs - no external servers or CDNs required
- Browser-Native: Direct peer-to-peer connections without signaling infrastructure
- Manual Invitation Exchange: URL/QR code-based peer discovery (truly serverless)
- Cross-Device Support: Connect phones, tablets, and computers on local network
- End-to-End Encryption: WebRTC provides transport encryption (DTLS)
- Privacy-First: No central servers tracking connections
- Full Markdown Support: Headers, lists, tables, code blocks, images, and links
- LaTeX Math Rendering: Mathematical equations using KaTeX (Obsidian-compatible)
- Mermaid Diagrams: Flowcharts, sequence diagrams, class diagrams, and more
- Syntax Highlighting: Code blocks with language-specific highlighting
- 3D Visualization: Interactive 3D object rendering using Three.js and Anime.js by the MCard Manager
- Bali Adventure: Explore the Ubud Rice Terraces in a React-based 2D RPG (
public/examples/games/play_ubud.html) - 3D Theater: High-fidelity 3D visualization engine for viewing complex data structures
- Music Visualizer V5: Interactive music notation with 3D frequency visualization, Web Workers, and FileLoader caching (
public/examples/Music/SyncedMusicVisualizerV5.html) - Morphism Cube: Category theory recursion schemes visualized in 3D (
public/examples/3DGames/MorphismCube/) - 3D Object Viewer: A dedicated 3D model viewer (Git Submodule) located at
public/examples/3DGames/3DObjectViewer. Ensure submodules are initialized to use this feature.
- Integrated AI Assistance: Access external AI tools like ChatGPT, Claude, and Gemini directly within the interface.
- Microphone Support: Enabled
microphonepermission for iframe integrations, allowing voice interaction with supported chatbots. - Smart Fallback: Automatically provides a direct link button for services that block iframe embedding (e.g., ChatGPT, Claude), ensuring users can always access their tools.
- MCard Manager: Advanced card management with IndexedDB persistence, handle support (
@welcome), and Duplications detection (v11+). - Modular HTML:
index.htmllogic is fully modularized into dedicated ESM-ready scripts (public/js/pwa-init.js,ui-inline-handlers.js, etc.) while preserving external interfaces. - Auth-Gated CSP: Production-ready Content Security Policy that defaults to strict rules and only enables
unsafe-eval(required for Pyodide) after secure authentication (HttpOnly cookie). - Hybrid Execution: Configurable CLM execution strategies (
auto,browser,server) to balance performance and security.
The system supports three execution modes for Cubical Logic Models:
- Auto (Default): Intelligently selects the best runtime. Prefers local browser execution via Pyodide/WebWorkers for privacy and offline support, falling back to server execution if resources are constrained.
- Browser (Local): Forces client-side execution using
mcard-jsand Pyodide. Fully offline-capable but requiresunsafe-eval(auth-gated). - Server (Remote): Offloads execution to the
/api/clm/executeendpoint. Useful for low-power devices or when strict CSP blocks WASM/eval.
- Smart Detection: Detects duplicate-type MCards (
{"type": "duplicate"}) viaBrowserContentTypeDetector. - Batch Operations: Quick removal of all duplicate entries to maintain a clean knowledge container.
- Sidebar Integration: Real-time count of duplicates with a distinct UI badge.
This project is built on the Cubic Logic Model (CLM) - 三套東西 (Three Sets) principle. Every component, test, and feature follows the CLM structure:
The entire project is served and run through mcard-js, providing:
| Server | Port | Purpose |
|---|---|---|
| Node WebSocket Server | 3001 | HTTP + WebSocket + API endpoints (Configurable via .env) |
| Express Static Server | 3001 | Serves all static files and CLM components |
| MCard Dev Server | 4000 | Configurable dev server via mcard-js |
# Start the unified server (HTTP + WebSocket + CLM APIs)
node ws-server.js # Serves on port 3000
# Start MCard-managed server (Integrated with serve.yaml)
./start-mcard-server.sh # Default port 4000Every CLM component follows the Abstract → Concrete → Balanced pattern:
# Example from clm-registry.yaml
- hash: "youtube-viewer"
name: "YouTube Video Viewer"
abstract:
context: "Video content presentation"
goal: "Embed and control YouTube playback"
concrete:
implementation: "components/youtube-viewer.html"
sandbox: "allow-scripts allow-same-origin"
balanced:
metrics_endpoint: "/metrics/youtube-viewer"
expected_load_time_ms: 800All tests are organized using CLM principles:
| Test Category | Purpose | CLM Alignment |
|---|---|---|
Smoke Tests (tests/smoke/) |
Fast navigation validation | Abstract (goal verification) |
Component Tests (tests/components/) |
Isolated component testing | Concrete (implementation) |
Feature Tests (tests/features/) |
Deep feature validation | Balanced (metrics & outcomes) |
# Run tests by CLM category
npm run test:smoke # Abstract - Does it load correctly?
npm run test:components # Concrete - Does the implementation work?
npm run test:features # Balanced - Does it meet performance metrics?The CLM Dashboard (/archive/html/index-clm-dashboard.html) provides:
- Registry Browser: View all registered CLM components
- Component Isolation: Each component runs in its own iframe
- Failure Containment: Crashing components don't affect others
- Performance Metrics: Real-time component load time monitoring
| Endpoint | Purpose |
|---|---|
GET /api/clm/registry |
Returns all registered CLM components |
GET /api/clm/component/:id |
Returns specific component configuration |
GET /api/clm/health/:id |
Health check for component |
POST /api/clm/telemetry |
Receives component telemetry data |
The PKC Landing Page isn't just a website; it's a resilient execution environment. By adopting the Cubic Logic Model (CLM), the project moves away from monolithic web design toward a "Micro-Frontend of Functions." Each component is treated as a mathematical transformation f(goal, process) → output. Isolation via iframes ensures that the "blast radius" of any specific failure (e.g., a heavy 3D game or a buggy external integration) is strictly limited, preserving the integrity of the host container.
The pivot from libp2p to a native WebRTC serverless model represents a critical realization: true decentralization requires removing even the "hidden" centralization of bootstrap nodes. By leveraging manual invitation exchanges (URL/QR), PKC establishes a trust-based, zero-infrastructure network that thrives on local connectivity without sacrificing privacy.
The integration of mcard-js transforms the browser from a simple viewer into a professional knowledge manager. The hybrid detection system in BrowserContentTypeDetector.js bridges the gap between structured JSON data and binary media, allowing the container to "understand" its contents rather than just "storing" them. This creates a foundation for Semantic Knowledge Containers where the data defines the UI.
The system is currently transitioning from a passive listener (basic indexing) to an active organizer (as seen in the Duplications Category). Future phases involving CRDT-based state synchronization and Gossip protocols will further solidify PKC as a robust alternative to centralized cloud silos.
- ✅ No Bootstrap Servers - Uses STUN only for NAT traversal
- ✅ No Signaling Servers - Manual invitation exchange via URL/QR
- ✅ No External Dependencies - Pure browser WebRTC APIs
- ✅ Zero Infrastructure - Works offline between local peers
- ✅ Privacy Preserving - No central tracking or data collection
1. Peer A → Create Invitation (generates offer + ICE candidates)
2. Manual Exchange → Share invitation URL via QR code, messaging, email
3. Peer B → Accept Invitation (generates answer)
4. Manual Exchange → Send answer back to Peer A
5. Peer A → Complete Connection (apply answer)
6. ✅ Direct P2P connection established
- Bundle Size: 20KB (vs 500KB+ for libp2p alternatives)
- Connection Time: 2-5 seconds (direct WebRTC)
- Message Latency: 10-50ms between connected peers
- Max Peers: 8 concurrent connections (recommended)
- Browser Support: Chrome 56+, Firefox 44+, Safari 11+
The project includes a high-performance 3D visualization engine for viewing complex data structures and models.
- Interactive Theater: A dedicated environment for 3D object interaction (
public/examples/THREEJS_ANIMEJS/Theater_Example.html) - Advanced Modeling: High-fidelity representations including the Causal Cone (spacetime structure) and PKC Box within a Crystal Ball (nested transparency).
- Data-Driven Objects: 3D objects defined in JSON files (
data/objects/) for easy extensibility - Real Satellite Textures: Earth with 2K satellite imagery from Solar System Scope
- Modular ESM Architecture: Cleanly separated logic for scenes, objects, animations, and UI with built-in cache management.
- Synthesized Audio: Procedural MIDI-like music generated in real-time using Tone.js
- Offline Support: All vendor libraries (Three.js, Anime.js, Tone.js) hosted locally in
/js/vendor/ - Dynamic Lighting: Interactive lighting presets (Neon, Sunset, Studio)
- High Performance: Optimized using Three.js R147 with WebGL acceleration
📁 Project Structure
LandingPage/
├── index.html # Entry point (modularized)
├── ws-server.js # Unified WebSocket + Static Backend
├── js/ # Core Application Logic
│ ├── pkc-core.js # Module Loader
│ ├── execution/ # Execution Mode Managers
│ ├── renderers/ # CLM & UI Renderers
│ └── modules/ # Feature Modules (Markdown, P2P)
├── public/ # Static Assets & Runtime Scripts
│ ├── js/ # Modular App Scripts (ESM)
│ │ ├── app-bootstrap.js # App Init
│ │ ├── mcard/ # MCard Logical Layer
│ │ └── ViewManager.js # View Routing Logic
│ ├── examples/ # Interactive Demos (Games, Vis)
│ └── data/ # Data artifacts
├── bmad/ # BMAD Architecture components
├── components/ # HTML implementation of CLMs
├── routes/ # Server-side routes (if strictly needed)
├── docs/ # Project Documentation
└── tests/ # Playwright E2E Tests
The structure follows a "Static Core, Dynamic Modules" philosophy:
js/: Contains the "System Code" - the unchanging logic that powers the container.public/js/: Contains "Application Code" - the logic that defines specific behaviors and UI interactions.public/examples/&data/: Content that is rendered by the system.components/: Concrete HTML/JS implementations of Abstract CLM goals.
This project uses Git submodules to manage large external components.
- 3DObjectViewer: Located at
public/examples/3DGames/3DObjectViewer. This is a standalone project maintained atgithub.com/xlp0/3DObjectViewerand included here to provide advanced 3D model viewing capabilities without bloating the main repository history.
# Clone repository with submodules (recommended)
git clone --recursive https://github.com/xlp0/LandingPage.git
cd LandingPage
# If you already cloned without --recursive:
# git submodule update --init --recursive
# Start MCard HTTP server with mcard-js integration (recommended)
./start-mcard-server.sh
# Or use Python HTTP server (basic features only)
python3 -m http.server 8000 --bind 0.0.0.0
# Or for local network access (all devices on WiFi)
python3 -m http.server 8000 --bind 0.0.0.0- Landing Page:
http://localhost:4000(with mcard-js) orhttp://localhost:8000(Python) - MCard Manager:
http://localhost:4000/index.html- Main interface with Apps navigation - Apps Navigation: Click "Apps" in sidebar to access:
- Calendar, Map, 3D Viewer
- Music Visualizer V5
- Morphism Cube v1 & v2
- P2P Demo:
http://localhost:8000/js/modules/p2p-serverless/example.html - Bali Adventure:
http://localhost:8000/public/examples/games/play_ubud.html - Documentation:
http://localhost:8000/pkc-docs-index.html
- Open P2P demo on two devices (same WiFi network)
- Device 1: Click "Create Invitation" → Copy invitation code
- Device 2: Click "Accept Invitation" → Paste code → Copy answer
- Device 1: Click "Complete Connection" → Paste answer
- ✅ Connected! Send messages between devices instantly
The application reads runtime settings from /app-config.json. Use this file to configure WebRTC/P2P and other app knobs without changing code.
Example:
{
"wsHost": "192.168.1.139",
"wsPort": 3001,
"wsPath": "/ws/",
"p2p": {
"iceServers": [
{ "urls": "stun:stun.l.google.com:19302" },
{ "urls": "stun:stun1.l.google.com:19302" }
]
}
}How it’s loaded:
js/modules/p2p-serverless/config.jsfetches/app-config.json(no-cache) and resolves effective config viaresolveP2PConfig().- Precedence (highest first): module init overrides →
app-config.json→ built‑in defaults. - Add TURN servers here if your environment requires relaying.
See also:
js/modules/p2p-serverless/README.md(module-level details)tests/README.md(why config matters for e2e)
{
"modules": [
{
"id": "p2p-serverless",
"entry": "/js/modules/p2p-serverless/index.js",
"enabled": true,
"when": "webrtc",
"config": {
"iceServers": [ /* optional override; prefer app-config.json */ ],
"channelName": "pkc-p2p-discovery",
"invitationTTL": 300000
}
}
]
}webrtc: WebRTC support (required for P2P)websocket: WebSocket support (optional)storage.idb: IndexedDB support (optional)
# Python (recommended for development)
python3 -m http.server 8000 --bind 0.0.0.0
# Node.js
npx serve . -p 8000
# PHP (built-in)
php -S localhost:8000- Static Hosting: GitHub Pages, Netlify, Vercel, S3
- CDN: Cloudflare, Fastly
- Traditional: Nginx, Apache, IIS
# Allow all network interfaces
python3 -m http.server 8000 --bind 0.0.0.0
# Access from other devices: http://YOUR_LOCAL_IP:8000The MCard system has been rebuilt to rely on the robust mcard-js library for core operations while upgrading specific browser behaviors:
MCardManager.js: Now orchestrated viamcard-js'sCardCollectionandIndexedDBEngine, ensuring reliable persistence and querying.BrowserContentTypeDetector.js: A hybrid detection system that combines library-standard MIME detection with a custom "Expanded Binary" detector for audio/video formats (MP4, FLAC, MKV, etc.) and specific CLM text patterns.- Handle Support: Native support for friendly names (
@welcome,@readme) alongside content-addressed hashes.
The MCard Manager ships with a small set of demo/default cards that are loaded from static files rather than being embedded (hard-coded) inside JavaScript.
The single source of truth for what gets imported (manifest + directory scans) is:
public/js/mcard/DemoMCardImportSources.js
By default, it imports from:
public/data/demo/manifest.json(curated demo items + their@handlenames)public/data/(recursive scan for additional content)public/assets/videos/(video scan for default video MCards)
This approach is intentionally preferred over keeping demo data as hard-coded strings/blobs in JavaScript because it:
- Keeps content separate from code (easier review and iteration)
- Avoids code churn when demo content changes
- Makes it easy to add/replace demo content by dropping files into
public/and adjusting the central import config - Works naturally with static hosting/CDNs and browser caching
Overrides:
MCARD_DEMO_IMPORT_SOURCES(JSON array) can override the default sources.- In localhost development,
DemoMCardImportSources.jswill attempt to read it from/.env. - In production/static hosting, prefer setting it via
app-config.jsonasmcardDemoImportSources.
- In localhost development,
Notes:
- Manifest paths are resolved under
/public/(for exampledata/demo/welcome.mdmaps to/public/data/demo/welcome.md). - The demo includes a
@pkc-box-demoasset using.webp. WebP is treated as an image in the UI; if the WebP is animated, it will animate as an animated image when rendered in the browser.
// Get P2P module
const p2p = await window.pkc.modules['p2p-serverless'];
// Create invitation
const invitation = await p2p.createInvitation();
console.log('Share this URL:', invitation.url);
// Accept invitation (from another peer)
await p2p.acceptInvitation(invitationUrl);
// Send messages
p2p.broadcast({ type: 'chat', message: 'Hello everyone!' });
// Listen for messages
p2p.onMessage(({ peerId, data }) => {
console.log('Message from', peerId, ':', data);
});- Navigate to
pkc-docs-index.html - Click any document card
- View rich markdown with LaTeX math and Mermaid diagrams
- Use "Back to Index" to return
Obsidian-compatible LaTeX syntax:
Einstein's formula: $E = mc^2$$$
\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right) \times V
$$- Greek letters:
$\alpha, \beta, \gamma$ - Fractions:
$\frac{a}{b}$ - Integrals:
$\int_0^\infty f(x) dx$ - Matrices:
$\begin{bmatrix} a & b \\ c & d \end{bmatrix}$
All Mermaid diagram types supported:
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Process]
B -->|No| D[End]
C --> D
| Feature | PKC Serverless | Traditional P2P | Client-Server |
|---|---|---|---|
| Server Dependencies | ❌ Zero | ❌ Zero | ✅ Required |
| External Libraries | ❌ Zero | ✅ Many | ✅ Many |
| Bundle Size | 20KB | 500KB+ | N/A |
| Connection Setup | Manual | DHT/Auto | N/A |
| Privacy | ✅ High | ❌ Low | |
| Offline Support | ✅ Full | ✅ Full | ❌ None |
| Infrastructure Cost | $0 | $0 | $$$ |
| Complexity | Low | High | High |
- ✅ Chrome/Edge 56+ (full support)
- ✅ Firefox 44+ (full support)
- ✅ Safari 11+ (full support)
⚠️ Mobile Safari (works, some limitations)
- ✅ Chrome/Edge (recommended)
- ✅ Firefox
- ✅ Safari
- ✅ Opera
docs/architecture-serverless-p2p.md- Complete system architecturedocs/p2p-serverless-implementation.md- Implementation detailsdocs/p2p-testing-guide.md- Testing instructionsjs/modules/p2p-serverless/README.md- API reference
PKC-DOCS-README.md- Comprehensive project documentationMODULES.md- Module system guideLATEX-SUPPORT-SUMMARY.md- LaTeX implementation details
docs/archive/p2p-libp2p-old-2025-11-07/- Previous libp2p implementationdocs/cleanup-libp2p-migration.md- Migration documentation
- The P2P system is modular and extensible
- See
js/modules/p2p-serverless/README.mdfor API details - Test changes using the provided example pages
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly (especially P2P functionality)
- Submit a pull request
- Lines of Code: ~4,500+ lines (including docs + new game examples)
- Modules: 3 active (markdown-renderer, net-gateway, p2p-serverless)
- P2P Bundle Size: 20KB (uncompressed)
- Libraries: Pure browser APIs (WebRTC, BroadcastChannel, etc.)
- Browser Support: Modern browsers (2016+)
- Server Options: 4+ (Python, Node.js, Nginx, IIS, static hosting)
- Documentation: 1,800+ lines across 8 docs
- Automated Tests: P2P Connectivity, Music Visualizer, Landing Page Features (Playwright)
- Last Updated: January 2026
# Start server
python3 -m http.server 8000 --bind 0.0.0.0
# Access from any device on your network:
# Landing Page: http://YOUR_LOCAL_IP:8000
# P2P Demo: http://YOUR_LOCAL_IP:8000/js/modules/p2p-serverless/example.html
# Bali Game: http://YOUR_LOCAL_IP:8000/public/examples/games/play_ubud.html- Open demo on two devices (phone + computer)
- Connect using invitation codes
- Send messages between devices
- Experience true peer-to-peer communication!
- Transport Encryption: WebRTC DTLS encryption
- No Central Servers: No single point of failure or tracking
- Manual Peer Verification: Users control who they connect to
- Privacy-First: No telemetry or external data collection
- HTTPS Recommended: Required for full WebRTC functionality
- CSP Headers: Security headers configured in nginx
- No External Dependencies: Reduces attack surface
- Static Content: No server-side processing
The project includes a comprehensive Playwright E2E test suite.
# Start WebSocket server (required)
node ws-server.js
# Run all tests
npx playwright test --project=chromium
# Run CLM Dashboard tests only
npx playwright test tests/test-clm-*.spec.cjs --project=chromium
# View HTML report
npx playwright show-report| Category | Tests | Description |
|---|---|---|
| CLM Dashboard | 18+ | Component loading, iframe isolation, performance |
| Landing Page | 6 | PWA modal, sidebar, app views, chat panel |
| Music Visualizer | 5+ | Audio playback, sync, timer display |
For detailed test documentation including:
- Complete test file reference
- Selector patterns and wait strategies
- Recent fixes and technical details
- Contribution guidelines
See tests/TEST_DOCUMENTATION.md
This project is provided as-is for exploring PKC design concepts and serverless P2P communication.
- Serverless P2P foundation
- WebRTC connection management
- Manual invitation exchange
- Basic messaging
- Documentation and testing
- Multi-peer topologies
- Gossip protocol routing
- Automatic peer discovery
- Network optimization
- CRDT integration
- Shared document editing
- Conflict resolution
- Persistence layers
- End-to-end encryption
- Peer authentication
- Message signing
- Rate limiting
- Fixed Apps dropdown in CardTypes sidebar - The Apps category dropdown was not responding to clicks. Root cause:
viewManagersingleton was created but not exposed towindow, causingwindow.viewManager.toggleSubmenu('apps')to fail silently. Fix: Addedwindow.viewManager = viewManager;inpublic/js/ViewManager.js. - Removed Hardcoded WebSocket Port - Replaced legacy hardcoded port
5321inServerCLMRunner.jswith dynamic port detection (window.location.port), defaulting to3000. This ensures the client correctly connects to the actual server port (e.g.,3001in dev) instead of failing to connect to a non-existent service.
Built with ❤️ for decentralized communication and personal knowledge management
PKC Landing Page - Where static meets dynamic, and centralized meets decentralized.