A step-by-step learning environment for WebAssembly (WASM) and PostgreSQL connections. This project is designed to help understand the integration between WASM, WebSockets, and PostgreSQL through hands-on implementation.
├── src/
│ ├── database/ # PostgreSQL client and operations
│ ├── websocket/ # WebSocket server and client
│ ├── wasm/ # WASM module loading utilities
│ ├── integration/ # WASM-WebSocket-Database bridge
│ └── index.ts # Main entry point
├── tests/ # Test files
├── scripts/ # Setup and utility scripts
├── wasm/ # Rust WASM module (to be created)
└── examples/ # Example applications (to be created)
- Node.js (v18 or higher)
- Docker and Docker Compose
- Rust (for WASM module development)
-
Install dependencies:
npm install
-
Set up environment:
cp .env.example .env
-
Start PostgreSQL database:
./scripts/setup-db.sh
-
Run tests:
npm test -
Build the project:
npm run build
This project follows a structured learning approach:
- Database Foundation - Learn PostgreSQL operations and connection patterns
- WebSocket Communication - Understand real-time bidirectional communication
- WASM Basics - Create and load WebAssembly modules
- Integration - Connect all components into a working system
npm run dev- Run development servernpm run build- Build TypeScript to JavaScriptnpm test- Run all testsnpm run test:watch- Run tests in watch modenpm run clean- Clean build artifacts
- Start database:
docker compose up -d postgres - Stop database:
docker compose down - Connect to database:
docker compose exec postgres psql -U postgres -d wasm_learning - View logs:
docker compose logs postgres
By completing this project, you will learn:
- PostgreSQL connection patterns and query execution
- WebSocket server implementation and client communication
- WebAssembly compilation, loading, and JavaScript interoperability
- System integration and error handling
- Testing strategies for distributed systems
This project now includes advanced production-ready features:
- Connection Pooling: Efficient database connection management
- Query Result Caching: Intelligent caching with TTL and LRU eviction
- Performance Monitoring: Real-time metrics and slow query detection
- Memory Management: Automatic cleanup and resource optimization
- Authentication: JWT tokens, API keys, username/password
- Authorization: Role-based access control (admin, user, readonly)
- Input Validation: SQL injection prevention and XSS protection
- Rate Limiting: Request throttling and DoS protection
- Audit Logging: Comprehensive security event logging
- Step-by-step Tutorial: Complete learning guide (
docs/TUTORIAL.md) - Security Best Practices: Production security guide (
docs/SECURITY.md) - Troubleshooting Guide: Common issues and solutions (
docs/TROUBLESHOOTING.md) - Interactive Examples: Performance monitoring and security demos
Try the advanced features:
# Performance monitoring demo
npx ts-node examples/performance-monitoring-demo.ts
# Security features demo
npx ts-node examples/security-demo.ts
# Interactive database playground
npx ts-node examples/security-demo.ts --websocket
open examples/database-playground.htmlMIT License - see LICENSE file for details.