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,322 @@
1
+ /**
2
+ * Runtime Configuration System for FluxStack
3
+ * Uses dynamic environment loading to solve Bun build issues
4
+ * Drop-in replacement for process.env based configuration
5
+ */
6
+
7
+ import { env, createEnvNamespace, envValidation } from '../utils/env-runtime'
8
+ import {
9
+ dynamicEnvironmentProcessor,
10
+ createDynamicConfig,
11
+ validateProductionEnv,
12
+ getDynamicEnvironmentInfo
13
+ } from './env-dynamic'
14
+ import type { FluxStackConfig } from './schema'
15
+ import { defaultFluxStackConfig } from './schema'
16
+
17
+ /**
18
+ * Runtime Configuration Builder
19
+ * Creates configuration that works with dynamic env loading
20
+ */
21
+ export class RuntimeConfigBuilder {
22
+ private config: Partial<FluxStackConfig> = {}
23
+
24
+ constructor() {
25
+ this.loadFromDefaults()
26
+ this.loadFromDynamicEnv()
27
+ }
28
+
29
+ /**
30
+ * Load default configuration
31
+ */
32
+ private loadFromDefaults(): this {
33
+ this.config = { ...defaultFluxStackConfig }
34
+ return this
35
+ }
36
+
37
+ /**
38
+ * Load from dynamic environment variables
39
+ */
40
+ private loadFromDynamicEnv(): this {
41
+ const envConfig = createDynamicConfig()
42
+ this.config = this.deepMerge(this.config, envConfig)
43
+ return this
44
+ }
45
+
46
+ /**
47
+ * Override specific configuration section
48
+ */
49
+ override(section: string, values: any): this {
50
+ this.setNestedProperty(this.config, section, values)
51
+ return this
52
+ }
53
+
54
+ /**
55
+ * Set individual configuration value
56
+ */
57
+ set(path: string, value: any): this {
58
+ this.setNestedProperty(this.config, path, value)
59
+ return this
60
+ }
61
+
62
+ /**
63
+ * Build final configuration
64
+ */
65
+ build(): FluxStackConfig {
66
+ // Validate production environment if needed
67
+ if (env.get('NODE_ENV') === 'production') {
68
+ validateProductionEnv()
69
+ }
70
+
71
+ return this.config as FluxStackConfig
72
+ }
73
+
74
+ /**
75
+ * Get current configuration state
76
+ */
77
+ current(): Partial<FluxStackConfig> {
78
+ return { ...this.config }
79
+ }
80
+
81
+ private deepMerge(target: any, source: any): any {
82
+ if (!source || typeof source !== 'object') return target
83
+ if (!target || typeof target !== 'object') return source
84
+
85
+ const result = { ...target }
86
+
87
+ for (const key in source) {
88
+ if (source.hasOwnProperty(key)) {
89
+ if (Array.isArray(source[key])) {
90
+ result[key] = [...source[key]]
91
+ } else if (typeof source[key] === 'object' && source[key] !== null) {
92
+ result[key] = this.deepMerge(target[key], source[key])
93
+ } else {
94
+ result[key] = source[key]
95
+ }
96
+ }
97
+ }
98
+
99
+ return result
100
+ }
101
+
102
+ private setNestedProperty(obj: any, path: string, value: any): void {
103
+ const keys = path.split('.')
104
+ let current = obj
105
+
106
+ for (let i = 0; i < keys.length - 1; i++) {
107
+ const key = keys[i]
108
+ if (!(key in current) || typeof current[key] !== 'object') {
109
+ current[key] = {}
110
+ }
111
+ current = current[key]
112
+ }
113
+
114
+ current[keys[keys.length - 1]] = value
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Create runtime configuration that works with Bun build
120
+ */
121
+ export function createRuntimeConfig(overrides?: Partial<FluxStackConfig>): FluxStackConfig {
122
+ const builder = new RuntimeConfigBuilder()
123
+
124
+ if (overrides) {
125
+ // Apply overrides
126
+ for (const [key, value] of Object.entries(overrides)) {
127
+ builder.override(key, value)
128
+ }
129
+ }
130
+
131
+ return builder.build()
132
+ }
133
+
134
+ /**
135
+ * Environment-specific configuration factory
136
+ */
137
+ export const runtimeConfig = {
138
+ /**
139
+ * Create development configuration
140
+ */
141
+ development(): FluxStackConfig {
142
+ return new RuntimeConfigBuilder()
143
+ .override('logging.level', env.get('LOG_LEVEL', 'debug'))
144
+ .override('logging.format', env.get('LOG_FORMAT', 'pretty'))
145
+ .override('build.optimization.minify', false)
146
+ .override('build.sourceMaps', true)
147
+ .override('monitoring.enabled', false)
148
+ .build()
149
+ },
150
+
151
+ /**
152
+ * Create production configuration
153
+ */
154
+ production(): FluxStackConfig {
155
+ return new RuntimeConfigBuilder()
156
+ .override('logging.level', env.get('LOG_LEVEL', 'warn'))
157
+ .override('logging.format', env.get('LOG_FORMAT', 'json'))
158
+ .override('build.optimization.minify', true)
159
+ .override('build.sourceMaps', false)
160
+ .override('monitoring.enabled', env.bool('MONITORING_ENABLED', true))
161
+ .build()
162
+ },
163
+
164
+ /**
165
+ * Create test configuration
166
+ */
167
+ test(): FluxStackConfig {
168
+ return new RuntimeConfigBuilder()
169
+ .override('logging.level', env.get('LOG_LEVEL', 'error'))
170
+ .override('server.port', 0) // Random port for tests
171
+ .override('client.port', 0)
172
+ .override('monitoring.enabled', false)
173
+ .build()
174
+ },
175
+
176
+ /**
177
+ * Auto-detect environment and create appropriate config
178
+ */
179
+ auto(overrides?: Partial<FluxStackConfig>): FluxStackConfig {
180
+ const environment = env.get('NODE_ENV', 'development')
181
+
182
+ let config: FluxStackConfig
183
+
184
+ switch (environment) {
185
+ case 'production':
186
+ config = this.production()
187
+ break
188
+ case 'test':
189
+ config = this.test()
190
+ break
191
+ default:
192
+ config = this.development()
193
+ }
194
+
195
+ if (overrides) {
196
+ const builder = new RuntimeConfigBuilder()
197
+ ;(builder as any).config = config
198
+
199
+ for (const [key, value] of Object.entries(overrides)) {
200
+ builder.override(key, value)
201
+ }
202
+
203
+ config = builder.build()
204
+ }
205
+
206
+ return config
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Specialized environment loaders for different domains
212
+ */
213
+ export const envLoaders = {
214
+ /**
215
+ * Database environment loader
216
+ */
217
+ database: createEnvNamespace('DATABASE_'),
218
+
219
+ /**
220
+ * JWT environment loader
221
+ */
222
+ jwt: createEnvNamespace('JWT_'),
223
+
224
+ /**
225
+ * SMTP environment loader
226
+ */
227
+ smtp: createEnvNamespace('SMTP_'),
228
+
229
+ /**
230
+ * CORS environment loader
231
+ */
232
+ cors: createEnvNamespace('CORS_'),
233
+
234
+ /**
235
+ * FluxStack specific environment loader
236
+ */
237
+ fluxstack: createEnvNamespace('FLUXSTACK_')
238
+ }
239
+
240
+ /**
241
+ * Configuration helpers that use dynamic env
242
+ */
243
+ export const configHelpers = {
244
+ /**
245
+ * Get database URL with validation
246
+ */
247
+ getDatabaseUrl(): string | null {
248
+ const url = env.get('DATABASE_URL')
249
+
250
+ if (url) {
251
+ envValidation.validate('DATABASE_URL',
252
+ (value) => value.includes('://'),
253
+ 'Must be a valid URL'
254
+ )
255
+ }
256
+
257
+ return url || null
258
+ },
259
+
260
+ /**
261
+ * Get CORS origins with proper defaults
262
+ */
263
+ getCorsOrigins(): string[] {
264
+ const origins = env.array('CORS_ORIGINS')
265
+
266
+ if (origins.length === 0) {
267
+ const environment = env.get('NODE_ENV', 'development')
268
+
269
+ if (environment === 'development') {
270
+ return ['http://localhost:3000', 'http://localhost:5173']
271
+ } else if (environment === 'production') {
272
+ return [] // Must be explicitly configured in production
273
+ }
274
+ }
275
+
276
+ return origins
277
+ },
278
+
279
+ /**
280
+ * Get server configuration with runtime env
281
+ */
282
+ getServerConfig() {
283
+ return {
284
+ port: env.num('PORT', 3000),
285
+ host: env.get('HOST', 'localhost'),
286
+ apiPrefix: env.get('API_PREFIX', '/api'),
287
+ cors: {
288
+ origins: this.getCorsOrigins(),
289
+ methods: env.array('CORS_METHODS', ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS']),
290
+ headers: env.array('CORS_HEADERS', ['Content-Type', 'Authorization']),
291
+ credentials: env.bool('CORS_CREDENTIALS', false),
292
+ maxAge: env.num('CORS_MAX_AGE', 86400)
293
+ }
294
+ }
295
+ },
296
+
297
+ /**
298
+ * Get client configuration with runtime env
299
+ */
300
+ getClientConfig() {
301
+ return {
302
+ port: env.num('VITE_PORT', 5173),
303
+ proxy: {
304
+ target: env.get('API_URL', 'http://localhost:3000'),
305
+ changeOrigin: env.bool('PROXY_CHANGE_ORIGIN', true)
306
+ },
307
+ build: {
308
+ outDir: env.get('CLIENT_BUILD_DIR', 'dist/client'),
309
+ sourceMaps: env.bool('CLIENT_SOURCEMAPS', env.get('NODE_ENV') === 'development'),
310
+ minify: env.bool('CLIENT_MINIFY', env.get('NODE_ENV') === 'production'),
311
+ target: env.get('CLIENT_TARGET', 'es2020')
312
+ }
313
+ }
314
+ }
315
+ }
316
+
317
+ /**
318
+ * Export main configuration function
319
+ */
320
+ export default function getRuntimeConfig(overrides?: Partial<FluxStackConfig>): FluxStackConfig {
321
+ return runtimeConfig.auto(overrides)
322
+ }