next-js-backend 1.0.0 → 2.1.3

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 (182) hide show
  1. package/README.md +221 -24
  2. package/cli/bin.ts +545 -0
  3. package/dist/index.d.ts +26 -3
  4. package/dist/index.js +47530 -55830
  5. package/dist/src/ai/a2a/a2a.client.d.ts +53 -0
  6. package/dist/src/ai/a2a/a2a.server.d.ts +61 -0
  7. package/dist/src/ai/a2a/a2a.types.d.ts +115 -0
  8. package/dist/src/ai/a2a/index.d.ts +3 -0
  9. package/dist/src/ai/agent.runtime.d.ts +62 -0
  10. package/dist/src/ai/ai.constants.d.ts +6 -0
  11. package/dist/src/ai/ai.decorators.d.ts +105 -0
  12. package/dist/src/ai/ai.module.d.ts +30 -0
  13. package/dist/src/ai/ai.service.d.ts +73 -0
  14. package/dist/src/ai/index.d.ts +16 -0
  15. package/dist/src/ai/memory/in-memory.store.d.ts +17 -0
  16. package/dist/src/ai/memory/index.d.ts +3 -0
  17. package/dist/src/ai/memory/memory.interface.d.ts +31 -0
  18. package/dist/src/ai/memory/redis.memory.d.ts +40 -0
  19. package/dist/src/ai/plugins/database.plugin.d.ts +37 -0
  20. package/dist/src/ai/plugins/index.d.ts +3 -0
  21. package/dist/src/ai/plugins/plugin.interface.d.ts +19 -0
  22. package/dist/src/ai/plugins/search.plugin.d.ts +30 -0
  23. package/dist/src/ai/provider.interface.d.ts +83 -0
  24. package/dist/src/ai/providers/anthropic.provider.d.ts +17 -0
  25. package/dist/src/ai/providers/google.provider.d.ts +17 -0
  26. package/dist/src/ai/providers/openai.provider.d.ts +14 -0
  27. package/dist/src/ai/structured-output.d.ts +30 -0
  28. package/dist/src/ai/testing/ai.test-bed.d.ts +48 -0
  29. package/dist/src/ai/testing/index.d.ts +2 -0
  30. package/dist/src/ai/testing/mock-llm.provider.d.ts +45 -0
  31. package/dist/src/ai/tool.registry.d.ts +46 -0
  32. package/dist/src/ai/workflow/index.d.ts +2 -0
  33. package/dist/src/ai/workflow/workflow.context.d.ts +35 -0
  34. package/dist/src/ai/workflow/workflow.runtime.d.ts +19 -0
  35. package/dist/src/auth/nextauth/index.d.ts +3 -0
  36. package/dist/src/auth/nextauth/nextauth.guard.d.ts +19 -0
  37. package/dist/src/auth/nextauth/nextauth.module.d.ts +36 -0
  38. package/dist/src/auth/nextauth/nextauth.service.d.ts +30 -0
  39. package/dist/src/cache/cache.interceptor.d.ts +5 -0
  40. package/dist/src/cache/cache.module.d.ts +13 -0
  41. package/dist/src/cache/cache.store.d.ts +15 -0
  42. package/dist/src/decorators/cache.decorator.d.ts +15 -0
  43. package/dist/src/decorators/middleware.decorator.d.ts +6 -0
  44. package/dist/src/decorators/module.decorator.d.ts +6 -6
  45. package/dist/src/decorators/param.decorator.d.ts +1 -0
  46. package/dist/src/decorators/rate-limit.decorator.d.ts +19 -0
  47. package/dist/src/decorators/sse.decorator.d.ts +19 -0
  48. package/dist/src/decorators/throttle.decorator.d.ts +17 -0
  49. package/dist/src/decorators/use-middleware.decorator.d.ts +12 -0
  50. package/dist/src/decorators/websocket.decorator.d.ts +43 -0
  51. package/dist/src/dev-mode/dev-mode.controller.d.ts +22 -0
  52. package/dist/src/dev-mode/dev-mode.middleware.d.ts +11 -0
  53. package/dist/src/dev-mode/dev-mode.module.d.ts +5 -0
  54. package/dist/src/dev-mode/dev-mode.service.d.ts +46 -0
  55. package/dist/src/di/container.d.ts +1 -0
  56. package/dist/src/di/inject.decorator.d.ts +2 -1
  57. package/dist/src/events/event-emitter.module.d.ts +14 -0
  58. package/dist/src/events/event-emitter.service.d.ts +36 -0
  59. package/dist/src/events/index.d.ts +3 -0
  60. package/dist/src/events/on-event.decorator.d.ts +18 -0
  61. package/dist/src/exceptions/http.exception.d.ts +0 -6
  62. package/dist/src/exceptions/validation.pipe.d.ts +1 -1
  63. package/dist/src/factory/elysia-factory.d.ts +2 -1
  64. package/dist/src/generated/prisma/browser.d.ts +4 -0
  65. package/dist/src/generated/prisma/client.d.ts +23 -0
  66. package/dist/src/generated/prisma/commonInputTypes.d.ts +1 -0
  67. package/dist/src/generated/prisma/enums.d.ts +1 -0
  68. package/dist/src/generated/prisma/internal/class.d.ts +119 -0
  69. package/dist/src/generated/prisma/internal/prismaNamespace.d.ts +393 -0
  70. package/dist/src/generated/prisma/internal/prismaNamespaceBrowser.d.ts +31 -0
  71. package/dist/src/generated/prisma/models.d.ts +1 -0
  72. package/dist/src/health/health.controller.d.ts +16 -0
  73. package/dist/src/health/health.module.d.ts +8 -0
  74. package/dist/src/health/health.service.d.ts +17 -0
  75. package/dist/src/health/index.d.ts +3 -0
  76. package/dist/src/interfaces.d.ts +7 -4
  77. package/dist/src/plugins/plugins.module.d.ts +21 -0
  78. package/dist/src/schedule/cron.decorator.d.ts +12 -0
  79. package/dist/src/schedule/index.d.ts +3 -0
  80. package/dist/src/schedule/schedule.module.d.ts +16 -0
  81. package/dist/src/schedule/schedule.service.d.ts +16 -0
  82. package/dist/src/services/logger.service.d.ts +6 -5
  83. package/dist/src/session/session.options.d.ts +1 -1
  84. package/dist/src/session/session.store.d.ts +4 -0
  85. package/dist/src/testing/index.d.ts +1 -0
  86. package/dist/src/testing/test.d.ts +87 -0
  87. package/index.ts +46 -3
  88. package/package.json +22 -6
  89. package/scripts/check-size.ts +33 -0
  90. package/scripts/eden-generate.ts +412 -0
  91. package/scripts/push.sh +77 -0
  92. package/src/ai/a2a/a2a.client.ts +227 -0
  93. package/src/ai/a2a/a2a.server.ts +264 -0
  94. package/src/ai/a2a/a2a.types.ts +161 -0
  95. package/src/ai/a2a/index.ts +4 -0
  96. package/src/ai/agent.runtime.ts +344 -0
  97. package/src/ai/ai.constants.ts +7 -0
  98. package/src/ai/ai.decorators.ts +162 -0
  99. package/src/ai/ai.module.ts +41 -0
  100. package/src/ai/ai.service.ts +208 -0
  101. package/src/ai/index.ts +29 -0
  102. package/src/ai/memory/in-memory.store.ts +35 -0
  103. package/src/ai/memory/index.ts +4 -0
  104. package/src/ai/memory/memory.interface.ts +41 -0
  105. package/src/ai/memory/redis.memory.ts +78 -0
  106. package/src/ai/plugins/database.plugin.ts +133 -0
  107. package/src/ai/plugins/index.ts +4 -0
  108. package/src/ai/plugins/plugin.interface.ts +22 -0
  109. package/src/ai/plugins/search.plugin.ts +124 -0
  110. package/src/ai/provider.interface.ts +120 -0
  111. package/src/ai/providers/anthropic.provider.ts +268 -0
  112. package/src/ai/providers/google.provider.ts +270 -0
  113. package/src/ai/providers/openai.provider.ts +209 -0
  114. package/src/ai/structured-output.ts +116 -0
  115. package/src/ai/testing/ai.test-bed.ts +83 -0
  116. package/src/ai/testing/index.ts +3 -0
  117. package/src/ai/testing/mock-llm.provider.ts +127 -0
  118. package/src/ai/tool.registry.ts +141 -0
  119. package/src/ai/workflow/index.ts +3 -0
  120. package/src/ai/workflow/workflow.context.ts +62 -0
  121. package/src/ai/workflow/workflow.runtime.ts +206 -0
  122. package/src/auth/jwt.service.ts +2 -2
  123. package/src/auth/nextauth/index.ts +3 -0
  124. package/src/auth/nextauth/nextauth.guard.ts +36 -0
  125. package/src/auth/nextauth/nextauth.module.ts +61 -0
  126. package/src/auth/nextauth/nextauth.service.ts +62 -0
  127. package/src/cache/cache.interceptor.ts +47 -0
  128. package/src/cache/cache.module.ts +51 -0
  129. package/src/cache/cache.store.ts +45 -0
  130. package/src/config/config.service.ts +8 -7
  131. package/src/decorators/cache.decorator.ts +28 -0
  132. package/src/decorators/middleware.decorator.ts +15 -0
  133. package/src/decorators/module.decorator.ts +6 -6
  134. package/src/decorators/param.decorator.ts +1 -0
  135. package/src/decorators/rate-limit.decorator.ts +34 -0
  136. package/src/decorators/sse.decorator.ts +27 -0
  137. package/src/decorators/throttle.decorator.ts +33 -0
  138. package/src/decorators/use-middleware.decorator.ts +25 -0
  139. package/src/decorators/websocket.decorator.ts +65 -0
  140. package/src/dev-mode/__tests__/dev-mode.module.test.ts +118 -0
  141. package/src/dev-mode/dev-mode.controller.ts +32 -0
  142. package/src/dev-mode/dev-mode.middleware.ts +69 -0
  143. package/src/dev-mode/dev-mode.module.ts +34 -0
  144. package/src/dev-mode/dev-mode.service.ts +88 -0
  145. package/src/di/container.ts +34 -18
  146. package/src/di/inject.decorator.ts +2 -1
  147. package/src/events/event-emitter.module.ts +20 -0
  148. package/src/events/event-emitter.service.ts +83 -0
  149. package/src/events/index.ts +3 -0
  150. package/src/events/on-event.decorator.ts +30 -0
  151. package/src/exceptions/http.exception.ts +1 -13
  152. package/src/exceptions/validation.pipe.ts +4 -10
  153. package/src/factory/__tests__/exception-filters.test.ts +3 -3
  154. package/src/factory/__tests__/file-upload.test.ts +44 -1
  155. package/src/factory/elysia-factory.ts +390 -72
  156. package/src/generated/prisma/browser.ts +20 -0
  157. package/src/generated/prisma/client.ts +44 -0
  158. package/src/generated/prisma/commonInputTypes.ts +18 -0
  159. package/src/generated/prisma/enums.ts +15 -0
  160. package/src/generated/prisma/internal/class.ts +196 -0
  161. package/src/generated/prisma/internal/prismaNamespace.ts +603 -0
  162. package/src/generated/prisma/internal/prismaNamespaceBrowser.ts +71 -0
  163. package/src/generated/prisma/models.ts +11 -0
  164. package/src/health/health.controller.ts +13 -0
  165. package/src/health/health.module.ts +16 -0
  166. package/src/health/health.service.ts +24 -0
  167. package/src/health/index.ts +3 -0
  168. package/src/interfaces.ts +8 -4
  169. package/src/plugins/__tests__/plugins.module.test.ts +96 -0
  170. package/src/plugins/plugins.module.ts +39 -0
  171. package/src/schedule/cron.decorator.ts +25 -0
  172. package/src/schedule/index.ts +3 -0
  173. package/src/schedule/schedule.module.ts +22 -0
  174. package/src/schedule/schedule.service.ts +54 -0
  175. package/src/services/__tests__/logger.service.test.ts +105 -0
  176. package/src/services/logger.service.ts +17 -16
  177. package/src/session/__tests__/session.module.test.ts +2 -2
  178. package/src/session/session.options.ts +1 -1
  179. package/src/session/session.service.ts +8 -4
  180. package/src/session/session.store.ts +18 -0
  181. package/src/testing/index.ts +1 -0
  182. package/src/testing/test.ts +122 -0
