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.
Files changed (185) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +272 -472
  3. package/bin/baraqex.js +150 -12
  4. package/dist/browser.d.ts +1 -1
  5. package/dist/browser.d.ts.map +1 -1
  6. package/dist/browser.js +2319 -205
  7. package/dist/browser.js.map +4 -4
  8. package/dist/core/batch.d.ts +10 -0
  9. package/dist/core/batch.d.ts.map +1 -0
  10. package/dist/core/component.d.ts +69 -0
  11. package/dist/core/component.d.ts.map +1 -0
  12. package/dist/core/context.d.ts +22 -0
  13. package/dist/core/context.d.ts.map +1 -0
  14. package/dist/core/errors.d.ts +125 -0
  15. package/dist/core/errors.d.ts.map +1 -0
  16. package/dist/core/event-bus.d.ts +29 -0
  17. package/dist/core/event-bus.d.ts.map +1 -0
  18. package/dist/core/forms.d.ts +128 -0
  19. package/dist/core/forms.d.ts.map +1 -0
  20. package/dist/core/hooks.d.ts +84 -0
  21. package/dist/core/hooks.d.ts.map +1 -0
  22. package/dist/core/index.d.ts +23 -0
  23. package/dist/core/index.d.ts.map +1 -0
  24. package/dist/core/jsx-runtime.d.ts +45 -0
  25. package/dist/core/jsx-runtime.d.ts.map +1 -0
  26. package/dist/core/lifecycle-events.d.ts +71 -0
  27. package/dist/core/lifecycle-events.d.ts.map +1 -0
  28. package/dist/core/renderer.d.ts +39 -0
  29. package/dist/core/renderer.d.ts.map +1 -0
  30. package/dist/core/router.d.ts +108 -0
  31. package/dist/core/router.d.ts.map +1 -0
  32. package/dist/core/server-renderer.d.ts +26 -0
  33. package/dist/core/server-renderer.d.ts.map +1 -0
  34. package/dist/core/store.d.ts +102 -0
  35. package/dist/core/store.d.ts.map +1 -0
  36. package/dist/core/types.d.ts +66 -0
  37. package/dist/core/types.d.ts.map +1 -0
  38. package/dist/core/utils.d.ts +153 -0
  39. package/dist/core/utils.d.ts.map +1 -0
  40. package/dist/core/vdom.d.ts +29 -0
  41. package/dist/core/vdom.d.ts.map +1 -0
  42. package/dist/index.d.ts +39 -35
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +2592 -508
  45. package/dist/index.js.map +4 -4
  46. package/dist/server/auth.d.ts +8 -3
  47. package/dist/server/auth.d.ts.map +1 -1
  48. package/dist/server/index.d.ts +2 -2
  49. package/dist/server/index.d.ts.map +1 -1
  50. package/dist/server/index.js +173 -112
  51. package/dist/server/index.js.map +4 -4
  52. package/dist/server/middleware.d.ts +10 -1
  53. package/dist/server/middleware.d.ts.map +1 -1
  54. package/package.json +224 -124
  55. package/templates/basic-app/src/main.jsx +336 -0
  56. package/templates/complete-app/api/hello.js +0 -0
  57. package/templates/complete-app/client.js +58 -0
  58. package/templates/complete-app/lib/frontend-hamroun.js +182 -0
  59. package/templates/complete-app/package.json +18 -0
  60. package/templates/complete-app/pages/about.js +119 -0
  61. package/templates/complete-app/pages/about.jsx +0 -0
  62. package/templates/complete-app/pages/index.js +157 -0
  63. package/templates/complete-app/pages/index.jsx +0 -0
  64. package/templates/complete-app/pages/wasm-demo.js +290 -0
  65. package/templates/complete-app/pages/wasm-demo.jsx +0 -0
  66. package/templates/complete-app/public/client.js +89 -0
  67. package/templates/complete-app/public/index.html +118 -0
  68. package/templates/complete-app/public/styles.css +76 -0
  69. package/templates/complete-app/readme.md +188 -0
  70. package/templates/complete-app/server.js +226 -0
  71. package/templates/complete-app/server.ts +275 -0
  72. package/templates/complete-app/src/App.tsx +59 -0
  73. package/templates/complete-app/src/client.ts +61 -0
  74. package/templates/complete-app/src/client.tsx +18 -0
  75. package/templates/complete-app/src/pages/index.tsx +51 -0
  76. package/templates/complete-app/src/server.ts +218 -0
  77. package/templates/complete-app/tsconfig.json +22 -0
  78. package/templates/complete-app/tsconfig.server.json +19 -0
  79. package/templates/complete-app/vite.config.js +57 -0
  80. package/templates/complete-app/vite.config.ts +30 -0
  81. package/templates/complete-app/wasm/build.bat +0 -0
  82. package/templates/complete-app/wasm/build.sh +0 -0
  83. package/templates/complete-app/wasm/example.go +0 -0
  84. package/templates/fullstack-app/README.md +37 -0
  85. package/templates/fullstack-app/api/hello.js +11 -0
  86. package/templates/fullstack-app/api/hello.ts +18 -0
  87. package/templates/fullstack-app/api/users/[id].ts +73 -0
  88. package/templates/fullstack-app/api/users/index.ts +32 -0
  89. package/templates/fullstack-app/build/main.css +874 -0
  90. package/templates/fullstack-app/build/main.css.map +7 -0
  91. package/templates/fullstack-app/build/main.js +967 -0
  92. package/templates/fullstack-app/build/main.js.map +7 -0
  93. package/templates/fullstack-app/build.ts +210 -0
  94. package/templates/fullstack-app/index.html +36 -0
  95. package/templates/fullstack-app/package.json +35 -0
  96. package/templates/fullstack-app/postcss.config.js +6 -0
  97. package/templates/fullstack-app/process-tailwind.js +45 -0
  98. package/templates/fullstack-app/public/_redirects +1 -0
  99. package/templates/fullstack-app/public/route-handler.js +47 -0
  100. package/templates/fullstack-app/public/spa-fix.html +17 -0
  101. package/templates/fullstack-app/public/styles.css +975 -0
  102. package/templates/fullstack-app/public/tailwind.css +15 -0
  103. package/templates/fullstack-app/server.js +267 -0
  104. package/templates/fullstack-app/server.ts +474 -0
  105. package/templates/fullstack-app/src/README.md +55 -0
  106. package/templates/fullstack-app/src/client.js +87 -0
  107. package/templates/fullstack-app/src/components/ClientHome.tsx +0 -0
  108. package/templates/fullstack-app/src/components/ErrorBoundary.tsx +36 -0
  109. package/templates/fullstack-app/src/components/Layout.tsx +42 -0
  110. package/templates/fullstack-app/src/components/StateDemo.tsx +207 -0
  111. package/templates/fullstack-app/src/components/UserList.tsx +44 -0
  112. package/templates/fullstack-app/src/config.ts +42 -0
  113. package/templates/fullstack-app/src/data/api.ts +206 -0
  114. package/templates/fullstack-app/src/main.tsx +155 -0
  115. package/templates/fullstack-app/src/middleware.ts +28 -0
  116. package/templates/fullstack-app/src/pages/404.tsx +28 -0
  117. package/templates/fullstack-app/src/pages/[id].tsx +0 -0
  118. package/templates/fullstack-app/src/pages/_app.tsx +11 -0
  119. package/templates/fullstack-app/src/pages/_document.tsx +25 -0
  120. package/templates/fullstack-app/src/pages/_error.tsx +45 -0
  121. package/templates/fullstack-app/src/pages/about/index.tsx +67 -0
  122. package/templates/fullstack-app/src/pages/about.tsx +71 -0
  123. package/templates/fullstack-app/src/pages/api/users/[id].ts +73 -0
  124. package/templates/fullstack-app/src/pages/api/users/index.ts +43 -0
  125. package/templates/fullstack-app/src/pages/index.tsx +110 -0
  126. package/templates/fullstack-app/src/pages/users/[id].tsx +153 -0
  127. package/templates/fullstack-app/src/pages/users.tsx +60 -0
  128. package/templates/fullstack-app/src/pages/wasm-demo.tsx +1 -0
  129. package/templates/fullstack-app/src/router.ts +255 -0
  130. package/templates/fullstack-app/src/styles.css +5 -0
  131. package/templates/fullstack-app/tailwind.config.js +11 -0
  132. package/templates/fullstack-app/tsconfig.json +18 -0
  133. package/templates/fullstack-app/vite.config.js +87 -0
  134. package/templates/go/build.bat +36 -0
  135. package/templates/go/build.sh +43 -0
  136. package/templates/go/example.go +205 -0
  137. package/templates/go-wasm-app/README.md +38 -0
  138. package/templates/go-wasm-app/babel.config.js +21 -0
  139. package/templates/go-wasm-app/build-client.js +49 -0
  140. package/templates/go-wasm-app/build-wasm.js +237 -0
  141. package/templates/go-wasm-app/build.config.js +62 -0
  142. package/templates/go-wasm-app/build.js +218 -0
  143. package/templates/go-wasm-app/package.json +32 -0
  144. package/templates/go-wasm-app/public/index.html +128 -0
  145. package/templates/go-wasm-app/public/styles.css +197 -0
  146. package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
  147. package/templates/go-wasm-app/public/wasm/wasm_exec.js +561 -0
  148. package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +39 -0
  149. package/templates/go-wasm-app/server.js +70 -0
  150. package/templates/go-wasm-app/src/App.jsx +38 -0
  151. package/templates/go-wasm-app/src/app.js +173 -0
  152. package/templates/go-wasm-app/src/client.js +57 -0
  153. package/templates/go-wasm-app/src/components/Footer.jsx +13 -0
  154. package/templates/go-wasm-app/src/components/Header.jsx +19 -0
  155. package/templates/go-wasm-app/src/components/WasmDemo.jsx +120 -0
  156. package/templates/go-wasm-app/src/main.jsx +12 -0
  157. package/templates/go-wasm-app/src/wasm/example.go +75 -0
  158. package/templates/go-wasm-app/tsconfig.server.json +18 -0
  159. package/templates/go-wasm-app/vite.config.js +45 -0
  160. package/templates/ssr-template/package.json +16 -10
  161. package/templates/wasm/package.json +43 -43
  162. package/templates/wasm/src/App.tsx +2 -2
  163. package/dist/forms/index.d.ts +0 -2
  164. package/dist/forms/index.d.ts.map +0 -1
  165. package/dist/forms/types.d.ts +0 -2
  166. package/dist/forms/types.d.ts.map +0 -1
  167. package/dist/frontend/components/WasmLoader.d.ts +0 -2
  168. package/dist/frontend/components/WasmLoader.d.ts.map +0 -1
  169. package/dist/frontend/hooks/useWasm.d.ts +0 -2
  170. package/dist/frontend/hooks/useWasm.d.ts.map +0 -1
  171. package/dist/frontend/index.d.ts +0 -2
  172. package/dist/frontend/index.d.ts.map +0 -1
  173. package/dist/router/index.d.ts +0 -2
  174. package/dist/router/index.d.ts.map +0 -1
  175. package/dist/router/types.d.ts +0 -2
  176. package/dist/router/types.d.ts.map +0 -1
  177. package/dist/store/index.d.ts +0 -2
  178. package/dist/store/index.d.ts.map +0 -1
  179. package/dist/store/types.d.ts +0 -2
  180. package/dist/store/types.d.ts.map +0 -1
  181. package/templates/basic-app/package-lock.json +0 -7173
  182. package/templates/fullstack-template/package-lock.json +0 -3558
  183. package/templates/ssr-template/package-lock.json +0 -5380
  184. package/templates/wasm/package-lock.json +0 -5347
  185. package/templates/wasm/public/example.wasm +0 -0
