xypriss 2.0.0 → 2.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.
Files changed (185) hide show
  1. package/README.md +170 -380
  2. package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js +10 -0
  3. package/dist/cjs/mods/security/src/algorithms/hash-algorithms.js.map +1 -1
  4. package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js +10 -0
  5. package/dist/cjs/mods/security/src/components/cache/cacheSys.utils.js.map +1 -1
  6. package/dist/cjs/mods/security/src/components/cache/index.js +10 -2
  7. package/dist/cjs/mods/security/src/components/cache/index.js.map +1 -1
  8. package/dist/cjs/mods/security/src/components/fortified-function/index.js +9 -0
  9. package/dist/cjs/mods/security/src/components/fortified-function/index.js.map +1 -1
  10. package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js +10 -0
  11. package/dist/cjs/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -1
  12. package/dist/cjs/mods/security/src/core/crypto.js +14 -0
  13. package/dist/cjs/mods/security/src/core/crypto.js.map +1 -1
  14. package/dist/cjs/mods/security/src/index.js +10 -1
  15. package/dist/cjs/mods/security/src/index.js.map +1 -1
  16. package/dist/cjs/shared/logger/Logger.js +372 -29
  17. package/dist/cjs/shared/logger/Logger.js.map +1 -1
  18. package/dist/cjs/src/cluster/bun-cluster-manager.js +91 -1
  19. package/dist/cjs/src/cluster/bun-cluster-manager.js.map +1 -1
  20. package/dist/cjs/src/cluster/cluster-manager.js +15 -3
  21. package/dist/cjs/src/cluster/cluster-manager.js.map +1 -1
  22. package/dist/cjs/src/cluster/modules/AutoScaler.js +4 -4
  23. package/dist/cjs/src/cluster/modules/AutoScaler.js.map +1 -1
  24. package/dist/cjs/src/cluster/modules/CrossPlatformMemory.js +2 -2
  25. package/dist/cjs/src/cluster/modules/CrossPlatformMemory.js.map +1 -1
  26. package/dist/cjs/src/cluster/modules/EventLoopMonitor.js +270 -0
  27. package/dist/cjs/src/cluster/modules/EventLoopMonitor.js.map +1 -0
  28. package/dist/cjs/src/cluster/modules/GCStatsTracker.js +200 -0
  29. package/dist/cjs/src/cluster/modules/GCStatsTracker.js.map +1 -0
  30. package/dist/cjs/src/cluster/modules/HeapStatsCollector.js +111 -0
  31. package/dist/cjs/src/cluster/modules/HeapStatsCollector.js.map +1 -0
  32. package/dist/cjs/src/cluster/modules/NetworkTracker.js +162 -0
  33. package/dist/cjs/src/cluster/modules/NetworkTracker.js.map +1 -0
  34. package/dist/cjs/src/cluster/modules/ThroughputCalculator.js +186 -0
  35. package/dist/cjs/src/cluster/modules/ThroughputCalculator.js.map +1 -0
  36. package/dist/cjs/src/cluster/modules/WorkerManager.js +14 -15
  37. package/dist/cjs/src/cluster/modules/WorkerManager.js.map +1 -1
  38. package/dist/cjs/src/cluster/modules/{LoadBalancer.js → strategy/LoadBalancer.js} +1 -1
  39. package/dist/cjs/src/cluster/modules/strategy/LoadBalancer.js.map +1 -0
  40. package/dist/cjs/src/middleware/built-in/sqlInjection.js +335 -0
  41. package/dist/cjs/src/middleware/built-in/sqlInjection.js.map +1 -0
  42. package/dist/cjs/src/middleware/safe-json-middleware.js +1 -1
  43. package/dist/cjs/src/middleware/safe-json-middleware.js.map +1 -1
  44. package/dist/cjs/src/middleware/security-middleware.js +447 -332
  45. package/dist/cjs/src/middleware/security-middleware.js.map +1 -1
  46. package/dist/cjs/src/plugins/modules/index.js +9 -3
  47. package/dist/cjs/src/plugins/modules/index.js.map +1 -1
  48. package/dist/cjs/src/server/FastServer.js +41 -1
  49. package/dist/cjs/src/server/FastServer.js.map +1 -1
  50. package/dist/cjs/src/server/ServerFactory.js +62 -2
  51. package/dist/cjs/src/server/ServerFactory.js.map +1 -1
  52. package/dist/cjs/src/server/components/fastapi/ClusterManagerComponent.js +32 -6
  53. package/dist/cjs/src/server/components/fastapi/ClusterManagerComponent.js.map +1 -1
  54. package/dist/cjs/src/server/components/fastapi/WorkerPoolComponent.js +206 -0
  55. package/dist/cjs/src/server/components/fastapi/WorkerPoolComponent.js.map +1 -0
  56. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js +3 -28
  57. package/dist/cjs/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  58. package/dist/cjs/src/server/components/fastapi/modules/UFRP/WorkerPoolManager.js +265 -0
  59. package/dist/cjs/src/server/components/fastapi/modules/UFRP/WorkerPoolManager.js.map +1 -0
  60. package/dist/cjs/src/server/components/fastapi/modules/UFRP/workers/Logger.js +236 -0
  61. package/dist/cjs/src/server/components/fastapi/modules/UFRP/workers/cpu-tasks.js +294 -0
  62. package/dist/cjs/src/server/components/fastapi/modules/UFRP/workers/enhanced-cpu-worker.js +433 -0
  63. package/dist/cjs/src/server/components/fastapi/modules/UFRP/workers/io-worker.js +1615 -0
  64. package/dist/cjs/src/server/components/lifecycle/ServerLifecycleManager.js +143 -24
  65. package/dist/cjs/src/server/components/lifecycle/ServerLifecycleManager.js.map +1 -1
  66. package/dist/cjs/src/server/const/default.js +23 -9
  67. package/dist/cjs/src/server/const/default.js.map +1 -1
  68. package/dist/cjs/src/server/core/HttpServer.js +8 -8
  69. package/dist/cjs/src/server/core/HttpServer.js.map +1 -1
  70. package/dist/cjs/src/server/core/XyprissApp.js +284 -17
  71. package/dist/cjs/src/server/core/XyprissApp.js.map +1 -1
  72. package/dist/cjs/src/server/handlers/NotFoundHandler.js +1 -1
  73. package/dist/cjs/src/server/handlers/NotFoundHandler.js.map +1 -1
  74. package/dist/cjs/src/server/middleware/MiddlewareManager.js +57 -12
  75. package/dist/cjs/src/server/middleware/MiddlewareManager.js.map +1 -1
  76. package/dist/cjs/src/server/utils/forceClosePort.js +1 -1
  77. package/dist/cjs/src/server/utils/forceClosePort.js.map +1 -1
  78. package/dist/esm/mods/security/src/algorithms/hash-algorithms.js +10 -0
  79. package/dist/esm/mods/security/src/algorithms/hash-algorithms.js.map +1 -1
  80. package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js +10 -0
  81. package/dist/esm/mods/security/src/components/cache/cacheSys.utils.js.map +1 -1
  82. package/dist/esm/mods/security/src/components/cache/index.js +10 -2
  83. package/dist/esm/mods/security/src/components/cache/index.js.map +1 -1
  84. package/dist/esm/mods/security/src/components/fortified-function/index.js +9 -0
  85. package/dist/esm/mods/security/src/components/fortified-function/index.js.map +1 -1
  86. package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js +10 -0
  87. package/dist/esm/mods/security/src/components/fortified-function/security/security-handler.js.map +1 -1
  88. package/dist/esm/mods/security/src/core/crypto.js +14 -0
  89. package/dist/esm/mods/security/src/core/crypto.js.map +1 -1
  90. package/dist/esm/mods/security/src/index.js +10 -1
  91. package/dist/esm/mods/security/src/index.js.map +1 -1
  92. package/dist/esm/shared/logger/Logger.js +372 -29
  93. package/dist/esm/shared/logger/Logger.js.map +1 -1
  94. package/dist/esm/src/cluster/bun-cluster-manager.js +91 -1
  95. package/dist/esm/src/cluster/bun-cluster-manager.js.map +1 -1
  96. package/dist/esm/src/cluster/cluster-manager.js +15 -3
  97. package/dist/esm/src/cluster/cluster-manager.js.map +1 -1
  98. package/dist/esm/src/cluster/modules/AutoScaler.js +4 -4
  99. package/dist/esm/src/cluster/modules/AutoScaler.js.map +1 -1
  100. package/dist/esm/src/cluster/modules/CrossPlatformMemory.js +2 -2
  101. package/dist/esm/src/cluster/modules/CrossPlatformMemory.js.map +1 -1
  102. package/dist/esm/src/cluster/modules/EventLoopMonitor.js +268 -0
  103. package/dist/esm/src/cluster/modules/EventLoopMonitor.js.map +1 -0
  104. package/dist/esm/src/cluster/modules/GCStatsTracker.js +198 -0
  105. package/dist/esm/src/cluster/modules/GCStatsTracker.js.map +1 -0
  106. package/dist/esm/src/cluster/modules/HeapStatsCollector.js +109 -0
  107. package/dist/esm/src/cluster/modules/HeapStatsCollector.js.map +1 -0
  108. package/dist/esm/src/cluster/modules/NetworkTracker.js +160 -0
  109. package/dist/esm/src/cluster/modules/NetworkTracker.js.map +1 -0
  110. package/dist/esm/src/cluster/modules/ThroughputCalculator.js +184 -0
  111. package/dist/esm/src/cluster/modules/ThroughputCalculator.js.map +1 -0
  112. package/dist/esm/src/cluster/modules/WorkerManager.js +14 -14
  113. package/dist/esm/src/cluster/modules/WorkerManager.js.map +1 -1
  114. package/dist/esm/src/cluster/modules/{LoadBalancer.js → strategy/LoadBalancer.js} +1 -1
  115. package/dist/esm/src/cluster/modules/strategy/LoadBalancer.js.map +1 -0
  116. package/dist/esm/src/middleware/built-in/sqlInjection.js +333 -0
  117. package/dist/esm/src/middleware/built-in/sqlInjection.js.map +1 -0
  118. package/dist/esm/src/middleware/safe-json-middleware.js +1 -1
  119. package/dist/esm/src/middleware/safe-json-middleware.js.map +1 -1
  120. package/dist/esm/src/middleware/security-middleware.js +447 -332
  121. package/dist/esm/src/middleware/security-middleware.js.map +1 -1
  122. package/dist/esm/src/plugins/modules/index.js +9 -3
  123. package/dist/esm/src/plugins/modules/index.js.map +1 -1
  124. package/dist/esm/src/server/FastServer.js +41 -1
  125. package/dist/esm/src/server/FastServer.js.map +1 -1
  126. package/dist/esm/src/server/ServerFactory.js +62 -2
  127. package/dist/esm/src/server/ServerFactory.js.map +1 -1
  128. package/dist/esm/src/server/components/fastapi/ClusterManagerComponent.js +32 -6
  129. package/dist/esm/src/server/components/fastapi/ClusterManagerComponent.js.map +1 -1
  130. package/dist/esm/src/server/components/fastapi/WorkerPoolComponent.js +204 -0
  131. package/dist/esm/src/server/components/fastapi/WorkerPoolComponent.js.map +1 -0
  132. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js +2 -27
  133. package/dist/esm/src/server/components/fastapi/console/ConsoleInterceptor.js.map +1 -1
  134. package/dist/esm/src/server/components/fastapi/modules/UFRP/WorkerPoolManager.js +263 -0
  135. package/dist/esm/src/server/components/fastapi/modules/UFRP/WorkerPoolManager.js.map +1 -0
  136. package/dist/esm/src/server/components/fastapi/modules/UFRP/workers/Logger.js +236 -0
  137. package/dist/esm/src/server/components/fastapi/modules/UFRP/workers/cpu-tasks.js +294 -0
  138. package/dist/esm/src/server/components/fastapi/modules/UFRP/workers/enhanced-cpu-worker.js +433 -0
  139. package/dist/esm/src/server/components/fastapi/modules/UFRP/workers/io-worker.js +1615 -0
  140. package/dist/esm/src/server/components/lifecycle/ServerLifecycleManager.js +143 -24
  141. package/dist/esm/src/server/components/lifecycle/ServerLifecycleManager.js.map +1 -1
  142. package/dist/esm/src/server/const/default.js +23 -9
  143. package/dist/esm/src/server/const/default.js.map +1 -1
  144. package/dist/esm/src/server/core/HttpServer.js +8 -8
  145. package/dist/esm/src/server/core/HttpServer.js.map +1 -1
  146. package/dist/esm/src/server/core/XyprissApp.js +284 -17
  147. package/dist/esm/src/server/core/XyprissApp.js.map +1 -1
  148. package/dist/esm/src/server/handlers/NotFoundHandler.js +1 -1
  149. package/dist/esm/src/server/handlers/NotFoundHandler.js.map +1 -1
  150. package/dist/esm/src/server/middleware/MiddlewareManager.js +57 -12
  151. package/dist/esm/src/server/middleware/MiddlewareManager.js.map +1 -1
  152. package/dist/esm/src/server/utils/forceClosePort.js +1 -1
  153. package/dist/esm/src/server/utils/forceClosePort.js.map +1 -1
  154. package/dist/index.d.ts +675 -516
  155. package/package.json +10 -11
  156. package/dist/cjs/src/cluster/index.js +0 -361
  157. package/dist/cjs/src/cluster/index.js.map +0 -1
  158. package/dist/cjs/src/cluster/modules/ClusterFactory.js +0 -539
  159. package/dist/cjs/src/cluster/modules/ClusterFactory.js.map +0 -1
  160. package/dist/cjs/src/cluster/modules/LoadBalancer.js.map +0 -1
  161. package/dist/cjs/src/server/components/fastapi/UltraFastRequestProcessor.js +0 -668
  162. package/dist/cjs/src/server/components/fastapi/UltraFastRequestProcessor.js.map +0 -1
  163. package/dist/cjs/src/server/components/fastapi/middlewares/MiddlewareAPI.js +0 -347
  164. package/dist/cjs/src/server/components/fastapi/middlewares/MiddlewareAPI.js.map +0 -1
  165. package/dist/cjs/src/server/components/fastapi/middlewares/MiddlewareMethodsManager.js +0 -204
  166. package/dist/cjs/src/server/components/fastapi/middlewares/MiddlewareMethodsManager.js.map +0 -1
  167. package/dist/cjs/src/server/components/fastapi/middlewares/middlewareManager.js +0 -953
  168. package/dist/cjs/src/server/components/fastapi/middlewares/middlewareManager.js.map +0 -1
  169. package/dist/cjs/src/server/components/fastapi/modules/UFRP/WorkerPool.js +0 -56
  170. package/dist/cjs/src/server/components/fastapi/modules/UFRP/WorkerPool.js.map +0 -1
  171. package/dist/esm/src/cluster/index.js +0 -339
  172. package/dist/esm/src/cluster/index.js.map +0 -1
  173. package/dist/esm/src/cluster/modules/ClusterFactory.js +0 -511
  174. package/dist/esm/src/cluster/modules/ClusterFactory.js.map +0 -1
  175. package/dist/esm/src/cluster/modules/LoadBalancer.js.map +0 -1
  176. package/dist/esm/src/server/components/fastapi/UltraFastRequestProcessor.js +0 -647
  177. package/dist/esm/src/server/components/fastapi/UltraFastRequestProcessor.js.map +0 -1
  178. package/dist/esm/src/server/components/fastapi/middlewares/MiddlewareAPI.js +0 -345
  179. package/dist/esm/src/server/components/fastapi/middlewares/MiddlewareAPI.js.map +0 -1
  180. package/dist/esm/src/server/components/fastapi/middlewares/MiddlewareMethodsManager.js +0 -202
  181. package/dist/esm/src/server/components/fastapi/middlewares/MiddlewareMethodsManager.js.map +0 -1
  182. package/dist/esm/src/server/components/fastapi/middlewares/middlewareManager.js +0 -951
  183. package/dist/esm/src/server/components/fastapi/middlewares/middlewareManager.js.map +0 -1
  184. package/dist/esm/src/server/components/fastapi/modules/UFRP/WorkerPool.js +0 -54
  185. package/dist/esm/src/server/components/fastapi/modules/UFRP/WorkerPool.js.map +0 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # XyPriss (Beta)