package/README.md CHANGED
@@ -2,29 +2,34 @@
2
2
  <img src="docs/src/assets/logo.png" width="300" alt="Next.js Backend Logo" />
3
3
  </p>
4
4
 
5
- # Next.js Backend (Elysia Nest-like Library)
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/next-js-backend"><img src="https://img.shields.io/npm/v/next-js-backend.svg?style=flat-square" alt="npm version" /></a>
7
+ <a href="https://www.npmjs.com/package/next-js-backend"><img src="https://img.shields.io/npm/dm/next-js-backend.svg?style=flat-square" alt="npm downloads" /></a>
8
+ <a href="https://github.com/nctuanit/nextjs-backend/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/next-js-backend.svg?style=flat-square" alt="license" /></a>
9
+ <img src="https://img.shields.io/badge/runtime-Bun-f9a8d4?style=flat-square" alt="runtime" />
10
+ <img src="https://img.shields.io/badge/tests-86%20passed-brightgreen?style=flat-square" alt="tests" />
11
+ </p>
6
12
 
7
- Một thư viện backend mạnh mẽ, tốc độ cao dành cho Node/Bun, được xây dựng trên nền tảng **ElysiaJS**. Nó mang kiến trúc **NestJS** quen thuộc và có tính cấu trúc cao (Decorators, Dependency Injection, Modules, Guards, Interceptors) đến với hệ sinh thái Elysia siêu tốc.
13
+ # Next.js Backend
8
14
 