package/README.md CHANGED
@@ -1,595 +1,395 @@
1
- # Baraqex 🚀
1
+ <div align="center">
2
2
 
3
- A powerful, modern JavaScript/TypeScript framework for building universal web applications with seamless WebAssembly integration, server-side rendering, and full-stack capabilities.
3
+ <img src="https://raw.githubusercontent.com/mohamedx2/baraqex/main/assets/logo.svg" alt="Baraqex Logo" width="180" height="180">
4
4
 
5
- ## ✨ Features
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
- ```bash
31
- npm install baraqex
32
- ```
7
+ ### ⚡ The Full-Stack Framework with WASM Superpowers
33
8
 
34
- ## 🚀 Quick Start
9
+ Build universal web applications with React-like syntax and Go-powered performance.
35
10
 
36
- ### Frontend Usage
11
+ [![npm version](https://img.shields.io/npm/v/baraqex?color=blue&label=npm)](https://www.npmjs.com/package/baraqex)
12
+ [![npm downloads](https://img.shields.io/npm/dm/baraqex?color=blue)](https://www.npmjs.com/package/baraqex)
13
+ [![GitHub stars](https://img.shields.io/github/stars/mohamedx2/baraqex?style=social)](https://github.com/mohamedx2/baraqex)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
15
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?logo=typescript)](https://www.typescriptlang.org/)
16
+ [![Docs](https://img.shields.io/badge/Docs-baraqex.tech-blue)](https://www.baraqex.tech)
37
17
 
38
- ```javascript
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
- function App() {
43
- const [count, setCount] = useState(0);
44
- const [wasmReady, setWasmReady] = useState(false);
20
+ </div>
45
21
 
46
- // Load WebAssembly module
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
- ## 📖 Documentation
24
+ ## Why Baraqex?
108
25
 
109
- ### WebAssembly Integration
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
- #### Browser WASM
34
+ ---
112
35
 
113
- ```javascript
114
- import { loadGoWasm, callWasmFunction, isWasmReady, getWasmFunctions } from 'baraqex';
36
+ ## ✨ Features
115
37
 
116
- // Load WASM module
117
- await loadGoWasm('/example.wasm', {
118
- debug: true,
119
- onLoad: (instance) => {
120
- console.log('WASM loaded!', instance);
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
- // Check if ready
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
- #### Server WASM
50
+ ---
138
51
 
139
- ```javascript
140
- import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
52
+ ## 🚀 Quick Start
141
53
 
142
- // Load WASM from file
143
- await loadGoWasmFromFile('./example.wasm', {
144
- debug: true,
145
- goWasmPath: './wasm_exec.cjs'
146
- });
54
+ ### Create a New Project
147
55
 
148
- // Use identical API as browser
149
- const result = callWasmFunction('goCalculate', 42);
56
+ ```bash
57
+ npx create-baraqex-app my-app
58
+ cd my-app
59
+ npm run dev
150
60
  ```
151
61
 
152
- #### Go WASM Example
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
- GOOS=js GOARCH=wasm go build -o example.wasm main.go
65
+ npm install baraqex
189
66
  ```
190
67
 
191
- ### Server-Side Rendering
68
+ ---
192
69
 
193
- #### Page Components
70
+ ## 📖 Basic Usage
194
71
 
195
- ```javascript
196
- // pages/index.js
197
- import { jsx } from 'baraqex';
72
+ ### Create a Component
73
+
74
+ ```jsx
75
+ import { jsx, useState } from 'baraqex';
198
76
 
199
- export default function HomePage(props) {
77
+ function Counter() {
78
+ const [count, setCount] = useState(0);
79
+
200
80
  return (
201
- <html>
202
- <head>
203
- <title>My App</title>
204
- </head>
205
- <body>
206
- <h1>Welcome to Baraqex!</h1>
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
- #### API Routes
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
- // GET /api/users
224
- const users = await getUsersFromDatabase();
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
- // POST /api/users
230
- const newUser = await createUser(req.body);
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
- ### Database Integration
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
- // MySQL
257
- const db = new Database({
258
- type: 'mysql',
259
- url: 'mysql://user:pass@localhost:3306/myapp'
260
- });
108
+ ```jsx
109
+ import { loadGoWasm, callWasmFunction } from 'baraqex';
261
110
 
262
- await db.connect();
263
- const users = await db.query('SELECT * FROM users WHERE active = ?', [true]);
111
+ // Load your Go WASM module
112
+ await loadGoWasm('/math.wasm');
264
113
 
265
- // PostgreSQL
266
- const db = new Database({
267
- type: 'postgres',
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
- ### Authentication
119
+ ### Start a Server
276
120
 
277
121
  ```javascript
278
- import { AuthService } from 'baraqex/server';
122
+ import { Server } from 'baraqex/server';
279
123
 
280
- const auth = new AuthService({
281
- secret: 'your-secret-key',
282
- expiresIn: '24h'
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
- // In your API routes
286
- export async function post(req, res) {
287
- const { username, password } = req.body;
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
- // Protected route
301
- export const middleware = [auth.requireAuth()];
141
+ ---
302
142
 
303
- export async function get(req, res) {
304
- // req.user is available
305
- res.json({ user: req.user });
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
- ## 🛠️ Development
189
+ ---
310
190
 
311
- ### Project Structure
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
- ### Build Scripts
195
+ ```jsx
196
+ import { jsx, useState, loadGoWasm, callWasmFunction } from 'baraqex';
332
197
 
333
- ```json
334
- {
335
- "scripts": {
336
- "dev": "baraqex dev",
337
- "build": "baraqex build",
338
- "start": "baraqex start",
339
- "build:wasm": "GOOS=js GOARCH=wasm go build -o public/app.wasm wasm/main.go"
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
- ### Development Server
230
+ ### Full-Stack API
345
231
 
346
232
  ```javascript
347
- import { createDevServer } from 'baraqex/server';
233
+ // server.js
234
+ import { Server } from 'baraqex/server';
348
235
 
349
- const server = createDevServer({
236
+ const server = new Server({
350
237
  port: 3000,
351
- enableCors: true
238
+ db: { type: 'mongodb', url: 'mongodb://localhost:27017/myapp' },
239
+ auth: { secret: 'your-secret-key' }
352
240
  });
353
241
 
354
- // Enable SSR with hot reloading
355
- server.enableSSR({ hydratable: true });
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
- import { createServer } from 'baraqex/server';
366
-
367
- const server = createServer({
368
- port: process.env.PORT || 3000,
369
- apiDir: './src/api',
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
- ### WASM Configuration
259
+ ---
389
260
 
390
- ```javascript
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
- // Server
403
- await loadGoWasmFromFile('./app.wasm', {
404
- debug: true,
405
- goWasmPath: './wasm_exec.cjs'
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
- ## 📊 Performance
281
+ ---
410
282
 
411
- ### WebAssembly Benefits
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
- ### Server Optimizations
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
- ## 🧪 Testing
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
- ### Complete Test Suite
295
+ Run benchmarks yourself:
426
296
 
427
297
  ```bash
428
- # Run all tests (builds project first)
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
- ### WASM Testing
301
+ ---
439
302
 
440
- ```javascript
441
- // test-wasm.js
442
- import { loadGoWasmFromFile, callWasmFunction } from 'baraqex/server';
303
+ ## 🧪 Testing
443
304
 
444
- async function testWasm() {
445
- await loadGoWasmFromFile('./example.wasm');
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
- testWasm();
458
- ```
309
+ # Run with coverage
310
+ npm run test:coverage
459
311
 
460
- ### Server Testing
312
+ # Run specific tests
313
+ npm run test:unit
314
+ npm run test:integration
461
315
 
462
- ```javascript
463
- import request from 'supertest';
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
- ### Test Results
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
- ## 🚀 Deployment
322
+ ## 🤝 Contributing
492
323
 
493
- ### Production Build
324
+ We love contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
494
325
 
495
326
  ```bash
496
- # Build WASM modules
497
- npm run build:wasm
327
+ # Clone the repo
328
+ git clone https://github.com/mohamedx2/baraqex.git
329
+ cd baraqex
498
330
 
499
- # Build application
500
- npm run build
331
+ # Install dependencies
332
+ npm install
501
333
 
502
- # Start production server
503
- npm start
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
- # Build app
527
- RUN npm run build
337
+ # Start development
338
+ npm run dev
339
+ ```
528
340
 
529
- EXPOSE 3000
341
+ ---
530
342
 
531
- CMD ["npm", "start"]
532
- ```
343
+ ## 📦 Templates
533
344
 
534
- ### Environment Variables
345
+ Create projects with pre-configured templates:
535
346
 
536
347
  ```bash
537
- # Server
538
- PORT=3000
539
- NODE_ENV=production
348
+ # Basic app
349
+ npx create-baraqex-app my-app --template basic
540
350
 
541
- # Database
542
- DATABASE_URL=mongodb://localhost:27017/myapp
351
+ # Full-stack with database
352
+ npx create-baraqex-app my-app --template fullstack
543
353
 
544
- # Authentication
545
- JWT_SECRET=your-super-secret-key
354
+ # SSR application
355
+ npx create-baraqex-app my-app --template ssr
546
356
 
547
- # WASM
548
- WASM_DEBUG=false
357
+ # WASM-powered app
358
+ npx create-baraqex-app my-app --template wasm
549
359
  ```
550
360
 
551
- ## 🤝 Contributing
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
- MIT License - see the [LICENSE](LICENSE) file for details.
363
+ ## 🗺️ Roadmap
563
364
 
564
- ## 🆘 Support
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
- - **Documentation**: [www.baraqex.tech](https://www.baraqex.tech)
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
- ## 🎯 Examples
379
+ ## 📄 License
573
380
 
574
- Check out the [examples directory](./examples) for complete sample applications:
381
+ MIT © [Mohamed X](https://github.com/mohamedx2)
575
382
 
576
- - **Basic WASM App** - Simple calculator with Go WASM
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
- ## 🔗 Related Projects
385
+ <div align="center">
583
386
 
584
- - **Go WASM Runtime**: Standard Go WebAssembly support
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
- **Made with ❤️ by the Baraqex team**
391
+ **One Culture, One Framework** | **ثقافة واحدة، إطار عمل واحد**
592
392
 
593
- *Build universal, high-performance web applications with the power of WebAssembly and modern JavaScript.*
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
- **Learn more at [www.baraqex.tech](https://www.baraqex.tech)**
395
+ </div>