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,317 @@
1
+ /**
2
+ * FluxStack Configuration System
3
+ * Unified interface for configuration loading, validation, and management
4
+ */
5
+
6
+ // Re-export all configuration types and utilities
7
+ export type {
8
+ FluxStackConfig,
9
+ AppConfig,
10
+ ServerConfig,
11
+ ClientConfig,
12
+ BuildConfig,
13
+ LoggingConfig,
14
+ MonitoringConfig,
15
+ PluginConfig,
16
+ DatabaseConfig,
17
+ AuthConfig,
18
+ EmailConfig,
19
+ StorageConfig,
20
+ LogLevel,
21
+ BuildTarget,
22
+ LogFormat
23
+ } from './schema'
24
+
25
+ export {
26
+ defaultFluxStackConfig,
27
+ environmentDefaults,
28
+ fluxStackConfigSchema
29
+ } from './schema'
30
+
31
+ export interface ConfigLoadOptions {
32
+ configPath?: string
33
+ environment?: string
34
+ envPrefix?: string
35
+ validateSchema?: boolean
36
+ }
37
+
38
+ export interface ConfigLoadResult {
39
+ config: FluxStackConfig
40
+ sources: string[]
41
+ warnings: string[]
42
+ errors: string[]
43
+ }
44
+
45
+ import {
46
+ loadConfig as _loadConfig,
47
+ loadConfigSync as _loadConfigSync,
48
+ getConfigValue,
49
+ hasConfigValue,
50
+ createConfigSubset
51
+ } from './loader'
52
+
53
+ import { environmentDefaults } from './schema'
54
+
55
+ export {
56
+ _loadConfig as loadConfig,
57
+ _loadConfigSync as loadConfigSync,
58
+ getConfigValue,
59
+ hasConfigValue,
60
+ createConfigSubset
61
+ }
62
+
63
+ export type {
64
+ ValidationResult,
65
+ ValidationError,
66
+ ValidationWarning
67
+ } from './validator'
68
+
69
+ export {
70
+ validateConfig,
71
+ validateConfigStrict,
72
+ createEnvironmentValidator,
73
+ validatePartialConfig,
74
+ getConfigSuggestions
75
+ } from './validator'
76
+
77
+ export type {
78
+ EnvironmentInfo,
79
+ ConfigPrecedence
80
+ } from './env'
81
+
82
+ export {
83
+ getEnvironmentInfo,
84
+ EnvConverter,
85
+ EnvironmentProcessor,
86
+ ConfigMerger,
87
+ EnvironmentConfigApplier,
88
+ environmentProcessor,
89
+ configMerger,
90
+ environmentConfigApplier,
91
+ isDevelopment,
92
+ isProduction,
93
+ isTest,
94
+ getEnvironmentRecommendations
95
+ } from './env'
96
+
97
+ // Main configuration loader with caching
98
+ let cachedConfig: FluxStackConfig | null = null
99
+ let configPromise: Promise<FluxStackConfig> | null = null
100
+
101
+ /**
102
+ * Get the current FluxStack configuration
103
+ * This function loads and caches the configuration on first call
104
+ */
105
+ export async function getConfig(options?: ConfigLoadOptions): Promise<FluxStackConfig> {
106
+ if (cachedConfig && !options) {
107
+ return cachedConfig
108
+ }
109
+
110
+ if (configPromise && !options) {
111
+ return configPromise
112
+ }
113
+
114
+ configPromise = loadConfiguration(options)
115
+ cachedConfig = await configPromise
116
+
117
+ return cachedConfig
118
+ }
119
+
120
+ /**
121
+ * Get configuration synchronously (limited functionality)
122
+ * Only loads from environment variables and defaults
123
+ */
124
+ export function getConfigSync(options?: ConfigLoadOptions): FluxStackConfig {
125
+ const result = _loadConfigSync(options)
126
+
127
+ if (result.errors.length > 0) {
128
+ console.warn('Configuration errors:', result.errors)
129
+ }
130
+
131
+ if (result.warnings.length > 0) {
132
+ console.warn('Configuration warnings:', result.warnings)
133
+ }
134
+
135
+ return result.config
136
+ }
137
+
138
+ /**
139
+ * Reload configuration (clears cache)
140
+ */
141
+ export async function reloadConfig(options?: ConfigLoadOptions): Promise<FluxStackConfig> {
142
+ cachedConfig = null
143
+ configPromise = null
144
+ return getConfig(options)
145
+ }
146
+
147
+ /**
148
+ * Internal configuration loader with error handling
149
+ */
150
+ async function loadConfiguration(options?: ConfigLoadOptions): Promise<FluxStackConfig> {
151
+ try {
152
+ const result = await _loadConfig(options)
153
+
154
+ // Log warnings if any
155
+ if (result.warnings.length > 0) {
156
+ console.warn('Configuration warnings:')
157
+ result.warnings.forEach(warning => console.warn(` - ${warning}`))
158
+ }
159
+
160
+ // Throw on errors
161
+ if (result.errors.length > 0) {
162
+ const errorMessage = [
163
+ 'Configuration loading failed:',
164
+ ...result.errors.map(e => ` - ${e}`)
165
+ ].join('\n')
166
+
167
+ throw new Error(errorMessage)
168
+ }
169
+
170
+ return result.config
171
+ } catch (error) {
172
+ console.error('Failed to load FluxStack configuration:', error)
173
+
174
+ // Fall back to default configuration with environment variables and environment defaults
175
+ const fallbackResult = _loadConfigSync(options)
176
+ console.warn('Using fallback configuration with environment variables only')
177
+
178
+ // Apply environment defaults to fallback configuration
179
+ const environment = process.env.NODE_ENV || 'development'
180
+ const envDefaults = environmentDefaults[environment as keyof typeof environmentDefaults]
181
+
182
+ if (envDefaults) {
183
+ // Simple merge for fallback with proper type casting
184
+ const configWithDefaults = {
185
+ ...fallbackResult.config,
186
+ logging: {
187
+ ...fallbackResult.config.logging,
188
+ ...((envDefaults as any).logging || {})
189
+ },
190
+ server: (envDefaults as any).server ? {
191
+ ...fallbackResult.config.server,
192
+ ...(envDefaults as any).server
193
+ } : fallbackResult.config.server,
194
+ client: (envDefaults as any).client ? {
195
+ ...fallbackResult.config.client,
196
+ ...(envDefaults as any).client
197
+ } : fallbackResult.config.client,
198
+ build: (envDefaults as any).build ? {
199
+ ...fallbackResult.config.build,
200
+ optimization: {
201
+ ...fallbackResult.config.build.optimization,
202
+ ...((envDefaults as any).build.optimization || {})
203
+ }
204
+ } : fallbackResult.config.build,
205
+ monitoring: (envDefaults as any).monitoring ? {
206
+ ...fallbackResult.config.monitoring,
207
+ ...(envDefaults as any).monitoring
208
+ } : fallbackResult.config.monitoring
209
+ } as FluxStackConfig
210
+ return configWithDefaults
211
+ }
212
+
213
+ return fallbackResult.config
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Create a configuration subset for plugins or modules
219
+ */
220
+ export function createPluginConfig<T = any>(
221
+ config: FluxStackConfig,
222
+ pluginName: string
223
+ ): T {
224
+ const pluginConfig = config.plugins.config[pluginName] || {}
225
+ const customConfig = config.custom?.[pluginName] || {}
226
+
227
+ return { ...pluginConfig, ...customConfig } as T
228
+ }
229
+
230
+ /**
231
+ * Check if a feature is enabled based on configuration
232
+ */
233
+ export function isFeatureEnabled(config: FluxStackConfig, feature: string): boolean {
234
+ // Check plugin configuration
235
+ if (config.plugins.enabled.includes(feature)) {
236
+ return !config.plugins.disabled.includes(feature)
237
+ }
238
+
239
+ // Check monitoring features
240
+ if (feature === 'monitoring') {
241
+ return config.monitoring.enabled
242
+ }
243
+
244
+ if (feature === 'metrics') {
245
+ return config.monitoring.enabled && config.monitoring.metrics.enabled
246
+ }
247
+
248
+ if (feature === 'profiling') {
249
+ return config.monitoring.enabled && config.monitoring.profiling.enabled
250
+ }
251
+
252
+ // Check custom features
253
+ return config.custom?.[feature] === true
254
+ }
255
+
256
+ /**
257
+ * Get database configuration if available
258
+ */
259
+ export function getDatabaseConfig(config: FluxStackConfig) {
260
+ return config.database || null
261
+ }
262
+
263
+ /**
264
+ * Get authentication configuration if available
265
+ */
266
+ export function getAuthConfig(config: FluxStackConfig) {
267
+ return config.auth || null
268
+ }
269
+
270
+ /**
271
+ * Get email configuration if available
272
+ */
273
+ export function getEmailConfig(config: FluxStackConfig) {
274
+ return config.email || null
275
+ }
276
+
277
+ /**
278
+ * Get storage configuration if available
279
+ */
280
+ export function getStorageConfig(config: FluxStackConfig) {
281
+ return config.storage || null
282
+ }
283
+
284
+ /**
285
+ * Backward compatibility function for legacy configuration
286
+ */
287
+ export function createLegacyConfig(config: FluxStackConfig) {
288
+ return {
289
+ port: config.server.port,
290
+ vitePort: config.client.port,
291
+ clientPath: 'app/client', // Fixed path for backward compatibility
292
+ apiPrefix: config.server.apiPrefix,
293
+ cors: {
294
+ origins: config.server.cors.origins,
295
+ methods: config.server.cors.methods,
296
+ headers: config.server.cors.headers
297
+ },
298
+ build: {
299
+ outDir: config.build.outDir,
300
+ target: config.build.target
301
+ }
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Environment configuration utilities
307
+ */
308
+ import { getEnvironmentInfo as _getEnvironmentInfo } from './env'
309
+ import type { FluxStackConfig } from './schema'
310
+
311
+ export const env = {
312
+ isDevelopment: () => _getEnvironmentInfo().isDevelopment,
313
+ isProduction: () => _getEnvironmentInfo().isProduction,
314
+ isTest: () => _getEnvironmentInfo().isTest,
315
+ getName: () => _getEnvironmentInfo().name,
316
+ getInfo: () => _getEnvironmentInfo()
317
+ }