9
- Được thiết kế tỉ mỉ để sẵn sàng cho **Serverless & Edge**, dễ dàng tích hợp trực tiếp vào Next.js App Router API endpoints thông qua `next-js-backend`.
15
+ A high-performance **NestJS-like** backend framework for **Bun**, powered by **ElysiaJS**. Write structured, decorator-based APIs with full DI, Guards, Interceptors, Pipes — and deploy to Next.js Edge, Vercel, or standalone.
10
16
 
11
- ---
17
+ ```bash
18
+ bun add next-js-backend
19
+ ```
20
+
21
+ ## ✨ Feature Overview
12
22
 
13
- ## 🚀 Tính Năng (Features)
14
-
15
- - **Kiến trúc giống NestJS**: Cấu trúc ứng dụng của bạn với `@Controller`, `@Injectable`, `@Module`.
16
- - **Lõi ElysiaJS**: Hoạt động dựa trên ElysiaJS Bun, mang lại hiệu suất tối đa cùng với sự tích hợp TypeBox.
17
- - **Dependency Injection**: Vùng chứa IoC siêu mạnh với đầy đủ tính năng, hỗ trợ `useClass`, `useValue`, `useFactory` và injection qua constructor tiêu chuẩn.
18
- - **Quy trình xử (Pipeline)**:
19
- - **Guards** (`@UseGuards`): Xác thực và phân quyền.
20
- - **Interceptors** (`@UseInterceptors`): Ghi log request/response, thay đổi biến đổi dữ liệu.
21
- - **Pipes** (`@UsePipes`): Xác thực định dạng dữ liệu (hỗ trợ tích hợp sẵn `ValidationPipe` với `class-validator`).
22
- - **Filters** (`@UseFilters`, `@Catch`): Quản luồng ngoại lệ (Custom Exception Handlers) toàn cục & theo cấp độ.
23
- - **Quản lý Phiên (Session)**: Module `SessionModule` tích hợp sẵn dùng Cookie với hệ thống lưu trữ có thể cắm ghép (Redis/DB/Memory).
24
- - **Core Modules**: Tích hợp sẵn `ConfigModule` (Xác thực tham số môi trường Env), `JwtModule` (Xác thực token) và `LoggerService`.
25
- - **Next.js API Routes**: Tương thích tức thì theo dạng drop-in với `export const { GET, POST } = bootstrap()`.
26
- - **Tải lên File (File Uploads)**: Hỗ trợ tự nhiên cho `@File()` / `@Files()` thông qua `multipart/form-data`.
27
- - **OpenAPI / Swagger**: Hỗ trợ xuất sắc nhất thông qua các plugin gốc của Elysia.
23
+ | Category | Features |
24
+ |----------|----------|
25
+ | **Architecture** | `@Controller`, `@Injectable`, `@Module`, Dependency Injection |
26
+ | **Routing** | `@Get`, `@Post`, `@Put`, `@Delete`, `@Patch`, `@Param`, `@Body`, `@Query`, `@Headers` |
27
+ | **Pipeline** | Guards, Interceptors, Pipes, Exception Filters, Global Middleware, `@UseMiddleware` |
28
+ | **Auth** | JWT Module, NextAuth (Auth.js v5), Session Module, `@Throttle` rate limiting |
29
+ | **Data** | Cache Module, Config Module (env validation), `@Cron` scheduling |
30
+ | **Realtime** | WebSocket Gateway, SSE Streaming, `@OnEvent` pub/sub |
31
+ | **Tooling** | CLI (`npx next-js-backend new`), Testing Utilities, Eden Treaty codegen |
32
+ | **DX** | DevMode Profiler, Health Check Module, OpenAPI/Swagger, File Upload |
28
33
 
