create-fluxstack 1.0.13 → 1.0.14
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/.env.example +29 -29
- package/app/client/README.md +69 -69
- package/app/client/index.html +14 -13
- package/app/client/src/App.tsx +157 -524
- package/app/client/src/components/ErrorBoundary.tsx +107 -0
- package/app/client/src/components/ErrorDisplay.css +365 -0
- package/app/client/src/components/ErrorDisplay.tsx +258 -0
- package/app/client/src/components/FluxStackConfig.tsx +1321 -0
- package/app/client/src/components/HybridLiveCounter.tsx +140 -0
- package/app/client/src/components/LiveClock.tsx +286 -0
- package/app/client/src/components/MainLayout.tsx +390 -0
- package/app/client/src/components/SidebarNavigation.tsx +391 -0
- package/app/client/src/components/StateDemo.tsx +178 -0
- package/app/client/src/components/SystemMonitor.tsx +1038 -0
- package/app/client/src/components/Teste.tsx +104 -0
- package/app/client/src/components/UserProfile.tsx +809 -0
- package/app/client/src/hooks/useAuth.ts +39 -0
- package/app/client/src/hooks/useNotifications.ts +56 -0
- package/app/client/src/lib/eden-api.ts +189 -53
- package/app/client/src/lib/errors.ts +340 -0
- package/app/client/src/lib/hooks/useErrorHandler.ts +258 -0
- package/app/client/src/lib/index.ts +45 -0
- package/app/client/src/main.tsx +3 -2
- package/app/client/src/pages/ApiDocs.tsx +182 -0
- package/app/client/src/pages/Demo.tsx +174 -0
- package/app/client/src/pages/HybridLive.tsx +263 -0
- package/app/client/src/pages/Overview.tsx +155 -0
- package/app/client/src/store/README.md +43 -0
- package/app/client/src/store/index.ts +16 -0
- package/app/client/src/store/slices/uiSlice.ts +151 -0
- package/app/client/src/store/slices/userSlice.ts +161 -0
- package/app/client/src/test/README.md +257 -0
- package/app/client/src/test/setup.ts +70 -0
- package/app/client/src/test/types.ts +12 -0
- package/app/client/src/vite-env.d.ts +1 -1
- package/app/client/tsconfig.app.json +44 -43
- package/app/client/tsconfig.json +7 -7
- package/app/client/tsconfig.node.json +25 -25
- package/app/client/zustand-setup.md +65 -0
- package/app/server/controllers/users.controller.ts +68 -68
- package/app/server/index.ts +9 -1
- package/app/server/live/CounterComponent.ts +191 -0
- package/app/server/live/FluxStackConfig.ts +529 -0
- package/app/server/live/LiveClockComponent.ts +214 -0
- package/app/server/live/SidebarNavigation.ts +156 -0
- package/app/server/live/SystemMonitor.ts +594 -0
- package/app/server/live/SystemMonitorIntegration.ts +151 -0
- package/app/server/live/TesteComponent.ts +87 -0
- package/app/server/live/UserProfileComponent.ts +135 -0
- package/app/server/live/register-components.ts +28 -0
- package/app/server/middleware/auth.ts +136 -0
- package/app/server/middleware/errorHandling.ts +250 -0
- package/app/server/middleware/index.ts +10 -0
- package/app/server/middleware/rateLimit.ts +193 -0
- package/app/server/middleware/requestLogging.ts +215 -0
- package/app/server/middleware/validation.ts +270 -0
- package/app/server/routes/index.ts +14 -2
- package/app/server/routes/upload.ts +92 -0
- package/app/server/routes/users.routes.ts +2 -9
- package/app/server/services/NotificationService.ts +302 -0
- package/app/server/services/UserService.ts +222 -0
- package/app/server/services/index.ts +46 -0
- package/core/cli/commands/plugin-deps.ts +263 -0
- package/core/cli/generators/README.md +339 -0
- package/core/cli/generators/component.ts +770 -0
- package/core/cli/generators/controller.ts +299 -0
- package/core/cli/generators/index.ts +144 -0
- package/core/cli/generators/interactive.ts +228 -0
- package/core/cli/generators/prompts.ts +83 -0
- package/core/cli/generators/route.ts +513 -0
- package/core/cli/generators/service.ts +465 -0
- package/core/cli/generators/template-engine.ts +154 -0
- package/core/cli/generators/types.ts +71 -0
- package/core/cli/generators/utils.ts +192 -0
- package/core/cli/index.ts +69 -0
- package/core/cli/plugin-discovery.ts +16 -85
- package/core/client/fluxstack.ts +17 -0
- package/core/client/hooks/index.ts +7 -0
- package/core/client/hooks/state-validator.ts +130 -0
- package/core/client/hooks/useAuth.ts +49 -0
- package/core/client/hooks/useChunkedUpload.ts +258 -0
- package/core/client/hooks/useHybridLiveComponent.ts +967 -0
- package/core/client/hooks/useWebSocket.ts +373 -0
- package/core/client/index.ts +47 -0
- package/core/client/state/createStore.ts +193 -0
- package/core/client/state/index.ts +15 -0
- package/core/config/env-dynamic.ts +1 -1
- package/core/config/env.ts +2 -1
- package/core/config/runtime-config.ts +3 -3
- package/core/config/schema.ts +84 -49
- package/core/framework/server.ts +30 -0
- package/core/index.ts +25 -0
- package/core/live/ComponentRegistry.ts +399 -0
- package/core/live/types.ts +164 -0
- package/core/plugins/built-in/live-components/commands/create-live-component.ts +1201 -0
- package/core/plugins/built-in/live-components/index.ts +27 -0
- package/core/plugins/built-in/logger/index.ts +1 -1
- package/core/plugins/built-in/monitoring/index.ts +1 -1
- package/core/plugins/built-in/static/index.ts +1 -1
- package/core/plugins/built-in/swagger/index.ts +1 -1
- package/core/plugins/built-in/vite/index.ts +1 -1
- package/core/plugins/dependency-manager.ts +384 -0
- package/core/plugins/index.ts +5 -1
- package/core/plugins/manager.ts +7 -3
- package/core/plugins/registry.ts +88 -10
- package/core/plugins/types.ts +11 -11
- package/core/server/framework.ts +43 -0
- package/core/server/index.ts +11 -1
- package/core/server/live/ComponentRegistry.ts +1017 -0
- package/core/server/live/FileUploadManager.ts +272 -0
- package/core/server/live/LiveComponentPerformanceMonitor.ts +930 -0
- package/core/server/live/SingleConnectionManager.ts +0 -0
- package/core/server/live/StateSignature.ts +644 -0
- package/core/server/live/WebSocketConnectionManager.ts +688 -0
- package/core/server/live/websocket-plugin.ts +435 -0
- package/core/server/middleware/errorHandling.ts +141 -0
- package/core/server/middleware/index.ts +16 -0
- package/core/server/plugins/static-files-plugin.ts +232 -0
- package/core/server/services/BaseService.ts +95 -0
- package/core/server/services/ServiceContainer.ts +144 -0
- package/core/server/services/index.ts +9 -0
- package/core/templates/create-project.ts +46 -2
- package/core/testing/index.ts +10 -0
- package/core/testing/setup.ts +74 -0
- package/core/types/build.ts +38 -14
- package/core/types/types.ts +319 -0
- package/core/utils/env-runtime.ts +7 -0
- package/core/utils/errors/handlers.ts +264 -39
- package/core/utils/errors/index.ts +528 -18
- package/core/utils/errors/middleware.ts +114 -0
- package/core/utils/logger/formatters.ts +222 -0
- package/core/utils/logger/index.ts +167 -48
- package/core/utils/logger/middleware.ts +253 -0
- package/core/utils/logger/performance.ts +384 -0
- package/core/utils/logger/transports.ts +365 -0
- package/create-fluxstack.ts +296 -296
- package/fluxstack.config.ts +17 -1
- package/package-template.json +66 -66
- package/package.json +31 -6
- package/public/README.md +16 -0
- package/vite.config.ts +29 -14
- package/.claude/settings.local.json +0 -74
- package/.github/workflows/ci-build-tests.yml +0 -480
- package/.github/workflows/dependency-management.yml +0 -324
- package/.github/workflows/release-validation.yml +0 -355
- package/.kiro/specs/fluxstack-architecture-optimization/design.md +0 -700
- package/.kiro/specs/fluxstack-architecture-optimization/requirements.md +0 -127
- package/.kiro/specs/fluxstack-architecture-optimization/tasks.md +0 -330
- package/CLAUDE.md +0 -200
- package/Dockerfile +0 -58
- package/Dockerfile.backend +0 -52
- package/Dockerfile.frontend +0 -54
- package/README-Docker.md +0 -85
- package/ai-context/00-QUICK-START.md +0 -86
- package/ai-context/README.md +0 -88
- package/ai-context/development/eden-treaty-guide.md +0 -362
- package/ai-context/development/patterns.md +0 -382
- package/ai-context/development/plugins-guide.md +0 -572
- package/ai-context/examples/crud-complete.md +0 -626
- package/ai-context/project/architecture.md +0 -399
- package/ai-context/project/overview.md +0 -213
- package/ai-context/recent-changes/eden-treaty-refactor.md +0 -281
- package/ai-context/recent-changes/type-inference-fix.md +0 -223
- package/ai-context/reference/environment-vars.md +0 -384
- package/ai-context/reference/troubleshooting.md +0 -407
- package/app/client/src/components/TestPage.tsx +0 -453
- package/bun.lock +0 -1063
- package/bunfig.toml +0 -16
- package/core/__tests__/integration.test.ts +0 -227
- package/core/build/index.ts +0 -186
- package/core/config/__tests__/config-loader.test.ts +0 -554
- package/core/config/__tests__/config-merger.test.ts +0 -657
- package/core/config/__tests__/env-converter.test.ts +0 -372
- package/core/config/__tests__/env-processor.test.ts +0 -431
- package/core/config/__tests__/env.test.ts +0 -452
- package/core/config/__tests__/integration.test.ts +0 -418
- package/core/config/__tests__/loader.test.ts +0 -331
- package/core/config/__tests__/schema.test.ts +0 -129
- package/core/config/__tests__/validator.test.ts +0 -318
- package/core/framework/__tests__/server.test.ts +0 -233
- package/core/plugins/__tests__/built-in.test.ts.disabled +0 -366
- package/core/plugins/__tests__/manager.test.ts +0 -398
- package/core/plugins/__tests__/monitoring.test.ts +0 -401
- package/core/plugins/__tests__/registry.test.ts +0 -335
- package/core/utils/__tests__/errors.test.ts +0 -139
- package/core/utils/__tests__/helpers.test.ts +0 -297
- package/core/utils/__tests__/logger.test.ts +0 -141
- package/create-test-app.ts +0 -156
- package/docker-compose.microservices.yml +0 -75
- package/docker-compose.simple.yml +0 -57
- package/docker-compose.yml +0 -71
- package/eslint.config.js +0 -23
- package/flux-cli.ts +0 -214
- package/nginx-lb.conf +0 -37
- package/publish.sh +0 -63
- package/run-clean.ts +0 -26
- package/run-env-tests.ts +0 -313
- package/tailwind.config.js +0 -34
- package/tests/__mocks__/api.ts +0 -56
- package/tests/fixtures/users.ts +0 -69
- package/tests/integration/api/users.routes.test.ts +0 -221
- package/tests/setup.ts +0 -29
- package/tests/unit/app/client/App-simple.test.tsx +0 -56
- package/tests/unit/app/client/App.test.tsx.skip +0 -237
- package/tests/unit/app/client/eden-api.test.ts +0 -186
- package/tests/unit/app/client/simple.test.tsx +0 -23
- package/tests/unit/app/controllers/users.controller.test.ts +0 -150
- package/tests/unit/core/create-project.test.ts.skip +0 -95
- package/tests/unit/core/framework.test.ts +0 -144
- package/tests/unit/core/plugins/logger.test.ts.skip +0 -268
- package/tests/unit/core/plugins/vite.test.ts.disabled +0 -188
- package/tests/utils/test-helpers.ts +0 -61
- package/vitest.config.ts +0 -50
- package/workspace.json +0 -6
|
@@ -1,700 +0,0 @@
|
|
|
1
|
-
# Design Document
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Este documento detalha o design para otimização da arquitetura FluxStack, focando em melhorar a organização, performance, developer experience e robustez do framework. O design mantém a filosofia core do FluxStack (simplicidade, type-safety, hot reload independente) enquanto resolve inconsistências estruturais e adiciona funcionalidades essenciais para produção.
|
|
6
|
-
|
|
7
|
-
## Architecture
|
|
8
|
-
|
|
9
|
-
### Nova Estrutura de Pastas Proposta
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
FluxStack/
|
|
13
|
-
├── 📦 package.json # Monorepo unificado
|
|
14
|
-
├── 🔧 fluxstack.config.ts # Configuração principal (movido do config/)
|
|
15
|
-
├── 🔧 vite.config.ts # Vite config
|
|
16
|
-
├── 🔧 tsconfig.json # TypeScript config
|
|
17
|
-
├── 🔧 eslint.config.js # ESLint config
|
|
18
|
-
├──
|
|
19
|
-
├── core/ # 🔧 Framework Core (otimizado)
|
|
20
|
-
│ ├── framework/ # Framework principal
|
|
21
|
-
│ │ ├── server.ts # FluxStackFramework class
|
|
22
|
-
│ │ ├── client.ts # Client utilities
|
|
23
|
-
│ │ └── types.ts # Core types
|
|
24
|
-
│ ├── plugins/ # Sistema de plugins
|
|
25
|
-
│ │ ├── built-in/ # Plugins integrados
|
|
26
|
-
│ │ │ ├── logger/ # Logger plugin aprimorado
|
|
27
|
-
│ │ │ ├── swagger/ # Swagger plugin
|
|
28
|
-
│ │ │ ├── vite/ # Vite integration
|
|
29
|
-
│ │ │ ├── static/ # Static files
|
|
30
|
-
│ │ │ ├── cors/ # CORS handling
|
|
31
|
-
│ │ │ └── monitoring/ # Performance monitoring
|
|
32
|
-
│ │ ├── registry.ts # Plugin registry
|
|
33
|
-
│ │ └── types.ts # Plugin types
|
|
34
|
-
│ ├── build/ # Build system otimizado
|
|
35
|
-
│ │ ├── builder.ts # Main builder class
|
|
36
|
-
│ │ ├── bundler.ts # Bundling logic
|
|
37
|
-
│ │ ├── optimizer.ts # Build optimizations
|
|
38
|
-
│ │ └── targets/ # Build targets (bun, node, docker)
|
|
39
|
-
│ ├── cli/ # CLI aprimorado
|
|
40
|
-
│ │ ├── index.ts # Main CLI
|
|
41
|
-
│ │ ├── commands/ # CLI commands
|
|
42
|
-
│ │ │ ├── dev.ts # Development command
|
|
43
|
-
│ │ │ ├── build.ts # Build command
|
|
44
|
-
│ │ │ ├── create.ts # Project creation
|
|
45
|
-
│ │ │ ├── generate.ts # Code generators
|
|
46
|
-
│ │ │ └── deploy.ts # Deploy helpers
|
|
47
|
-
│ │ └── utils/ # CLI utilities
|
|
48
|
-
│ ├── config/ # Configuration system
|
|
49
|
-
│ │ ├── loader.ts # Config loader
|
|
50
|
-
│ │ ├── validator.ts # Config validation
|
|
51
|
-
│ │ ├── env.ts # Environment handling
|
|
52
|
-
│ │ └── schema.ts # Configuration schema
|
|
53
|
-
│ ├── utils/ # Core utilities
|
|
54
|
-
│ │ ├── logger/ # Logging system
|
|
55
|
-
│ │ │ ├── index.ts # Main logger
|
|
56
|
-
│ │ │ ├── formatters.ts # Log formatters
|
|
57
|
-
│ │ │ └── transports.ts # Log transports
|
|
58
|
-
│ │ ├── errors/ # Error handling
|
|
59
|
-
│ │ │ ├── index.ts # Error classes
|
|
60
|
-
│ │ │ ├── handlers.ts # Error handlers
|
|
61
|
-
│ │ │ └── codes.ts # Error codes
|
|
62
|
-
│ │ ├── monitoring/ # Performance monitoring
|
|
63
|
-
│ │ │ ├── metrics.ts # Metrics collection
|
|
64
|
-
│ │ │ ├── profiler.ts # Performance profiling
|
|
65
|
-
│ │ │ └── exporters.ts # Metrics exporters
|
|
66
|
-
│ │ └── helpers.ts # General utilities
|
|
67
|
-
│ └── types/ # Core types
|
|
68
|
-
│ ├── index.ts # Main types export
|
|
69
|
-
│ ├── config.ts # Configuration types
|
|
70
|
-
│ ├── plugin.ts # Plugin types
|
|
71
|
-
│ └── api.ts # API types
|
|
72
|
-
│
|
|
73
|
-
├── app/ # 👨💻 User Application
|
|
74
|
-
│ ├── server/ # Backend
|
|
75
|
-
│ │ ├── controllers/ # Business logic
|
|
76
|
-
│ │ ├── routes/ # API routes
|
|
77
|
-
│ │ ├── middleware/ # Custom middleware
|
|
78
|
-
│ │ ├── services/ # Business services
|
|
79
|
-
│ │ ├── models/ # Data models
|
|
80
|
-
│ │ ├── types/ # Server-specific types
|
|
81
|
-
│ │ ├── index.ts # Main server entry
|
|
82
|
-
│ │ └── standalone.ts # Standalone server
|
|
83
|
-
│ ├── client/ # Frontend
|
|
84
|
-
│ │ ├── src/
|
|
85
|
-
│ │ │ ├── components/ # React components
|
|
86
|
-
│ │ │ ├── pages/ # Page components
|
|
87
|
-
│ │ │ ├── hooks/ # Custom hooks
|
|
88
|
-
│ │ │ ├── store/ # State management
|
|
89
|
-
│ │ │ │ ├── index.ts # Store setup
|
|
90
|
-
│ │ │ │ ├── slices/ # State slices
|
|
91
|
-
│ │ │ │ └── middleware.ts # Store middleware
|
|
92
|
-
│ │ │ ├── lib/ # Client libraries
|
|
93
|
-
│ │ │ │ ├── api.ts # Eden Treaty client
|
|
94
|
-
│ │ │ │ ├── errors.ts # Error handling
|
|
95
|
-
│ │ │ │ └── utils.ts # Client utilities
|
|
96
|
-
│ │ │ ├── types/ # Client-specific types
|
|
97
|
-
│ │ │ ├── assets/ # Static assets
|
|
98
|
-
│ │ │ ├── styles/ # Global styles
|
|
99
|
-
│ │ │ ├── App.tsx # Main app component
|
|
100
|
-
│ │ │ └── main.tsx # Entry point
|
|
101
|
-
│ │ ├── public/ # Public assets
|
|
102
|
-
│ │ ├── index.html # HTML template
|
|
103
|
-
│ │ └── standalone.ts # Standalone client
|
|
104
|
-
│ └── shared/ # Shared code
|
|
105
|
-
│ ├── types/ # Shared types
|
|
106
|
-
│ │ ├── index.ts # Main types
|
|
107
|
-
│ │ ├── api.ts # API types
|
|
108
|
-
│ │ ├── entities.ts # Entity types
|
|
109
|
-
│ │ └── common.ts # Common types
|
|
110
|
-
│ ├── utils/ # Shared utilities
|
|
111
|
-
│ ├── constants/ # Shared constants
|
|
112
|
-
│ └── schemas/ # Validation schemas
|
|
113
|
-
│
|
|
114
|
-
├── tests/ # 🧪 Testing
|
|
115
|
-
│ ├── unit/ # Unit tests
|
|
116
|
-
│ ├── integration/ # Integration tests
|
|
117
|
-
│ ├── e2e/ # End-to-end tests
|
|
118
|
-
│ ├── fixtures/ # Test fixtures
|
|
119
|
-
│ ├── mocks/ # Test mocks
|
|
120
|
-
│ ├── utils/ # Test utilities
|
|
121
|
-
│ └── setup.ts # Test setup
|
|
122
|
-
│
|
|
123
|
-
├── docs/ # 📚 Documentation
|
|
124
|
-
│ ├── api/ # API documentation
|
|
125
|
-
│ ├── guides/ # User guides
|
|
126
|
-
│ ├── examples/ # Code examples
|
|
127
|
-
│ └── README.md # Documentation index
|
|
128
|
-
│
|
|
129
|
-
├── scripts/ # 🔧 Build/Deploy scripts
|
|
130
|
-
│ ├── build.ts # Build scripts
|
|
131
|
-
│ ├── deploy.ts # Deploy scripts
|
|
132
|
-
│ └── migrate.ts # Migration scripts
|
|
133
|
-
│
|
|
134
|
-
└── dist/ # 📦 Build output
|
|
135
|
-
├── client/ # Frontend build
|
|
136
|
-
├── server/ # Backend build
|
|
137
|
-
└── docs/ # Documentation build
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### Principais Mudanças Estruturais
|
|
141
|
-
|
|
142
|
-
1. **Configuração Principal Movida**: `fluxstack.config.ts` no root para melhor descoberta
|
|
143
|
-
2. **Core Reorganizado**: Estrutura mais clara por funcionalidade
|
|
144
|
-
3. **Plugin System Expandido**: Plugins built-in organizados e registry centralizado
|
|
145
|
-
4. **Build System Modular**: Separação clara entre builder, bundler e optimizer
|
|
146
|
-
5. **Utilities Estruturados**: Logger, errors e monitoring como módulos independentes
|
|
147
|
-
6. **App Structure Melhorada**: Separação clara entre controllers, services e models
|
|
148
|
-
7. **State Management**: Pasta dedicada para gerenciamento de estado no client
|
|
149
|
-
8. **Documentation**: Pasta dedicada para documentação estruturada
|
|
150
|
-
|
|
151
|
-
## Components and Interfaces
|
|
152
|
-
|
|
153
|
-
### 1. Enhanced Configuration System
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
// core/config/schema.ts
|
|
157
|
-
export interface FluxStackConfig {
|
|
158
|
-
// Core settings
|
|
159
|
-
app: {
|
|
160
|
-
name: string
|
|
161
|
-
version: string
|
|
162
|
-
description?: string
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Server configuration
|
|
166
|
-
server: {
|
|
167
|
-
port: number
|
|
168
|
-
host: string
|
|
169
|
-
apiPrefix: string
|
|
170
|
-
cors: CorsConfig
|
|
171
|
-
middleware: MiddlewareConfig[]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Client configuration
|
|
175
|
-
client: {
|
|
176
|
-
port: number
|
|
177
|
-
proxy: ProxyConfig
|
|
178
|
-
build: ClientBuildConfig
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Build configuration
|
|
182
|
-
build: {
|
|
183
|
-
target: 'bun' | 'node' | 'docker'
|
|
184
|
-
outDir: string
|
|
185
|
-
optimization: OptimizationConfig
|
|
186
|
-
sourceMaps: boolean
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Plugin configuration
|
|
190
|
-
plugins: {
|
|
191
|
-
enabled: string[]
|
|
192
|
-
disabled: string[]
|
|
193
|
-
config: Record<string, any>
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Logging configuration
|
|
197
|
-
logging: {
|
|
198
|
-
level: LogLevel
|
|
199
|
-
format: 'json' | 'pretty'
|
|
200
|
-
transports: LogTransport[]
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Monitoring configuration
|
|
204
|
-
monitoring: {
|
|
205
|
-
enabled: boolean
|
|
206
|
-
metrics: MetricsConfig
|
|
207
|
-
profiling: ProfilingConfig
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Environment-specific overrides
|
|
211
|
-
environments: {
|
|
212
|
-
development?: Partial<FluxStackConfig>
|
|
213
|
-
production?: Partial<FluxStackConfig>
|
|
214
|
-
test?: Partial<FluxStackConfig>
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### 2. Enhanced Plugin System
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
// core/plugins/types.ts
|
|
223
|
-
export interface Plugin {
|
|
224
|
-
name: string
|
|
225
|
-
version?: string
|
|
226
|
-
description?: string
|
|
227
|
-
dependencies?: string[]
|
|
228
|
-
priority?: number
|
|
229
|
-
|
|
230
|
-
// Lifecycle hooks
|
|
231
|
-
setup?: (context: PluginContext) => void | Promise<void>
|
|
232
|
-
onServerStart?: (context: PluginContext) => void | Promise<void>
|
|
233
|
-
onServerStop?: (context: PluginContext) => void | Promise<void>
|
|
234
|
-
onRequest?: (context: RequestContext) => void | Promise<void>
|
|
235
|
-
onResponse?: (context: ResponseContext) => void | Promise<void>
|
|
236
|
-
onError?: (context: ErrorContext) => void | Promise<void>
|
|
237
|
-
|
|
238
|
-
// Configuration
|
|
239
|
-
configSchema?: any
|
|
240
|
-
defaultConfig?: any
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface PluginContext {
|
|
244
|
-
config: FluxStackConfig
|
|
245
|
-
logger: Logger
|
|
246
|
-
app: Elysia
|
|
247
|
-
utils: PluginUtils
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// core/plugins/registry.ts
|
|
251
|
-
export class PluginRegistry {
|
|
252
|
-
private plugins: Map<string, Plugin> = new Map()
|
|
253
|
-
private loadOrder: string[] = []
|
|
254
|
-
|
|
255
|
-
register(plugin: Plugin): void
|
|
256
|
-
unregister(name: string): void
|
|
257
|
-
get(name: string): Plugin | undefined
|
|
258
|
-
getAll(): Plugin[]
|
|
259
|
-
getLoadOrder(): string[]
|
|
260
|
-
validateDependencies(): void
|
|
261
|
-
}
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### 3. Enhanced Logging System
|
|
265
|
-
|
|
266
|
-
```typescript
|
|
267
|
-
// core/utils/logger/index.ts
|
|
268
|
-
export interface Logger {
|
|
269
|
-
debug(message: string, meta?: any): void
|
|
270
|
-
info(message: string, meta?: any): void
|
|
271
|
-
warn(message: string, meta?: any): void
|
|
272
|
-
error(message: string, meta?: any): void
|
|
273
|
-
|
|
274
|
-
// Contextual logging
|
|
275
|
-
child(context: any): Logger
|
|
276
|
-
|
|
277
|
-
// Performance logging
|
|
278
|
-
time(label: string): void
|
|
279
|
-
timeEnd(label: string): void
|
|
280
|
-
|
|
281
|
-
// Request logging
|
|
282
|
-
request(req: Request, res?: Response, duration?: number): void
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export interface LogTransport {
|
|
286
|
-
name: string
|
|
287
|
-
level: LogLevel
|
|
288
|
-
format: LogFormatter
|
|
289
|
-
output: LogOutput
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class FluxStackLogger implements Logger {
|
|
293
|
-
private transports: LogTransport[] = []
|
|
294
|
-
private context: any = {}
|
|
295
|
-
|
|
296
|
-
constructor(config: LoggingConfig) {
|
|
297
|
-
this.setupTransports(config)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Implementation methods...
|
|
301
|
-
}
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### 4. Enhanced Error Handling
|
|
305
|
-
|
|
306
|
-
```typescript
|
|
307
|
-
// core/utils/errors/index.ts
|
|
308
|
-
export class FluxStackError extends Error {
|
|
309
|
-
public readonly code: string
|
|
310
|
-
public readonly statusCode: number
|
|
311
|
-
public readonly context?: any
|
|
312
|
-
public readonly timestamp: Date
|
|
313
|
-
|
|
314
|
-
constructor(
|
|
315
|
-
message: string,
|
|
316
|
-
code: string,
|
|
317
|
-
statusCode: number = 500,
|
|
318
|
-
context?: any
|
|
319
|
-
) {
|
|
320
|
-
super(message)
|
|
321
|
-
this.name = 'FluxStackError'
|
|
322
|
-
this.code = code
|
|
323
|
-
this.statusCode = statusCode
|
|
324
|
-
this.context = context
|
|
325
|
-
this.timestamp = new Date()
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export class ValidationError extends FluxStackError {
|
|
330
|
-
constructor(message: string, context?: any) {
|
|
331
|
-
super(message, 'VALIDATION_ERROR', 400, context)
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export class NotFoundError extends FluxStackError {
|
|
336
|
-
constructor(resource: string) {
|
|
337
|
-
super(`${resource} not found`, 'NOT_FOUND', 404)
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// Error handler middleware
|
|
342
|
-
export const errorHandler = (error: Error, context: any) => {
|
|
343
|
-
const logger = context.logger
|
|
344
|
-
|
|
345
|
-
if (error instanceof FluxStackError) {
|
|
346
|
-
logger.error(error.message, {
|
|
347
|
-
code: error.code,
|
|
348
|
-
statusCode: error.statusCode,
|
|
349
|
-
context: error.context,
|
|
350
|
-
stack: error.stack
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
return {
|
|
354
|
-
error: {
|
|
355
|
-
message: error.message,
|
|
356
|
-
code: error.code,
|
|
357
|
-
...(error.context && { details: error.context })
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// Handle unknown errors
|
|
363
|
-
logger.error('Unhandled error', { error: error.message, stack: error.stack })
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
error: {
|
|
367
|
-
message: 'Internal server error',
|
|
368
|
-
code: 'INTERNAL_ERROR'
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### 5. Performance Monitoring
|
|
375
|
-
|
|
376
|
-
```typescript
|
|
377
|
-
// core/utils/monitoring/metrics.ts
|
|
378
|
-
export interface Metrics {
|
|
379
|
-
// HTTP metrics
|
|
380
|
-
httpRequestsTotal: Counter
|
|
381
|
-
httpRequestDuration: Histogram
|
|
382
|
-
httpRequestSize: Histogram
|
|
383
|
-
httpResponseSize: Histogram
|
|
384
|
-
|
|
385
|
-
// System metrics
|
|
386
|
-
memoryUsage: Gauge
|
|
387
|
-
cpuUsage: Gauge
|
|
388
|
-
eventLoopLag: Histogram
|
|
389
|
-
|
|
390
|
-
// Custom metrics
|
|
391
|
-
custom: Map<string, Metric>
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export class MetricsCollector {
|
|
395
|
-
private metrics: Metrics
|
|
396
|
-
private exporters: MetricsExporter[] = []
|
|
397
|
-
|
|
398
|
-
constructor(config: MetricsConfig) {
|
|
399
|
-
this.setupMetrics(config)
|
|
400
|
-
this.setupExporters(config)
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Metric collection methods
|
|
404
|
-
recordHttpRequest(method: string, path: string, statusCode: number, duration: number): void
|
|
405
|
-
recordMemoryUsage(): void
|
|
406
|
-
recordCpuUsage(): void
|
|
407
|
-
|
|
408
|
-
// Custom metrics
|
|
409
|
-
createCounter(name: string, help: string, labels?: string[]): Counter
|
|
410
|
-
createGauge(name: string, help: string, labels?: string[]): Gauge
|
|
411
|
-
createHistogram(name: string, help: string, buckets?: number[]): Histogram
|
|
412
|
-
|
|
413
|
-
// Export metrics
|
|
414
|
-
export(): Promise<string>
|
|
415
|
-
}
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
### 6. Enhanced Build System
|
|
419
|
-
|
|
420
|
-
```typescript
|
|
421
|
-
// core/build/builder.ts
|
|
422
|
-
export class FluxStackBuilder {
|
|
423
|
-
private config: FluxStackConfig
|
|
424
|
-
private bundler: Bundler
|
|
425
|
-
private optimizer: Optimizer
|
|
426
|
-
|
|
427
|
-
constructor(config: FluxStackConfig) {
|
|
428
|
-
this.config = config
|
|
429
|
-
this.bundler = new Bundler(config.build)
|
|
430
|
-
this.optimizer = new Optimizer(config.build.optimization)
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
async build(target?: BuildTarget): Promise<BuildResult> {
|
|
434
|
-
const startTime = Date.now()
|
|
435
|
-
|
|
436
|
-
try {
|
|
437
|
-
// Validate configuration
|
|
438
|
-
await this.validateConfig()
|
|
439
|
-
|
|
440
|
-
// Clean output directory
|
|
441
|
-
await this.clean()
|
|
442
|
-
|
|
443
|
-
// Build client
|
|
444
|
-
const clientResult = await this.buildClient()
|
|
445
|
-
|
|
446
|
-
// Build server
|
|
447
|
-
const serverResult = await this.buildServer()
|
|
448
|
-
|
|
449
|
-
// Optimize build
|
|
450
|
-
await this.optimize()
|
|
451
|
-
|
|
452
|
-
// Generate build manifest
|
|
453
|
-
const manifest = await this.generateManifest()
|
|
454
|
-
|
|
455
|
-
const duration = Date.now() - startTime
|
|
456
|
-
|
|
457
|
-
return {
|
|
458
|
-
success: true,
|
|
459
|
-
duration,
|
|
460
|
-
client: clientResult,
|
|
461
|
-
server: serverResult,
|
|
462
|
-
manifest
|
|
463
|
-
}
|
|
464
|
-
} catch (error) {
|
|
465
|
-
return {
|
|
466
|
-
success: false,
|
|
467
|
-
error: error.message,
|
|
468
|
-
duration: Date.now() - startTime
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// Individual build methods...
|
|
474
|
-
}
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
### 7. State Management Integration
|
|
478
|
-
|
|
479
|
-
```typescript
|
|
480
|
-
// app/client/src/store/index.ts
|
|
481
|
-
export interface AppState {
|
|
482
|
-
user: UserState
|
|
483
|
-
ui: UIState
|
|
484
|
-
api: APIState
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export interface StoreConfig {
|
|
488
|
-
persist?: {
|
|
489
|
-
key: string
|
|
490
|
-
storage: 'localStorage' | 'sessionStorage'
|
|
491
|
-
whitelist?: string[]
|
|
492
|
-
}
|
|
493
|
-
middleware?: Middleware[]
|
|
494
|
-
devtools?: boolean
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export class FluxStackStore {
|
|
498
|
-
private store: Store<AppState>
|
|
499
|
-
private config: StoreConfig
|
|
500
|
-
|
|
501
|
-
constructor(config: StoreConfig) {
|
|
502
|
-
this.config = config
|
|
503
|
-
this.store = this.createStore()
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
private createStore(): Store<AppState> {
|
|
507
|
-
// Store creation logic with middleware, persistence, etc.
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// Store methods
|
|
511
|
-
getState(): AppState
|
|
512
|
-
dispatch(action: Action): void
|
|
513
|
-
subscribe(listener: () => void): () => void
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// React integration
|
|
517
|
-
export const useAppStore = () => {
|
|
518
|
-
const store = useContext(StoreContext)
|
|
519
|
-
return store
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
export const useAppSelector = <T>(selector: (state: AppState) => T) => {
|
|
523
|
-
const store = useAppStore()
|
|
524
|
-
return useSyncExternalStore(
|
|
525
|
-
store.subscribe,
|
|
526
|
-
() => selector(store.getState())
|
|
527
|
-
)
|
|
528
|
-
}
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
## Data Models
|
|
532
|
-
|
|
533
|
-
### Configuration Schema
|
|
534
|
-
|
|
535
|
-
```typescript
|
|
536
|
-
// Configuração principal com validação
|
|
537
|
-
export const configSchema = {
|
|
538
|
-
type: 'object',
|
|
539
|
-
properties: {
|
|
540
|
-
app: {
|
|
541
|
-
type: 'object',
|
|
542
|
-
properties: {
|
|
543
|
-
name: { type: 'string', minLength: 1 },
|
|
544
|
-
version: { type: 'string', pattern: '^\\d+\\.\\d+\\.\\d+' },
|
|
545
|
-
description: { type: 'string' }
|
|
546
|
-
},
|
|
547
|
-
required: ['name', 'version']
|
|
548
|
-
},
|
|
549
|
-
server: {
|
|
550
|
-
type: 'object',
|
|
551
|
-
properties: {
|
|
552
|
-
port: { type: 'number', minimum: 1, maximum: 65535 },
|
|
553
|
-
host: { type: 'string' },
|
|
554
|
-
apiPrefix: { type: 'string', pattern: '^/' }
|
|
555
|
-
},
|
|
556
|
-
required: ['port', 'host', 'apiPrefix']
|
|
557
|
-
}
|
|
558
|
-
// ... resto do schema
|
|
559
|
-
},
|
|
560
|
-
required: ['app', 'server']
|
|
561
|
-
}
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
### Plugin Metadata
|
|
565
|
-
|
|
566
|
-
```typescript
|
|
567
|
-
export interface PluginManifest {
|
|
568
|
-
name: string
|
|
569
|
-
version: string
|
|
570
|
-
description: string
|
|
571
|
-
author: string
|
|
572
|
-
license: string
|
|
573
|
-
homepage?: string
|
|
574
|
-
repository?: string
|
|
575
|
-
keywords: string[]
|
|
576
|
-
dependencies: Record<string, string>
|
|
577
|
-
peerDependencies?: Record<string, string>
|
|
578
|
-
fluxstack: {
|
|
579
|
-
version: string
|
|
580
|
-
hooks: string[]
|
|
581
|
-
config?: any
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
```
|
|
585
|
-
|
|
586
|
-
### Build Manifest
|
|
587
|
-
|
|
588
|
-
```typescript
|
|
589
|
-
export interface BuildManifest {
|
|
590
|
-
version: string
|
|
591
|
-
timestamp: string
|
|
592
|
-
target: BuildTarget
|
|
593
|
-
client: {
|
|
594
|
-
entryPoints: string[]
|
|
595
|
-
assets: AssetManifest[]
|
|
596
|
-
chunks: ChunkManifest[]
|
|
597
|
-
}
|
|
598
|
-
server: {
|
|
599
|
-
entryPoint: string
|
|
600
|
-
dependencies: string[]
|
|
601
|
-
}
|
|
602
|
-
optimization: {
|
|
603
|
-
minified: boolean
|
|
604
|
-
treeshaken: boolean
|
|
605
|
-
compressed: boolean
|
|
606
|
-
}
|
|
607
|
-
metrics: {
|
|
608
|
-
buildTime: number
|
|
609
|
-
bundleSize: number
|
|
610
|
-
chunkCount: number
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
```
|
|
614
|
-
|
|
615
|
-
## Error Handling
|
|
616
|
-
|
|
617
|
-
### Centralized Error Management
|
|
618
|
-
|
|
619
|
-
1. **Error Classification**: Diferentes tipos de erro com códigos específicos
|
|
620
|
-
2. **Context Preservation**: Manter contexto da requisição em todos os erros
|
|
621
|
-
3. **User-Friendly Messages**: Mensagens apropriadas para diferentes audiências
|
|
622
|
-
4. **Logging Integration**: Todos os erros são logados com contexto completo
|
|
623
|
-
5. **Recovery Strategies**: Tentativas de recuperação automática quando possível
|
|
624
|
-
|
|
625
|
-
### Error Flow
|
|
626
|
-
|
|
627
|
-
```
|
|
628
|
-
Request → Validation → Business Logic → Response
|
|
629
|
-
↓ ↓ ↓ ↓
|
|
630
|
-
Error Handler ← Error Handler ← Error Handler ← Error Handler
|
|
631
|
-
↓
|
|
632
|
-
Logger → Metrics → User Response
|
|
633
|
-
```
|
|
634
|
-
|
|
635
|
-
## Testing Strategy
|
|
636
|
-
|
|
637
|
-
### Test Organization
|
|
638
|
-
|
|
639
|
-
1. **Unit Tests**: Testam componentes individuais isoladamente
|
|
640
|
-
2. **Integration Tests**: Testam interação entre componentes
|
|
641
|
-
3. **E2E Tests**: Testam fluxos completos da aplicação
|
|
642
|
-
4. **Performance Tests**: Testam performance e carga
|
|
643
|
-
5. **Plugin Tests**: Testam plugins individualmente e em conjunto
|
|
644
|
-
|
|
645
|
-
### Test Infrastructure
|
|
646
|
-
|
|
647
|
-
```typescript
|
|
648
|
-
// Enhanced test utilities
|
|
649
|
-
export class FluxStackTestUtils {
|
|
650
|
-
static createTestApp(config?: Partial<FluxStackConfig>): FluxStackFramework
|
|
651
|
-
static createTestClient(app: FluxStackFramework): TestClient
|
|
652
|
-
static mockPlugin(name: string, hooks?: Partial<Plugin>): Plugin
|
|
653
|
-
static createTestStore(initialState?: Partial<AppState>): Store
|
|
654
|
-
static waitForCondition(condition: () => boolean, timeout?: number): Promise<void>
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// Test fixtures
|
|
658
|
-
export const testFixtures = {
|
|
659
|
-
users: [/* test users */],
|
|
660
|
-
config: {/* test config */},
|
|
661
|
-
plugins: [/* test plugins */]
|
|
662
|
-
}
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
### Performance Testing
|
|
666
|
-
|
|
667
|
-
```typescript
|
|
668
|
-
// Performance benchmarks
|
|
669
|
-
export class PerformanceBenchmarks {
|
|
670
|
-
static async benchmarkStartupTime(): Promise<number>
|
|
671
|
-
static async benchmarkRequestThroughput(): Promise<number>
|
|
672
|
-
static async benchmarkMemoryUsage(): Promise<MemoryMetrics>
|
|
673
|
-
static async benchmarkBuildTime(): Promise<number>
|
|
674
|
-
}
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
## Implementation Notes
|
|
678
|
-
|
|
679
|
-
### Migration Strategy
|
|
680
|
-
|
|
681
|
-
1. **Backward Compatibility**: Manter compatibilidade com projetos existentes
|
|
682
|
-
2. **Gradual Migration**: Permitir migração gradual de funcionalidades
|
|
683
|
-
3. **Migration Scripts**: Scripts automáticos para migrar estrutura de pastas
|
|
684
|
-
4. **Documentation**: Guias detalhados de migração
|
|
685
|
-
|
|
686
|
-
### Performance Considerations
|
|
687
|
-
|
|
688
|
-
1. **Lazy Loading**: Carregar plugins e módulos apenas quando necessário
|
|
689
|
-
2. **Caching**: Cache inteligente para builds e configurações
|
|
690
|
-
3. **Bundle Optimization**: Tree-shaking e code splitting automático
|
|
691
|
-
4. **Memory Management**: Monitoramento e otimização de uso de memória
|
|
692
|
-
|
|
693
|
-
### Security Considerations
|
|
694
|
-
|
|
695
|
-
1. **Input Validation**: Validação rigorosa de todas as entradas
|
|
696
|
-
2. **Error Information**: Não vazar informações sensíveis em erros
|
|
697
|
-
3. **Plugin Security**: Sandboxing e validação de plugins
|
|
698
|
-
4. **Dependency Security**: Auditoria automática de dependências
|
|
699
|
-
|
|
700
|
-
Este design mantém a simplicidade e poder do FluxStack atual enquanto resolve as inconsistências identificadas e adiciona funcionalidades essenciais para um framework de produção robusto.
|