create-fluxstack 1.19.0 → 1.20.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/LLMD/INDEX.md +1 -1
- package/LLMD/MAINTENANCE.md +197 -197
- package/LLMD/MIGRATION.md +44 -1
- package/LLMD/agent.md +20 -7
- package/LLMD/config/declarative-system.md +268 -268
- package/LLMD/config/environment-vars.md +3 -6
- package/LLMD/config/runtime-reload.md +401 -401
- package/LLMD/core/build-system.md +599 -599
- package/LLMD/core/framework-lifecycle.md +249 -229
- package/LLMD/core/plugin-system.md +154 -100
- package/LLMD/patterns/anti-patterns.md +397 -397
- package/LLMD/patterns/project-structure.md +264 -264
- package/LLMD/patterns/type-safety.md +61 -5
- package/LLMD/reference/cli-commands.md +31 -7
- package/LLMD/reference/plugin-hooks.md +4 -2
- package/LLMD/reference/troubleshooting.md +364 -364
- package/LLMD/resources/controllers.md +465 -465
- package/LLMD/resources/live-auth.md +178 -1
- package/LLMD/resources/live-binary-delta.md +3 -1
- package/LLMD/resources/live-components.md +1192 -1041
- package/LLMD/resources/live-logging.md +3 -1
- package/LLMD/resources/live-rooms.md +1 -1
- package/LLMD/resources/live-upload.md +228 -181
- package/LLMD/resources/plugins-external.md +8 -7
- package/LLMD/resources/rest-auth.md +290 -290
- package/LLMD/resources/routes-eden.md +254 -254
- package/app/client/.live-stubs/LiveAdminPanel.js +15 -0
- package/app/client/.live-stubs/LiveCounter.js +9 -0
- package/app/client/.live-stubs/LiveForm.js +11 -0
- package/app/client/.live-stubs/LiveLocalCounter.js +8 -0
- package/app/client/.live-stubs/LivePingPong.js +10 -0
- package/app/client/.live-stubs/LiveRoomChat.js +11 -0
- package/app/client/.live-stubs/LiveSharedCounter.js +10 -0
- package/app/client/.live-stubs/LiveUpload.js +15 -0
- package/app/server/live/auto-generated-components.ts +1 -1
- package/core/utils/version.ts +6 -6
- package/package.json +108 -108
|
@@ -1,229 +1,249 @@
|
|
|
1
|
-
# Framework Lifecycle
|
|
2
|
-
|
|
3
|
-
**Version:** 1.
|
|
4
|
-
|
|
5
|
-
## Quick Facts
|
|
6
|
-
|
|
7
|
-
- Framework class: `FluxStackFramework` in `core/framework/server.ts`
|
|
8
|
-
- Initialization: Constructor → Plugin
|
|
9
|
-
- Request flow: 13 hook points from request to response
|
|
10
|
-
- Shutdown: Graceful with reverse-order plugin cleanup
|
|
11
|
-
- Plugin loading:
|
|
12
|
-
|
|
13
|
-
## Initialization Sequence
|
|
14
|
-
|
|
15
|
-
```mermaid
|
|
16
|
-
sequenceDiagram
|
|
17
|
-
participant App as Application
|
|
18
|
-
participant FW as FluxStackFramework
|
|
19
|
-
participant
|
|
20
|
-
participant
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
FW->>
|
|
25
|
-
FW->>
|
|
26
|
-
FW->>
|
|
27
|
-
FW->>FW:
|
|
28
|
-
FW->>FW:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
FW
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
loop For each plugin (load order)
|
|
45
|
-
FW->>Plugins:
|
|
46
|
-
end
|
|
47
|
-
loop For each plugin (load order)
|
|
48
|
-
FW->>Plugins:
|
|
49
|
-
end
|
|
50
|
-
loop For each plugin (load order)
|
|
51
|
-
FW->>Plugins:
|
|
52
|
-
end
|
|
53
|
-
loop For each plugin (load order)
|
|
54
|
-
FW->>Plugins:
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
###
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
##
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|