29
34
  ---
30
35
 
@@ -46,6 +51,19 @@ Một thư viện backend mạnh mẽ, tốc độ cao dành cho Node/Bun, đư
46
51
  bun install next-js-backend
47
52
  ```
48
53
 
54
+ ### Cấu hình TypeScript (Bắt buộc)
55
+
56
+ Thư viện này phụ thuộc hoàn toàn vào kỹ thuật **Decorators**. Bạn **bắt buộc** phải kích hoạt các cờ sau trong file `tsconfig.json` ở thư mục gốc của dự án:
57
+
58
+ ```json
59
+ {
60
+ "compilerOptions": {
61
+ "experimentalDecorators": true,
62
+ "emitDecoratorMetadata": true
63
+ }
64
+ }
65
+ ```
66
+
49
67
  ### Chạy các Ứng Dụng Mẫu (Samples)
50
68
 
51
69
  Chúng tôi cung cấp một số ứng dụng mẫu trong thư mục `samples/` để giúp bạn làm quen nhanh chóng:
@@ -348,6 +366,93 @@ logger.error("Error occurred", error.stack);
348
366
  logger.warn("Warning log");
349
367
  ```
350
368
 
369
+ **CacheModule (Lưu trữ và phục hồi dữ liệu tốc độ cao):**
370
+
371
+ ```typescript
372
+ import { CacheModule, Controller, Get, UseInterceptors, CacheInterceptor } from "next-js-backend";
373
+
374
+ @Module({
375
+ imports: [
376
+ CacheModule.register({ ttl: 60, max: 100 }) // ttl bằng giây
377
+ ]
378
+ })
379
+ class AppModule {}
380
+
381
+ @Controller("/products")
382
+ @UseInterceptors(CacheInterceptor)
383
+ export class ProductsController {
384
+ @Get()
385
+ getProducts() {
386
+ return { data: "This will be cached for 60 seconds" };
387
+ }
388
+ }
389
+ ```
390
+
391
+ **WebSocket Gateway (Giao tiếp Real-time):**
392
+
393
+ ```typescript
394
+ import { WebSocketGateway, WebSocketServer, SubscribeMessage, MessageBody, ConnectedSocket } from "next-js-backend";
395
+
396
+ @WebSocketGateway({ path: "/ws" })
397
+ export class ChatGateway {
398
+ @WebSocketServer()
399
+ server: any;
400
+
401
+ @SubscribeMessage("message")
402
+ handleMessage(@MessageBody() data: any, @ConnectedSocket() client: any) {
403
+ // Phát sự kiện lại cho client
404
+ client.send(JSON.stringify({ event: "reply", data }));
405
+ }
406
+ }
407
+ ```
408
+
409
+ **Global Middleware (Phần mềm trung gian toàn cục):**
410
+
411
+ ```typescript
412
+ import { Middleware, NestMiddleware, MiddlewareConsumer } from "next-js-backend";
413
+
414
+ @Middleware()
415
+ export class LoggerMiddleware implements NestMiddleware {
416
+ use(req: Request, res: Response, next: () => void) {
417
+ console.log(`Incoming request: ${req.url}`);
418
+ next();
419
+ }
420
+ }
421
+
422
+ // Đăng ký Middleware trong Module
423
+ @Module({
424
+ controllers: [/* ... */]
425
+ })
426
+ export class AppModule {
427
+ configure(consumer: MiddlewareConsumer) {
428
+ consumer.apply(LoggerMiddleware).forRoutes('*');
429
+ }
430
+ }
431
+ ```
432
+
433
+ **DevMode Profiler (Thống kê và Cấu hình Môi trường Phát triển):**
434
+
435
+ Request Profiler được nhúng nguyên bản sử dụng `onAfterResponse` scope của Elysia, cho phép bạn quan sát toàn bộ độ trễ (latency), body, mã lỗi (status) mà hiệu năng Server bị sụt giảm cực kì thấp.
436
+
437
+ ```typescript
438
+ import { DevModeModule, ElysiaFactory } from "next-js-backend";
439
+
440
+ @Module({
441
+ imports: [
442
+ DevModeModule.register({
443
+ enabled: process.env.NODE_NODE !== 'production', // Chỉ kích hoạt khi dev
444
+ maxHistory: 50 // Theo dõi 50 requests gần nhất
445
+ })
446
+ ]
447
+ })
448
+ export class AppModule {}
449
+
450
+ // Sau khi khởi chạy server, NextJs Backend sẽ mở sẵn các endpoint dưới đây:
451
+ // GET /dev/history -> Lịch sử Requests (body, latency, status)
452
+ // GET /dev/stats -> Tổng số Requests, tỉ lệ lỗi (Error Ratio)
453
+ // GET /dev/history/clear -> Xóa lịch sử
454
+ ```
455
+
351
456
  ## 🌍 Mở Rộng Type Toàn Cục (Global Type Augmentation)
