blaizejs 0.1.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 ADDED
@@ -0,0 +1,308 @@
1
+ # BlaizeJS
2
+
3
+ 🔥 A blazing-fast, TypeScript-first API framework with file-based routing, powerful plugins, and end-to-end type safety.
4
+
5
+ ## Overview
6
+
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.
8
+
9
+ ## Features
10
+
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
18
+
19
+ ## Project Structure
20
+
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
+ ```
47
+
48
+ ## Getting Started
49
+
50
+ ### Installation
51
+
52
+ ```bash
53
+ pnpm install blaizejs
54
+ ```
55
+
56
+ ### Quick Start
57
+
58
+ Create a new file `server.ts`:
59
+
60
+ ```typescript
61
+ import { createServer } from 'blaizejs';
62
+
63
+ const server = createServer({
64
+ port: 3000,
65
+ routesDir: './routes',
66
+ });
67
+
68
+ server.listen().then(() => {
69
+ console.log(`Server running at http://localhost:${server.port}`);
70
+ });
71
+ ```
72
+
73
+ Create a route file `routes/hello.ts`:
74
+
75
+ ```typescript
76
+ import { Middleware } from 'blaizejs';
77
+
78
+ // Export default middleware function
79
+ export default function helloRoute(): Middleware {
80
+ return async (ctx, next) => {
81
+ ctx.json({ message: 'Hello, World!' });
82
+ await next();
83
+ };
84
+ }
85
+ ```
86
+
87
+ Start the server:
88
+
89
+ ```bash
90
+ ts-node server.ts
91
+ ```
92
+
93
+ Visit http://localhost:3000/hello to see your API in action.
94
+
95
+ ## Middleware
96
+
97
+ BlaizeJS uses a simple middleware system similar to Express or Koa, but with full TypeScript support:
98
+
99
+ ```typescript
100
+ import { createServer, Middleware } from 'blaizejs';
101
+
102
+ // Create logging middleware
103
+ const logger: Middleware = async (ctx, next) => {
104
+ const start = Date.now();
105
+ console.log(`${ctx.method} ${ctx.path}`);
106
+
107
+ await next();
108
+
109
+ const ms = Date.now() - start;
110
+ console.log(`${ctx.method} ${ctx.path} - ${ctx.status} (${ms}ms)`);
111
+ };
112
+
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
+ };
126
+
127
+ // Create server with middleware
128
+ const server = createServer({
129
+ middleware: [errorHandler, logger],
130
+ });
131
+
132
+ // Add more middleware after server creation
133
+ server.use(async (ctx, next) => {
134
+ ctx.state.userIp = ctx.req.socket.remoteAddress;
135
+ await next();
136
+ });
137
+
138
+ server.listen(3000);
139
+ ```
140
+
141
+ ## Context API
142
+
143
+ The Context object provides a unified interface for handling requests and responses:
144
+
145
+ ```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
+ });
165
+ };
166
+ ```
167
+
168
+ ## HTTP/2 Support
169
+
170
+ BlaizeJS supports HTTP/2 with fallback to HTTP/1.1:
171
+
172
+ ```typescript
173
+ import { createServer } from 'blaizejs';
174
+ import fs from 'node:fs';
175
+ import path from 'node:path';
176
+
177
+ // Create HTTP/2 server with TLS
178
+ const server = createServer({
179
+ port: 3000,
180
+ http2: {
181
+ enabled: true,
182
+ keyFile: path.join(__dirname, 'certs/key.pem'),
183
+ certFile: path.join(__dirname, 'certs/cert.pem'),
184
+ },
185
+ });
186
+
187
+ server.listen();
188
+ ```
189
+
190
+ ## Plugin System
191
+
192
+ Extend functionality with plugins:
193
+
194
+ ```typescript
195
+ import { createServer } from 'blaizejs';
196
+ import corsPlugin from '@blaizejs/cors-plugin';
197
+ import loggerPlugin from '@blaizejs/logger-plugin';
198
+
199
+ const server = createServer({
200
+ plugins: [corsPlugin({ origin: '*' }), loggerPlugin({ level: 'info' })],
201
+ });
202
+
203
+ // Register plugins after server creation
204
+ server.register(myCustomPlugin()).then(() => {
205
+ server.listen(3000);
206
+ });
207
+ ```
208
+
209
+ ## CLI Commands (Coming Soon)
210
+
211
+ BlaizeJS will include a CLI for project creation and development:
212
+
213
+ ```bash
214
+ # Install the CLI globally
215
+ pnpm install -g @blaizejs/cli
216
+
217
+ # Create a new project
218
+ blaize create my-api
219
+
220
+ # Start development server
221
+ blaize dev
222
+
223
+ # Build for production
224
+ blaize build
225
+
226
+ # Run in production
227
+ blaize start
228
+ ```
229
+
230
+ ## Development
231
+
232
+ ### Building the Project
233
+
234
+ ```bash
235
+ # Install dependencies
236
+ pnpm install
237
+
238
+ # Build the project
239
+ pnpm run build
240
+
241
+ # Run tests
242
+ pnpm test
243
+
244
+ # Start development server with example
245
+ pnpm run dev
246
+ ```
247
+
248
+ ### Running Examples
249
+
250
+ ```bash
251
+ # Run basic example
252
+ pnpm run example:basic
253
+
254
+ # Run middleware example
255
+ pnpm run example:middleware
256
+
257
+ # Run routing example
258
+ pnpm run example:routing
259
+
260
+ # Run plugin example
261
+ pnpm run example:plugins
262
+ ```
263
+
264
+ ## Contributing
265
+
266
+ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to BlaizeJS.
267
+
268
+ ## Roadmap
269
+
270
+ ### Phase 1: Core Implementation
271
+
272
+ - ✅ Basic HTTP server
273
+ - ✅ Context API
274
+ - ✅ Middleware system
275
+ - ⬜ HTTP/2 support
276
+ - ⬜ File-based router
277
+ - ⬜ Type-safe parameters
278
+
279
+ ### Phase 2: Advanced Features
280
+
281
+ - ⬜ Plugin system
282
+ - ⬜ Type inference system
283
+ - ⬜ Client library generation
284
+ - ⬜ OpenAPI integration
285
+ - ⬜ Performance optimizations
286
+ - ⬜ Documentation
287
+
288
+ ### Phase 3: Ecosystem
289
+
290
+ - ⬜ CLI tool
291
+ - ⬜ Core plugins (CORS, logging, validation)
292
+ - ⬜ Premium plugins (authentication, caching)
293
+ - ⬜ Example applications
294
+ - ⬜ Deployment guides
295
+
296
+ ## License
297
+
298
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
299
+
300
+ ## Acknowledgments
301
+
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.
303
+
304
+ ---
305
+
306
+ <div align="center">
307
+ <sub>Built with ❤️ for the modern web.</sub>
308
+ </div>