blaizejs 0.1.0 โ†’ 0.2.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/README.md CHANGED
@@ -1,308 +1,856 @@
1
- # BlaizeJS
1
+ # ๐Ÿš€ BlaizeJS Core
2
+
3
+ > A blazing-fast, type-safe Node.js framework with file-based routing, powerful middleware, and end-to-end type safety
4
+
5
+ [![npm version](https://badge.fury.io/js/blaizejs.svg)](https://badge.fury.io/js/blaizejs)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
8
+
9
+ ## ๐Ÿ“‹ Table of Contents
10
+
11
+ - [๐ŸŒŸ Features](#-features)
12
+ - [๐Ÿ“ฆ Installation](#-installation)
13
+ - [๐Ÿš€ Quick Start](#-quick-start)
14
+ - [๐Ÿ—๏ธ Architecture Overview](#๏ธ-architecture-overview)
15
+ - [๐Ÿ“ Project Structure](#-project-structure)
16
+ - [๐ŸŒ Production Deployment](#-production-deployment)
17
+ - [๐Ÿ”— Framework Modules](#-framework-modules)
18
+ - [๐Ÿงฉ Plugin Ecosystem](#-plugin-ecosystem)
19
+ - [๐Ÿ“ก Type-Safe Client](#-type-safe-client)
20
+ - [โœ… Testing](#-testing)
21
+ - [๐Ÿค Contributing](#-contributing)
22
+ - [๐Ÿ—บ๏ธ Roadmap](#๏ธ-roadmap)
23
+
24
+ ## ๐ŸŒŸ Features
25
+
26
+ - โšก **Blazing Fast Performance** - HTTP/2 by default with HTTP/1.1 fallback
27
+ - ๐Ÿ”’ **End-to-End Type Safety** - Full TypeScript support from API to client
28
+ - ๐Ÿ“ **File-Based Routing** - Intuitive routing based on file structure
29
+ - ๐Ÿ”— **Powerful Middleware System** - Composable middleware with onion-style execution
30
+ - ๐Ÿงฉ **Plugin Architecture** - Extensible with lifecycle management
31
+ - ๐ŸŒ **Context Management** - AsyncLocalStorage for automatic context propagation
32
+ - ๐Ÿ”„ **Hot Reloading** - Instant development feedback
33
+ - ๐Ÿ›ก๏ธ **Schema Validation** - Built-in Zod integration for request/response validation
34
+ - ๐Ÿ”— **Client Generation** - Automatic type-safe API client generation
35
+ - ๐Ÿš€ **Production Ready** - Graceful shutdown, error handling, and monitoring
36
+
37
+ ## ๐Ÿ“ฆ Installation
2
38
 
3
- ๐Ÿ”ฅ A blazing-fast, TypeScript-first API framework with file-based routing, powerful plugins, and end-to-end type safety.
39
+ ```bash
40
+ # Using pnpm (recommended)
41
+ pnpm add blaizejs
4
42
 
5
- ## Overview
43
+ # Using npm
44
+ npm install blaizejs
6
45
 
7
- BlaizeJS is a modern Node.js framework designed for building high-performance, type-safe APIs. It features file-based routing, a powerful middleware system, an extensible plugin architecture, and end-to-end type safety with zero configuration. Both the middleware and plugin systems are designed to be powerful yet intuitive, allowing developers to extend functionality with minimal effort.
46
+ # Using yarn
47
+ yarn add blaizejs
48
+ ```
8
49
 
9
- ## Features
50
+ ### ๐Ÿ“‹ Requirements
10
51
 
11
- - **HTTP/2 Support** - Built on modern Node.js with HTTP/2 and HTTP/1.1 fallback
12
- - **File-based Routing** - Just create files in your routes directory and they automatically become API endpoints
13
- - **Type Safety** - Full TypeScript support with automatic route type inference
14
- - **Middleware System** - Intuitive middleware chain for request/response processing
15
- - **Plugin Architecture** - Extend functionality with a powerful plugin system
16
- - **Context API** - Clean, unified interface for request handling using AsyncLocalStorage
17
- - **Developer Experience** - Fast refresh during development with minimal configuration
52
+ - **Node.js**: >= 22.0.0 (LTS recommended)
53
+ - **TypeScript**: >= 5.8.3 (for development)
54
+ - **Package Manager**: pnpm 9.7.0+ (recommended)
18
55
 
19
- ## Project Structure
56
+ ## ๐Ÿš€ Quick Start
20
57
 
21
- ```
22
- blaizejs/
23
- โ”œโ”€โ”€ src/ # Source code
24
- โ”‚ โ”œโ”€โ”€ context/ # Request/response context
25
- โ”‚ โ”œโ”€โ”€ middleware/ # Middleware system
26
- โ”‚ โ”œโ”€โ”€ plugins/ # Plugin system
27
- โ”‚ โ”œโ”€โ”€ router/ # File-based routing
28
- โ”‚ โ”œโ”€โ”€ server/ # HTTP/2 server implementation
29
- โ”‚ โ”œโ”€โ”€ types/ # TypeScript type definitions
30
- โ”‚ โ”œโ”€โ”€ utils/ # Utility functions
31
- โ”‚ โ””โ”€โ”€ index.ts # Main entry point
32
- โ”œโ”€โ”€ examples/ # Example applications
33
- โ”‚ โ”œโ”€โ”€ basic/ # Basic server example
34
- โ”‚ โ”œโ”€โ”€ middleware/ # Middleware examples
35
- โ”‚ โ”œโ”€โ”€ plugins/ # Plugin examples
36
- โ”‚ โ””โ”€โ”€ routing/ # Routing examples
37
- โ”œโ”€โ”€ tests/ # Test suite
38
- โ”‚ โ”œโ”€โ”€ context/ # Context tests
39
- โ”‚ โ”œโ”€โ”€ middleware/ # Middleware tests
40
- โ”‚ โ”œโ”€โ”€ plugins/ # Plugin tests
41
- โ”‚ โ”œโ”€โ”€ router/ # Router tests
42
- โ”‚ โ”œโ”€โ”€ server/ # Server tests
43
- โ”‚ โ””โ”€โ”€ integration/ # Integration tests
44
- โ”œโ”€โ”€ package.json # Project configuration
45
- โ””โ”€โ”€ tsconfig.json # TypeScript configuration
46
- ```
58
+ ### ๐ŸŽฏ Create Your First Server
47
59
 
48
- ## Getting Started
60
+ ```typescript
61
+ import { createServer } from 'blaizejs';
62
+ import { fileURLToPath } from 'node:url';
63
+ import path from 'node:path';
49
64
 
50
- ### Installation
65
+ // Required for ESM module path resolution
66
+ const __filename = fileURLToPath(import.meta.url);
67
+ const __dirname = path.dirname(__filename);
51
68
 
52
- ```bash
53
- pnpm install blaizejs
54
- ```
69
+ // Create server with automatic routing
70
+ const server = createServer({
71
+ routesDir: path.resolve(__dirname, './routes'),
72
+ });
55
73
 
56
- ### Quick Start
74
+ await server.listen();
75
+ console.log('๐Ÿš€ Server running on https://localhost:3000');
76
+ ```
57
77
 
58
- Create a new file `server.ts`:
78
+ ### ๐Ÿ“ Create Your First Route
59
79
 
60
80
  ```typescript
61
- import { createServer } from 'blaizejs';
81
+ // routes/users.ts
82
+ import { createGetRoute, createPostRoute } from 'blaizejs';
83
+ import { z } from 'zod';
84
+
85
+ // GET /users - List users with type safety
86
+ export const getUsers = createGetRoute({
87
+ schema: {
88
+ query: z.object({
89
+ limit: z.coerce.number().min(1).max(100).default(10),
90
+ search: z.string().optional(),
91
+ }),
92
+ response: z.object({
93
+ users: z.array(
94
+ z.object({
95
+ id: z.string(),
96
+ name: z.string(),
97
+ email: z.string(),
98
+ })
99
+ ),
100
+ total: z.number(),
101
+ }),
102
+ },
103
+ handler: async ctx => {
104
+ // Query params are automatically typed and validated
105
+ const { limit, search } = ctx.request.query;
62
106
 
63
- const server = createServer({
64
- port: 3000,
65
- routesDir: './routes',
107
+ const users = await findUsers({ limit, search });
108
+ return { users, total: users.length };
109
+ },
66
110
  });
67
111
 
68
- server.listen().then(() => {
69
- console.log(`Server running at http://localhost:${server.port}`);
112
+ // POST /users - Create user with validation
113
+ export const createUser = createPostRoute({
114
+ schema: {
115
+ body: z.object({
116
+ name: z.string().min(1),
117
+ email: z.string().email(),
118
+ }),
119
+ response: z.object({
120
+ id: z.string(),
121
+ name: z.string(),
122
+ email: z.string(),
123
+ createdAt: z.string(),
124
+ }),
125
+ },
126
+ handler: async ctx => {
127
+ // Request body is automatically validated
128
+ const userData = ctx.request.body;
129
+
130
+ const user = await createNewUser(userData);
131
+ return user;
132
+ },
70
133
  });
71
134
  ```
72
135
 
73
- Create a route file `routes/hello.ts`:
136
+ ### ๐Ÿ”— Add Middleware
74
137
 
75
138
  ```typescript
76
- import { Middleware } from 'blaizejs';
139
+ import { createServer, createMiddleware } from 'blaizejs';
140
+ import { fileURLToPath } from 'node:url';
141
+ import path from 'node:path';
142
+
143
+ const __filename = fileURLToPath(import.meta.url);
144
+ const __dirname = path.dirname(__filename);
145
+
146
+ // Create logging middleware
147
+ const logger = createMiddleware({
148
+ name: 'logger',
149
+ handler: async (ctx, next) => {
150
+ const start = Date.now();
151
+ console.log(`โ†’ ${ctx.request.method} ${ctx.request.path}`);
77
152
 
78
- // Export default middleware function
79
- export default function helloRoute(): Middleware {
80
- return async (ctx, next) => {
81
- ctx.json({ message: 'Hello, World!' });
82
153
  await next();
83
- };
84
- }
154
+
155
+ const duration = Date.now() - start;
156
+ console.log(`โ† ${ctx.response.raw.statusCode} (${duration}ms)`);
157
+ },
158
+ });
159
+
160
+ // Create server with middleware
161
+ const server = createServer({
162
+ routesDir: path.resolve(__dirname, './routes'),
163
+ middleware: [logger],
164
+ });
165
+
166
+ await server.listen();
85
167
  ```
86
168
 
87
- Start the server:
169
+ ## ๐Ÿ—๏ธ Architecture Overview
88
170
 
89
- ```bash
90
- ts-node server.ts
171
+ BlaizeJS is built around five core modules that work together seamlessly:
172
+
173
+ ```mermaid
174
+ graph TD
175
+ A[Server] --> B[Router]
176
+ A --> C[Context]
177
+ B --> D[Middleware]
178
+ A --> E[Plugins]
179
+
180
+ B --> F[File-based Routes]
181
+ C --> G[AsyncLocalStorage]
182
+ D --> H[Composable Pipeline]
183
+ E --> I[Lifecycle Management]
184
+
185
+ F --> J[Type-safe Handlers]
186
+ G --> K[State Management]
187
+ H --> L[Request/Response Flow]
188
+ I --> M[Plugin Integration]
91
189
  ```
92
190
 
93
- Visit http://localhost:3000/hello to see your API in action.
191
+ ### ๐Ÿ”„ Request Lifecycle
94
192
 
95
- ## Middleware
193
+ 1. **Server** receives HTTP request
194
+ 2. **Context** creates request/response wrappers with AsyncLocalStorage
195
+ 3. **Router** matches request to file-based route
196
+ 4. **Middleware** executes in onion-style pattern
197
+ 5. **Route Handler** processes request with full type safety
198
+ 6. **Context** sends validated response
96
199
 
97
- BlaizeJS uses a simple middleware system similar to Express or Koa, but with full TypeScript support:
200
+ ## ๐Ÿ“ Project Structure
98
201
 
99
- ```typescript
100
- import { createServer, Middleware } from 'blaizejs';
202
+ ### ๐ŸŽฏ Recommended Structure
101
203
 
102
- // Create logging middleware
103
- const logger: Middleware = async (ctx, next) => {
104
- const start = Date.now();
105
- console.log(`${ctx.method} ${ctx.path}`);
204
+ ```
205
+ my-blaize-app/
206
+ โ”œโ”€โ”€ src/
207
+ โ”‚ โ”œโ”€โ”€ server.ts # Server entry point
208
+ โ”‚ โ”œโ”€โ”€ app-routes.ts # Route registry for blaize client
209
+ โ”‚ โ”œโ”€โ”€ routes/ # File-based routes
210
+ โ”‚ โ”‚ โ”œโ”€โ”€ index.ts # โ†’ /
211
+ โ”‚ โ”‚ โ”œโ”€โ”€ users.ts # โ†’ /users
212
+ โ”‚ โ”‚ โ”œโ”€โ”€ users/
213
+ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [id].ts # โ†’ /users/:id
214
+ โ”‚ โ”‚ โ””โ”€โ”€ api/
215
+ โ”‚ โ”‚ โ””โ”€โ”€ v1/
216
+ โ”‚ โ”‚ โ””โ”€โ”€ posts.ts # โ†’ /api/v1/posts
217
+ โ”‚ โ”œโ”€โ”€ middleware/ # Custom middleware
218
+ โ”‚ โ”œโ”€โ”€ plugins/ # Custom plugins
219
+ โ”‚ โ””โ”€โ”€ types/ # Shared types
220
+ โ”œโ”€โ”€ tests/ # Test files
221
+ โ”œโ”€โ”€ package.json
222
+ โ””โ”€โ”€ tsconfig.json
223
+ ```
106
224
 
107
- await next();
225
+ ### ๐Ÿ“Š Module Responsibilities
108
226
 
109
- const ms = Date.now() - start;
110
- console.log(`${ctx.method} ${ctx.path} - ${ctx.status} (${ms}ms)`);
111
- };
227
+ | Module | Purpose | Key Features |
228
+ | -------------- | ------------------------- | -------------------------- |
229
+ | **Server** | HTTP server management | HTTP/2, SSL, lifecycle |
230
+ | **Router** | Request routing | File-based, type-safe |
231
+ | **Context** | Request/response handling | AsyncLocalStorage, state |
232
+ | **Middleware** | Request processing | Composable, error handling |
233
+ | **Plugins** | Framework extension | Lifecycle, validation |
112
234
 
113
- // Create error handling middleware
114
- const errorHandler: Middleware = async (ctx, next) => {
115
- try {
116
- await next();
117
- } catch (err) {
118
- console.error('Request error:', err);
119
- ctx.status = 500;
120
- ctx.json({
121
- error: 'Internal Server Error',
122
- message: process.env.NODE_ENV === 'production' ? undefined : String(err),
123
- });
124
- }
125
- };
235
+ ## ๐ŸŒ Production Deployment
126
236
 
127
- // Create server with middleware
237
+ ### โš ๏ธ HTTP/2 Hosting Limitations
238
+
239
+ BlaizeJS defaults to HTTP/2 for optimal performance, but many hosting providers don't expose SSL certificate access required for HTTP/2:
240
+
241
+ ```typescript
242
+ // Production configuration for hosting providers
128
243
  const server = createServer({
129
- middleware: [errorHandler, logger],
244
+ routesDir: path.resolve(__dirname, './routes'),
245
+ http2: {
246
+ // Disable HTTP/2 if certificates aren't accessible
247
+ enabled: process.env.HTTP2_ENABLED === 'true',
248
+ },
130
249
  });
250
+ ```
131
251
 
132
- // Add more middleware after server creation
133
- server.use(async (ctx, next) => {
134
- ctx.state.userIp = ctx.req.socket.remoteAddress;
135
- await next();
252
+ ### ๐Ÿ”ง Hosting Provider Configurations
253
+
254
+ ```typescript
255
+ // Vercel/Netlify (HTTP/1.1 only)
256
+ const server = createServer({
257
+ port: parseInt(process.env.PORT || '3000'),
258
+ routesDir: path.resolve(__dirname, './routes'),
259
+ http2: { enabled: false },
136
260
  });
137
261
 
138
- server.listen(3000);
139
- ```
262
+ // VPS/Dedicated (HTTP/2 with Let's Encrypt)
263
+ const server = createServer({
264
+ port: 443,
265
+ host: '0.0.0.0',
266
+ routesDir: path.resolve(__dirname, './routes'),
267
+ http2: {
268
+ enabled: true,
269
+ keyFile: '/etc/letsencrypt/live/yourdomain.com/privkey.pem',
270
+ certFile: '/etc/letsencrypt/live/yourdomain.com/fullchain.pem',
271
+ },
272
+ });
140
273
 
141
- ## Context API
274
+ // Docker Container
275
+ const server = createServer({
276
+ port: parseInt(process.env.PORT || '3000'),
277
+ host: '0.0.0.0',
278
+ routesDir: path.resolve(__dirname, './routes'),
279
+ http2: {
280
+ enabled: process.env.SSL_CERT_PATH && process.env.SSL_KEY_PATH,
281
+ keyFile: process.env.SSL_KEY_PATH,
282
+ certFile: process.env.SSL_CERT_PATH,
283
+ },
284
+ });
285
+ ```
142
286
 
143
- The Context object provides a unified interface for handling requests and responses:
287
+ ### ๐Ÿš€ Environment Configuration
144
288
 
145
289
  ```typescript
146
- // Example middleware using context
147
- const middleware: Middleware = async (ctx, next) => {
148
- // Access request data
149
- console.log('Method:', ctx.method);
150
- console.log('Path:', ctx.path);
151
- console.log('Query parameters:', ctx.query);
152
-
153
- // Add data to state (available to other middleware)
154
- ctx.state.userId = 'user_123';
155
-
156
- // Continue to next middleware
157
- await next();
158
-
159
- // Send response
160
- ctx.status = 200;
161
- ctx.json({
162
- user: ctx.state.userId,
163
- data: 'Response data',
164
- });
290
+ // Environment-aware server setup
291
+ const getServerConfig = () => {
292
+ const env = process.env.NODE_ENV || 'development';
293
+
294
+ switch (env) {
295
+ case 'development':
296
+ return {
297
+ port: 3000,
298
+ routesDir: path.resolve(__dirname, './routes'),
299
+ http2: { enabled: true }, // Auto-generates certs
300
+ };
301
+
302
+ case 'production':
303
+ return {
304
+ port: parseInt(process.env.PORT || '443'),
305
+ host: '0.0.0.0',
306
+ routesDir: path.resolve(__dirname, './dist/routes'),
307
+ http2: {
308
+ enabled: !!process.env.SSL_CERT_PATH,
309
+ keyFile: process.env.SSL_KEY_PATH,
310
+ certFile: process.env.SSL_CERT_PATH,
311
+ },
312
+ };
313
+
314
+ case 'test':
315
+ return {
316
+ port: 0,
317
+ routesDir: path.resolve(__dirname, './test-fixtures/routes'),
318
+ http2: { enabled: false },
319
+ };
320
+ }
165
321
  };
322
+
323
+ const server = createServer(getServerConfig());
166
324
  ```
167
325
 
168
- ## HTTP/2 Support
326
+ > **๐Ÿ”„ HTTP/2 Workaround:** We're actively working on solutions for HTTP/2 deployment in constrained hosting environments. Follow our roadmap for updates.
327
+
328
+ ## ๐Ÿ”— Framework Modules
169
329
 
170
- BlaizeJS supports HTTP/2 with fallback to HTTP/1.1:
330
+ ### ๐ŸŒ Server Module
331
+
332
+ High-performance HTTP/2 server with graceful lifecycle management.
171
333
 
172
334
  ```typescript
173
335
  import { createServer } from 'blaizejs';
174
- import fs from 'node:fs';
175
- import path from 'node:path';
176
336
 
177
- // Create HTTP/2 server with TLS
178
337
  const server = createServer({
179
338
  port: 3000,
180
- http2: {
181
- enabled: true,
182
- keyFile: path.join(__dirname, 'certs/key.pem'),
183
- certFile: path.join(__dirname, 'certs/cert.pem'),
339
+ routesDir: './routes',
340
+ http2: { enabled: true },
341
+ });
342
+
343
+ // Event-driven lifecycle
344
+ server.events.on('started', () => console.log('Server ready'));
345
+ server.events.on('stopping', () => console.log('Graceful shutdown'));
346
+
347
+ await server.listen();
348
+ ```
349
+
350
+ [๐Ÿ“– Server Module Documentation](./src/server/README.md)
351
+
352
+ ### ๐Ÿš€ Router Module
353
+
354
+ File-based routing with automatic path generation and type safety.
355
+
356
+ ```typescript
357
+ import { createGetRoute } from 'blaizejs';
358
+ import { z } from 'zod';
359
+
360
+ // routes/posts/[id].ts โ†’ GET /posts/:id
361
+ export const getPost = createGetRoute({
362
+ schema: {
363
+ params: z.object({ id: z.string().uuid() }),
364
+ response: z.object({
365
+ id: z.string(),
366
+ title: z.string(),
367
+ content: z.string(),
368
+ }),
369
+ },
370
+ handler: async (ctx, params) => {
371
+ return await findPost(params.id);
184
372
  },
185
373
  });
374
+ ```
375
+
376
+ [๐Ÿ“– Router Module Documentation](./src/router/README.md)
377
+
378
+ ### ๐Ÿ”— Context Module
379
+
380
+ Request/response context with AsyncLocalStorage integration.
186
381
 
187
- server.listen();
382
+ ```typescript
383
+ import { getCurrentContext, setState, getState } from 'blaizejs';
384
+
385
+ export const handler = async () => {
386
+ const ctx = getCurrentContext(); // Available anywhere
387
+
388
+ // Request data
389
+ const userAgent = ctx.request.header('user-agent');
390
+ const body = ctx.request.body;
391
+
392
+ // State management
393
+ setState('userId', '123');
394
+ const userId = getState<string>('userId');
395
+
396
+ // Response
397
+ return ctx.response.json({ success: true });
398
+ };
188
399
  ```
189
400
 
190
- ## Plugin System
401
+ [๐Ÿ“– Context Module Documentation](./src/context/README.md)
191
402
 
192
- Extend functionality with plugins:
403
+ ### ๐Ÿ”— Middleware Module
404
+
405
+ Composable middleware with onion-style execution.
193
406
 
194
407
  ```typescript
195
- import { createServer } from 'blaizejs';
196
- import corsPlugin from '@blaizejs/cors-plugin';
197
- import loggerPlugin from '@blaizejs/logger-plugin';
408
+ import { createMiddleware, compose } from 'blaizejs';
198
409
 
199
- const server = createServer({
200
- plugins: [corsPlugin({ origin: '*' }), loggerPlugin({ level: 'info' })],
410
+ const auth = createMiddleware({
411
+ name: 'auth',
412
+ handler: async (ctx, next) => {
413
+ // Pre-processing
414
+ const token = ctx.request.header('authorization');
415
+ if (!token) return ctx.response.status(401).json({ error: 'Unauthorized' });
416
+
417
+ await next();
418
+
419
+ // Post-processing
420
+ ctx.response.header('X-Authenticated', 'true');
421
+ },
201
422
  });
202
423
 
203
- // Register plugins after server creation
204
- server.register(myCustomPlugin()).then(() => {
205
- server.listen(3000);
424
+ // Compose multiple middleware
425
+ const apiMiddleware = compose([cors, auth, rateLimit]);
426
+ ```
427
+
428
+ [๐Ÿ“– Middleware Module Documentation](./src/middleware/README.md)
429
+
430
+ ### ๐Ÿงฉ Plugins Module
431
+
432
+ Extensible plugin system with lifecycle management.
433
+
434
+ ```typescript
435
+ import { createPlugin } from 'blaizejs';
436
+
437
+ const databasePlugin = createPlugin(
438
+ 'database',
439
+ '1.0.0',
440
+ async (server, options) => {
441
+ let db: Database;
442
+
443
+ return {
444
+ initialize: async () => {
445
+ db = await connectToDatabase(options.connectionString);
446
+ server.context.setGlobal('db', db);
447
+ },
448
+ terminate: async () => {
449
+ await db.close();
450
+ },
451
+ };
452
+ },
453
+ { connectionString: 'mongodb://localhost:27017/app' }
454
+ );
455
+
456
+ const server = createServer({
457
+ routesDir: './routes',
458
+ plugins: [databasePlugin()],
206
459
  });
207
460
  ```
208
461
 
209
- ## CLI Commands (Coming Soon)
462
+ [๐Ÿ“– Plugins Module Documentation](./src/plugins/README.md)
463
+
464
+ ## ๐Ÿงฉ Plugin Ecosystem
465
+
466
+ ### ๐Ÿ—๏ธ Official Plugins
467
+
468
+ | Plugin | Purpose | Status |
469
+ | ----------------------------- | ------------------------------ | -------------- |
470
+ | `@blaizejs/auth-plugin` | Authentication & authorization | ๐Ÿ”„ Coming Soon |
471
+ | `@blaizejs/database-plugin` | Database integration | ๐Ÿ”„ Coming Soon |
472
+ | `@blaizejs/cache-plugin` | Caching strategies | ๐Ÿ”„ Coming Soon |
473
+ | `@blaizejs/validation-plugin` | Enhanced validation | ๐Ÿ”„ Coming Soon |
474
+ | `@blaizejs/monitoring-plugin` | Metrics & observability | ๐Ÿ”„ Coming Soon |
475
+
476
+ ### ๐Ÿ› ๏ธ Creating Custom Plugins
477
+
478
+ ```typescript
479
+ import { createPlugin } from 'blaizejs';
480
+
481
+ export const myPlugin = createPlugin(
482
+ 'my-plugin',
483
+ '1.0.0',
484
+ (server, options) => {
485
+ // Add middleware
486
+ server.use(
487
+ createMiddleware({
488
+ name: 'my-middleware',
489
+ handler: async (ctx, next) => {
490
+ // Plugin logic
491
+ await next();
492
+ },
493
+ })
494
+ );
495
+
496
+ // Add routes
497
+ server.router.addRoute('GET', '/plugin-route', {
498
+ handler: () => ({ message: 'From plugin' }),
499
+ });
500
+ },
501
+ {
502
+ /* default options */
503
+ }
504
+ );
505
+ ```
506
+
507
+ ## ๐Ÿ“ก Type-Safe Client
508
+
509
+ BlaizeJS provides seamless client generation with the `@blaizejs/client` package for consuming your APIs with full type safety:
210
510
 
211
- BlaizeJS will include a CLI for project creation and development:
511
+ ### ๐Ÿ“ฆ Client Installation
212
512
 
213
513
  ```bash
214
- # Install the CLI globally
215
- pnpm install -g @blaizejs/cli
514
+ # Install the client package
515
+ pnpm add @blaizejs/client
516
+ ```
517
+
518
+ ### ๐ŸŽฏ Export Your Routes
519
+
520
+ First, export your routes from your server for client consumption:
521
+
522
+ ```typescript
523
+ // routes/hello.ts
524
+ import { createGetRoute, createPostRoute } from 'blaizejs';
525
+ import { z } from 'zod';
526
+
527
+ export const getHello = createGetRoute({
528
+ schema: {
529
+ query: z.object({
530
+ name: z.string().optional(),
531
+ }),
532
+ response: z.object({
533
+ message: z.string(),
534
+ timestamp: z.string(),
535
+ }),
536
+ },
537
+ handler: async ctx => {
538
+ const { name } = ctx.request.query;
539
+ return {
540
+ message: `Hello ${name || 'World'}!`,
541
+ timestamp: new Date().toISOString(),
542
+ };
543
+ },
544
+ });
545
+
546
+ export const postHello = createPostRoute({
547
+ schema: {
548
+ body: z.object({
549
+ message: z.string(),
550
+ }),
551
+ response: z.object({
552
+ id: z.string(),
553
+ echo: z.string(),
554
+ }),
555
+ },
556
+ handler: async ctx => {
557
+ const { message } = ctx.request.body;
558
+ return {
559
+ id: crypto.randomUUID(),
560
+ echo: message,
561
+ };
562
+ },
563
+ });
564
+ ```
565
+
566
+ ```typescript
567
+ // app-routes.ts - Export all your routes
568
+ import { getHello, postHello } from './routes/hello.js';
569
+
570
+ export const routes = {
571
+ getHello,
572
+ postHello,
573
+ } as const;
574
+ ```
575
+
576
+ ### ๐Ÿ”— Create Type-Safe Client
577
+
578
+ ```typescript
579
+ // client.ts
580
+ import { createClient } from '@blaizejs/client';
581
+ import { routes } from './app-routes.js';
582
+
583
+ // Create client with full type safety
584
+ const client = createClient('http://localhost:3000', routes);
585
+
586
+ // Fully typed API calls with method grouping
587
+ const helloData = await client.$get.getHello({
588
+ query: { name: 'TypeScript' }, // Typed and validated
589
+ });
590
+
591
+ console.log(helloData.message); // Type: string
592
+ console.log(helloData.timestamp); // Type: string
593
+
594
+ // POST request with body validation
595
+ const postData = await client.$post.postHello({
596
+ body: { message: 'Hello from client!' }, // Typed and validated
597
+ });
598
+
599
+ console.log(postData.id); // Type: string
600
+ console.log(postData.echo); // Type: string
601
+ ```
216
602
 
217
- # Create a new project
218
- blaize create my-api
603
+ ### ๐ŸŽ›๏ธ Client Configuration
219
604
 
220
- # Start development server
221
- blaize dev
605
+ ```typescript
606
+ import { createClient } from '@blaizejs/client';
607
+ import type { ClientConfig } from '@blaizejs/types';
608
+
609
+ // Advanced client configuration
610
+ const config: ClientConfig = {
611
+ baseUrl: 'https://api.example.com',
612
+ defaultHeaders: {
613
+ Authorization: 'Bearer your-token',
614
+ 'User-Agent': 'MyApp/1.0.0',
615
+ },
616
+ timeout: 10000,
617
+ };
618
+
619
+ const client = createClient(config, routes);
620
+
621
+ // All requests will use the configured headers and timeout
622
+ const data = await client.$get.getHello();
623
+ ```
624
+
625
+ ### ๐Ÿ” Client Method Structure
626
+
627
+ The client organizes methods by HTTP verb using the `$method` pattern:
628
+
629
+ ```typescript
630
+ // Available client methods
631
+ client.$get.routeName(); // GET requests
632
+ client.$post.routeName(); // POST requests
633
+ client.$put.routeName(); // PUT requests
634
+ client.$delete.routeName(); // DELETE requests
635
+ client.$patch.routeName(); // PATCH requests
636
+ client.$head.routeName(); // HEAD requests
637
+ client.$options.routeName(); // OPTIONS requests
638
+ ```
639
+
640
+ **Key Client Features:**
641
+
642
+ - ๐Ÿ”’ **Full Type Safety** - Automatically inferred from your route schemas
643
+ - โœ… **Request Validation** - Client-side validation before sending requests
644
+ - ๐Ÿ“Š **Response Validation** - Runtime validation of API responses
645
+ - ๐ŸŽฏ **IntelliSense Support** - Complete autocomplete for all routes and parameters
646
+ - ๐Ÿ”„ **Error Handling** - Typed error responses with detailed validation messages
647
+ - โšก **Lightweight** - Minimal runtime overhead with proxy-based implementation
222
648
 
223
- # Build for production
224
- blaize build
649
+ [๐Ÿ“– Client Package Documentation](https://github.com/jleajones/blaize/tree/main/packages/blaize-client#readme)
225
650
 
226
- # Run in production
227
- blaize start
651
+ ## โœ… Testing
652
+
653
+ ### ๐Ÿงช Framework Testing Tools
654
+
655
+ BlaizeJS provides comprehensive testing utilities:
656
+
657
+ ```typescript
658
+ import { describe, test, expect } from 'vitest';
659
+ import { createTestContext } from '@blaizejs/testing-utils';
660
+ import { getUsers } from '../routes/users';
661
+
662
+ describe('Users API', () => {
663
+ test('should return paginated users', async () => {
664
+ const ctx = createTestContext({
665
+ method: 'GET',
666
+ path: '/users',
667
+ query: { limit: '5', offset: '0' },
668
+ });
669
+
670
+ const result = await getUsers.handler(ctx, {});
671
+
672
+ expect(result).toEqual({
673
+ users: expect.arrayContaining([
674
+ expect.objectContaining({
675
+ id: expect.any(String),
676
+ name: expect.any(String),
677
+ email: expect.any(String),
678
+ }),
679
+ ]),
680
+ total: expect.any(Number),
681
+ });
682
+ });
683
+ });
228
684
  ```
229
685
 
230
- ## Development
686
+ ### ๐Ÿ”ง Testing Configuration
687
+
688
+ ```json
689
+ {
690
+ "scripts": {
691
+ "test": "vitest run",
692
+ "test:watch": "vitest",
693
+ "test:coverage": "vitest run --coverage"
694
+ }
695
+ }
696
+ ```
231
697
 
232
- ### Building the Project
698
+ ### ๐Ÿƒโ€โ™‚๏ธ Running Tests
233
699
 
234
700
  ```bash
235
- # Install dependencies
236
- pnpm install
701
+ # Run all tests
702
+ pnpm test
703
+
704
+ # Watch mode
705
+ pnpm test:watch
706
+
707
+ # Coverage report
708
+ pnpm test:coverage
709
+
710
+ # Test specific modules
711
+ pnpm test server
712
+ pnpm test router
713
+ pnpm test middleware
714
+ ```
715
+
716
+ ## ๐Ÿค Contributing
237
717
 
238
- # Build the project
239
- pnpm run build
718
+ We welcome contributions to BlaizeJS! Please see our [Contributing Guide](../../CONTRIBUTING.md) for details.
719
+
720
+ ### ๐Ÿ› ๏ธ Development Setup
721
+
722
+ ```bash
723
+ # Clone the repository
724
+ git clone https://github.com/jleajones/blaize.git
725
+ cd blaize
726
+
727
+ # Install dependencies (uses pnpm workspaces)
728
+ pnpm install
240
729
 
241
730
  # Run tests
242
731
  pnpm test
243
732
 
244
- # Start development server with example
245
- pnpm run dev
733
+ # Start development
734
+ pnpm dev
735
+
736
+ # Build all packages
737
+ pnpm build
246
738
  ```
247
739
 
248
- ### Running Examples
740
+ ### ๐Ÿ—๏ธ Monorepo Structure
249
741
 
250
- ```bash
251
- # Run basic example
252
- pnpm run example:basic
742
+ ```
743
+ blaize/
744
+ โ”œโ”€โ”€ packages/
745
+ โ”‚ โ”œโ”€โ”€ blaizejs/ # Core framework (this package)
746
+ โ”‚ โ”œโ”€โ”€ client/ # Type-safe client generator
747
+ โ”‚ โ”œโ”€โ”€ types/ # Shared TypeScript types
748
+ โ”‚ โ”œโ”€โ”€ testing-utils/ # Testing utilities
749
+ โ”‚ โ””โ”€โ”€ configs/ # Shared configurations
750
+ โ”œโ”€โ”€ plugins/ # Official plugins
751
+ โ”œโ”€โ”€ apps/ # Example applications
752
+ โ””โ”€โ”€ docs/ # Documentation
753
+ ```
253
754
 
254
- # Run middleware example
255
- pnpm run example:middleware
755
+ ### ๐Ÿ“ Code Standards
256
756
 
257
- # Run routing example
258
- pnpm run example:routing
757
+ - โœ… **TypeScript**: Strict mode enabled for all packages
758
+ - โœ… **Testing**: Comprehensive test coverage with Vitest
759
+ - โœ… **Linting**: ESLint with consistent configuration
760
+ - โœ… **Formatting**: Prettier for code formatting
761
+ - โœ… **Commits**: Conventional commits for clear history
762
+ - โœ… **Documentation**: JSDoc comments for public APIs
259
763
 
260
- # Run plugin example
261
- pnpm run example:plugins
764
+ ### ๐Ÿ”ง Available Scripts
765
+
766
+ ```bash
767
+ pnpm build # Build all packages
768
+ pnpm dev # Start development mode
769
+ pnpm lint # Run ESLint across packages
770
+ pnpm format # Format code with Prettier
771
+ pnpm type-check # Run TypeScript checks
772
+ pnpm clean # Clean all build artifacts
773
+ pnpm changeset # Create changeset for versioning
262
774
  ```
263
775
 
264
- ## Contributing
776
+ ### ๐Ÿงช Testing Guidelines
777
+
778
+ When contributing to the core framework:
265
779
 
266
- We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to BlaizeJS.
780
+ - โœ… Test all HTTP/2 and HTTP/1.1 compatibility
781
+ - โœ… Test ESM module resolution and path handling
782
+ - โœ… Test AsyncLocalStorage context propagation
783
+ - โœ… Test middleware composition and error handling
784
+ - โœ… Test plugin lifecycle management
785
+ - โœ… Include integration tests with real HTTP requests
786
+ - โœ… Test production deployment scenarios
787
+ - โœ… Test type safety and schema validation
267
788
 
268
- ## Roadmap
789
+ ### ๐ŸŽฏ Architecture Guidelines
269
790
 
270
- ### Phase 1: Core Implementation
791
+ Key principles for core framework development:
271
792
 
272
- - โœ… Basic HTTP server
273
- - โœ… Context API
274
- - โœ… Middleware system
275
- - โฌœ HTTP/2 support
276
- - โฌœ File-based router
277
- - โฌœ Type-safe parameters
793
+ - ๐Ÿ”’ **Type Safety First** - Everything should be typed and validated
794
+ - โšก **Performance** - Minimal overhead and optimal execution
795
+ - ๐Ÿงฉ **Modularity** - Clean separation between modules
796
+ - ๐Ÿ”„ **Async/Await** - Modern async patterns throughout
797
+ - ๐Ÿ›ก๏ธ **Error Handling** - Comprehensive error management
798
+ - ๐Ÿ“– **Documentation** - Clear examples and API docs
278
799
 
279
- ### Phase 2: Advanced Features
800
+ ## ๐Ÿ—บ๏ธ Roadmap
280
801
 
281
- - โฌœ Plugin system
282
- - โฌœ Type inference system
283
- - โฌœ Client library generation
284
- - โฌœ OpenAPI integration
285
- - โฌœ Performance optimizations
286
- - โฌœ Documentation
802
+ ### ๐Ÿš€ Current (v0.1.x)
287
803
 
288
- ### Phase 3: Ecosystem
804
+ - โœ… **HTTP/2 Server** with HTTP/1.1 fallback and SSL support
805
+ - โœ… **File-Based Routing** with automatic path generation and hot reloading
806
+ - โœ… **Type-Safe Routes** with Zod schema validation and route creators
807
+ - โœ… **Composable Middleware** with onion execution and error handling
808
+ - โœ… **Plugin System** with lifecycle management and validation
809
+ - โœ… **Context Management** with AsyncLocalStorage and state isolation
810
+ - โœ… **Testing Utilities** with comprehensive test helpers
811
+ - โœ… **ESM Support** with proper module resolution
812
+ - โœ… **Client Generation** with full type safety (separate package)
289
813
 
290
- - โฌœ CLI tool
291
- - โฌœ Core plugins (CORS, logging, validation)
292
- - โฌœ Premium plugins (authentication, caching)
293
- - โฌœ Example applications
294
- - โฌœ Deployment guides
814
+ ### ๐ŸŽฏ Next Release (v0.2.x)
295
815
 
296
- ## License
816
+ - ๐Ÿ”„ **HTTP/2 Hosting Solutions** - Workarounds for hosting provider limitations
817
+ - ๐Ÿ”„ **Performance Optimizations** - Radix tree improvements and caching
818
+ - ๐Ÿ”„ **Advanced Schema Validation** - Enhanced Zod integration and custom validators
819
+ - ๐Ÿ”„ **Built-in Monitoring** - Performance metrics and health checks
820
+ - ๐Ÿ”„ **Route Groups** - Organized routing with shared middleware
821
+ - ๐Ÿ”„ **Plugin Registry** - Centralized plugin discovery and management
297
822
 
298
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
823
+ ### ๐Ÿ”ฎ Future (v0.3.x+)
299
824
 
300
- ## Acknowledgments
825
+ - ๐Ÿ”„ **GraphQL Integration** - File-based GraphQL resolvers
826
+ - ๐Ÿ”„ **WebSocket Support** - Real-time endpoints with type safety
827
+ - ๐Ÿ”„ **Server-Side Streaming** - Streaming responses and SSE
828
+ - ๐Ÿ”„ **Edge Runtime** - Deployment to edge computing platforms
829
+ - ๐Ÿ”„ **Zero-Config Deployment** - One-command deployment to various platforms
830
+ - ๐Ÿ”„ **Advanced Caching** - Multi-layer caching strategies
301
831
 
302
- Inspired by modern frameworks and tools including Express, Fastify, Next.js, and tRPC, BlaizeJS aims to combine the best aspects of these approaches while embracing modern JavaScript and TypeScript features.
832
+ ### ๐ŸŒŸ Long-term Vision
833
+
834
+ - ๐Ÿ”„ **Visual Development** - GUI tools for route and middleware management
835
+ - ๐Ÿ”„ **AI-Powered Optimization** - Automatic performance tuning and suggestions
836
+ - ๐Ÿ”„ **Multi-Protocol Support** - gRPC, WebSocket, and HTTP/3 in unified framework
837
+ - ๐Ÿ”„ **Microservices Platform** - Service mesh integration and distributed systems
838
+ - ๐Ÿ”„ **Enterprise Features** - Advanced security, compliance, and governance
839
+
840
+ ---
841
+
842
+ ## ๐Ÿ“š Related Documentation
843
+
844
+ - ๐ŸŒ [Server Module](./src/server/README.md) - HTTP server creation and lifecycle management
845
+ - ๐Ÿš€ [Router Module](./src/router/README.md) - File-based routing and type-safe handlers
846
+ - ๐Ÿ”— [Context Module](./src/context/README.md) - Request/response context and state management
847
+ - ๐Ÿ”— [Middleware Module](./src/middleware/README.md) - Composable middleware system
848
+ - ๐Ÿงฉ [Plugins Module](./src/plugins/README.md) - Plugin architecture and lifecycle
849
+ - ๐Ÿ”— [Client Package](./src/client/README.md) - Type-safe API client generation
850
+ - ๐Ÿงช [Testing Utils](./src/testing-utils/README.md) - Testing utilities and helpers
303
851
 
304
852
  ---
305
853
 
306
- <div align="center">
307
- <sub>Built with โค๏ธ for the modern web.</sub>
308
- </div>
854
+ **Built with โค๏ธ by the BlaizeJS team**
855
+
856
+ For questions, feature requests, or bug reports, please [open an issue](https://github.com/jleajones/blaize/issues) on GitHub.