352
457
 
353
458
  Để lấy được tối đa sự an toàn Typescript (Type safety) khi sử dụng các phương pháp lấy biến động `@Session()` hay xử lý trong custom Guards, thư viện bóc tách các Types chuẩn bị sẵn (mở) Global interfaces cho bạn can thiệp từ `.d.ts` (ví dụ, chèn code vào file `globals.d.ts` hoặc `next-env.d.ts` của repository bạn).
@@ -375,19 +480,111 @@ Và giờ đây, bất kì lúc nào bạn tiến hành dùng decorater `@Sessio
375
480
 
376
481
  ---
377
482
 
378
- ## 🧪 Testing (Chạy Thử Nghiệm)
483
+ ### 8. CLI Tool
379
484
 
380
- Chúng tôi sử dụng môi trường test trực tiếp thông qua runner của Bun (`bun:test`). Tất cả files cấu hình bài test nghiệm thu thư mục nguồn (source) đều chứa bên trong thư mục `__tests__` đi liền cạnh.
485
+ Scaffold projects and generate code instantly:
381
486
 
382
487
  ```bash
383
- bun test
488
+ # Tạo project mới
489
+ npx next-js-backend new my-api
490
+
491
+ # Sinh code
492
+ npx next-js-backend g resource users # module + controller + service
493
+ npx next-js-backend g controller posts
494
+ npx next-js-backend g guard auth
495
+ ```
496
+
497
+ ### 9. Testing Utilities
498
+
499
+ ```typescript
500
+ import { Test } from 'next-js-backend';
501
+
502
+ const module = await Test.createTestingModule({
503
+ controllers: [UserController],
504
+ providers: [UserService],
505
+ })
506
+ .overrideProvider(UserService).useValue(mockService)
507
+ .compile();
508
+
509
+ const app = await module.createApp();
510
+ const res = await app.handle(new Request('http://localhost/users'));
511
+ ```
512
+
513
+ ### 10. Eden Treaty — Type-Safe API Client
514
+
515
+ Auto-generate type-safe client from controllers:
516
+
517
+ ```bash
518
+ bun run eden:generate src/app.module.ts --output src/eden.ts --watch
519
+ ```
520
+
521
+ ```typescript
522
+ import { treaty } from '@elysiajs/eden';
523
+ import type { App } from './eden';
524
+
525
+ const api = treaty<App>('http://localhost:3000');
526
+ const { data } = await api.users.get(); // ← full autocomplete
527
+ const { data: user } = await api.users.post({ name: 'Alice' }); // ← body enforced
528
+ ```
529
+
530
+ ### 11. Task Scheduling & Events
531
+
532
+ ```typescript
533
+ @Injectable()
534
+ export class TasksService {
535
+ @Cron('0 0 * * *')
536
+ async dailyCleanup() { ... }
537
+ }
538
+
539
+ @Injectable()
540
+ export class NotifyService {
541
+ @OnEvent('user.created')
542
+ async sendWelcome(data: { email: string }) { ... }
543
+ }
544
+ ```
545
+
546
+ ### 12. Health Check
547
+
548
+ ```typescript
549
+ @Module({ imports: [HealthModule] })
550
+ // GET /health → { status: 'ok', uptime, memory }
551
+ ```
552
+
553
+ ### 13. @Throttle & @UseMiddleware
554
+
555
+ ```typescript
556
+ @Throttle({ limit: 5, ttl: 60 }) // 5 requests / 60s
557
+ @Get('/expensive')
558
+ compute() { ... }
559
+
560
+ @UseMiddleware(LoggingMiddleware)
561
+ @Get('/data')
562
+ getData() { ... }
384
563
  ```
385
564
 
386
565
  ---
387
566
 
388
- ## 💖 Lời Cảm Ơn (Acknowledgements)
567
+ ## 📊 So Sánh (Comparison)
389
568
 
390
- Đặc biệt gửi lời cảm ơn tới **Antigravity** (Google DeepMind) đã đồng hành, hỗ trợ kỹ thuật và giúp tôi hiện thực hóa toàn bộ ý tưởng của Thư viện này từ những dòng code đầu tiên. Cùng với sức mạnh của tinh thần pair-programming, **Next.js Backend** đã ra đời!
569
+ | Feature | next-js-backend | NestJS | Hono |
570
+ |---------|:-:|:-:|:-:|
571
+ | Bun native | ✅ | ❌ | ✅ |
572
+ | Decorators + DI | ✅ | ✅ | ❌ |
573
+ | Next.js Edge | ✅ | ❌ | ⚠️ |
574
+ | Type-safe client | ✅ Eden | ❌ | ❌ |
575
+ | Guards / Interceptors | ✅ | ✅ | ❌ |
576
+ | WebSocket | ✅ | ✅ | ❌ |
577
+ | CLI scaffolding | ✅ | ✅ | ❌ |
578
+ | Bundle size | ~50KB | ~2MB | ~14KB |
579
+
580
+ ---
581
+
582
+ ## 🧪 Testing
583
+
584
+ ```bash
585
+ bun test # 86 tests, 228 assertions
586
+ bun run typecheck # tsc --noEmit
587
+ ```
391
588
 
392
589
  ---
393
590