create-fluxstack 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/.env +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/app/client/README.md +69 -0
  5. package/app/client/frontend-only.ts +12 -0
  6. package/app/client/index.html +13 -0
  7. package/app/client/public/vite.svg +1 -0
  8. package/app/client/src/App.css +883 -0
  9. package/app/client/src/App.tsx +669 -0
  10. package/app/client/src/assets/react.svg +1 -0
  11. package/app/client/src/components/TestPage.tsx +453 -0
  12. package/app/client/src/index.css +51 -0
  13. package/app/client/src/lib/eden-api.ts +110 -0
  14. package/app/client/src/main.tsx +10 -0
  15. package/app/client/src/vite-env.d.ts +1 -0
  16. package/app/client/tsconfig.app.json +43 -0
  17. package/app/client/tsconfig.json +7 -0
  18. package/app/client/tsconfig.node.json +25 -0
  19. package/app/server/app.ts +10 -0
  20. package/app/server/backend-only.ts +15 -0
  21. package/app/server/controllers/users.controller.ts +69 -0
  22. package/app/server/index.ts +104 -0
  23. package/app/server/routes/index.ts +25 -0
  24. package/app/server/routes/users.routes.ts +121 -0
  25. package/app/server/types/index.ts +1 -0
  26. package/app/shared/types/index.ts +18 -0
  27. package/bun.lock +1053 -0
  28. package/core/__tests__/integration.test.ts +227 -0
  29. package/core/build/index.ts +186 -0
  30. package/core/cli/command-registry.ts +334 -0
  31. package/core/cli/index.ts +394 -0
  32. package/core/cli/plugin-discovery.ts +200 -0
  33. package/core/client/standalone.ts +57 -0
  34. package/core/config/__tests__/config-loader.test.ts +591 -0
  35. package/core/config/__tests__/config-merger.test.ts +657 -0
  36. package/core/config/__tests__/env-converter.test.ts +372 -0
  37. package/core/config/__tests__/env-processor.test.ts +431 -0
  38. package/core/config/__tests__/env.test.ts +452 -0
  39. package/core/config/__tests__/integration.test.ts +418 -0
  40. package/core/config/__tests__/loader.test.ts +331 -0
  41. package/core/config/__tests__/schema.test.ts +129 -0
  42. package/core/config/__tests__/validator.test.ts +318 -0
  43. package/core/config/env-dynamic.ts +326 -0
  44. package/core/config/env.ts +597 -0
  45. package/core/config/index.ts +317 -0
  46. package/core/config/loader.ts +546 -0
  47. package/core/config/runtime-config.ts +322 -0
  48. package/core/config/schema.ts +694 -0
  49. package/core/config/validator.ts +540 -0
  50. package/core/framework/__tests__/server.test.ts +233 -0
  51. package/core/framework/client.ts +132 -0
  52. package/core/framework/index.ts +8 -0
  53. package/core/framework/server.ts +501 -0
  54. package/core/framework/types.ts +63 -0
  55. package/core/plugins/__tests__/built-in.test.ts.disabled +366 -0
  56. package/core/plugins/__tests__/manager.test.ts +398 -0
  57. package/core/plugins/__tests__/monitoring.test.ts +401 -0
  58. package/core/plugins/__tests__/registry.test.ts +335 -0
  59. package/core/plugins/built-in/index.ts +142 -0
  60. package/core/plugins/built-in/logger/index.ts +180 -0
  61. package/core/plugins/built-in/monitoring/README.md +193 -0
  62. package/core/plugins/built-in/monitoring/index.ts +912 -0
  63. package/core/plugins/built-in/static/index.ts +289 -0
  64. package/core/plugins/built-in/swagger/index.ts +229 -0
  65. package/core/plugins/built-in/vite/index.ts +316 -0
  66. package/core/plugins/config.ts +348 -0
  67. package/core/plugins/discovery.ts +350 -0
  68. package/core/plugins/executor.ts +351 -0
  69. package/core/plugins/index.ts +195 -0
  70. package/core/plugins/manager.ts +583 -0
  71. package/core/plugins/registry.ts +424 -0
  72. package/core/plugins/types.ts +254 -0
  73. package/core/server/framework.ts +123 -0
  74. package/core/server/index.ts +8 -0
  75. package/core/server/plugins/database.ts +182 -0
  76. package/core/server/plugins/logger.ts +47 -0
  77. package/core/server/plugins/swagger.ts +34 -0
  78. package/core/server/standalone.ts +91 -0
  79. package/core/templates/create-project.ts +455 -0
  80. package/core/types/api.ts +169 -0
  81. package/core/types/build.ts +174 -0
  82. package/core/types/config.ts +68 -0
  83. package/core/types/index.ts +127 -0
  84. package/core/types/plugin.ts +94 -0
  85. package/core/utils/__tests__/errors.test.ts +139 -0
  86. package/core/utils/__tests__/helpers.test.ts +297 -0
  87. package/core/utils/__tests__/logger.test.ts +141 -0
  88. package/core/utils/env-runtime-v2.ts +232 -0
  89. package/core/utils/env-runtime.ts +252 -0
  90. package/core/utils/errors/codes.ts +115 -0
  91. package/core/utils/errors/handlers.ts +63 -0
  92. package/core/utils/errors/index.ts +81 -0
  93. package/core/utils/helpers.ts +180 -0
  94. package/core/utils/index.ts +18 -0
  95. package/core/utils/logger/index.ts +161 -0
  96. package/core/utils/logger.ts +106 -0
  97. package/core/utils/monitoring/index.ts +212 -0
  98. package/create-fluxstack.ts +231 -0
  99. package/package.json +43 -0
  100. package/tsconfig.json +51 -0
  101. package/vite.config.ts +42 -0
