baraqex 1.0.74 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/README.md +272 -472
- package/bin/baraqex.js +150 -12
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2319 -205
- package/dist/browser.js.map +4 -4
- package/dist/core/batch.d.ts +10 -0
- package/dist/core/batch.d.ts.map +1 -0
- package/dist/core/component.d.ts +69 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/context.d.ts +22 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/errors.d.ts +125 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/event-bus.d.ts +29 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/forms.d.ts +128 -0
- package/dist/core/forms.d.ts.map +1 -0
- package/dist/core/hooks.d.ts +84 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/index.d.ts +23 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/jsx-runtime.d.ts +45 -0
- package/dist/core/jsx-runtime.d.ts.map +1 -0
- package/dist/core/lifecycle-events.d.ts +71 -0
- package/dist/core/lifecycle-events.d.ts.map +1 -0
- package/dist/core/renderer.d.ts +39 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/router.d.ts +108 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/server-renderer.d.ts +26 -0
- package/dist/core/server-renderer.d.ts.map +1 -0
- package/dist/core/store.d.ts +102 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/types.d.ts +66 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/utils.d.ts +153 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/vdom.d.ts +29 -0
- package/dist/core/vdom.d.ts.map +1 -0
- package/dist/index.d.ts +39 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2592 -508
- package/dist/index.js.map +4 -4
- package/dist/server/auth.d.ts +8 -3
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +173 -112
- package/dist/server/index.js.map +4 -4
- package/dist/server/middleware.d.ts +10 -1
- package/dist/server/middleware.d.ts.map +1 -1
- package/package.json +224 -124
- package/templates/basic-app/src/main.jsx +336 -0
- package/templates/complete-app/api/hello.js +0 -0
- package/templates/complete-app/client.js +58 -0
- package/templates/complete-app/lib/frontend-hamroun.js +182 -0
- package/templates/complete-app/package.json +18 -0
- package/templates/complete-app/pages/about.js +119 -0
- package/templates/complete-app/pages/about.jsx +0 -0
- package/templates/complete-app/pages/index.js +157 -0
- package/templates/complete-app/pages/index.jsx +0 -0
- package/templates/complete-app/pages/wasm-demo.js +290 -0
- package/templates/complete-app/pages/wasm-demo.jsx +0 -0
- package/templates/complete-app/public/client.js +89 -0
- package/templates/complete-app/public/index.html +118 -0
- package/templates/complete-app/public/styles.css +76 -0
- package/templates/complete-app/readme.md +188 -0
- package/templates/complete-app/server.js +226 -0
- package/templates/complete-app/server.ts +275 -0
- package/templates/complete-app/src/App.tsx +59 -0
- package/templates/complete-app/src/client.ts +61 -0
- package/templates/complete-app/src/client.tsx +18 -0
- package/templates/complete-app/src/pages/index.tsx +51 -0
- package/templates/complete-app/src/server.ts +218 -0
- package/templates/complete-app/tsconfig.json +22 -0
- package/templates/complete-app/tsconfig.server.json +19 -0
- package/templates/complete-app/vite.config.js +57 -0
- package/templates/complete-app/vite.config.ts +30 -0
- package/templates/complete-app/wasm/build.bat +0 -0
- package/templates/complete-app/wasm/build.sh +0 -0
- package/templates/complete-app/wasm/example.go +0 -0
- package/templates/fullstack-app/README.md +37 -0
- package/templates/fullstack-app/api/hello.js +11 -0
- package/templates/fullstack-app/api/hello.ts +18 -0
- package/templates/fullstack-app/api/users/[id].ts +73 -0
- package/templates/fullstack-app/api/users/index.ts +32 -0
- package/templates/fullstack-app/build/main.css +874 -0
- package/templates/fullstack-app/build/main.css.map +7 -0
- package/templates/fullstack-app/build/main.js +967 -0
- package/templates/fullstack-app/build/main.js.map +7 -0
- package/templates/fullstack-app/build.ts +210 -0
- package/templates/fullstack-app/index.html +36 -0
- package/templates/fullstack-app/package.json +35 -0
- package/templates/fullstack-app/postcss.config.js +6 -0
- package/templates/fullstack-app/process-tailwind.js +45 -0
- package/templates/fullstack-app/public/_redirects +1 -0
- package/templates/fullstack-app/public/route-handler.js +47 -0
- package/templates/fullstack-app/public/spa-fix.html +17 -0
- package/templates/fullstack-app/public/styles.css +975 -0
- package/templates/fullstack-app/public/tailwind.css +15 -0
- package/templates/fullstack-app/server.js +267 -0
- package/templates/fullstack-app/server.ts +474 -0
- package/templates/fullstack-app/src/README.md +55 -0
- package/templates/fullstack-app/src/client.js +87 -0
- package/templates/fullstack-app/src/components/ClientHome.tsx +0 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.tsx +36 -0
- package/templates/fullstack-app/src/components/Layout.tsx +42 -0
- package/templates/fullstack-app/src/components/StateDemo.tsx +207 -0
- package/templates/fullstack-app/src/components/UserList.tsx +44 -0
- package/templates/fullstack-app/src/config.ts +42 -0
- package/templates/fullstack-app/src/data/api.ts +206 -0
- package/templates/fullstack-app/src/main.tsx +155 -0
- package/templates/fullstack-app/src/middleware.ts +28 -0
- package/templates/fullstack-app/src/pages/404.tsx +28 -0
- package/templates/fullstack-app/src/pages/[id].tsx +0 -0
- package/templates/fullstack-app/src/pages/_app.tsx +11 -0
- package/templates/fullstack-app/src/pages/_document.tsx +25 -0
- package/templates/fullstack-app/src/pages/_error.tsx +45 -0
- package/templates/fullstack-app/src/pages/about/index.tsx +67 -0
- package/templates/fullstack-app/src/pages/about.tsx +71 -0
- package/templates/fullstack-app/src/pages/api/users/[id].ts +73 -0
- package/templates/fullstack-app/src/pages/api/users/index.ts +43 -0
- package/templates/fullstack-app/src/pages/index.tsx +110 -0
- package/templates/fullstack-app/src/pages/users/[id].tsx +153 -0
- package/templates/fullstack-app/src/pages/users.tsx +60 -0
- package/templates/fullstack-app/src/pages/wasm-demo.tsx +1 -0
- package/templates/fullstack-app/src/router.ts +255 -0
- package/templates/fullstack-app/src/styles.css +5 -0
- package/templates/fullstack-app/tailwind.config.js +11 -0
- package/templates/fullstack-app/tsconfig.json +18 -0
- package/templates/fullstack-app/vite.config.js +87 -0
- package/templates/go/build.bat +36 -0
- package/templates/go/build.sh +43 -0
- package/templates/go/example.go +205 -0
- package/templates/go-wasm-app/README.md +38 -0
- package/templates/go-wasm-app/babel.config.js +21 -0
- package/templates/go-wasm-app/build-client.js +49 -0
- package/templates/go-wasm-app/build-wasm.js +237 -0
- package/templates/go-wasm-app/build.config.js +62 -0
- package/templates/go-wasm-app/build.js +218 -0
- package/templates/go-wasm-app/package.json +32 -0
- package/templates/go-wasm-app/public/index.html +128 -0
- package/templates/go-wasm-app/public/styles.css +197 -0
- package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
- package/templates/go-wasm-app/public/wasm/wasm_exec.js +561 -0
- package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +39 -0
- package/templates/go-wasm-app/server.js +70 -0
- package/templates/go-wasm-app/src/App.jsx +38 -0
- package/templates/go-wasm-app/src/app.js +173 -0
- package/templates/go-wasm-app/src/client.js +57 -0
- package/templates/go-wasm-app/src/components/Footer.jsx +13 -0
- package/templates/go-wasm-app/src/components/Header.jsx +19 -0
- package/templates/go-wasm-app/src/components/WasmDemo.jsx +120 -0
- package/templates/go-wasm-app/src/main.jsx +12 -0
- package/templates/go-wasm-app/src/wasm/example.go +75 -0
- package/templates/go-wasm-app/tsconfig.server.json +18 -0
- package/templates/go-wasm-app/vite.config.js +45 -0
- package/templates/ssr-template/package.json +16 -10
- package/templates/wasm/package.json +43 -43
- package/templates/wasm/src/App.tsx +2 -2
- package/dist/forms/index.d.ts +0 -2
- package/dist/forms/index.d.ts.map +0 -1
- package/dist/forms/types.d.ts +0 -2
- package/dist/forms/types.d.ts.map +0 -1
- package/dist/frontend/components/WasmLoader.d.ts +0 -2
- package/dist/frontend/components/WasmLoader.d.ts.map +0 -1
- package/dist/frontend/hooks/useWasm.d.ts +0 -2
- package/dist/frontend/hooks/useWasm.d.ts.map +0 -1
- package/dist/frontend/index.d.ts +0 -2
- package/dist/frontend/index.d.ts.map +0 -1
- package/dist/router/index.d.ts +0 -2
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/types.d.ts +0 -2
- package/dist/router/types.d.ts.map +0 -1
- package/dist/store/index.d.ts +0 -2
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/types.d.ts +0 -2
- package/dist/store/types.d.ts.map +0 -1
- package/templates/basic-app/package-lock.json +0 -7173
- package/templates/fullstack-template/package-lock.json +0 -3558
- package/templates/ssr-template/package-lock.json +0 -5380
- package/templates/wasm/package-lock.json +0 -5347
- package/templates/wasm/public/example.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,595 +1,395 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<img src="https://raw.githubusercontent.com/mohamedx2/baraqex/main/assets/logo.svg" alt="Baraqex Logo" width="180" height="180">
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
### 🎯 Core Features
|
|
8
|
-
- **Universal JSX Support** - Modern React-like components without dependencies
|
|
9
|
-
- **WebAssembly Integration** - Seamless Go WASM support for both browser and Node.js
|
|
10
|
-
- **Server-Side Rendering** - Built-in SSR with hydration support
|
|
11
|
-
- **Full-Stack Framework** - Complete backend server with API routes
|
|
12
|
-
- **TypeScript First** - Full TypeScript support with excellent IntelliSense
|
|
13
|
-
- **Zero Dependencies** - Lightweight core with optional features
|
|
14
|
-
|
|
15
|
-
### 🌐 WebAssembly Features
|
|
16
|
-
- **Browser WASM** - Load and execute Go WASM modules in the browser
|
|
17
|
-
- **Server WASM** - Run Go WASM functions in Node.js environment
|
|
18
|
-
- **Unified API** - Identical interface for browser and server environments
|
|
19
|
-
- **Hot Reloading** - Development support with fast refresh
|
|
20
|
-
|
|
21
|
-
### 🔧 Backend Features
|
|
22
|
-
- **Express Integration** - Built on Express.js for reliability
|
|
23
|
-
- **API Routes** - File-based API routing system
|
|
24
|
-
- **Authentication** - JWT-based auth with middleware support
|
|
25
|
-
- **Database Support** - MongoDB, MySQL, PostgreSQL adapters
|
|
26
|
-
- **Static Serving** - Efficient static file serving
|
|
27
|
-
|
|
28
|
-
## 📦 Installation
|
|
5
|
+
# Baraqex
|
|
29
6
|
|
|
30
|
-
|
|
31
|
-
npm install baraqex
|
|
32
|
-
```
|
|
7
|
+
### ⚡ The Full-Stack Framework with WASM Superpowers
|
|
33
8
|
|
|
34
|
-
|
|
9
|
+
Build universal web applications with React-like syntax and Go-powered performance.
|
|
35
10
|
|
|
36
|
-
|
|
11
|
+
[](https://www.npmjs.com/package/baraqex)
|
|
12
|
+
[](https://www.npmjs.com/package/baraqex)
|
|
13
|
+
[](https://github.com/mohamedx2/baraqex)
|
|
14
|
+
[](https://opensource.org/licenses/MIT)
|
|
15
|
+
[](https://www.typescriptlang.org/)
|
|
16
|
+
[](https://www.baraqex.tech)
|
|
37
17
|
|
|
38
|
-
|
|
39
|
-
import { jsx, useState } from 'baraqex';
|
|
40
|
-
import { loadGoWasm, callWasmFunction } from 'baraqex';
|
|
18
|
+
[Get Started](#-quick-start) · [Documentation](https://www.baraqex.tech/docs) · [Examples](#-examples) · [Contributing](#-contributing)
|
|
41
19
|
|
|
42
|
-
|
|
43
|
-
const [count, setCount] = useState(0);
|
|
44
|
-
const [wasmReady, setWasmReady] = useState(false);
|
|
20
|
+
</div>
|
|
45
21
|
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
async function initWasm() {
|
|
49
|
-
await loadGoWasm('/app.wasm');
|
|
50
|
-
setWasmReady(true);
|
|
51
|
-
}
|
|
52
|
-
initWasm();
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
const handleCalculate = () => {
|
|
56
|
-
if (wasmReady) {
|
|
57
|
-
// Call Go WASM function
|
|
58
|
-
const result = callWasmFunction('calculate', count);
|
|
59
|
-
console.log('WASM result:', result);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<div>
|
|
65
|
-
<h1>Baraqex App</h1>
|
|
66
|
-
<p>Count: {count}</p>
|
|
67
|
-
<button onClick={() => setCount(count + 1)}>
|
|
68
|
-
Increment
|
|
69
|
-
</button>
|
|
70
|
-
<button onClick={handleCalculate} disabled={!wasmReady}>
|
|
71
|
-
Calculate with WASM
|
|
72
|
-
</button>
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export default App;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Server Usage
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
import { createServer } from 'baraqex/server';
|
|
84
|
-
import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
|
|
85
|
-
|
|
86
|
-
// Create server
|
|
87
|
-
const server = createServer({
|
|
88
|
-
port: 3000,
|
|
89
|
-
apiDir: './api',
|
|
90
|
-
pagesDir: './pages',
|
|
91
|
-
staticDir: './public'
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Load WASM for server-side processing
|
|
95
|
-
async function initServerWasm() {
|
|
96
|
-
await loadGoWasmFromFile('./compute.wasm');
|
|
97
|
-
console.log('Server WASM ready!');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Start server
|
|
101
|
-
server.start().then(() => {
|
|
102
|
-
console.log('Server running on http://localhost:3000');
|
|
103
|
-
initServerWasm();
|
|
104
|
-
});
|
|
105
|
-
```
|
|
22
|
+
---
|
|
106
23
|
|
|
107
|
-
##
|
|
24
|
+
## Why Baraqex?
|
|
108
25
|
|
|
109
|
-
|
|
26
|
+
| Feature | Baraqex | Others |
|
|
27
|
+
|---------|---------|--------|
|
|
28
|
+
| 🚀 **WASM Integration** | Native Go/WASM support | Manual setup required |
|
|
29
|
+
| 🔄 **Universal Rendering** | SSR + CSR + Static | Framework-specific |
|
|
30
|
+
| ⚡ **Zero Config** | Works out of the box | Complex configuration |
|
|
31
|
+
| 🎯 **Full-Stack** | Frontend + Backend + API | Separate tools needed |
|
|
32
|
+
| 📦 **Tiny Bundle** | < 15KB gzipped | Often 50KB+ |
|
|
110
33
|
|
|
111
|
-
|
|
34
|
+
---
|
|
112
35
|
|
|
113
|
-
|
|
114
|
-
import { loadGoWasm, callWasmFunction, isWasmReady, getWasmFunctions } from 'baraqex';
|
|
36
|
+
## ✨ Features
|
|
115
37
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
38
|
+
- **🔥 WebAssembly First** - Run Go code in the browser at near-native speed
|
|
39
|
+
- **⚛️ React-like Syntax** - Familiar JSX with hooks (`useState`, `useEffect`, etc.)
|
|
40
|
+
- **🌐 Universal Rendering** - SSR, CSR, and Static Generation
|
|
41
|
+
- **🛣️ File-based Routing** - Automatic API routes from your file structure
|
|
42
|
+
- **🔐 Built-in Auth** - JWT authentication with password hashing
|
|
43
|
+
- **🗄️ Database Adapters** - MongoDB, PostgreSQL, MySQL out of the box
|
|
44
|
+
- **📡 Real-time** - WebSocket support for live updates
|
|
45
|
+
- **🎨 TypeScript** - Full type safety and IntelliSense
|
|
46
|
+
- **🧪 Tested** - 140+ tests with 56% coverage
|
|
123
47
|
|
|
124
|
-
|
|
125
|
-
if (isWasmReady()) {
|
|
126
|
-
// Get available functions
|
|
127
|
-
const functions = getWasmFunctions();
|
|
128
|
-
console.log('Available functions:', functions);
|
|
129
|
-
|
|
130
|
-
// Call functions
|
|
131
|
-
const greeting = callWasmFunction('goHello', 'World');
|
|
132
|
-
const sum = callWasmFunction('goAdd', 10, 20);
|
|
133
|
-
const fibonacci = callWasmFunction('goFibonacci', 10);
|
|
134
|
-
}
|
|
135
|
-
```
|
|
48
|
+
> **Built on [frontend-hamroun](https://www.npmjs.com/package/frontend-hamroun)** - The lightweight React-like core (~8KB gzipped)
|
|
136
49
|
|
|
137
|
-
|
|
50
|
+
---
|
|
138
51
|
|
|
139
|
-
|
|
140
|
-
import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
|
|
52
|
+
## 🚀 Quick Start
|
|
141
53
|
|
|
142
|
-
|
|
143
|
-
await loadGoWasmFromFile('./example.wasm', {
|
|
144
|
-
debug: true,
|
|
145
|
-
goWasmPath: './wasm_exec.cjs'
|
|
146
|
-
});
|
|
54
|
+
### Create a New Project
|
|
147
55
|
|
|
148
|
-
|
|
149
|
-
|
|
56
|
+
```bash
|
|
57
|
+
npx create-baraqex-app my-app
|
|
58
|
+
cd my-app
|
|
59
|
+
npm run dev
|
|
150
60
|
```
|
|
151
61
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```go
|
|
155
|
-
// main.go
|
|
156
|
-
package main
|
|
157
|
-
|
|
158
|
-
import (
|
|
159
|
-
"fmt"
|
|
160
|
-
"syscall/js"
|
|
161
|
-
)
|
|
62
|
+
### Or Install Manually
|
|
162
63
|
|
|
163
|
-
func goHello(this js.Value, args []js.Value) interface{} {
|
|
164
|
-
name := args[0].String()
|
|
165
|
-
return fmt.Sprintf("Hello, %s from Go WASM!", name)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
func goAdd(this js.Value, args []js.Value) interface{} {
|
|
169
|
-
a := args[0].Float()
|
|
170
|
-
b := args[1].Float()
|
|
171
|
-
return a + b
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
func main() {
|
|
175
|
-
// Register functions
|
|
176
|
-
js.Global().Set("goHello", js.FuncOf(goHello))
|
|
177
|
-
js.Global().Set("goAdd", js.FuncOf(goAdd))
|
|
178
|
-
|
|
179
|
-
fmt.Println("Go WASM ready!")
|
|
180
|
-
|
|
181
|
-
// Keep running
|
|
182
|
-
select {}
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Build with:
|
|
187
64
|
```bash
|
|
188
|
-
|
|
65
|
+
npm install baraqex
|
|
189
66
|
```
|
|
190
67
|
|
|
191
|
-
|
|
68
|
+
---
|
|
192
69
|
|
|
193
|
-
|
|
70
|
+
## 📖 Basic Usage
|
|
194
71
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
72
|
+
### Create a Component
|
|
73
|
+
|
|
74
|
+
```jsx
|
|
75
|
+
import { jsx, useState } from 'baraqex';
|
|
198
76
|
|
|
199
|
-
|
|
77
|
+
function Counter() {
|
|
78
|
+
const [count, setCount] = useState(0);
|
|
79
|
+
|
|
200
80
|
return (
|
|
201
|
-
<
|
|
202
|
-
<
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<p>Server time: {props.api.serverTime}</p>
|
|
208
|
-
</body>
|
|
209
|
-
</html>
|
|
81
|
+
<div>
|
|
82
|
+
<h1>Count: {count}</h1>
|
|
83
|
+
<button onClick={() => setCount(count + 1)}>
|
|
84
|
+
Increment
|
|
85
|
+
</button>
|
|
86
|
+
</div>
|
|
210
87
|
);
|
|
211
88
|
}
|
|
212
|
-
|
|
213
|
-
// Optional: Add metadata
|
|
214
|
-
HomePage.getTitle = (props) => 'Home - My App';
|
|
215
|
-
HomePage.getDescription = (props) => 'Welcome to my application';
|
|
216
89
|
```
|
|
217
90
|
|
|
218
|
-
|
|
91
|
+
### Create an API Route
|
|
219
92
|
|
|
220
93
|
```javascript
|
|
221
|
-
// api/users.js
|
|
94
|
+
// api/users.js - automatically becomes /api/users
|
|
222
95
|
export async function get(req, res) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
res.json({ users });
|
|
96
|
+
const users = await db.query('SELECT * FROM users');
|
|
97
|
+
res.json(users);
|
|
226
98
|
}
|
|
227
99
|
|
|
228
100
|
export async function post(req, res) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
res.json({ user: newUser });
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// api/users/[id].js
|
|
235
|
-
export async function get(req, res) {
|
|
236
|
-
// GET /api/users/:id
|
|
237
|
-
const user = await getUserById(req.params.id);
|
|
238
|
-
res.json({ user });
|
|
101
|
+
const user = await db.insert('users', req.body);
|
|
102
|
+
res.status(201).json(user);
|
|
239
103
|
}
|
|
240
104
|
```
|
|
241
105
|
|
|
242
|
-
###
|
|
243
|
-
|
|
244
|
-
```javascript
|
|
245
|
-
import { Database } from 'baraqex/server';
|
|
246
|
-
|
|
247
|
-
// MongoDB
|
|
248
|
-
const db = new Database({
|
|
249
|
-
type: 'mongodb',
|
|
250
|
-
url: 'mongodb://localhost:27017/myapp'
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
await db.connect();
|
|
254
|
-
const collection = db.getMongoDb().collection('users');
|
|
106
|
+
### Use WebAssembly
|
|
255
107
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
type: 'mysql',
|
|
259
|
-
url: 'mysql://user:pass@localhost:3306/myapp'
|
|
260
|
-
});
|
|
108
|
+
```jsx
|
|
109
|
+
import { loadGoWasm, callWasmFunction } from 'baraqex';
|
|
261
110
|
|
|
262
|
-
|
|
263
|
-
|
|
111
|
+
// Load your Go WASM module
|
|
112
|
+
await loadGoWasm('/math.wasm');
|
|
264
113
|
|
|
265
|
-
//
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
url: 'postgresql://user:pass@localhost:5432/myapp'
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
await db.connect();
|
|
272
|
-
const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
|
|
114
|
+
// Call Go functions from JavaScript
|
|
115
|
+
const result = callWasmFunction('fibonacci', 1000000);
|
|
116
|
+
console.log(result); // Computed in milliseconds!
|
|
273
117
|
```
|
|
274
118
|
|
|
275
|
-
###
|
|
119
|
+
### Start a Server
|
|
276
120
|
|
|
277
121
|
```javascript
|
|
278
|
-
import {
|
|
122
|
+
import { Server } from 'baraqex/server';
|
|
279
123
|
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
124
|
+
const server = new Server({
|
|
125
|
+
port: 3000,
|
|
126
|
+
apiDir: './api',
|
|
127
|
+
pagesDir: './pages',
|
|
128
|
+
db: {
|
|
129
|
+
type: 'postgres',
|
|
130
|
+
url: process.env.DATABASE_URL
|
|
131
|
+
},
|
|
132
|
+
auth: {
|
|
133
|
+
secret: process.env.JWT_SECRET
|
|
134
|
+
}
|
|
283
135
|
});
|
|
284
136
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
// Validate user
|
|
290
|
-
const user = await validateUser(username, password);
|
|
291
|
-
if (!user) {
|
|
292
|
-
return res.status(401).json({ error: 'Invalid credentials' });
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Generate token
|
|
296
|
-
const token = auth.generateToken(user);
|
|
297
|
-
res.json({ token, user });
|
|
298
|
-
}
|
|
137
|
+
await server.start();
|
|
138
|
+
// 🚀 Server running at http://localhost:3000
|
|
139
|
+
```
|
|
299
140
|
|
|
300
|
-
|
|
301
|
-
export const middleware = [auth.requireAuth()];
|
|
141
|
+
---
|
|
302
142
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
143
|
+
## 📚 Documentation
|
|
144
|
+
|
|
145
|
+
### Core Concepts
|
|
146
|
+
|
|
147
|
+
| Topic | Description |
|
|
148
|
+
|-------|-------------|
|
|
149
|
+
| [Components](docs/components.md) | Creating and composing components |
|
|
150
|
+
| [Hooks](docs/hooks.md) | useState, useEffect, useContext, and more |
|
|
151
|
+
| [Routing](docs/routing.md) | File-based and programmatic routing |
|
|
152
|
+
| [Server](docs/server.md) | Express-based server with middleware |
|
|
153
|
+
| [Database](docs/database.md) | MongoDB, PostgreSQL, MySQL adapters |
|
|
154
|
+
| [Authentication](docs/auth.md) | JWT tokens and password hashing |
|
|
155
|
+
| [WebAssembly](docs/wasm.md) | Go WASM integration guide |
|
|
156
|
+
| [SSR](docs/ssr.md) | Server-side rendering |
|
|
157
|
+
|
|
158
|
+
### API Reference
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Browser APIs
|
|
162
|
+
import {
|
|
163
|
+
jsx,
|
|
164
|
+
Fragment,
|
|
165
|
+
render,
|
|
166
|
+
useState,
|
|
167
|
+
useEffect,
|
|
168
|
+
useContext,
|
|
169
|
+
useRef,
|
|
170
|
+
useMemo,
|
|
171
|
+
useCallback,
|
|
172
|
+
loadGoWasm,
|
|
173
|
+
callWasmFunction,
|
|
174
|
+
getWasmExports
|
|
175
|
+
} from 'baraqex';
|
|
176
|
+
|
|
177
|
+
// Server APIs
|
|
178
|
+
import {
|
|
179
|
+
Server,
|
|
180
|
+
Database,
|
|
181
|
+
AuthService,
|
|
182
|
+
ApiRouter,
|
|
183
|
+
rateLimit,
|
|
184
|
+
requestLogger,
|
|
185
|
+
errorHandler
|
|
186
|
+
} from 'baraqex/server';
|
|
307
187
|
```
|
|
308
188
|
|
|
309
|
-
|
|
189
|
+
---
|
|
310
190
|
|
|
311
|
-
|
|
191
|
+
## 🎯 Examples
|
|
312
192
|
|
|
313
|
-
|
|
314
|
-
my-app/
|
|
315
|
-
├── src/
|
|
316
|
-
│ ├── pages/ # SSR pages
|
|
317
|
-
│ │ ├── index.js # Home page
|
|
318
|
-
│ │ └── about.js # About page
|
|
319
|
-
│ ├── api/ # API routes
|
|
320
|
-
│ │ ├── users.js # /api/users
|
|
321
|
-
│ │ └── auth/ # /api/auth/*
|
|
322
|
-
│ └── components/ # Reusable components
|
|
323
|
-
├── public/ # Static files
|
|
324
|
-
│ ├── app.wasm # WebAssembly modules
|
|
325
|
-
│ └── styles.css # Stylesheets
|
|
326
|
-
├── wasm/ # Go WASM source
|
|
327
|
-
│ └── main.go # Go functions
|
|
328
|
-
└── package.json
|
|
329
|
-
```
|
|
193
|
+
### Todo App with WASM
|
|
330
194
|
|
|
331
|
-
|
|
195
|
+
```jsx
|
|
196
|
+
import { jsx, useState, loadGoWasm, callWasmFunction } from 'baraqex';
|
|
332
197
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
198
|
+
function TodoApp() {
|
|
199
|
+
const [todos, setTodos] = useState([]);
|
|
200
|
+
const [input, setInput] = useState('');
|
|
201
|
+
|
|
202
|
+
const addTodo = () => {
|
|
203
|
+
// Use WASM for validation/processing
|
|
204
|
+
const validated = callWasmFunction('validateTodo', input);
|
|
205
|
+
if (validated) {
|
|
206
|
+
setTodos([...todos, { id: Date.now(), text: input }]);
|
|
207
|
+
setInput('');
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<div className="todo-app">
|
|
213
|
+
<h1>📝 WASM Todo</h1>
|
|
214
|
+
<input
|
|
215
|
+
value={input}
|
|
216
|
+
onChange={(e) => setInput(e.target.value)}
|
|
217
|
+
placeholder="Add a todo..."
|
|
218
|
+
/>
|
|
219
|
+
<button onClick={addTodo}>Add</button>
|
|
220
|
+
<ul>
|
|
221
|
+
{todos.map(todo => (
|
|
222
|
+
<li key={todo.id}>{todo.text}</li>
|
|
223
|
+
))}
|
|
224
|
+
</ul>
|
|
225
|
+
</div>
|
|
226
|
+
);
|
|
341
227
|
}
|
|
342
228
|
```
|
|
343
229
|
|
|
344
|
-
###
|
|
230
|
+
### Full-Stack API
|
|
345
231
|
|
|
346
232
|
```javascript
|
|
347
|
-
|
|
233
|
+
// server.js
|
|
234
|
+
import { Server } from 'baraqex/server';
|
|
348
235
|
|
|
349
|
-
const server =
|
|
236
|
+
const server = new Server({
|
|
350
237
|
port: 3000,
|
|
351
|
-
|
|
238
|
+
db: { type: 'mongodb', url: 'mongodb://localhost:27017/myapp' },
|
|
239
|
+
auth: { secret: 'your-secret-key' }
|
|
352
240
|
});
|
|
353
241
|
|
|
354
|
-
//
|
|
355
|
-
server.
|
|
242
|
+
// Custom middleware
|
|
243
|
+
server.use((req, res, next) => {
|
|
244
|
+
console.log(`${req.method} ${req.url}`);
|
|
245
|
+
next();
|
|
246
|
+
});
|
|
356
247
|
|
|
357
248
|
await server.start();
|
|
358
249
|
```
|
|
359
250
|
|
|
360
|
-
## 🔧 Configuration
|
|
361
|
-
|
|
362
|
-
### Server Configuration
|
|
363
|
-
|
|
364
251
|
```javascript
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
pagesDir: './src/pages',
|
|
371
|
-
staticDir: './public',
|
|
372
|
-
enableCors: true,
|
|
373
|
-
corsOptions: {
|
|
374
|
-
origin: ['http://localhost:3000'],
|
|
375
|
-
credentials: true
|
|
376
|
-
},
|
|
377
|
-
db: {
|
|
378
|
-
type: 'mongodb',
|
|
379
|
-
url: process.env.DATABASE_URL
|
|
380
|
-
},
|
|
381
|
-
auth: {
|
|
382
|
-
secret: process.env.JWT_SECRET,
|
|
383
|
-
expiresIn: '7d'
|
|
384
|
-
}
|
|
385
|
-
});
|
|
252
|
+
// api/posts/[id].js - Dynamic routes
|
|
253
|
+
export async function get(req, res, { db }) {
|
|
254
|
+
const post = await db.query(`SELECT * FROM posts WHERE id = $1`, [req.params.id]);
|
|
255
|
+
res.json(post);
|
|
256
|
+
}
|
|
386
257
|
```
|
|
387
258
|
|
|
388
|
-
|
|
259
|
+
---
|
|
389
260
|
|
|
390
|
-
|
|
391
|
-
// Browser
|
|
392
|
-
await loadGoWasm('/app.wasm', {
|
|
393
|
-
debug: process.env.NODE_ENV === 'development',
|
|
394
|
-
importObject: {
|
|
395
|
-
// Custom WASM imports
|
|
396
|
-
},
|
|
397
|
-
onLoad: (instance) => {
|
|
398
|
-
console.log('WASM loaded with exports:', instance.exports);
|
|
399
|
-
}
|
|
400
|
-
});
|
|
261
|
+
## 🏗️ Project Structure
|
|
401
262
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
263
|
+
```
|
|
264
|
+
my-app/
|
|
265
|
+
├── api/ # API routes (file-based)
|
|
266
|
+
│ ├── users.js # → /api/users
|
|
267
|
+
│ └── posts/
|
|
268
|
+
│ ├── index.js # → /api/posts
|
|
269
|
+
│ └── [id].js # → /api/posts/:id
|
|
270
|
+
├── pages/ # Page components
|
|
271
|
+
│ ├── index.jsx # → /
|
|
272
|
+
│ └── about.jsx # → /about
|
|
273
|
+
├── public/ # Static assets
|
|
274
|
+
├── src/
|
|
275
|
+
│ ├── components/ # Reusable components
|
|
276
|
+
│ └── wasm/ # Go WASM source files
|
|
277
|
+
├── package.json
|
|
278
|
+
└── baraqex.config.js # Optional configuration
|
|
407
279
|
```
|
|
408
280
|
|
|
409
|
-
|
|
281
|
+
---
|
|
410
282
|
|
|
411
|
-
|
|
412
|
-
- **Near-native performance** for compute-intensive tasks
|
|
413
|
-
- **Memory efficiency** with direct memory access
|
|
414
|
-
- **Parallel processing** capabilities
|
|
415
|
-
- **Type safety** with compiled languages
|
|
283
|
+
## ⚡ Performance
|
|
416
284
|
|
|
417
|
-
|
|
418
|
-
- **Built-in caching** for static assets
|
|
419
|
-
- **Compression** support (gzip, brotli)
|
|
420
|
-
- **HTTP/2** ready
|
|
421
|
-
- **Cluster mode** for production
|
|
285
|
+
Baraqex is designed for speed:
|
|
422
286
|
|
|
423
|
-
|
|
287
|
+
| Metric | Value |
|
|
288
|
+
|--------|-------|
|
|
289
|
+
| Bundle Size | 14.2 KB (gzipped) |
|
|
290
|
+
| First Paint | < 50ms |
|
|
291
|
+
| Server Start | < 200ms |
|
|
292
|
+
| WASM Load | < 100ms |
|
|
293
|
+
| Rate Limit Check | < 0.01ms |
|
|
424
294
|
|
|
425
|
-
|
|
295
|
+
Run benchmarks yourself:
|
|
426
296
|
|
|
427
297
|
```bash
|
|
428
|
-
|
|
429
|
-
npm test
|
|
430
|
-
|
|
431
|
-
# Run server function tests only
|
|
432
|
-
npm run test:server
|
|
433
|
-
|
|
434
|
-
# Run WASM integration tests only
|
|
435
|
-
npm run test:wasm
|
|
298
|
+
npm run benchmark
|
|
436
299
|
```
|
|
437
300
|
|
|
438
|
-
|
|
301
|
+
---
|
|
439
302
|
|
|
440
|
-
|
|
441
|
-
// test-wasm.js
|
|
442
|
-
import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
|
|
303
|
+
## 🧪 Testing
|
|
443
304
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
// Test functions
|
|
448
|
-
const greeting = callWasmFunction('goHello', 'Test');
|
|
449
|
-
console.assert(greeting.includes('Test'), 'Hello function works');
|
|
450
|
-
|
|
451
|
-
const sum = callWasmFunction('goAdd', 5, 3);
|
|
452
|
-
console.assert(sum === 8, 'Add function works');
|
|
453
|
-
|
|
454
|
-
console.log('All WASM tests passed!');
|
|
455
|
-
}
|
|
305
|
+
```bash
|
|
306
|
+
# Run all tests
|
|
307
|
+
npm test
|
|
456
308
|
|
|
457
|
-
|
|
458
|
-
|
|
309
|
+
# Run with coverage
|
|
310
|
+
npm run test:coverage
|
|
459
311
|
|
|
460
|
-
|
|
312
|
+
# Run specific tests
|
|
313
|
+
npm run test:unit
|
|
314
|
+
npm run test:integration
|
|
461
315
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
import { createServer } from 'baraqex/server';
|
|
465
|
-
|
|
466
|
-
const server = createServer();
|
|
467
|
-
const app = server.getExpressApp();
|
|
468
|
-
|
|
469
|
-
describe('API Routes', () => {
|
|
470
|
-
test('GET /api/users', async () => {
|
|
471
|
-
const response = await request(app)
|
|
472
|
-
.get('/api/users')
|
|
473
|
-
.expect(200);
|
|
474
|
-
|
|
475
|
-
expect(response.body).toHaveProperty('users');
|
|
476
|
-
});
|
|
477
|
-
});
|
|
316
|
+
# Run benchmarks
|
|
317
|
+
npm run test:benchmarks
|
|
478
318
|
```
|
|
479
319
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
The test suite covers:
|
|
483
|
-
- ✅ **Server Creation** - Basic server setup and configuration
|
|
484
|
-
- ✅ **Database Connections** - MongoDB, MySQL, PostgreSQL adapters
|
|
485
|
-
- ✅ **Authentication** - JWT token generation and validation
|
|
486
|
-
- ✅ **WebAssembly Integration** - Go WASM loading and function calls
|
|
487
|
-
- ✅ **API Routes** - Dynamic route registration and handling
|
|
488
|
-
- ✅ **Server Utilities** - Helper functions and middleware
|
|
489
|
-
- ✅ **Template Generation** - HTML document and error page creation
|
|
320
|
+
---
|
|
490
321
|
|
|
491
|
-
##
|
|
322
|
+
## 🤝 Contributing
|
|
492
323
|
|
|
493
|
-
|
|
324
|
+
We love contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
494
325
|
|
|
495
326
|
```bash
|
|
496
|
-
#
|
|
497
|
-
|
|
327
|
+
# Clone the repo
|
|
328
|
+
git clone https://github.com/mohamedx2/baraqex.git
|
|
329
|
+
cd baraqex
|
|
498
330
|
|
|
499
|
-
#
|
|
500
|
-
npm
|
|
331
|
+
# Install dependencies
|
|
332
|
+
npm install
|
|
501
333
|
|
|
502
|
-
#
|
|
503
|
-
npm
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
### Docker Deployment
|
|
507
|
-
|
|
508
|
-
```dockerfile
|
|
509
|
-
FROM node:18-alpine
|
|
510
|
-
|
|
511
|
-
WORKDIR /app
|
|
512
|
-
|
|
513
|
-
# Install Go for WASM building
|
|
514
|
-
RUN apk add --no-cache go
|
|
515
|
-
|
|
516
|
-
# Copy package files
|
|
517
|
-
COPY package*.json ./
|
|
518
|
-
RUN npm ci --only=production
|
|
519
|
-
|
|
520
|
-
# Copy source
|
|
521
|
-
COPY . .
|
|
522
|
-
|
|
523
|
-
# Build WASM
|
|
524
|
-
RUN npm run build:wasm
|
|
334
|
+
# Run tests
|
|
335
|
+
npm test
|
|
525
336
|
|
|
526
|
-
#
|
|
527
|
-
|
|
337
|
+
# Start development
|
|
338
|
+
npm run dev
|
|
339
|
+
```
|
|
528
340
|
|
|
529
|
-
|
|
341
|
+
---
|
|
530
342
|
|
|
531
|
-
|
|
532
|
-
```
|
|
343
|
+
## 📦 Templates
|
|
533
344
|
|
|
534
|
-
|
|
345
|
+
Create projects with pre-configured templates:
|
|
535
346
|
|
|
536
347
|
```bash
|
|
537
|
-
#
|
|
538
|
-
|
|
539
|
-
NODE_ENV=production
|
|
348
|
+
# Basic app
|
|
349
|
+
npx create-baraqex-app my-app --template basic
|
|
540
350
|
|
|
541
|
-
#
|
|
542
|
-
|
|
351
|
+
# Full-stack with database
|
|
352
|
+
npx create-baraqex-app my-app --template fullstack
|
|
543
353
|
|
|
544
|
-
#
|
|
545
|
-
|
|
354
|
+
# SSR application
|
|
355
|
+
npx create-baraqex-app my-app --template ssr
|
|
546
356
|
|
|
547
|
-
# WASM
|
|
548
|
-
|
|
357
|
+
# WASM-powered app
|
|
358
|
+
npx create-baraqex-app my-app --template wasm
|
|
549
359
|
```
|
|
550
360
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
1. Fork the repository
|
|
554
|
-
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
555
|
-
3. Make changes and add tests
|
|
556
|
-
4. Commit: `git commit -m 'Add amazing feature'`
|
|
557
|
-
5. Push: `git push origin feature/amazing-feature`
|
|
558
|
-
6. Submit a Pull Request
|
|
559
|
-
|
|
560
|
-
## 📄 License
|
|
361
|
+
---
|
|
561
362
|
|
|
562
|
-
|
|
363
|
+
## 🗺️ Roadmap
|
|
563
364
|
|
|
564
|
-
|
|
365
|
+
- [x] Core framework with JSX support
|
|
366
|
+
- [x] WebAssembly integration
|
|
367
|
+
- [x] Server-side rendering
|
|
368
|
+
- [x] Database adapters (MongoDB, PostgreSQL, MySQL)
|
|
369
|
+
- [x] Authentication system
|
|
370
|
+
- [x] CLI with project scaffolding
|
|
371
|
+
- [ ] Edge runtime support
|
|
372
|
+
- [ ] GraphQL integration
|
|
373
|
+
- [ ] React Server Components
|
|
374
|
+
- [ ] Incremental Static Regeneration
|
|
375
|
+
- [ ] Built-in caching layer
|
|
565
376
|
|
|
566
|
-
|
|
567
|
-
- **Website**: [www.baraqex.tech](https://www.baraqex.tech)
|
|
568
|
-
- **Issues**: [GitHub Issues](https://github.com/hamroun/baraqex/issues)
|
|
569
|
-
- **Discussions**: [GitHub Discussions](https://github.com/hamroun/baraqex/discussions)
|
|
570
|
-
- **Discord**: [Join our community](https://discord.gg/baraqex)
|
|
377
|
+
---
|
|
571
378
|
|
|
572
|
-
##
|
|
379
|
+
## 📄 License
|
|
573
380
|
|
|
574
|
-
|
|
381
|
+
MIT © [Mohamed X](https://github.com/mohamedx2)
|
|
575
382
|
|
|
576
|
-
|
|
577
|
-
- **Full-Stack Todo** - Complete CRUD app with auth
|
|
578
|
-
- **Real-time Chat** - WebSocket integration
|
|
579
|
-
- **E-commerce Site** - Complex SSR application
|
|
580
|
-
- **Data Visualization** - WASM-powered charts
|
|
383
|
+
---
|
|
581
384
|
|
|
582
|
-
|
|
385
|
+
<div align="center">
|
|
583
386
|
|
|
584
|
-
|
|
585
|
-
- **Express.js**: The underlying server framework
|
|
586
|
-
- **TypeScript**: Type safety and developer experience
|
|
587
|
-
- **Official Website**: [www.baraqex.tech](https://www.baraqex.tech)
|
|
387
|
+
**[⬆ Back to Top](#baraqex)**
|
|
588
388
|
|
|
589
|
-
|
|
389
|
+
Made with ❤️ by the Baraqex team
|
|
590
390
|
|
|
591
|
-
**
|
|
391
|
+
**One Culture, One Framework** | **ثقافة واحدة، إطار عمل واحد**
|
|
592
392
|
|
|
593
|
-
|
|
393
|
+
[Website](https://www.baraqex.tech) · [Docs](https://www.baraqex.tech/docs) · [GitHub](https://github.com/mohamedx2/baraqex) · [npm](https://www.npmjs.com/package/baraqex) · [Arabic Community](https://www.baraqex.tech/arabic)
|
|
594
394
|
|
|
595
|
-
|
|
395
|
+
</div>
|