@tamyla/clodo-framework 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.
- package/CHANGELOG.md +564 -0
- package/LICENSE +21 -0
- package/README.md +1393 -0
- package/bin/README.md +71 -0
- package/bin/clodo-service.js +416 -0
- package/bin/security/security-cli.js +96 -0
- package/bin/service-management/README.md +74 -0
- package/bin/service-management/create-service.js +129 -0
- package/bin/service-management/init-service.js +102 -0
- package/bin/service-management/init-service.js.backup +889 -0
- package/bin/shared/config/customer-cli.js +293 -0
- package/dist/config/ConfigurationManager.js +159 -0
- package/dist/config/CustomerConfigCLI.js +220 -0
- package/dist/config/FeatureManager.js +426 -0
- package/dist/config/customers.js +441 -0
- package/dist/config/domains.js +180 -0
- package/dist/config/features.js +225 -0
- package/dist/config/index.js +6 -0
- package/dist/database/database-orchestrator.js +730 -0
- package/dist/database/index.js +4 -0
- package/dist/deployment/auditor.js +971 -0
- package/dist/deployment/index.js +10 -0
- package/dist/deployment/rollback-manager.js +523 -0
- package/dist/deployment/testers/api-tester.js +80 -0
- package/dist/deployment/testers/auth-tester.js +129 -0
- package/dist/deployment/testers/core.js +217 -0
- package/dist/deployment/testers/database-tester.js +105 -0
- package/dist/deployment/testers/index.js +74 -0
- package/dist/deployment/testers/load-tester.js +120 -0
- package/dist/deployment/testers/performance-tester.js +105 -0
- package/dist/deployment/validator.js +558 -0
- package/dist/deployment/wrangler-deployer.js +574 -0
- package/dist/handlers/GenericRouteHandler.js +532 -0
- package/dist/index.js +39 -0
- package/dist/migration/MigrationAdapters.js +562 -0
- package/dist/modules/ModuleManager.js +668 -0
- package/dist/modules/security.js +98 -0
- package/dist/orchestration/cross-domain-coordinator.js +1083 -0
- package/dist/orchestration/index.js +5 -0
- package/dist/orchestration/modules/DeploymentCoordinator.js +258 -0
- package/dist/orchestration/modules/DomainResolver.js +196 -0
- package/dist/orchestration/modules/StateManager.js +332 -0
- package/dist/orchestration/multi-domain-orchestrator.js +255 -0
- package/dist/routing/EnhancedRouter.js +158 -0
- package/dist/schema/SchemaManager.js +778 -0
- package/dist/security/ConfigurationValidator.js +490 -0
- package/dist/security/DeploymentManager.js +208 -0
- package/dist/security/SecretGenerator.js +142 -0
- package/dist/security/SecurityCLI.js +228 -0
- package/dist/security/index.js +51 -0
- package/dist/security/patterns/environment-rules.js +66 -0
- package/dist/security/patterns/insecure-patterns.js +21 -0
- package/dist/service-management/ConfirmationEngine.js +411 -0
- package/dist/service-management/ErrorTracker.js +294 -0
- package/dist/service-management/GenerationEngine.js +3109 -0
- package/dist/service-management/InputCollector.js +237 -0
- package/dist/service-management/ServiceCreator.js +229 -0
- package/dist/service-management/ServiceInitializer.js +448 -0
- package/dist/service-management/ServiceOrchestrator.js +638 -0
- package/dist/service-management/handlers/ConfigMutator.js +130 -0
- package/dist/service-management/handlers/ConfirmationHandler.js +71 -0
- package/dist/service-management/handlers/GenerationHandler.js +80 -0
- package/dist/service-management/handlers/InputHandler.js +59 -0
- package/dist/service-management/handlers/ValidationHandler.js +203 -0
- package/dist/service-management/index.js +7 -0
- package/dist/services/GenericDataService.js +488 -0
- package/dist/shared/cloudflare/domain-discovery.js +562 -0
- package/dist/shared/cloudflare/domain-manager.js +912 -0
- package/dist/shared/cloudflare/index.js +8 -0
- package/dist/shared/cloudflare/ops.js +387 -0
- package/dist/shared/config/cache.js +1167 -0
- package/dist/shared/config/command-config-manager.js +174 -0
- package/dist/shared/config/customer-cli.js +258 -0
- package/dist/shared/config/index.js +9 -0
- package/dist/shared/config/manager.js +289 -0
- package/dist/shared/database/connection-manager.js +338 -0
- package/dist/shared/database/index.js +7 -0
- package/dist/shared/database/orchestrator.js +632 -0
- package/dist/shared/deployment/auditor.js +971 -0
- package/dist/shared/deployment/index.js +10 -0
- package/dist/shared/deployment/rollback-manager.js +523 -0
- package/dist/shared/deployment/validator.js +558 -0
- package/dist/shared/index.js +32 -0
- package/dist/shared/monitoring/health-checker.js +250 -0
- package/dist/shared/monitoring/index.js +8 -0
- package/dist/shared/monitoring/memory-manager.js +382 -0
- package/dist/shared/monitoring/production-monitor.js +390 -0
- package/dist/shared/production-tester/api-tester.js +80 -0
- package/dist/shared/production-tester/auth-tester.js +129 -0
- package/dist/shared/production-tester/core.js +217 -0
- package/dist/shared/production-tester/database-tester.js +105 -0
- package/dist/shared/production-tester/index.js +74 -0
- package/dist/shared/production-tester/load-tester.js +120 -0
- package/dist/shared/production-tester/performance-tester.js +105 -0
- package/dist/shared/security/api-token-manager.js +296 -0
- package/dist/shared/security/index.js +8 -0
- package/dist/shared/security/secret-generator.js +918 -0
- package/dist/shared/security/secure-token-manager.js +379 -0
- package/dist/shared/utils/error-recovery.js +240 -0
- package/dist/shared/utils/graceful-shutdown-manager.js +380 -0
- package/dist/shared/utils/index.js +9 -0
- package/dist/shared/utils/interactive-prompts.js +134 -0
- package/dist/shared/utils/rate-limiter.js +249 -0
- package/dist/utils/ErrorHandler.js +173 -0
- package/dist/utils/deployment/config-cache.js +1160 -0
- package/dist/utils/deployment/index.js +6 -0
- package/dist/utils/deployment/interactive-prompts.js +97 -0
- package/dist/utils/deployment/secret-generator.js +896 -0
- package/dist/utils/dirname-helper.js +35 -0
- package/dist/utils/domain-config.js +159 -0
- package/dist/utils/error-recovery.js +240 -0
- package/dist/utils/esm-helper.js +52 -0
- package/dist/utils/framework-config.js +481 -0
- package/dist/utils/graceful-shutdown-manager.js +379 -0
- package/dist/utils/health-checker.js +114 -0
- package/dist/utils/index.js +36 -0
- package/dist/utils/prompt-handler.js +98 -0
- package/dist/utils/usage-tracker.js +252 -0
- package/dist/utils/validation.js +112 -0
- package/dist/version/VersionDetector.js +723 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/integration.js +332 -0
- package/docs/FRAMEWORK-ARCHITECTURE-OVERVIEW.md +206 -0
- package/docs/INTEGRATION_GUIDE.md +2045 -0
- package/docs/README.md +82 -0
- package/docs/SECURITY.md +242 -0
- package/docs/deployment/deployment-guide.md +540 -0
- package/docs/overview.md +280 -0
- package/package.json +176 -0
- package/types/index.d.ts +575 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { featureManager, COMMON_FEATURES } from '../config/features.js';
|
|
2
|
+
import { getDomainFromEnv, createEnvironmentConfig } from '../config/domains.js';
|
|
3
|
+
import { createLogger } from '../utils/index.js';
|
|
4
|
+
const logger = createLogger('WorkerIntegration');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Initializes a service with domain and feature context
|
|
8
|
+
* @param {Object} env - Cloudflare Worker environment
|
|
9
|
+
* @param {Object} domainConfigs - Available domain configurations
|
|
10
|
+
* @returns {Object} Service initialization context
|
|
11
|
+
*/
|
|
12
|
+
export const initializeService = (env, domainConfigs = {}) => {
|
|
13
|
+
try {
|
|
14
|
+
// Get domain configuration from environment
|
|
15
|
+
const domainConfig = getDomainFromEnv(env, domainConfigs);
|
|
16
|
+
if (!domainConfig) {
|
|
17
|
+
throw new Error('No domain configuration found for service initialization');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Set domain in feature manager
|
|
21
|
+
featureManager.setDomain(domainConfig);
|
|
22
|
+
|
|
23
|
+
// Create environment-specific config
|
|
24
|
+
const environment = env.ENVIRONMENT || env.NODE_ENV || 'development';
|
|
25
|
+
const envConfig = createEnvironmentConfig(domainConfig, environment);
|
|
26
|
+
|
|
27
|
+
// Initialize service context
|
|
28
|
+
const serviceContext = {
|
|
29
|
+
domain: domainConfig.name,
|
|
30
|
+
environment,
|
|
31
|
+
features: featureManager.getEnabledFeatures(),
|
|
32
|
+
config: envConfig,
|
|
33
|
+
env,
|
|
34
|
+
isProduction: environment === 'production',
|
|
35
|
+
isStaging: environment === 'staging',
|
|
36
|
+
isDevelopment: environment === 'development'
|
|
37
|
+
};
|
|
38
|
+
logger.info(`Service initialized: ${domainConfig.name} (${environment})`);
|
|
39
|
+
logger.debug(`Enabled features: ${serviceContext.features.join(', ')}`);
|
|
40
|
+
return serviceContext;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
logger.error(`Service initialization failed: ${error.message}`);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a feature guard middleware for Cloudflare Workers
|
|
49
|
+
* @param {string} featureName - Name of the feature to guard
|
|
50
|
+
* @param {Object} options - Guard options
|
|
51
|
+
* @returns {Function} Feature guard middleware
|
|
52
|
+
*/
|
|
53
|
+
export const createFeatureGuard = (featureName, options = {}) => {
|
|
54
|
+
const {
|
|
55
|
+
fallbackResponse = null,
|
|
56
|
+
required = true,
|
|
57
|
+
logAccess = true
|
|
58
|
+
} = options;
|
|
59
|
+
return handler => {
|
|
60
|
+
return async (request, env, ctx) => {
|
|
61
|
+
const isEnabled = featureManager.isEnabled(featureName);
|
|
62
|
+
if (logAccess) {
|
|
63
|
+
logger.debug(`Feature access: ${featureName} = ${isEnabled}`);
|
|
64
|
+
}
|
|
65
|
+
if (required && !isEnabled) {
|
|
66
|
+
const response = fallbackResponse || new Response(JSON.stringify({
|
|
67
|
+
error: 'Feature not available',
|
|
68
|
+
feature: featureName,
|
|
69
|
+
message: `The ${featureName} feature is not enabled for this domain`
|
|
70
|
+
}), {
|
|
71
|
+
status: 404,
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json'
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
logger.warn(`Feature guard blocked access to ${featureName}`);
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
if (!isEnabled) {
|
|
80
|
+
logger.info(`Feature ${featureName} disabled, skipping handler`);
|
|
81
|
+
return fallbackResponse || new Response('Not Found', {
|
|
82
|
+
status: 404
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Feature is enabled, proceed with handler
|
|
87
|
+
return handler(request, env, ctx);
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Creates a route-based feature guard
|
|
94
|
+
* @param {Object} routeConfig - Route configuration with feature requirements
|
|
95
|
+
* @returns {Function} Route guard middleware
|
|
96
|
+
*/
|
|
97
|
+
export const createRouteGuard = routeConfig => {
|
|
98
|
+
return handler => {
|
|
99
|
+
return async (request, env, ctx) => {
|
|
100
|
+
// Check route-specific feature requirements
|
|
101
|
+
for (const [feature, required] of Object.entries(routeConfig)) {
|
|
102
|
+
if (required && !featureManager.isEnabled(feature)) {
|
|
103
|
+
logger.warn(`Route blocked: missing required feature ${feature}`);
|
|
104
|
+
return new Response(JSON.stringify({
|
|
105
|
+
error: 'Feature required',
|
|
106
|
+
feature,
|
|
107
|
+
message: `This endpoint requires the ${feature} feature`
|
|
108
|
+
}), {
|
|
109
|
+
status: 403,
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json'
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return handler(request, env, ctx);
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates an environment-based guard
|
|
123
|
+
* @param {string[]} allowedEnvironments - Array of allowed environments
|
|
124
|
+
* @returns {Function} Environment guard middleware
|
|
125
|
+
*/
|
|
126
|
+
export const createEnvironmentGuard = (allowedEnvironments = ['production', 'staging']) => {
|
|
127
|
+
return handler => {
|
|
128
|
+
return async (request, env, ctx) => {
|
|
129
|
+
const currentEnv = env.ENVIRONMENT || env.NODE_ENV || 'development';
|
|
130
|
+
if (!allowedEnvironments.includes(currentEnv)) {
|
|
131
|
+
logger.warn(`Environment guard blocked: ${currentEnv} not in ${allowedEnvironments.join(', ')}`);
|
|
132
|
+
return new Response('Not Found', {
|
|
133
|
+
status: 404
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return handler(request, env, ctx);
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a rate limiting guard (basic implementation)
|
|
143
|
+
* @param {Object} options - Rate limiting options
|
|
144
|
+
* @returns {Function} Rate limiting middleware
|
|
145
|
+
*/
|
|
146
|
+
export const createRateLimitGuard = (options = {}) => {
|
|
147
|
+
const {
|
|
148
|
+
windowMs = 60000,
|
|
149
|
+
// 1 minute
|
|
150
|
+
maxRequests = 100,
|
|
151
|
+
skipSuccessfulRequests = false,
|
|
152
|
+
skipFailedRequests = false
|
|
153
|
+
} = options;
|
|
154
|
+
const requests = new Map();
|
|
155
|
+
const cleanup = () => {
|
|
156
|
+
const now = Date.now();
|
|
157
|
+
for (const [key, data] of requests.entries()) {
|
|
158
|
+
if (now - data.resetTime > windowMs) {
|
|
159
|
+
requests.delete(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
return handler => {
|
|
164
|
+
return async (request, env, ctx) => {
|
|
165
|
+
// Skip rate limiting if feature is disabled
|
|
166
|
+
if (!featureManager.isEnabled(COMMON_FEATURES.RATE_LIMITING)) {
|
|
167
|
+
return handler(request, env, ctx);
|
|
168
|
+
}
|
|
169
|
+
const clientId = request.headers.get('CF-Connecting-IP') || 'anonymous';
|
|
170
|
+
const now = Date.now();
|
|
171
|
+
cleanup();
|
|
172
|
+
const clientData = requests.get(clientId) || {
|
|
173
|
+
count: 0,
|
|
174
|
+
resetTime: now + windowMs
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// Reset counter if window has passed
|
|
178
|
+
if (now > clientData.resetTime) {
|
|
179
|
+
clientData.count = 0;
|
|
180
|
+
clientData.resetTime = now + windowMs;
|
|
181
|
+
}
|
|
182
|
+
clientData.count++;
|
|
183
|
+
requests.set(clientId, clientData);
|
|
184
|
+
|
|
185
|
+
// Check if limit exceeded
|
|
186
|
+
if (clientData.count > maxRequests) {
|
|
187
|
+
logger.warn(`Rate limit exceeded for ${clientId}`);
|
|
188
|
+
return new Response(JSON.stringify({
|
|
189
|
+
error: 'Too many requests',
|
|
190
|
+
retryAfter: Math.ceil((clientData.resetTime - now) / 1000)
|
|
191
|
+
}), {
|
|
192
|
+
status: 429,
|
|
193
|
+
headers: {
|
|
194
|
+
'Content-Type': 'application/json',
|
|
195
|
+
'Retry-After': Math.ceil((clientData.resetTime - now) / 1000).toString()
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
const response = await handler(request, env, ctx);
|
|
200
|
+
|
|
201
|
+
// Optionally skip successful/failed requests from count
|
|
202
|
+
if (skipSuccessfulRequests && response.ok || skipFailedRequests && !response.ok) {
|
|
203
|
+
clientData.count--;
|
|
204
|
+
requests.set(clientId, clientData);
|
|
205
|
+
}
|
|
206
|
+
return response;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Creates CORS middleware
|
|
213
|
+
* @param {Object} options - CORS options
|
|
214
|
+
* @returns {Function} CORS middleware
|
|
215
|
+
*/
|
|
216
|
+
export const createCorsMiddleware = (options = {}) => {
|
|
217
|
+
const {
|
|
218
|
+
origins = ['*'],
|
|
219
|
+
methods = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
220
|
+
headers = ['Content-Type', 'Authorization'],
|
|
221
|
+
credentials = false,
|
|
222
|
+
maxAge = 86400
|
|
223
|
+
} = options;
|
|
224
|
+
return handler => {
|
|
225
|
+
return async (request, env, ctx) => {
|
|
226
|
+
// Handle preflight requests
|
|
227
|
+
if (request.method === 'OPTIONS') {
|
|
228
|
+
const origin = request.headers.get('Origin');
|
|
229
|
+
|
|
230
|
+
// Check if origin is allowed
|
|
231
|
+
const isWildcard = origins.includes('*');
|
|
232
|
+
const isOriginAllowed = isWildcard || origin && origins.includes(origin);
|
|
233
|
+
if (!isOriginAllowed) {
|
|
234
|
+
return new Response('CORS policy violation: Origin not allowed', {
|
|
235
|
+
status: 403,
|
|
236
|
+
headers: {
|
|
237
|
+
'Content-Type': 'text/plain'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
const allowedOrigin = isWildcard ? '*' : origin;
|
|
242
|
+
return new Response(null, {
|
|
243
|
+
status: 200,
|
|
244
|
+
headers: {
|
|
245
|
+
'Access-Control-Allow-Origin': allowedOrigin,
|
|
246
|
+
'Access-Control-Allow-Methods': methods.join(', '),
|
|
247
|
+
'Access-Control-Allow-Headers': headers.join(', '),
|
|
248
|
+
'Access-Control-Max-Age': maxAge.toString(),
|
|
249
|
+
...(credentials && {
|
|
250
|
+
'Access-Control-Allow-Credentials': 'true'
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Handle actual requests
|
|
257
|
+
const response = await handler(request, env, ctx);
|
|
258
|
+
const origin = request.headers.get('Origin');
|
|
259
|
+
|
|
260
|
+
// Add CORS headers to response only if origin is allowed
|
|
261
|
+
const isWildcard = origins.includes('*');
|
|
262
|
+
const isOriginAllowed = isWildcard || origin && origins.includes(origin);
|
|
263
|
+
if (isOriginAllowed) {
|
|
264
|
+
const allowedOrigin = isWildcard ? '*' : origin;
|
|
265
|
+
response.headers.set('Access-Control-Allow-Origin', allowedOrigin);
|
|
266
|
+
response.headers.set('Access-Control-Allow-Methods', methods.join(', '));
|
|
267
|
+
response.headers.set('Access-Control-Allow-Headers', headers.join(', '));
|
|
268
|
+
if (credentials) {
|
|
269
|
+
response.headers.set('Access-Control-Allow-Credentials', 'true');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return response;
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Creates error handling middleware
|
|
279
|
+
* @param {Object} options - Error handling options
|
|
280
|
+
* @returns {Function} Error handling middleware
|
|
281
|
+
*/
|
|
282
|
+
export const createErrorHandler = (options = {}) => {
|
|
283
|
+
const {
|
|
284
|
+
includeStack = false,
|
|
285
|
+
logErrors = true,
|
|
286
|
+
transformError = null
|
|
287
|
+
} = options;
|
|
288
|
+
return handler => {
|
|
289
|
+
return async (request, env, ctx) => {
|
|
290
|
+
try {
|
|
291
|
+
return await handler(request, env, ctx);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (logErrors) {
|
|
294
|
+
logger.error(`Request error: ${error.message}`, {
|
|
295
|
+
url: request.url,
|
|
296
|
+
method: request.method,
|
|
297
|
+
stack: includeStack ? error.stack : undefined
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Transform error if transformer provided
|
|
302
|
+
let errorResponse = {
|
|
303
|
+
error: 'Internal Server Error',
|
|
304
|
+
message: error.message,
|
|
305
|
+
...(includeStack && {
|
|
306
|
+
stack: error.stack
|
|
307
|
+
})
|
|
308
|
+
};
|
|
309
|
+
if (transformError) {
|
|
310
|
+
errorResponse = transformError(error, errorResponse);
|
|
311
|
+
}
|
|
312
|
+
return new Response(JSON.stringify(errorResponse), {
|
|
313
|
+
status: 500,
|
|
314
|
+
headers: {
|
|
315
|
+
'Content-Type': 'application/json'
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Composes multiple middleware functions
|
|
325
|
+
* @param {...Function} middlewares - Middleware functions to compose
|
|
326
|
+
* @returns {Function} Composed middleware
|
|
327
|
+
*/
|
|
328
|
+
export const composeMiddleware = (...middlewares) => {
|
|
329
|
+
return middlewares.reduce((composed, middleware) => {
|
|
330
|
+
return handler => middleware(composed(handler));
|
|
331
|
+
});
|
|
332
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# CLODO Framework Architecture Overview
|
|
2
|
+
|
|
3
|
+
## Framework Philosophy
|
|
4
|
+
|
|
5
|
+
The CLODO Framework implements a sophisticated **component-based architecture** where reusable "Clodo bricks" can be snapped together to build complex enterprise applications. Each component handles one concern perfectly, enabling rapid development of autonomous, domain-specific services.
|
|
6
|
+
|
|
7
|
+
## Core Architecture
|
|
8
|
+
|
|
9
|
+
### Three-Layer Design
|
|
10
|
+
|
|
11
|
+
#### 🎯 **Framework Core (Published Package)**
|
|
12
|
+
The main library that downstream applications import and use:
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
import {
|
|
16
|
+
GenericDataService,
|
|
17
|
+
SchemaManager,
|
|
18
|
+
CrossDomainCoordinator,
|
|
19
|
+
ConfigurationCacheManager
|
|
20
|
+
} from '@tamyla/clodo-framework';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Key Components:**
|
|
24
|
+
- **Data Management**: GenericDataService, SchemaManager, DatabaseOrchestrator
|
|
25
|
+
- **Request Handling**: EnhancedRouter, GenericRouteHandler
|
|
26
|
+
- **Configuration**: Domain configs, feature flags, customer management
|
|
27
|
+
- **Orchestration**: Cross-domain coordination, deployment automation
|
|
28
|
+
- **Security**: Configuration validation, secret management
|
|
29
|
+
|
|
30
|
+
#### 🛠️ **CLI Tools (Development Interface)**
|
|
31
|
+
Command-line tools for development, administration, and deployment:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Interactive deployment
|
|
35
|
+
node bin/deployment/enterprise-deploy.js deploy --interactive
|
|
36
|
+
|
|
37
|
+
# Database management
|
|
38
|
+
node bin/database/enterprise-db-manager.js migrate api.example.com
|
|
39
|
+
|
|
40
|
+
# Portfolio operations
|
|
41
|
+
node bin/portfolio/portfolio-manager.js deploy
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Available Tools:**
|
|
45
|
+
- **Deployment CLI**: Interactive and automated deployment workflows
|
|
46
|
+
- **Database CLI**: Migration, backup, health monitoring, optimization
|
|
47
|
+
- **Portfolio CLI**: Multi-domain portfolio management and analytics
|
|
48
|
+
- **Service Management**: Automated service initialization and templates
|
|
49
|
+
|
|
50
|
+
#### 🔧 **Shared Utilities (Internal Implementation)**
|
|
51
|
+
Internal utilities that power the CLI tools and framework components.
|
|
52
|
+
|
|
53
|
+
## Intelligent Execution Model
|
|
54
|
+
|
|
55
|
+
### Smart Component Resolution
|
|
56
|
+
|
|
57
|
+
The framework uses **intelligent dependency resolution** to automatically:
|
|
58
|
+
- **Discover services** through domain-based configuration
|
|
59
|
+
- **Cache frequently used data** (schemas, queries, configurations)
|
|
60
|
+
- **Pool database connections** with automatic health monitoring
|
|
61
|
+
- **Validate configurations** progressively (syntax → semantic → integration)
|
|
62
|
+
|
|
63
|
+
### Auto-Discovery & Orchestration
|
|
64
|
+
|
|
65
|
+
Services automatically find and coordinate with each other through:
|
|
66
|
+
- **Cloudflare API integration** for domain discovery
|
|
67
|
+
- **Configuration inheritance** (global → customer → domain → service)
|
|
68
|
+
- **Dependency graph analysis** for safe deployment ordering
|
|
69
|
+
- **Cross-domain coordination** with failure isolation
|
|
70
|
+
|
|
71
|
+
## Usage Patterns
|
|
72
|
+
|
|
73
|
+
### Library Usage (Programmatic)
|
|
74
|
+
**Best for**: Building custom services, integrating with existing codebases
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// Direct component usage
|
|
78
|
+
import { GenericDataService, SchemaManager } from '@tamyla/clodo-framework';
|
|
79
|
+
|
|
80
|
+
const service = new GenericDataService(d1Client, 'users');
|
|
81
|
+
const users = await service.findAll({ limit: 10 });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### CLI Usage (Command Line)
|
|
85
|
+
**Best for**: Development workflows, administration, one-off operations
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Deploy a service
|
|
89
|
+
node bin/deployment/enterprise-deploy.js deploy api.example.com
|
|
90
|
+
|
|
91
|
+
# Manage database
|
|
92
|
+
node bin/database/enterprise-db-manager.js health api.example.com
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Hybrid Approach
|
|
96
|
+
Most teams use both: CLI tools for development/administration, library components for service implementation.
|
|
97
|
+
|
|
98
|
+
## Key Features
|
|
99
|
+
|
|
100
|
+
### 🔒 **Security by Default**
|
|
101
|
+
- Automatic security validation on all deployments
|
|
102
|
+
- Environment-specific security requirements
|
|
103
|
+
- Cryptographic key generation and management
|
|
104
|
+
- Prevention of insecure configurations reaching production
|
|
105
|
+
|
|
106
|
+
### ⚡ **Performance Optimized**
|
|
107
|
+
- Multi-layer caching (schemas, queries, configurations)
|
|
108
|
+
- Connection pooling with health monitoring
|
|
109
|
+
- Lazy component initialization
|
|
110
|
+
- Query optimization and result caching
|
|
111
|
+
|
|
112
|
+
### 🛡️ **Enterprise Reliable**
|
|
113
|
+
- Circuit breaker patterns for external services
|
|
114
|
+
- Exponential backoff for retries
|
|
115
|
+
- Graceful degradation on failures
|
|
116
|
+
- Comprehensive error recovery
|
|
117
|
+
|
|
118
|
+
### 📊 **Observable**
|
|
119
|
+
- Built-in performance monitoring
|
|
120
|
+
- Deployment auditing and logging
|
|
121
|
+
- Health checks and alerting
|
|
122
|
+
- Comprehensive telemetry
|
|
123
|
+
|
|
124
|
+
## Design Principles
|
|
125
|
+
|
|
126
|
+
### 🎪 **Clodo Architecture**
|
|
127
|
+
- **Single Responsibility**: Each component has one clear purpose
|
|
128
|
+
- **Composability**: Components combine in any configuration
|
|
129
|
+
- **Reusability**: Components work across different contexts
|
|
130
|
+
- **Testability**: Isolated testing of individual components with modular testing capabilities
|
|
131
|
+
- **Modular Testing**: Individual test modules (API, Auth, Database, Performance) for granular control
|
|
132
|
+
- **Observability**: Every operation is logged and monitored
|
|
133
|
+
|
|
134
|
+
### 🏗️ **Convention over Configuration**
|
|
135
|
+
- Standard patterns reduce decision complexity
|
|
136
|
+
- Sensible defaults with override capabilities
|
|
137
|
+
- Consistent naming and structure
|
|
138
|
+
- Predictable behavior across components
|
|
139
|
+
|
|
140
|
+
### 🔧 **Modular Extensibility**
|
|
141
|
+
- Service types can be added without core changes
|
|
142
|
+
- Custom validators and adapters can be plugged in
|
|
143
|
+
- Database backends can be swapped
|
|
144
|
+
- Deployment strategies are configurable
|
|
145
|
+
|
|
146
|
+
## Getting Started
|
|
147
|
+
|
|
148
|
+
### For Service Developers
|
|
149
|
+
1. **Install**: `npm install @tamyla/clodo-framework`
|
|
150
|
+
2. **Import components** you need for your service
|
|
151
|
+
3. **Configure** domains, features, and database connections
|
|
152
|
+
4. **Deploy** using CLI tools or embed deployment logic
|
|
153
|
+
|
|
154
|
+
### For Platform Administrators
|
|
155
|
+
1. **Use CLI tools** for deployment and management
|
|
156
|
+
2. **Monitor** services through built-in telemetry
|
|
157
|
+
3. **Configure** multi-tenant environments
|
|
158
|
+
4. **Scale** by adding more domains and services
|
|
159
|
+
|
|
160
|
+
## Architecture Benefits
|
|
161
|
+
|
|
162
|
+
### For Small Businesses
|
|
163
|
+
- **Cost Effective**: Generic components = affordable custom software
|
|
164
|
+
- **Fast Time-to-Market**: Configuration over custom development
|
|
165
|
+
- **Scalable**: Start simple, add complexity as you grow
|
|
166
|
+
- **Maintainable**: Framework handles infrastructure complexity
|
|
167
|
+
|
|
168
|
+
### For Enterprise Teams
|
|
169
|
+
- **Consistency**: Standardized patterns across services
|
|
170
|
+
- **Reliability**: Battle-tested components with enterprise features
|
|
171
|
+
- **Developer Productivity**: Focus on business logic, not infrastructure
|
|
172
|
+
- **Operational Excellence**: Built-in monitoring, security, and automation
|
|
173
|
+
|
|
174
|
+
## Integration Examples
|
|
175
|
+
|
|
176
|
+
### Basic CRUD Service
|
|
177
|
+
```javascript
|
|
178
|
+
import { GenericDataService, SchemaManager } from '@tamyla/clodo-framework';
|
|
179
|
+
|
|
180
|
+
export default {
|
|
181
|
+
async fetch(request, env) {
|
|
182
|
+
const service = new GenericDataService(env.DB, 'products');
|
|
183
|
+
const products = await service.findAll();
|
|
184
|
+
return Response.json(products);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Multi-Domain Orchestration
|
|
190
|
+
```javascript
|
|
191
|
+
import { CrossDomainCoordinator } from '@tamyla/clodo-framework';
|
|
192
|
+
|
|
193
|
+
const coordinator = new CrossDomainCoordinator({
|
|
194
|
+
domains: ['api.example.com', 'auth.example.com'],
|
|
195
|
+
enableMonitoring: true
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
await coordinator.deployAll();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Conclusion
|
|
202
|
+
|
|
203
|
+
The CLODO Framework provides a sophisticated yet approachable way to build enterprise-grade applications. By combining reusable components with intelligent orchestration, it enables both rapid development and enterprise reliability. The dual interface (library + CLI) serves different user needs while maintaining architectural integrity.
|
|
204
|
+
|
|
205
|
+
Whether you're building a simple CRUD service or a complex multi-domain enterprise application, the framework provides the components and intelligence to get you there efficiently and reliably.</content>
|
|
206
|
+
<parameter name="filePath">c:\Users\Admin\Documents\coding\tamyla\clodo-framework\docs\FRAMEWORK-ARCHITECTURE-OVERVIEW.md
|