create-fluxstack 1.19.0 → 1.20.1

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 (37) hide show
  1. package/LLMD/INDEX.md +1 -1
  2. package/LLMD/MAINTENANCE.md +197 -197
  3. package/LLMD/MIGRATION.md +44 -1
  4. package/LLMD/agent.md +20 -7
  5. package/LLMD/config/declarative-system.md +268 -268
  6. package/LLMD/config/environment-vars.md +3 -6
  7. package/LLMD/config/runtime-reload.md +401 -401
  8. package/LLMD/core/build-system.md +599 -599
  9. package/LLMD/core/framework-lifecycle.md +249 -229
  10. package/LLMD/core/plugin-system.md +154 -100
  11. package/LLMD/patterns/anti-patterns.md +397 -397
  12. package/LLMD/patterns/project-structure.md +264 -264
  13. package/LLMD/patterns/type-safety.md +61 -5
  14. package/LLMD/reference/cli-commands.md +31 -7
  15. package/LLMD/reference/plugin-hooks.md +4 -2
  16. package/LLMD/reference/troubleshooting.md +364 -364
  17. package/LLMD/resources/controllers.md +465 -465
  18. package/LLMD/resources/live-auth.md +178 -1
  19. package/LLMD/resources/live-binary-delta.md +3 -1
  20. package/LLMD/resources/live-components.md +1192 -1041
  21. package/LLMD/resources/live-logging.md +3 -1
  22. package/LLMD/resources/live-rooms.md +1 -1
  23. package/LLMD/resources/live-upload.md +228 -181
  24. package/LLMD/resources/plugins-external.md +8 -7
  25. package/LLMD/resources/rest-auth.md +290 -290
  26. package/LLMD/resources/routes-eden.md +254 -254
  27. package/app/client/.live-stubs/LiveAdminPanel.js +15 -0
  28. package/app/client/.live-stubs/LiveCounter.js +9 -0
  29. package/app/client/.live-stubs/LiveForm.js +11 -0
  30. package/app/client/.live-stubs/LiveLocalCounter.js +8 -0
  31. package/app/client/.live-stubs/LivePingPong.js +10 -0
  32. package/app/client/.live-stubs/LiveRoomChat.js +11 -0
  33. package/app/client/.live-stubs/LiveSharedCounter.js +10 -0
  34. package/app/client/.live-stubs/LiveUpload.js +15 -0
  35. package/app/server/live/auto-generated-components.ts +1 -1
  36. package/core/utils/version.ts +6 -6
  37. package/package.json +108 -108