5
5
 
6
- A Node.js web framework with Express-like API, built-in security middleware, and routing system
6
+ A powerful Node.js web framework with built-in security, clustering, and performance optimizations for modern web applications.
7
7
 
8
8
  [![npm version](https://badge.fury.io/js/xypriss.svg)](https://badge.fury.io/js/xypriss)
9
9
  [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
@@ -14,122 +14,123 @@ A Node.js web framework with Express-like API, built-in security middleware, and
14
14
 
15
15
  ---
16
16
 
17
- ## About XyPriss
17
+ ## Overview
18
18
 
19
- XyPriss is a Node.js web framework with an Express-like API, built from the ground up with TypeScript. It provides built-in security middleware, a flexible routing system, and performance optimizations without depending on Express.
19
+ XyPriss is a powerful, TypeScript-first, open-source Node.js web framework that enhances your development experience with built-in security middleware, clustering, and performance optimizations. Whether you're building new applications or enhancing existing ones, XyPriss provides the tools you need for scalable, secure web development. Join our community and contribute on GitHub!
20
20
 
21
- ### Key Benefits
21
+ ### Key Features
22
22
 
23
- - Independent web framework with Express-like API
24
- - Built-in security middleware (12 security modules)
25
- - Flexible routing system with wildcard and parameter support
26
- - TypeScript support with full type definitions
23
+ - **Familiar API**: Intuitive syntax for defining routes and middleware that feels natural to Node.js developers.
24
+ - **Built-in Security**: Includes 12+ security middleware modules for common protections like CSRF, XSS, and rate limiting.
25
+ - **Flexible Routing**: Supports parameters, wildcards, and modular routers.
26
+ - **TypeScript Support**: Full type definitions for a better developer experience.
27
+ - **Performance**: Advanced clustering, caching, and performance optimizations built-in.
27
28
 
28
- > **Migration Notice**: This library is the evolved version of FortifyJS. The FortifyJS library will be deprecated soon - migrate to XyPriss for continued support and new features. [Learn more](https://github.com/nehonix/FortifyJS)
29
+ > **Note**: XyPriss is the successor to FortifyJS, which will be deprecated. Migrate to XyPriss for continued support and new features. [Migration Guide](https://github.com/nehonix/FortifyJS).
29
30
 
30
31
  ---
31
32
 
32
- ## Quick Start
33
+ ## Installation
34
+
35
+ Install XyPriss via npm or yarn:
33
36
 
34
37
  ```bash
35
- # Install XyPriss
36
38
  npm install xypriss
37
-
38
- # Or with yarn
39
+ # or
39
40
  yarn add xypriss
40
41
  ```
41
42
 
43
+ For additional security features, install the security module:
44
+
45
+ ```bash
46
+ npm install xypriss-security
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Quick Start
52
+
53
+ Create a basic server with XyPriss:
54
+
42
55
  ```typescript
43
56
  import { createServer } from "xypriss";
44
57
 
45
- // Create a XyPriss server
46
58
  const server = createServer({
47
59
  server: { port: 3000 },
48
60
  security: { enabled: true },
49
61
  performance: { clustering: true },
50
62
  });
51
63
 
52
- // Use Express-like API
53
64
  server.get("/", (req, res) => {
54
- res.json({
55
- message: "Hello from XyPriss!",
56
- powered: "Nehonix",
57
- });
65
+ res.json({ message: "Hello from XyPriss!", powered: "Nehonix" });
58
66
  });
59
67
 
60
- // Start the server
61
- server.start();
68
+ server.start(() => {
69
+ console.log(`Server running at http://localhost:${server.getPort()}`);
70
+ });
62
71
  ```
63
72
 
64
- Your server is now running with built-in security middleware and routing capabilities.
73
+ This sets up a server with security middleware and clustering enabled, listening on port 3000.
74
+
75
+ ### Works Great With Express
76
+
77
+ XyPriss is designed to complement the Node.js ecosystem, not replace it. You can:
78
+
79
+ - **Use XyPriss standalone** for new projects that need built-in security and clustering
80
+ - **Enhance existing Express apps** by integrating XyPriss security modules
81
+ - **Run both frameworks** side by side for different services
82
+ - **Migrate gradually** by moving specific routes or services to XyPriss
83
+
84
+ ```typescript
85
+ // Example: Using XyPriss security with Express
86
+ import express from "express";
87
+ import { XyPrissSecurity } from "xypriss-security";
88
+
89
+ const app = express();
90
+
91
+ // Add XyPriss security to your Express app
92
+ app.use(
93
+ XyPrissSecurity.middleware({
94
+ csrf: true,
95
+ xss: true,
96
+ rateLimit: { windowMs: 15 * 60 * 1000, max: 100 },
97
+ })
98
+ );
99
+
100
+ app.listen(3000);
101
+ ```
65
102
 
66
103
  ---
67
104
 
68
105
  ## Table of Contents
69
106
 
70
- - [About XyPriss](#about-xypriss)
71
- - [Quick Start](#quick-start)
72
- - [Key Features](#key-features)
73
- - [Routing System](#routing-system)
74
- - [Security and Reliability](#security-and-reliability)
75
- - [Performance and Scalability](#performance-and-scalability)
76
- - [Developer Experience](#developer-experience)
77
- - [Routing Documentation](#routing-documentation)
107
+ - [Overview](#overview)
78
108
  - [Installation](#installation)
79
- - [Basic Usage](#basic-usage)
109
+ - [Quick Start](#quick-start)
110
+ - [Routing](#routing)
111
+ - [Security](#security)
112
+ - [Performance](#performance)
80
113
  - [Configuration](#configuration)
81
- - [Documentation](#documentation)
114
+ - [Modules](#modules)
82
115
  - [Contributing](#contributing)
83
116
  - [License](#license)
84
117
  - [Support](#support)
85
118
 
86
119
  ---
87
120
 
88
- ## Key Features
89
-
90
- ### Routing System
91
-
92
- - Express-like API for familiar development experience
93
- - Advanced route patterns with parameter support (`:id`, `:name`)
94
- - Wildcard routing with single (`*`) and multi-segment (`**`) support
95
- - Router mounting and middleware support
96
- - Route-specific middleware and parameter extraction
97
-
98
- ### Security and Reliability
99
-
100
- - 12 built-in security middleware modules
101
- - CSRF protection with csrf-csrf library
102
- - Security headers (Helmet), CORS, rate limiting
103
- - Input validation and sanitization (XSS, MongoDB injection protection)
104
- - Request logging and monitoring
121
+ ## Routing
105
122
 
106
- ### Performance and Scalability
123
+ XyPriss provides a flexible routing system with support for parameters, wildcards, and modular routers.
107
124
 
108
- - Independent HTTP server implementation
109
- - Fast server initialization with minimal overhead
110
- - Multi-tier caching system supporting memory, Redis, and hybrid strategies
111
- - Automatic port detection and switching with configurable port ranges
112
- - Built-in clustering with automatic scaling based on system load
113
-
114
- ### Developer Experience
115
- - Complete TypeScript support with type definitions
116
- - Extensible plugin system for custom functionality
117
- - Comprehensive documentation and examples
118
-
119
- ## Routing Documentation
120
-
121
- XyPriss provides a flexible routing system with Express-like API but without Express dependency.
122
-
123
- ### Basic Routing
125
+ ### Basic Routes
124
126
 
125
127
  ```typescript
126
128
  import { createServer } from "xypriss";
127
129
 
128
130
  const app = createServer();
129
131
 
130
- // Basic routes
131
132
  app.get("/", (req, res) => {
132
- res.json({ message: "Hello World" });
133
+ res.json({ message: "Welcome to XyPriss" });
133
134
  });
134
135
 
135
136
  app.post("/users", (req, res) => {
@@ -139,100 +140,61 @@ app.post("/users", (req, res) => {
139
140
  app.put("/users/:id", (req, res) => {
140
141
  res.json({ message: "User updated", id: req.params.id });
141
142
  });
142
-
143
- app.delete("/users/:id", (req, res) => {
144
- res.json({ message: "User deleted", id: req.params.id });
145
- });
146
143
  ```
147
144
 
148
145
  ### Route Parameters
149
146
 
147
+ Extract dynamic segments from URLs:
148
+
150
149
  ```typescript
151
- // Single parameter
152
150
  app.get("/users/:id", (req, res) => {
153
- const userId = req.params.id;
154
- res.json({ userId });
151
+ res.json({ userId: req.params.id });
155
152
  });
156
153
 
157
- // Multiple parameters
158
154
  app.get("/users/:userId/posts/:postId", (req, res) => {
159
- const { userId, postId } = req.params;
160
- res.json({ userId, postId });
155
+ res.json({ userId: req.params.userId, postId: req.params.postId });
161
156
  });
162
157
  ```
163
158
 
164
159
  ### Wildcard Routes
165
160
 
166
- XyPriss supports two types of wildcards:
167
-
168
- #### Single Wildcard (`*`) - Matches one path segment
161
+ - **Single Wildcard (`*`)**: Matches one path segment.
162
+ - **Multi-segment Wildcard (`**`)\*\*: Matches multiple path segments.
169
163
 
170
164
  ```typescript
171
- // Matches: /files/document.pdf, /files/image.jpg
172
- // Does NOT match: /files/folder/document.pdf
173
165
  app.get("/files/*", (req, res) => {
174
- const filename = req.params["*"];
175
- res.json({ filename });
166
+ res.json({ filename: req.params["*"] }); // e.g., "document.pdf"
176
167
  });
177
- ```
178
168
 
179
- #### Double Wildcard (`**`) - Matches multiple path segments
180
-
181
- ```typescript
182
- // Matches: /api/v1/users, /api/v1/users/123/posts
183
169
  app.get("/api/**", (req, res) => {
184
- const path = req.params["**"];
185
- res.json({ capturedPath: path });
170
+ res.json({ path: req.params["**"] }); // e.g., "v1/users/123"
186
171
  });
187
172
  ```
188
173
 
189
- ### Router System
174
+ ### Modular Routers
190
175
 
191
- Create modular routes using the Router system:
176
+ Organize routes with routers:
192
177
 
193
178
  ```typescript
194
- import { createServer, Router } from "xypriss"; // import XyPrissRouter for full control
179
+ import { createServer, Router } from "xypriss";
195
180
 
196
181
  const app = createServer();
197
-
198
- // Create a router
199
182
  const userRouter = Router();
200
183
 
201
- // Add routes to router
202
184
  userRouter.get("/", (req, res) => {
203
- res.json({ message: "Get all users" });
185
+ res.json({ message: "List users" });
204
186
  });
205
187
 
206
188
  userRouter.get("/:id", (req, res) => {
207
189
  res.json({ message: "Get user", id: req.params.id });
208
190
  });
209
191
 
210
- userRouter.post("/", (req, res) => {
211
- res.json({ message: "Create user", data: req.body });
212
- });
213
-
214
- // Mount router at /api/users
215
192
  app.use("/api/users", userRouter);
216
-
217
- // Router with middleware
218
- const adminRouter = Router();
219
-
220
- adminRouter.use((req, res, next) => {
221
- // Admin authentication middleware
222
- console.log("Admin route accessed");
223
- next();
224
- });
225
-
226
- adminRouter.get("/dashboard", (req, res) => {
227
- res.json({ message: "Admin dashboard" });
228
- });
229
-
230
- app.use("/admin", adminRouter);
231
193
  ```
232
194
 
233
195
  ### Middleware
234
196
 
235
- Add middleware to routes or routers:
197
+ Apply middleware globally, per route, or per router:
236
198
 
237
199
  ```typescript
238
200
  // Global middleware
@@ -245,7 +207,6 @@ app.use((req, res, next) => {
245
207
  app.get(
246
208
  "/protected",
247
209
  (req, res, next) => {
248
- // Authentication middleware
249
210
  if (!req.headers.authorization) {
250
211
  return res.status(401).json({ error: "Unauthorized" });
251
212
  }
@@ -255,258 +216,83 @@ app.get(
255
216
  res.json({ message: "Protected resource" });
256
217
  }
257
218
  );
258
-
259
- // Router middleware
260
- const apiRouter = Router();
261
-
262
- apiRouter.use((req, res, next) => {
263
- // API-specific middleware
264
- res.setHeader("X-API-Version", "1.0");
265
- next();
266
- });
267
- ```
268
-
269
- ### Route Examples
270
-
271
- ```typescript
272
- // Combined parameters and wildcards
273
- app.get("/users/:id/files/*", (req, res) => {
274
- const { id } = req.params;
275
- const filename = req.params["*"];
276
- res.json({ userId: id, filename });
277
- });
278
-
279
- // Deep wildcard routing
280
- app.get("/docs/**", (req, res) => {
281
- const docPath = req.params["**"];
282
- res.json({ documentPath: docPath });
283
- });
284
-
285
- // API versioning with routers
286
- const v1Router = Router();
287
- const v2Router = Router();
288
-
289
- v1Router.get("/users", (req, res) => {
290
- res.json({ version: "v1", users: [] });
291
- });
292
-
293
- v2Router.get("/users", (req, res) => {
294
- res.json({ version: "v2", users: [], pagination: {} });
295
- });
296
-
297
- app.use("/api/v1", v1Router);
298
- app.use("/api/v2", v2Router);
299
- ```
300
-
301
- ## Installation
302
-
303
- ```bash
304
- npm install xypriss
305
- ```
306
-
307
- For security features:
308
-
309
- ```bash
310
- npm install xypriss xypriss-security
311
219
  ```
312
220
 
313
- ## Quick Start
221
+ ---
314
222
 
315
- ### Basic Server Setup
223
+ ## Security
316
224
 
317
- ```typescript
318
- import { createServer } from "xypriss";
225
+ XyPriss includes 12 built-in security middleware modules to protect your application:
319
226
 
320
- // Create a new XyPriss server
321
- const app = createServer({
322
- server: {
323
- port: 3000,
324
- host: "localhost",
325
- autoPortSwitch: {
326
- enabled: true,
327
- portRange: [8086, 3010],
328
- },
329
- },
330
- cache: {
331
- strategy: "memory",
332
- maxSize: 100 * 1024 * 1024, // 100MB
333
- ttl: 3600, // 1 hour
334
- },
335
- });
227
+ - **CSRF Protection**: Via the `csrf-csrf` library.
228
+ - **Security Headers**: Powered by Helmet for secure HTTP headers.
229
+ - **CORS**: Configurable cross-origin resource sharing.
230
+ - **Rate Limiting**: Prevents abuse by limiting requests per IP.
231
+ - **Input Validation**: Sanitizes inputs to prevent XSS and injection attacks.
232
+ - **Request Logging**: Monitors and logs incoming requests.
336
233
 
337
- // Define routes using Express-like syntax
338
- app.get("/", (req, res) => {
339
- res.json({ message: "Hello from XyPriss!" });
340
- });
341
-
342
- app.get("/api/users/:id", (req, res) => {
343
- const userId = req.params.id;
344
- res.json({ userId, data: "User data" });
345
- });
346
-
347
- // Start the server
348
- app.start(undefined, () => {
349
- console.log(
350
- "Secure XyPriss server running at http://localhost:" + app.getPort()
351
- );
352
- });
353
- ```
354
-
355
- ### Advanced Configuration
234
+ Enable security features:
356
235
 
357
236
  ```typescript
358
237
  import { createServer } from "xypriss";
359
238
 
360
239
  const server = createServer({
361
- env: "production",
362
-
363
- server: {
364
- port: 8080,
365
- host: "0.0.0.0",
366
- autoPortSwitch: {
367
- enabled: true,
368
- maxAttempts: 5,
369
- portRange: [8080, 8090],
370
- strategy: "increment",
371
- },
372
- },
373
-
374
- cache: {
375
- strategy: "hybrid", // Memory + Redis
376
- maxSize: 500 * 1024 * 1024, // 500MB
377
- ttl: 7200, // 2 hours
378
- redis: {
379
- host: "localhost",
380
- port: 6379,
381
- cluster: true,
382
- nodes: [
383
- { host: "redis-1", port: 6379 },
384
- { host: "redis-2", port: 6379 },
385
- ],
386
- },
387
- },
388
-
389
- requestManagement: {
390
- timeout: {
391
- enabled: true,
392
- defaultTimeout: 30000, // 30 seconds
393
- routes: {
394
- "/api/upload": 300000, // 5 minutes for uploads
395
- "/api/quick": 5000, // 5 seconds for quick endpoints
396
- },
397
- },
398
- concurrency: {
399
- maxConcurrentRequests: 1000,
400
- maxPerIP: 50,
401
- },
402
- },
403
-
404
- cluster: {
240
+ security: {
405
241
  enabled: true,
406
- workers: "auto", // Auto-detect CPU cores
407
- autoScale: {
408
- enabled: true,
409
- minWorkers: 2,
410
- maxWorkers: 8,
411
- cpuThreshold: 80,
412
- },
242
+ csrf: { enabled: true },
243
+ rateLimit: { max: 100, windowMs: 15 * 60 * 1000 }, // 100 requests per 15 minutes
413
244
  },
414
245
  });
415
246
  ```
416
247
 
417
- ### With XyPriss Security Integration
248
+ For advanced security, use the `xypriss-security` module:
418
249
 
419
250
  ```typescript
420
251
  import { createServer } from "xypriss";
421
- import { XyPrissSecurity as security, fString, fArray } from "xypriss-security";
252
+ import { fString, generateSecureToken } from "xypriss-security";
422
253
 
423
- const server = createServer({
424
- server: {
425
- port: 3000,
426
- host: "localhost",
427
- },
428
- });
429
-
430
- // Secure route with encryption
431
- server.post("/api/secure-data", async (req, res) => {
432
- try {
433
- // Use secure data structures
434
- const secureData = fArray(req.body.sensitiveArray);
435
- const securePassword = fString(req.body.password, {
436
- protectionLevel: "maximum",
437
- enableEncryption: true,
438
- });
439
-
440
- // Generate secure token
441
- const token = security.generateSecureToken({
442
- length: 32,
443
- entropy: "maximum",
444
- });
445
-
446
- res.json({
447
- success: true,
448
- token,
449
- dataLength: secureData.length,
450
- });
451
- } catch (error) {
452
- res.status(500).json({ error: "Security operation failed" });
453
- }
454
- });
254
+ const server = createServer();
455
255
 
456
- server.start(undefined, () => {
457
- console.log(
458
- "Secure XyPriss server running at http://localhost:" + server.getPort()
459
- );
256
+ server.post("/api/secure", async (req, res) => {
257
+ const secureData = fString(req.body.data, { enableEncryption: true });
258
+ const token = generateSecureToken({ length: 32 });
259
+ res.json({ token, data: secureData });
460
260
  });
461
261
  ```
462
262
 
463
- ## Architecture
464
-
465
- ### Core Framework (`xypriss`)
263
+ ---
466
264
 
467
- - Server Factory: Independent HTTP server creation with `createServer()`
468
- - Routing System: Express-like API with advanced pattern matching
469
- - Security Middleware: 12 built-in security modules
470
- - Cache Engine: Multi-tier caching system with intelligent invalidation
471
- - Plugin System: Extensible plugin architecture
265
+ ## Performance
472
266
 
473
- ### Security Module (`xypriss-security`)
267
+ XyPriss is designed for efficiency and scalability:
474
268
 
475
- XyPriss integrates with the XyPriss Security toolkit, providing:
269
+ - **Independent HTTP Server**: No Express dependency, reducing overhead.
270
+ - **Clustering**: Automatic scaling based on CPU cores.
271
+ - **Caching**: Supports memory, Redis, or hybrid caching strategies.
272
+ - **Auto Port Switching**: Detects and switches ports if conflicts arise.
476
273
 
477
- - Secure Data Structures: `fArray`, `fString`, `fObject` with encryption
478
- - Cryptographic Functions: Token generation, hashing, key derivation
479
- - Advanced Security: Post-quantum cryptography, tamper-evident logging
480
- - Performance: Fortified functions with security monitoring
274
+ Example configuration:
481
275
 
482
276
  ```typescript
483
- import { createServer } from "xypriss";
484
- import {
485
- XyPrissSecurity as security, // or just import XyPriss
486
- fArray,
487
- fString,
488
- fObject,
489
- generateSecureToken,
490
- } from "xypriss-security";
491
-
492
- // Use both together
493
277
  const server = createServer({
494
- /* config */
278
+ server: {
279
+ port: 3000,
280
+ autoPortSwitch: { enabled: true, portRange: [3000, 3100] },
281
+ },
282
+ cache: {
283
+ strategy: "memory",
284
+ maxSize: 100 * 1024 * 1024, // 100MB
285
+ ttl: 3600, // 1 hour
286
+ },
287
+ cluster: { enabled: true, workers: "auto" },
495
288
  });
496
289
  ```
497
290
 
498
- ## Documentation
499
-
500
- - [Getting Started Guide](./docs/getting-started.md)
501
- - [Routing System](./docs/routing.md)
502
- - [Security Guide](./docs/security.md)
503
- - [API Reference](./docs/api-reference.md)
504
- - [Configuration Options](./docs/configuration.md)
505
- - [Plugin Development](./docs/plugins.md)
291
+ ---
506
292
 
507
293
  ## Configuration
508
294
 
509
- XyPriss supports extensive configuration through the `ServerOptions` interface:
295
+ Customize XyPriss with the `ServerOptions` interface:
510
296
 
511
297
  ```typescript
512
298
  interface ServerOptions {
@@ -515,90 +301,94 @@ interface ServerOptions {
515
301
  port?: number;
516
302
  host?: string;
517
303
  autoPortSwitch?: {
518
- enabled?: boolean;
304
+ enabled: boolean;
519
305
  portRange?: [number, number];
520
- strategy?: "increment" | "random" | "predefined";
306
+ strategy?: "increment" | "random";
521
307
  };
522
308
  };
523
309
  cache?: {
524
- strategy?: "auto" | "memory" | "redis" | "hybrid";
310
+ strategy?: "memory" | "redis" | "hybrid";
525
311
  maxSize?: number;
526
312
  ttl?: number;
527
- redis?: RedisConfig;
313
+ redis?: { host: string; port: number; cluster?: boolean };
314
+ };
315
+ security?: {
316
+ enabled?: boolean;
317
+ csrf?: { enabled: boolean };
318
+ rateLimit?: { max: number; windowMs: number };
319
+ };
320
+ cluster?: {
321
+ enabled: boolean;
322
+ workers?: number | "auto";
528
323
  };
529
- requestManagement?: RequestManagementConfig;
530
- cluster?: ClusterConfig;
531
- // ... and many more options
532
324
  }
533
325
  ```
534
326
 
535
- ## Performance
536
-
537
- XyPriss is optimized for production use:
327
+ Example:
538
328
 
539
- - Fast server initialization with minimal overhead
540
- - High-throughput request handling
541
- - Efficient memory usage with automatic cleanup
542
- - Low-latency cache access
543
- - Horizontal scaling through clustering
329
+ ```typescript
330
+ const server = createServer({
331
+ env: "production",
332
+ server: { port: 8080, host: "0.0.0.0" },
333
+ cache: { strategy: "redis", redis: { host: "localhost", port: 6379 } },
334
+ });
335
+ ```
544
336
 
545
- ## Available Modules
337
+ ---
546
338
 
547
- XyPriss includes several specialized modules for enhanced functionality:
339
+ ## Modules
548
340
 
549
- ### ACPES - Advanced Cross-Platform Encrypted Storage
341
+ ### ACPES (Advanced Cross-Platform Encrypted Storage)
550
342
 
551
343
  **Location**: `mods/ACPES/`
552
344
 
553
- A secure, cross-platform storage solution that works seamlessly across Web, Mobile (React Native), and Node.js environments.
345
+ A secure storage solution for web, mobile, and Node.js environments.
554
346
 
555
- **Features:**
347
+ **Features**:
556
348
 
557
- - Cross-platform compatibility (Web, Mobile, Node.js)
558
- - Double AES-256 encryption with PBKDF2 key derivation
559
- - Integrity verification with HMAC-SHA256 checksums
560
- - Device fingerprinting for unique encryption keys
561
- - Automatic lockout protection against brute force attacks
562
- - TTL support for automatic data expiration
563
- - LZ-string compression for large data
349
+ - AES-256 encryption with PBKDF2 key derivation.
350
+ - HMAC-SHA256 for integrity verification.
351
+ - TTL for automatic data expiration.
352
+ - LZ-string compression for large data.
564
353
 
565
- **Quick Usage:**
354
+ **Usage**:
566
355
 
567
356
  ```typescript
568
357
  import { Storage, STORAGE_KEYS } from "xypriss-acpes";
569
358
 
570
- // Store sensitive data
571
- await Storage.setItem(STORAGE_KEYS.SESSION_TOKEN, "your-token");
572
-
573
- // Retrieve data
359
+ await Storage.setItem(STORAGE_KEYS.SESSION_TOKEN, "secure-token");
574
360
  const token = await Storage.getItem(STORAGE_KEYS.SESSION_TOKEN);
575
361
  ```
576
362
 
577
- **Documentation**: [ACPES Documentation](./mods/ACPES/docs/)
363
+ **Docs**: [ACPES Documentation](./mods/ACPES/docs/)
578
364
 
579
365
  ### Security Module
580
366
 
581
367
  **Location**: `mods/security/`
582
368
 
583
- Comprehensive security utilities and middleware for XyPriss applications.
369
+ Provides utilities for secure data handling and request protection.
584
370
 
585
- **Features:**
371
+ **Features**:
586
372
 
587
- - Request validation and sanitization
588
- - Rate limiting and DDoS protection
589
- - Security headers management
590
- - Authentication and authorization utilities
591
- - Cryptographic functions and secure random generation
373
+ - Input sanitization and validation.
374
+ - Cryptographic functions (e.g., secure token generation).
375
+ - Rate limiting and DDoS protection.
592
376
 
593
- **Documentation**: [Security Module Documentation](./mods/security/docs/)
377
+ **Docs**: [Security Documentation](./mods/security/docs/)
378
+
379
+ ---
594
380
 
595
381
  ## Contributing
596
382
 
597
- Contributions are welcome. Please see our [Contributing Guide](./CONTRIBUTING.md).
383
+ We welcome contributions! See the [Contributing Guide](./CONTRIBUTING.md) for details on how to get started.
384
+
385
+ ---
598
386
 
599
387
  ## License
600
388
 
601
- MIT License - see [LICENSE](./LICENSE) file for details.
389
+ XyPriss is licensed under the [MIT License](./LICENSE).
390
+
391
+ ---
602
392
 
603
393
  ## Support
604
394
 
@@ -610,7 +400,7 @@ MIT License - see [LICENSE](./LICENSE) file for details.
610
400
 
611
401
  ### Powered by Nehonix
612
402
 
613
- XyPriss is developed and maintained by the Nehonix Team.
403
+ Developed and maintained by the Nehonix Team.
614
404
 
615
405
  [![Website](https://img.shields.io/badge/Website-nehonix.space-blue?style=for-the-badge&logo=globe)](https://nehonix.space)
616
406
  [![GitHub](https://img.shields.io/badge/GitHub-Nehonix--Team-black?style=for-the-badge&logo=github)](https://github.com/Nehonix-Team)