@@ -0,0 +1,193 @@
1
+ # FluxStack Monitoring Plugin
2
+
3
+ The monitoring plugin provides comprehensive performance monitoring, metrics collection, and system monitoring for FluxStack applications.
4
+
5
+ ## Features
6
+
7
+ - **HTTP Metrics**: Request/response timing, status codes, request/response sizes
8
+ - **System Metrics**: Memory usage, CPU usage, event loop lag, load average
9
+ - **Custom Metrics**: Counters, gauges, and histograms
10
+ - **Multiple Exporters**: Console, Prometheus, JSON, and file exporters
11
+ - **Alert System**: Configurable thresholds and alerts
12
+ - **Metrics Endpoint**: Built-in `/metrics` endpoint for Prometheus scraping
13
+
14
+ ## Configuration
15
+
16
+ ```typescript
17
+ // fluxstack.config.ts
18
+ export default {
19
+ plugins: {
20
+ config: {
21
+ monitoring: {
22
+ enabled: true,
23
+ httpMetrics: true,
24
+ systemMetrics: true,
25
+ customMetrics: true,
26
+ collectInterval: 5000, // 5 seconds
27
+ retentionPeriod: 300000, // 5 minutes
28
+
29
+ exporters: [
30
+ {
31
+ type: "prometheus",
32
+ endpoint: "/metrics",
33
+ enabled: true,
34
+ format: "text"
35
+ },
36
+ {
37
+ type: "console",
38
+ interval: 30000,
39
+ enabled: false
40
+ },
41
+ {
42
+ type: "file",
43
+ filePath: "./logs/metrics.json",
44
+ interval: 60000,
45
+ enabled: true,
46
+ format: "json"
47
+ }
48
+ ],
49
+
50
+ thresholds: {
51
+ responseTime: 1000, // ms
52
+ errorRate: 0.05, // 5%
53
+ memoryUsage: 0.8, // 80%
54
+ cpuUsage: 0.8 // 80%
55
+ },
56
+
57
+ alerts: [
58
+ {
59
+ metric: "http_request_duration_ms",
60
+ operator: ">",
61
+ value: 2000,
62
+ severity: "warning",
63
+ message: "High response time detected"
64
+ },
65
+ {
66
+ metric: "process_memory_rss_bytes",
67
+ operator: ">",
68
+ value: 1000000000, // 1GB
69
+ severity: "error",
70
+ message: "High memory usage"
71
+ }
72
+ ]
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## Metrics Collected
80
+
81
+ ### HTTP Metrics
82
+ - `http_requests_total` - Total number of HTTP requests
83
+ - `http_responses_total` - Total number of HTTP responses
84
+ - `http_errors_total` - Total number of HTTP errors
85
+ - `http_request_duration_seconds` - HTTP request duration histogram
86
+ - `http_request_size_bytes` - HTTP request size histogram
87
+ - `http_response_size_bytes` - HTTP response size histogram
88
+
89
+ ### System Metrics
90
+ - `process_memory_rss_bytes` - Process resident set size
91
+ - `process_memory_heap_used_bytes` - Process heap used
92
+ - `process_memory_heap_total_bytes` - Process heap total
93
+ - `process_memory_external_bytes` - Process external memory
94
+ - `process_cpu_user_seconds_total` - Process CPU user time
95
+ - `process_cpu_system_seconds_total` - Process CPU system time
96
+ - `process_uptime_seconds` - Process uptime
97
+ - `nodejs_eventloop_lag_seconds` - Node.js event loop lag
98
+ - `system_memory_total_bytes` - System total memory
99
+ - `system_memory_free_bytes` - System free memory
100
+ - `system_load_average_1m` - System load average (1 minute)
101
+
102
+ ## Exporters
103
+
104
+ ### Prometheus Exporter
105
+ Exports metrics in Prometheus format. Can be configured to:
106
+ - Serve metrics at `/metrics` endpoint (default)
107
+ - Push metrics to Prometheus pushgateway
108
+
109
+ ### Console Exporter
110
+ Logs metrics to console at specified intervals.
111
+
112
+ ### JSON Exporter
113
+ Exports metrics in JSON format to:
114
+ - HTTP endpoint (POST request)
115
+ - Console logs
116
+
117
+ ### File Exporter
118
+ Writes metrics to file in JSON or Prometheus format.
119
+
120
+ ## Usage
121
+
122
+ The monitoring plugin is automatically loaded and configured through the FluxStack plugin system. Once enabled, it will:
123
+
124
+ 1. Start collecting system metrics at the configured interval
125
+ 2. Record HTTP request/response metrics automatically
126
+ 3. Export metrics according to the configured exporters
127
+ 4. Monitor alert thresholds and log warnings/errors
128
+
129
+ ## Accessing Metrics
130
+
131
+ ### Prometheus Endpoint
132
+ Visit `http://localhost:3000/metrics` (or your configured endpoint) to see Prometheus-formatted metrics.
133
+
134
+ ### Programmatic Access
135
+ ```typescript
136
+ import { MetricsCollector } from 'fluxstack/core/utils/monitoring'
137
+
138
+ const collector = new MetricsCollector()
139
+
140
+ // Create custom metrics
141
+ const myCounter = collector.createCounter('my_custom_counter', 'My custom counter')
142
+ myCounter.inc(1)
143
+
144
+ const myGauge = collector.createGauge('my_custom_gauge', 'My custom gauge')
145
+ myGauge.set(42)
146
+
147
+ const myHistogram = collector.createHistogram('my_custom_histogram', 'My custom histogram')
148
+ myHistogram.observe(1.5)
149
+
150
+ // Get system metrics
151
+ const systemMetrics = collector.getSystemMetrics()
152
+ console.log('Memory usage:', systemMetrics.memoryUsage)
153
+
154
+ // Export metrics
155
+ const prometheusData = collector.exportPrometheus()
156
+ console.log(prometheusData)
157
+ ```
158
+
159
+ ## Alert Configuration
160
+
161
+ Alerts can be configured to monitor specific metrics and trigger notifications when thresholds are exceeded:
162
+
163
+ ```typescript
164
+ alerts: [
165
+ {
166
+ metric: "http_request_duration_ms",
167
+ operator: ">",
168
+ value: 2000,
169
+ severity: "warning",
170
+ message: "High response time detected"
171
+ },
172
+ {
173
+ metric: "process_memory_rss_bytes",
174
+ operator: ">",
175
+ value: 1000000000, // 1GB
176
+ severity: "error",
177
+ message: "High memory usage"
178
+ }
179
+ ]
180
+ ```
181
+
182
+ Supported operators: `>`, `<`, `>=`, `<=`, `==`, `!=`
183
+ Supported severities: `info`, `warning`, `error`, `critical`
184
+
185
+ ## Requirements Satisfied
186
+
187
+ This monitoring plugin satisfies the following requirements:
188
+
189
+ - **7.1**: Collects basic metrics (response time, memory usage, etc.)
190
+ - **7.2**: Provides detailed performance logging with timing
191
+ - **7.3**: Identifies performance problems through thresholds and alerts
192
+ - **7.4**: Includes basic metrics dashboard via `/metrics` endpoint
193
+ - **7.5**: Supports integration with external monitoring systems (Prometheus, etc.)