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,233 @@
1
+ /**
2
+ * Tests for FluxStack Framework Server
3
+ */
4
+
5
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
6
+ import { FluxStackFramework } from '../server'
7
+ import type { Plugin } from '../../plugins/types'
8
+
9
+ // Mock dependencies
10
+ vi.mock('../../config', () => ({
11
+ getConfigSync: vi.fn(() => ({
12
+ server: {
13
+ port: 3000,
14
+ apiPrefix: '/api',
15
+ cors: {
16
+ origins: ['*'],
17
+ methods: ['GET', 'POST'],
18
+ headers: ['Content-Type'],
19
+ credentials: false
20
+ }
21
+ },
22
+ app: {
23
+ name: 'test-app',
24
+ version: '1.0.0'
25
+ }
26
+ })),
27
+ getEnvironmentInfo: vi.fn(() => ({
28
+ isDevelopment: true,
29
+ isProduction: false,
30
+ isTest: true,
31
+ name: 'test'
32
+ }))
33
+ }))
34
+
35
+ vi.mock('../../utils/logger', () => ({
36
+ logger: {
37
+ framework: vi.fn(),
38
+ warn: vi.fn(),
39
+ error: vi.fn(),
40
+ child: vi.fn(() => ({
41
+ framework: vi.fn(),
42
+ warn: vi.fn(),
43
+ error: vi.fn()
44
+ }))
45
+ }
46
+ }))
47
+
48
+ vi.mock('../../utils/errors/handlers', () => ({
49
+ createErrorHandler: vi.fn(() => vi.fn())
50
+ }))
51
+
52
+ vi.mock('elysia', () => ({
53
+ Elysia: vi.fn(() => ({
54
+ onRequest: vi.fn().mockReturnThis(),
55
+ onAfterHandle: vi.fn().mockReturnThis(),
56
+ onError: vi.fn().mockReturnThis(),
57
+ options: vi.fn().mockReturnThis(),
58
+ use: vi.fn().mockReturnThis(),
59
+ listen: vi.fn((_port, callback) => {
60
+ if (callback) callback()
61
+ })
62
+ }))
63
+ }))
64
+
65
+ describe('FluxStackFramework', () => {
66
+ let framework: FluxStackFramework
67
+
68
+ beforeEach(() => {
69
+ framework = new FluxStackFramework()
70
+ })
71
+
72
+ afterEach(() => {
73
+ vi.clearAllMocks()
74
+ })
75
+
76
+ describe('Constructor', () => {
77
+ it('should initialize framework with default config', () => {
78
+ expect(framework).toBeInstanceOf(FluxStackFramework)
79
+ expect(framework.getContext()).toBeDefined()
80
+ expect(framework.getApp()).toBeDefined()
81
+ expect(framework.getPluginRegistry()).toBeDefined()
82
+ })
83
+
84
+ it('should initialize framework with custom config', () => {
85
+ const customConfig = {
86
+ server: {
87
+ port: 4000,
88
+ host: 'localhost',
89
+ apiPrefix: '/custom-api',
90
+ cors: {
91
+ origins: ['*'],
92
+ methods: ['GET', 'POST'],
93
+ headers: ['Content-Type'],
94
+ credentials: false,
95
+ maxAge: 86400
96
+ },
97
+ middleware: []
98
+ }
99
+ }
100
+
101
+ const customFramework = new FluxStackFramework(customConfig)
102
+ const context = customFramework.getContext()
103
+
104
+ expect(context.config.server.port).toBe(4000)
105
+ expect(context.config.server.apiPrefix).toBe('/custom-api')
106
+ })
107
+
108
+ it('should set up context correctly', () => {
109
+ const context = framework.getContext()
110
+
111
+ expect(context.isDevelopment).toBe(true)
112
+ expect(context.isProduction).toBe(false)
113
+ expect(context.isTest).toBe(true)
114
+ expect(context.environment).toBe('test')
115
+ })
116
+ })
117
+
118
+ describe('Plugin Management', () => {
119
+ it('should register plugins successfully', () => {
120
+ const mockPlugin: Plugin = {
121
+ name: 'test-plugin',
122
+ setup: vi.fn()
123
+ }
124
+
125
+ expect(() => framework.use(mockPlugin)).not.toThrow()
126
+ expect(framework.getPluginRegistry().get('test-plugin')).toBe(mockPlugin)
127
+ })
128
+
129
+ it('should throw error when registering duplicate plugin', () => {
130
+ const mockPlugin: Plugin = {
131
+ name: 'duplicate-plugin',
132
+ setup: vi.fn()
133
+ }
134
+
135
+ framework.use(mockPlugin)
136
+ expect(() => framework.use(mockPlugin)).toThrow()
137
+ })
138
+
139
+ it('should validate plugin dependencies', async () => {
140
+ const pluginA: Plugin = {
141
+ name: 'plugin-a',
142
+ setup: vi.fn()
143
+ }
144
+
145
+ const pluginB: Plugin = {
146
+ name: 'plugin-b',
147
+ dependencies: ['plugin-a'],
148
+ setup: vi.fn()
149
+ }
150
+
151
+ framework.use(pluginA)
152
+ framework.use(pluginB)
153
+
154
+ await expect(framework.start()).resolves.not.toThrow()
155
+ })
156
+
157
+ it('should throw error for missing dependencies', async () => {
158
+ const pluginWithMissingDep: Plugin = {
159
+ name: 'plugin-with-missing-dep',
160
+ dependencies: ['non-existent-plugin'],
161
+ setup: vi.fn()
162
+ }
163
+
164
+ framework.use(pluginWithMissingDep)
165
+ await expect(framework.start()).rejects.toThrow()
166
+ })
167
+ })
168
+
169
+ describe('Lifecycle Management', () => {
170
+ it('should start framework successfully', async () => {
171
+ const mockPlugin: Plugin = {
172
+ name: 'lifecycle-plugin',
173
+ setup: vi.fn(),
174
+ onServerStart: vi.fn()
175
+ }
176
+
177
+ framework.use(mockPlugin)
178
+ await framework.start()
179
+
180
+ expect(mockPlugin.setup).toHaveBeenCalled()
181
+ expect(mockPlugin.onServerStart).toHaveBeenCalled()
182
+ })
183
+
184
+ it('should stop framework successfully', async () => {
185
+ const mockPlugin: Plugin = {
186
+ name: 'lifecycle-plugin',
187
+ setup: vi.fn(),
188
+ onServerStart: vi.fn(),
189
+ onServerStop: vi.fn()
190
+ }
191
+
192
+ framework.use(mockPlugin)
193
+ await framework.start()
194
+ await framework.stop()
195
+
196
+ expect(mockPlugin.onServerStop).toHaveBeenCalled()
197
+ })
198
+
199
+ it('should not start framework twice', async () => {
200
+ await framework.start()
201
+ await framework.start() // Should not throw or cause issues
202
+
203
+ // Should log warning about already started
204
+ const { logger } = await import('../../utils/logger')
205
+ expect(logger.warn).toHaveBeenCalled()
206
+ })
207
+
208
+ it('should handle plugin setup errors', async () => {
209
+ const errorPlugin: Plugin = {
210
+ name: 'error-plugin',
211
+ setup: vi.fn().mockRejectedValue(new Error('Setup failed'))
212
+ }
213
+
214
+ framework.use(errorPlugin)
215
+ await expect(framework.start()).rejects.toThrow('Setup failed')
216
+ })
217
+ })
218
+
219
+ describe('Routes', () => {
220
+ it('should add routes to the app', () => {
221
+ const mockRouteModule = { get: vi.fn() }
222
+
223
+ expect(() => framework.routes(mockRouteModule)).not.toThrow()
224
+ })
225
+ })
226
+
227
+ describe('Error Handling', () => {
228
+ it('should set up error handling', async () => {
229
+ const { createErrorHandler } = await import('../../utils/errors/handlers')
230
+ expect(createErrorHandler).toHaveBeenCalled()
231
+ })
232
+ })
233
+ })
@@ -0,0 +1,132 @@
1
+ /**
2
+ * FluxStack Client Framework Utilities
3
+ * Provides client-side utilities and integrations
4
+ */
5
+
6
+ import type { FluxStackConfig } from "../types"
7
+
8
+ export interface ClientFrameworkOptions {
9
+ config: FluxStackConfig
10
+ baseUrl?: string
11
+ timeout?: number
12
+ retries?: number
13
+ }
14
+
15
+ export class FluxStackClient {
16
+ private config: FluxStackConfig
17
+ private baseUrl: string
18
+ private timeout: number
19
+ private retries: number
20
+
21
+ constructor(options: ClientFrameworkOptions) {
22
+ this.config = options.config
23
+ this.baseUrl = options.baseUrl || `http://localhost:${options.config.server.port}`
24
+ this.timeout = options.timeout || 10000
25
+ this.retries = options.retries || 3
26
+ }
27
+
28
+ // Create a configured fetch client
29
+ createFetchClient() {
30
+ return async (url: string, options: RequestInit = {}) => {
31
+ const fullUrl = url.startsWith('http') ? url : `${this.baseUrl}${url}`
32
+
33
+ const requestOptions: RequestInit = {
34
+ ...options,
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ ...options.headers
38
+ }
39
+ }
40
+
41
+ // Add timeout
42
+ const controller = new AbortController()
43
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout)
44
+ requestOptions.signal = controller.signal
45
+
46
+ try {
47
+ const response = await fetch(fullUrl, requestOptions)
48
+ clearTimeout(timeoutId)
49
+
50
+ if (!response.ok) {
51
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`)
52
+ }
53
+
54
+ return response
55
+ } catch (error) {
56
+ clearTimeout(timeoutId)
57
+ throw error
58
+ }
59
+ }
60
+ }
61
+
62
+ // Create API client with retry logic
63
+ createApiClient() {
64
+ const fetchClient = this.createFetchClient()
65
+
66
+ return {
67
+ get: async <T>(url: string): Promise<T> => {
68
+ return this.withRetry(async () => {
69
+ const response = await fetchClient(url, { method: 'GET' })
70
+ return response.json()
71
+ })
72
+ },
73
+
74
+ post: async <T>(url: string, data: any): Promise<T> => {
75
+ return this.withRetry(async () => {
76
+ const response = await fetchClient(url, {
77
+ method: 'POST',
78
+ body: JSON.stringify(data)
79
+ })
80
+ return response.json()
81
+ })
82
+ },
83
+
84
+ put: async <T>(url: string, data: any): Promise<T> => {
85
+ return this.withRetry(async () => {
86
+ const response = await fetchClient(url, {
87
+ method: 'PUT',
88
+ body: JSON.stringify(data)
89
+ })
90
+ return response.json()
91
+ })
92
+ },
93
+
94
+ delete: async <T>(url: string): Promise<T> => {
95
+ return this.withRetry(async () => {
96
+ const response = await fetchClient(url, { method: 'DELETE' })
97
+ return response.json()
98
+ })
99
+ }
100
+ }
101
+ }
102
+
103
+ private async withRetry<T>(fn: () => Promise<T>): Promise<T> {
104
+ let lastError: Error
105
+
106
+ for (let attempt = 1; attempt <= this.retries; attempt++) {
107
+ try {
108
+ return await fn()
109
+ } catch (error) {
110
+ lastError = error as Error
111
+
112
+ if (attempt === this.retries) {
113
+ throw lastError
114
+ }
115
+
116
+ // Exponential backoff
117
+ const delay = Math.min(1000 * Math.pow(2, attempt - 1), 10000)
118
+ await new Promise(resolve => setTimeout(resolve, delay))
119
+ }
120
+ }
121
+
122
+ throw lastError!
123
+ }
124
+
125
+ getConfig(): FluxStackConfig {
126
+ return this.config
127
+ }
128
+
129
+ getBaseUrl(): string {
130
+ return this.baseUrl
131
+ }
132
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * FluxStack Framework Core
3
+ * Main exports for the framework components
4
+ */
5
+
6
+ export { FluxStackFramework } from "./server"
7
+ export { FluxStackClient } from "./client"
8
+ export * from "./types"