Developed by @7etsuo
Join our community on Discord!
- Introduction
- Framework Overview
- Project Structure
- Backend Components
- Frontend Setup
- WebAssembly Integration
- API Reference
- Authentication
- Database Integration
- WebSocket Functionality
- Deployment Guide
- Troubleshooting
- Contributing
WebForge is a robust web application framework designed to seamlessly integrate WebAssembly modules with a full-stack JavaScript environment. It provides a solid foundation for building high-performance web applications that leverage the power of WebAssembly while maintaining the flexibility and ease of use of modern web technologies.
WebForge consists of three main components:
- Backend: A Node.js server using Express.js
- Frontend: A React-based client application
- WebAssembly: C/C++ code compiled to WebAssembly modules
Key features:
- RESTful API for WebAssembly module management
- JWT-based authentication
- Real-time updates via WebSockets
- MongoDB integration for data persistence
- Modular architecture for easy customization and extension
/WebForge
├── backend/
│ ├── src/
│ │ ├── config/
│ │ ├── controllers/
│ │ ├── middleware/
│ │ ├── models/
│ │ ├── routes/
│ │ ├── services/
│ │ └── utils/
│ ├── tests/
│ ├── .env
│ ├── package.json
│ └── server.js
├── frontend/
│ ├── public/
│ ├── src/
│ ├── package.json
│ └── README.md
├── wasm/
│ ├── src/
│ ├── build/
│ └── compile-wasm.sh
├── .gitignore
└── README.md
The main entry point for the backend server. It sets up Express.js, middleware, and starts the HTTP server.
Contains configuration settings loaded from environment variables.
Contains logic for handling API requests:
authController.js
: Manages user authenticationwasmController.js
: Handles WebAssembly module operations
Custom middleware functions:
authMiddleware.js
: Verifies JWT tokens for protected routeserrorHandler.js
: Global error handlingvalidateRequest.js
: Input validation using Joi
Mongoose models for MongoDB:
User.js
: User account schemaRefreshToken.js
: Refresh token schemaWebAssemblyModule.js
: WebAssembly module metadata schema
Defines API endpoints and links them to controller functions.
wasmService.js
: Business logic for WebAssembly module operationswsHandler.js
: WebSocket message handling
Utility functions and helpers:
logger.js
: Logging utility using Winston
(Note: The frontend is not fully implemented in the current version. This section provides a guide for setting it up.)
- Navigate to the
frontend
directory - Install dependencies:
npm install
- Start the development server:
npm start
The frontend should be built using React and should interact with the backend API for authentication and WebAssembly module management.
- Place your C/C++ source files in the
wasm/src/
directory - Use the
compile-wasm.sh
script to compile your code:./wasm/compile-wasm.sh your_file.c
- The compiled
.wasm
file will be placed inwasm/build/
Use the /api/wasm/modules
POST endpoint to upload a new module:
const response = await fetch('/api/wasm/modules', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
},
body: JSON.stringify({
name: 'module_name',
content: 'base64_encoded_wasm_binary'
})
});
-
Fetch the module:
const response = await fetch('/api/wasm/modules/module_name'); const wasmBinary = await response.arrayBuffer();
-
Instantiate the module:
const wasmModule = await WebAssembly.instantiate(wasmBinary);
-
Call exported functions:
const result = wasmModule.instance.exports.your_function(args);
POST /api/register
: Register a new userPOST /api/login
: Authenticate and receive JWT tokensPOST /api/token
: Refresh access tokenDELETE /api/logout
: Invalidate refresh token
GET /api/wasm/modules
: List all modulesGET /api/wasm/modules/:name
: Get a specific modulePOST /api/wasm/modules
: Create a new modulePUT /api/wasm/modules/:name
: Update an existing module
WebForge uses JWT for authentication. After logging in, you'll receive an access token and a refresh token. Include the access token in the Authorization header for protected routes:
Authorization: Bearer YOUR_ACCESS_TOKEN
WebForge uses MongoDB for data persistence. Ensure you have MongoDB installed and running, then update the MONGO_URI
in your .env
file.
WebForge includes WebSocket support for real-time updates. Connect to the WebSocket server and listen for events:
const socket = new WebSocket('ws://your-server-url');
socket.onmessage = (event) => {
console.log('Received:', event.data);
};
- Set up a MongoDB database (e.g., MongoDB Atlas)
- Configure environment variables for production
- Build the frontend:
cd frontend && npm run build
- Deploy the backend to a Node.js hosting service (e.g., Heroku, DigitalOcean)
- Serve the frontend build directory as static files or deploy to a CDN
- Ensure all dependencies are installed:
npm install
in bothbackend/
andfrontend/
- Check MongoDB connection string in
.env
- Verify that WebAssembly modules are correctly compiled and accessible
Contributions to WebForge are welcome! Please refer to the CONTRIBUTING.md
file (if available) for guidelines on how to contribute to the project.
For more detailed information or specific inquiries, please refer to the inline documentation in each file or reach out to the project maintainers.