This module provides the backend infrastructure for api-ape's WebSocket-based Remote Procedure Events (RPE) system. It transforms standard HTTP servers into real-time API servers with automatic controller routing.
- Multi-runtime support — Code must work on Node.js, Bun, and Deno; use runtime detection via
lib/wsProvider.js - Zero dependencies — Avoid external packages; use built-in WebSocket polyfill when native unavailable
- JSS encoding — Always use
utils/jssfor message serialization to preserve extended types - Controller context — Controllers receive
thiscontext withclientId,broadcast,send, and embedded data - Binary transfers — Use the tag system (
<!B>,<!A>,<!F>) for file handling
server/
├── index.js # Entry point (exports lib/main)
├── client/ # Server-side client (index.js + connection management)
├── lib/ # Core server implementation
├── plugins/ # Binary data handling plugins
├── adapters/ # 🌲 Forest distributed mesh adapters
├── socket/ # WebSocket message handlers
├── security/ # Origin validation & CSRF protection
└── utils/ # Server utilities
Main entry point that re-exports the ape initializer from lib/main.js. This is what users get when they require('api-ape') or import { ape } from 'api-ape'.
Server-side WebSocket client module for outbound connections. Contains the main client (index.js) and connection management. See client/files.md.
Core server implementation including initialization, controller loading, broadcasting, and WebSocket handling. See lib/files.md.
Binary data handling utilities. See plugins/files.md.
Database adapters for the Forest distributed mesh system (Redis, MongoDB, PostgreSQL, Supabase, Firebase). See adapters/files.md.
WebSocket message handlers for connection validation, incoming message processing, and response serialization. See socket/files.md.
Origin validation and CSRF protection for WebSocket connections. See security/files.md.
Server utilities including controller loading, ID generation, and User-Agent parsing. See utils/files.md.