@@ -1,229 +1,249 @@
1
- # Framework Lifecycle
2
-
3
- **Version:** 1.11.0 | **Updated:** 2025-02-08
4
-
5
- ## Quick Facts
6
-
7
- - Framework class: `FluxStackFramework` in `core/framework/server.ts`
8
- - Initialization: Constructor → Plugin Discovery → Setup Hooks → Server Start
9
- - Request flow: 13 hook points from request to response
10
- - Shutdown: Graceful with reverse-order plugin cleanup
11
- - Plugin loading: Dependency-based topological sort with priority
12
-
13
- ## Initialization Sequence
14
-
15
- ```mermaid
16
- sequenceDiagram
17
- participant App as Application
18
- participant FW as FluxStackFramework
19
- participant PM as PluginManager
20
- participant PR as PluginRegistry
21
- participant Plugins as Plugins
22
-
23
- App->>FW: new FluxStackFramework(config)
24
- FW->>FW: Create Elysia app
25
- FW->>PR: new PluginRegistry()
26
- FW->>PM: new PluginManager()
27
- FW->>FW: setupCors()
28
- FW->>FW: setupHeadHandler()
29
- FW->>FW: setupHooks()
30
- FW->>FW: setupErrorHandling()
31
- FW->>PM: initializeAutomaticPlugins()
32
- PM->>PM: discoverPlugins()
33
- PM->>PR: register(plugin)
34
- PR->>PR: updateLoadOrder()
35
- loop For each plugin
36
- PM->>Plugins: onConfigLoad(context)
37
- end
38
-
39
- App->>FW: start()
40
- FW->>PR: validateDependencies()
41
- loop For each plugin (load order)
42
- FW->>Plugins: setup(context)
43
- end
44
- loop For each plugin (load order)
45
- FW->>Plugins: onBeforeServerStart(context)
46
- end
47
- loop For each plugin (load order)
48
- FW->>Plugins: Mount plugin routes
49
- end
50
- loop For each plugin (load order)
51
- FW->>Plugins: onServerStart(context)
52
- end
53
- loop For each plugin (load order)
54
- FW->>Plugins: onAfterServerStart(context)
55
- end
56
-
57
- App->>FW: listen(port)
58
- FW->>FW: Display startup banner
59
- ```
60
-
61
- ## Plugin Loading Order
62
-
63
- Plugins are loaded in dependency-aware order:
64
-
65
- 1. **Discovery Phase** (automatic, during constructor):
66
- - Scan `plugins/` directory (project plugins)
67
- - Scan `node_modules/` for npm plugins (if enabled)
68
- - Whitelist validation for npm plugins
69
- - Dependency resolution
70
-
71
- 2. **Registration Phase**:
72
- - Validate plugin structure
73
- - Store in registry
74
- - Build dependency graph
75
- - Calculate load order (topological sort)
76
-
77
- 3. **Configuration Phase** (during `initializeAutomaticPlugins()`):
78
- - Execute `onConfigLoad` hooks in load order
79
- - Plugins can modify configuration
80
-
81
- 4. **Setup Phase** (during `start()`):
82
- - Validate all dependencies exist
83
- - Execute `setup` hooks in load order
84
- - Execute `onBeforeServerStart` hooks
85
- - Mount plugin routes (if plugin has Elysia plugin)
86
- - Execute `onServerStart` hooks
87
- - Execute `onAfterServerStart` hooks
88
-
89
- ## Hook Execution Order
90
-
91
- ### Lifecycle Hooks
92
-
93
- ```
94
- onConfigLoad setup → onBeforeServerStart → onServerStart → onAfterServerStart
95
- ```
96
-
97
- - **onConfigLoad**: Modify configuration before framework starts
98
- - **setup**: Initialize plugin resources (databases, connections)
99
- - **onBeforeServerStart**: Register routes, middleware
100
- - **onServerStart**: Start background tasks
101
- - **onAfterServerStart**: Post-startup tasks (logging, metrics)
102
-
103
- ### Request/Response Pipeline
104
-
105
- ```mermaid
106
- graph TD
107
- A[Incoming Request] --> B[onRequest]
108
- B --> C[onRequestValidation]
109
- C --> D{Validation Failed?}
110
- D -->|Yes| E[Return 400 Error]
111
- D -->|No| F[onBeforeRoute]
112
- F --> G{Plugin Handled?}
113
- G -->|Yes| H[Return Plugin Response]
114
- G -->|No| I[Route Handler]
115
- I --> J[onAfterRoute]
116
- J --> K[onBeforeResponse]
117
- K --> L[onResponseTransform]
118
- L --> M[Log Request]
119
- M --> N[onResponse]
120
- N --> O[Return Response]
121
- ```
122
-
123
- **Hook Execution Order:**
124
-
125
- 1. **onRequest**: Log request, authenticate, add context
126
- 2. **onRequestValidation**: Custom validation logic
127
- 3. **onBeforeRoute**: Handle request before routing (auth, caching)
128
- 4. **[Route Handler Executes]**
129
- 5. **onAfterRoute**: Access route params, log matched route
130
- 6. **onBeforeResponse**: Modify headers, status code
131
- 7. **onResponseTransform**: Transform response body
132
- 8. **[Automatic Request Logging]**
133
- 9. **onResponse**: Final logging, metrics collection
134
-
135
- ### Error Handling Flow
136
-
137
- ```
138
- Error Occurs → onError (each plugin) → Plugin Handled? → Return Response or Default Error
139
- ```
140
-
141
- - Plugins can handle errors by setting `context.handled = true`
142
- - Vite plugin uses this for SPA fallback
143
- - FluxStackError instances use custom status codes
144
- - Unhandled errors return 500 with message (dev) or generic (prod)
145
-
146
- ## Request Lifecycle Details
147
-
148
- ### CORS Setup
149
-
150
- Applied via `onRequest` hook:
151
- - Sets `Access-Control-Allow-Origin`
152
- - Sets `Access-Control-Allow-Methods`
153
- - Sets `Access-Control-Allow-Headers`
154
- - Handles OPTIONS preflight requests
155
-
156
- ### HEAD Request Handling
157
-
158
- Global HEAD handler prevents Elysia bug:
159
- - Returns empty body with appropriate headers
160
- - API routes: `Content-Type: application/json`
161
- - Static files: `Content-Type: text/html` or appropriate type
162
-
163
- ### Request Timing
164
-
165
- - Start time stored in `onRequest`
166
- - Duration calculated in `onAfterHandle`
167
- - Timing key stored in response headers
168
- - Cleanup after response sent
169
-
170
- ## Shutdown Sequence
171
-
172
- ```mermaid
173
- sequenceDiagram
174
- participant Signal as SIGTERM/SIGINT
175
- participant FW as FluxStackFramework
176
- participant Plugins as Plugins
177
-
178
- Signal->>FW: Shutdown signal
179
- FW->>FW: stop()
180
- loop For each plugin (reverse order)
181
- FW->>Plugins: onBeforeServerStop(context)
182
- end
183
- loop For each plugin (reverse order)
184
- FW->>Plugins: onServerStop(context)
185
- end
186
- FW->>FW: Set isStarted = false
187
- FW->>Signal: process.exit(0)
188
- ```
189
-
190
- **Shutdown Hooks:**
191
-
192
- 1. **onBeforeServerStop**: Prepare for shutdown (stop accepting requests)
193
- 2. **onServerStop**: Cleanup resources (close connections, save state)
194
-
195
- **Reverse Order**: Plugins shut down in reverse of load order to respect dependencies
196
-
197
- ## Plugin Context
198
-
199
- Every plugin receives a `PluginContext` object:
200
-
201
- ```typescript
202
- {
203
- config: FluxStackConfig, // Full framework configuration
204
- logger: Logger, // Plugin-specific logger
205
- app: Elysia, // Elysia app instance
206
- utils: PluginUtils, // Utility functions
207
- registry: PluginRegistry // Access to other plugins
208
- }
209
- ```
210
-
211
- ## Error Recovery
212
-
213
- - Plugin hook failures are caught and logged
214
- - `onPluginError` hook notified on all other plugins
215
- - Framework continues execution (non-blocking)
216
- - Build hooks can stop build on error
217
-
218
- ## Performance Considerations
219
-
220
- - Plugin discovery is asynchronous (non-blocking)
221
- - Hooks execute sequentially (predictable order)
222
- - Request timing tracked with minimal overhead
223
- - Automatic cleanup of timing data
224
-
225
- ## Related
226
-
227
- - [Plugin System](./plugin-system.md) - Plugin architecture details
228
- - [Plugin Hooks Reference](../reference/plugin-hooks.md) - Complete hook list
229
- - [Build System](./build-system.md) - Build lifecycle
1
+ # Framework Lifecycle
2
+
3
+ **Version:** 1.19.0 | **Updated:** 2026-04-14
4
+
5
+ ## Quick Facts
6
+
7
+ - Framework class: `FluxStackFramework` in `core/framework/server.ts`
8
+ - Initialization: Constructor → Manual Plugin Registration (.use()) → Setup Hooks → Server Start
9
+ - Request flow: 13 hook points from request to response
10
+ - Shutdown: Graceful with reverse-order plugin cleanup
11
+ - Plugin loading: Explicit registration via `.use()` with dependency-based topological sort
12
+
13
+ ## Initialization Sequence
14
+
15
+ ```mermaid
16
+ sequenceDiagram
17
+ participant App as Application
18
+ participant FW as FluxStackFramework
19
+ participant PR as PluginRegistry
20
+ participant Plugins as Plugins
21
+
22
+ App->>FW: new FluxStackFramework()
23
+ FW->>FW: Create Elysia app
24
+ FW->>PR: new PluginRegistry()
25
+ FW->>FW: setupCors()
26
+ FW->>FW: setupHeadHandler()
27
+ FW->>FW: setupHooks()
28
+ FW->>FW: setupErrorHandling()
29
+
30
+ App->>FW: .use(swaggerPlugin)
31
+ App->>FW: .use(liveComponentsPlugin)
32
+ App->>FW: .use(csrfProtectionPlugin)
33
+ App->>FW: .use(vitePlugin) (if full-stack mode)
34
+ loop For each registered plugin
35
+ FW->>PR: register(plugin)
36
+ PR->>PR: updateLoadOrder()
37
+ end
38
+ loop For each plugin
39
+ FW->>Plugins: onConfigLoad(context)
40
+ end
41
+
42
+ App->>FW: listen()
43
+ FW->>PR: validateDependencies()
44
+ loop For each plugin (load order)
45
+ FW->>Plugins: setup(context)
46
+ end
47
+ loop For each plugin (load order)
48
+ FW->>Plugins: onBeforeServerStart(context)
49
+ end
50
+ loop For each plugin (load order)
51
+ FW->>Plugins: Mount plugin routes
52
+ end
53
+ loop For each plugin (load order)
54
+ FW->>Plugins: onServerStart(context)
55
+ end
56
+ loop For each plugin (load order)
57
+ FW->>Plugins: onAfterServerStart(context)
58
+ end
59
+
60
+ FW->>FW: Display startup banner
61
+ ```
62
+
63
+ ## Plugin Registration
64
+
65
+ All plugins are registered manually via `.use()` in `app/server/index.ts`. Auto-discovery was removed in `@fluxstack/plugin-kit@0.4.0` because it broke silently in production bundles (`dist/node_modules/` does not exist). Every plugin the app wants to enable must be explicitly imported and `.use()`-d.
66
+
67
+ **Current registration in `app/server/index.ts`:**
68
+
69
+ ```typescript
70
+ import { FluxStackFramework } from "@core/server"
71
+ import { vitePlugin } from "@core/plugins/built-in/vite"
72
+ import { swaggerPlugin } from "@core/plugins/built-in/swagger"
73
+ import { liveComponentsPlugin } from "@core/server/live"
74
+ import { csrfProtectionPlugin } from "@fluxstack/plugin-csrf-protection"
75
+
76
+ const framework = new FluxStackFramework()
77
+ .use(swaggerPlugin)
78
+ .use(liveComponentsPlugin)
79
+ .use(csrfProtectionPlugin)
80
+
81
+ // Vite only in full-stack mode
82
+ if (appConfig.mode !== 'backend-only') {
83
+ framework.use(vitePlugin)
84
+ }
85
+
86
+ framework.routes(appInstance)
87
+ await framework.listen()
88
+ ```
89
+
90
+ **Plugin loading phases:**
91
+
92
+ 1. **Registration Phase** (during `.use()` calls):
93
+ - Validate plugin structure
94
+ - Store in registry
95
+ - Build dependency graph
96
+ - Calculate load order (topological sort)
97
+
98
+ 2. **Configuration Phase** (after registration):
99
+ - Execute `onConfigLoad` hooks in load order
100
+ - Plugins can modify configuration
101
+
102
+ 3. **Setup Phase** (during `listen()`):
103
+ - Validate all dependencies exist
104
+ - Execute `setup` hooks in load order
105
+ - Execute `onBeforeServerStart` hooks
106
+ - Mount plugin routes (if plugin has Elysia plugin)
107
+ - Execute `onServerStart` hooks
108
+ - Execute `onAfterServerStart` hooks
109
+
110
+ ## Hook Execution Order
111
+
112
+ ### Lifecycle Hooks
113
+
114
+ ```
115
+ onConfigLoad setup → onBeforeServerStart → onServerStart → onAfterServerStart
116
+ ```
117
+
118
+ - **onConfigLoad**: Modify configuration before framework starts
119
+ - **setup**: Initialize plugin resources (databases, connections)
120
+ - **onBeforeServerStart**: Register routes, middleware
121
+ - **onServerStart**: Start background tasks
122
+ - **onAfterServerStart**: Post-startup tasks (logging, metrics)
123
+
124
+ ### Request/Response Pipeline
125
+
126
+ ```mermaid
127
+ graph TD
128
+ A[Incoming Request] --> B[onRequest]
129
+ B --> C[onRequestValidation]
130
+ C --> D{Validation Failed?}
131
+ D -->|Yes| E[Return 400 Error]
132
+ D -->|No| F[onBeforeRoute]
133
+ F --> G{Plugin Handled?}
134
+ G -->|Yes| H[Return Plugin Response]
135
+ G -->|No| I[Route Handler]
136
+ I --> J[onAfterRoute]
137
+ J --> K[onBeforeResponse]
138
+ K --> L[onResponseTransform]
139
+ L --> M[Log Request]
140
+ M --> N[onResponse]
141
+ N --> O[Return Response]
142
+ ```
143
+
144
+ **Hook Execution Order:**
145
+
146
+ 1. **onRequest**: Log request, authenticate, add context
147
+ 2. **onRequestValidation**: Custom validation logic
148
+ 3. **onBeforeRoute**: Handle request before routing (auth, caching)
149
+ 4. **[Route Handler Executes]**
150
+ 5. **onAfterRoute**: Access route params, log matched route
151
+ 6. **onBeforeResponse**: Modify headers, status code
152
+ 7. **onResponseTransform**: Transform response body
153
+ 8. **[Automatic Request Logging]**
154
+ 9. **onResponse**: Final logging, metrics collection
155
+
156
+ ### Error Handling Flow
157
+
158
+ ```
159
+ Error Occurs onError (each plugin) → Plugin Handled? → Return Response or Default Error
160
+ ```
161
+
162
+ - Plugins can handle errors by setting `context.handled = true`
163
+ - Vite plugin uses this for SPA fallback
164
+ - FluxStackError instances use custom status codes
165
+ - Unhandled errors return 500 with message (dev) or generic (prod)
166
+
167
+ ## Request Lifecycle Details
168
+
169
+ ### CORS Setup
170
+
171
+ Applied via `onRequest` hook:
172
+ - Sets `Access-Control-Allow-Origin`
173
+ - Sets `Access-Control-Allow-Methods`
174
+ - Sets `Access-Control-Allow-Headers`
175
+ - Handles OPTIONS preflight requests
176
+
177
+ ### HEAD Request Handling
178
+
179
+ Global HEAD handler prevents Elysia bug:
180
+ - Returns empty body with appropriate headers
181
+ - API routes: `Content-Type: application/json`
182
+ - Static files: `Content-Type: text/html` or appropriate type
183
+
184
+ ### Request Timing
185
+
186
+ - Start time stored in `onRequest`
187
+ - Duration calculated in `onAfterHandle`
188
+ - Timing key stored in response headers
189
+ - Cleanup after response sent
190
+
191
+ ## Shutdown Sequence
192
+
193
+ ```mermaid
194
+ sequenceDiagram
195
+ participant Signal as SIGTERM/SIGINT
196
+ participant FW as FluxStackFramework
197
+ participant Plugins as Plugins
198
+
199
+ Signal->>FW: Shutdown signal
200
+ FW->>FW: stop()
201
+ loop For each plugin (reverse order)
202
+ FW->>Plugins: onBeforeServerStop(context)
203
+ end
204
+ loop For each plugin (reverse order)
205
+ FW->>Plugins: onServerStop(context)
206
+ end
207
+ FW->>FW: Set isStarted = false
208
+ FW->>Signal: process.exit(0)
209
+ ```
210
+
211
+ **Shutdown Hooks:**
212
+
213
+ 1. **onBeforeServerStop**: Prepare for shutdown (stop accepting requests)
214
+ 2. **onServerStop**: Cleanup resources (close connections, save state)
215
+
216
+ **Reverse Order**: Plugins shut down in reverse of load order to respect dependencies
217
+
218
+ ## Plugin Context
219
+
220
+ Every plugin receives a `PluginContext` object:
221
+
222
+ ```typescript
223
+ {
224
+ config: FluxStackConfig, // Full framework configuration
225
+ logger: Logger, // Plugin-specific logger
226
+ app: Elysia, // Elysia app instance
227
+ utils: PluginUtils, // Utility functions
228
+ registry: PluginRegistry // Access to other plugins
229
+ }
230
+ ```
231
+
232
+ ## Error Recovery
233
+
234
+ - Plugin hook failures are caught and logged
235
+ - `onPluginError` hook notified on all other plugins
236
+ - Framework continues execution (non-blocking)
237
+ - Build hooks can stop build on error
238
+
239
+ ## Performance Considerations
240
+
241
+ - Hooks execute sequentially (predictable order)
242
+ - Request timing tracked with minimal overhead
243
+ - Automatic cleanup of timing data
244
+
245
+ ## Related
246
+
247
+ - [Plugin System](./plugin-system.md) - Plugin architecture details
248
+ - [Plugin Hooks Reference](../reference/plugin-hooks.md) - Complete hook list
249
+ - [Build System](./build-system.md) - Build lifecycle