@vee-stack/delta-cli 2.0.4 → 2.0.5

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 (135) hide show
  1. package/dist/analyzer/commands/analyze.js +260 -0
  2. package/dist/analyzer/commands/config.js +83 -0
  3. package/dist/analyzer/commands/report.js +38 -0
  4. package/dist/analyzer/generators/report.generator.js +123 -0
  5. package/dist/analyzer/index.js +44 -0
  6. package/dist/analyzer/scanners/project.scanner.js +92 -0
  7. package/dist/analyzer/validators/contracts.validator.js +42 -0
  8. package/dist/analyzer/validators/maintainability.validator.js +40 -0
  9. package/dist/analyzer/validators/observability.validator.js +39 -0
  10. package/dist/analyzer/validators/performance.validator.js +42 -0
  11. package/dist/analyzer/validators/security.validator.js +66 -0
  12. package/dist/analyzer/validators/soc.validator.js +75 -0
  13. package/dist/apps/cli/src/analyzer/commands/analyze.js +256 -0
  14. package/dist/apps/cli/src/analyzer/commands/config.js +83 -0
  15. package/dist/apps/cli/src/analyzer/commands/report.js +38 -0
  16. package/dist/apps/cli/src/analyzer/generators/report.generator.js +123 -0
  17. package/dist/apps/cli/src/analyzer/index.js +44 -0
  18. package/dist/apps/cli/src/analyzer/scanners/project.scanner.js +92 -0
  19. package/dist/apps/cli/src/analyzer/validators/contracts.validator.js +42 -0
  20. package/dist/apps/cli/src/analyzer/validators/maintainability.validator.js +40 -0
  21. package/dist/apps/cli/src/analyzer/validators/observability.validator.js +39 -0
  22. package/dist/apps/cli/src/analyzer/validators/performance.validator.js +42 -0
  23. package/dist/apps/cli/src/analyzer/validators/security.validator.js +66 -0
  24. package/dist/apps/cli/src/analyzer/validators/soc.validator.js +75 -0
  25. package/dist/apps/cli/src/auth/secure-auth.js +312 -0
  26. package/dist/apps/cli/src/commands/analyze.js +286 -0
  27. package/dist/apps/cli/src/commands/auth-new.js +37 -0
  28. package/dist/apps/cli/src/commands/auth.js +122 -0
  29. package/dist/apps/cli/src/commands/config.js +49 -0
  30. package/dist/apps/cli/src/commands/deploy.js +6 -0
  31. package/dist/apps/cli/src/commands/init.js +47 -0
  32. package/dist/apps/cli/src/commands/logout.js +23 -0
  33. package/dist/apps/cli/src/commands/plugins.js +21 -0
  34. package/dist/apps/cli/src/commands/status.js +80 -0
  35. package/dist/apps/cli/src/commands/sync.js +6 -0
  36. package/dist/apps/cli/src/commands/whoami.js +115 -0
  37. package/dist/apps/cli/src/components/Dashboard.js +168 -0
  38. package/dist/apps/cli/src/components/DeltaApp.js +56 -0
  39. package/dist/apps/cli/src/components/UnifiedManager.js +324 -0
  40. package/dist/apps/cli/src/core/audit.js +184 -0
  41. package/dist/apps/cli/src/core/completion.js +294 -0
  42. package/dist/apps/cli/src/core/contracts.js +6 -0
  43. package/dist/apps/cli/src/core/engine.js +124 -0
  44. package/dist/apps/cli/src/core/exit-codes.js +71 -0
  45. package/dist/apps/cli/src/core/hooks.js +181 -0
  46. package/dist/apps/cli/src/core/index.js +7 -0
  47. package/dist/apps/cli/src/core/policy.js +115 -0
  48. package/dist/apps/cli/src/core/profiles.js +161 -0
  49. package/dist/apps/cli/src/core/wizard.js +203 -0
  50. package/dist/apps/cli/src/index.js +636 -0
  51. package/dist/apps/cli/src/interactive/index.js +11 -0
  52. package/dist/apps/cli/src/plugins/GitStatusPlugin.js +99 -0
  53. package/dist/apps/cli/src/providers/ai-provider.js +74 -0
  54. package/dist/apps/cli/src/providers/local-provider.js +302 -0
  55. package/dist/apps/cli/src/providers/remote-provider.js +100 -0
  56. package/dist/apps/cli/src/types/api.js +3 -0
  57. package/dist/apps/cli/src/ui.js +219 -0
  58. package/dist/apps/cli/src/welcome.js +81 -0
  59. package/dist/auth/secure-auth.js +418 -0
  60. package/dist/bundle.js +45 -45
  61. package/dist/commands/analyze.js +363 -0
  62. package/dist/commands/auth-new.js +37 -0
  63. package/dist/commands/auth.js +133 -0
  64. package/dist/commands/config.js +50 -0
  65. package/dist/commands/deploy.js +6 -0
  66. package/dist/commands/init.js +47 -0
  67. package/dist/commands/logout.js +30 -0
  68. package/dist/commands/plugins.js +21 -0
  69. package/dist/commands/status.js +82 -0
  70. package/dist/commands/sync.js +6 -0
  71. package/dist/commands/whoami.js +71 -0
  72. package/dist/components/Dashboard.js +169 -0
  73. package/dist/components/DeltaApp.js +57 -0
  74. package/dist/components/UnifiedManager.js +344 -0
  75. package/dist/core/audit.js +184 -0
  76. package/dist/core/completion.js +294 -0
  77. package/dist/core/contracts.js +6 -0
  78. package/dist/core/engine.js +124 -0
  79. package/dist/core/exit-codes.js +71 -0
  80. package/dist/core/hooks.js +181 -0
  81. package/dist/core/index.js +7 -0
  82. package/dist/core/policy.js +115 -0
  83. package/dist/core/profiles.js +161 -0
  84. package/dist/core/wizard.js +203 -0
  85. package/dist/index.js +387 -0
  86. package/dist/interactive/index.js +11 -0
  87. package/dist/packages/domain/src/constitution/contracts/index.js +43 -0
  88. package/dist/packages/domain/src/constitution/contracts/ts.rules.js +268 -0
  89. package/dist/packages/domain/src/constitution/index.js +139 -0
  90. package/dist/packages/domain/src/constitution/maintainability/index.js +43 -0
  91. package/dist/packages/domain/src/constitution/maintainability/ts.rules.js +344 -0
  92. package/dist/packages/domain/src/constitution/observability/index.js +43 -0
  93. package/dist/packages/domain/src/constitution/observability/ts.rules.js +307 -0
  94. package/dist/packages/domain/src/constitution/performance/index.js +43 -0
  95. package/dist/packages/domain/src/constitution/performance/ts.rules.js +325 -0
  96. package/dist/packages/domain/src/constitution/security/index.js +50 -0
  97. package/dist/packages/domain/src/constitution/security/ts.rules.js +267 -0
  98. package/dist/packages/domain/src/constitution/soc/index.js +43 -0
  99. package/dist/packages/domain/src/constitution/soc/ts.rules.js +360 -0
  100. package/dist/packages/domain/src/contracts/analysis.contract.js +18 -0
  101. package/dist/packages/domain/src/contracts/index.js +7 -0
  102. package/dist/packages/domain/src/contracts/projects.contract.js +18 -0
  103. package/dist/packages/domain/src/control/registry/rules.registry.js +29 -0
  104. package/dist/packages/domain/src/control/schemas/policies.js +6 -0
  105. package/dist/packages/domain/src/core/analysis/discovery.js +163 -0
  106. package/dist/packages/domain/src/core/analysis/engine.contract.js +298 -0
  107. package/dist/packages/domain/src/core/analysis/engine.js +77 -0
  108. package/dist/packages/domain/src/core/analysis/index.js +14 -0
  109. package/dist/packages/domain/src/core/analysis/orchestrator.js +242 -0
  110. package/dist/packages/domain/src/core/comparison/engine.js +29 -0
  111. package/dist/packages/domain/src/core/comparison/index.js +5 -0
  112. package/dist/packages/domain/src/core/documentation/index.js +5 -0
  113. package/dist/packages/domain/src/core/documentation/pipeline.js +41 -0
  114. package/dist/packages/domain/src/core/fs/adapter.js +111 -0
  115. package/dist/packages/domain/src/core/fs/index.js +5 -0
  116. package/dist/packages/domain/src/core/parser/unified-parser.js +166 -0
  117. package/dist/packages/domain/src/index.js +33 -0
  118. package/dist/packages/domain/src/plugin/registry.js +195 -0
  119. package/dist/packages/domain/src/plugin/types.js +6 -0
  120. package/dist/packages/domain/src/ports/analysis.engine.js +7 -0
  121. package/dist/packages/domain/src/ports/audit.logger.js +7 -0
  122. package/dist/packages/domain/src/ports/project.repository.js +7 -0
  123. package/dist/packages/domain/src/rules/index.js +134 -0
  124. package/dist/packages/domain/src/types/analysis.js +6 -0
  125. package/dist/packages/domain/src/types/errors.js +53 -0
  126. package/dist/packages/domain/src/types/fs.js +6 -0
  127. package/dist/packages/domain/src/types/index.js +7 -0
  128. package/dist/plugins/GitStatusPlugin.js +93 -0
  129. package/dist/providers/ai-provider.js +74 -0
  130. package/dist/providers/local-provider.js +304 -0
  131. package/dist/providers/remote-provider.js +100 -0
  132. package/dist/types/api.js +3 -0
  133. package/dist/ui.js +219 -0
  134. package/dist/welcome.js +81 -0
  135. package/package.json +18 -18
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Delta Constitution - Performance Rules Index
3
+ * @description Performance rules for all supported languages
4
+ * @version 1.0.0
5
+ */
6
+ // TypeScript / Node.js Rules
7
+ export { default as ts, PerformanceRules as TSPerformanceRules } from './ts.rules';
8
+ // Language-agnostic exports
9
+ export const PerformanceAxis = {
10
+ name: 'Performance',
11
+ description: 'Lazy Loading, Caching, Code Splitting, Bundle Optimization',
12
+ weight: 20,
13
+ languages: ['typescript', 'javascript', 'node'],
14
+ principles: [
15
+ {
16
+ id: 'PERF-001',
17
+ name: 'Lazy Loading',
18
+ description: 'Each Feature must be lazy-loadable independently',
19
+ },
20
+ {
21
+ id: 'PERF-002',
22
+ name: 'Code Splitting',
23
+ description: 'Automatic chunking per Feature and Route',
24
+ },
25
+ {
26
+ id: 'PERF-003',
27
+ name: 'Caching Layers',
28
+ description: 'Multi-layer caching (L1 Memory, L2 SWR, L3 Redis)',
29
+ },
30
+ {
31
+ id: 'PERF-004',
32
+ name: 'Bundle Optimization',
33
+ description: 'Tree shaking, compression, size limits',
34
+ },
35
+ {
36
+ id: 'PERF-005',
37
+ name: 'Stateless Core',
38
+ description: 'Stateless Core for easy concurrency',
39
+ },
40
+ ],
41
+ };
42
+ export default PerformanceAxis;
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Delta Constitution - Performance Rules
3
+ * @description Performance standards and optimization guidelines
4
+ * @version 1.0.0
5
+ * @see docs/architecture/CONSTITUTION.md
6
+ */
7
+ // =============================================================================
8
+ // PERFORMANCE RULE DEFINITIONS
9
+ // =============================================================================
10
+ export const PerformanceRules = {
11
+ version: '1.0.0',
12
+ lastUpdated: '2026-02-10',
13
+ // ============================================================================
14
+ // 1. LAZY LOADING
15
+ // ============================================================================
16
+ lazyLoading: {
17
+ enabled: true,
18
+ required: true,
19
+ description: 'Each Feature must be lazy-loadable independently',
20
+ requirements: {
21
+ features: {
22
+ pattern: 'dynamic imports',
23
+ implementation: 'React.lazy() or Next.js dynamic()',
24
+ required: true,
25
+ },
26
+ components: {
27
+ pattern: 'dynamic imports for heavy components',
28
+ implementation: 'Component-level code splitting',
29
+ required: true,
30
+ },
31
+ routes: {
32
+ pattern: 'route-based code splitting',
33
+ implementation: 'Next.js automatic code splitting',
34
+ required: true,
35
+ },
36
+ },
37
+ patterns: {
38
+ correct: [
39
+ "const UploadFeature = dynamic(() => import('@/features/upload'))",
40
+ "const HeavyChart = lazy(() => import('./HeavyChart'))",
41
+ ],
42
+ forbidden: [
43
+ "import { UploadFeature } from '@/features/upload' // static import of heavy feature",
44
+ ],
45
+ },
46
+ check: {
47
+ maxInitialBundle: '500KB',
48
+ maxFeatureBundle: '200KB',
49
+ },
50
+ },
51
+ // ============================================================================
52
+ // 2. CODE SPLITTING
53
+ // ============================================================================
54
+ codeSplitting: {
55
+ enabled: true,
56
+ required: true,
57
+ description: 'Automatic chunking per Feature and Route',
58
+ strategies: {
59
+ routeBased: {
60
+ enabled: true,
61
+ description: 'Next.js automatically splits by route',
62
+ },
63
+ componentBased: {
64
+ enabled: true,
65
+ description: 'Large components loaded on demand',
66
+ threshold: '50KB',
67
+ },
68
+ libraryBased: {
69
+ enabled: true,
70
+ description: 'Heavy libraries (charts, editors) split separately',
71
+ },
72
+ },
73
+ bundleTargets: {
74
+ initial: '300KB',
75
+ async: '150KB per chunk',
76
+ total: '2MB max',
77
+ },
78
+ },
79
+ // ============================================================================
80
+ // 3. CACHING LAYERS
81
+ // ============================================================================
82
+ caching: {
83
+ enabled: true,
84
+ required: true,
85
+ description: 'Multi-layer caching strategy',
86
+ layers: {
87
+ l1_memory: {
88
+ name: 'L1: In-Memory Cache',
89
+ scope: 'process',
90
+ ttl: '5 minutes',
91
+ useCase: 'AST parsing results, computed values',
92
+ implementation: 'lru-cache or Map',
93
+ },
94
+ l2_swr: {
95
+ name: 'L2: SWR/React Query',
96
+ scope: 'client',
97
+ ttl: 'configurable',
98
+ useCase: 'API data, user data',
99
+ implementation: 'SWR or React Query',
100
+ },
101
+ l3_redis: {
102
+ name: 'L3: Redis Cache',
103
+ scope: 'server',
104
+ ttl: '1 hour',
105
+ useCase: 'Session data, rate limiting',
106
+ implementation: 'Redis',
107
+ },
108
+ l4_fs: {
109
+ name: 'L4: File System Cache',
110
+ scope: 'server',
111
+ ttl: '1 hour',
112
+ useCase: 'Reports, temporary files',
113
+ implementation: 'OS temp directory',
114
+ },
115
+ },
116
+ rules: [
117
+ {
118
+ id: 'PERF-CACHE-001',
119
+ name: 'Cache Pure Functions',
120
+ description: 'Core pure functions can be safely cached',
121
+ severity: 'recommendation',
122
+ },
123
+ {
124
+ id: 'PERF-CACHE-002',
125
+ name: 'No Cache Without TTL',
126
+ description: 'All caches must have expiration',
127
+ severity: 'warning',
128
+ },
129
+ ],
130
+ },
131
+ // ============================================================================
132
+ // 4. BUNDLE OPTIMIZATION
133
+ // ============================================================================
134
+ bundleOptimization: {
135
+ enabled: true,
136
+ required: true,
137
+ description: 'Optimized bundle size and tree shaking',
138
+ targets: {
139
+ initialLoad: '300KB',
140
+ timeToInteractive: '3 seconds',
141
+ lighthousePerformance: '90+',
142
+ },
143
+ techniques: {
144
+ treeShaking: {
145
+ enabled: true,
146
+ description: 'Dead code elimination',
147
+ requirement: 'Use ES modules (import/export)',
148
+ },
149
+ dynamicImports: {
150
+ enabled: true,
151
+ description: 'Load code on demand',
152
+ requirement: 'Split by feature/route',
153
+ },
154
+ dependencyOptimization: {
155
+ enabled: true,
156
+ description: 'Optimize third-party deps',
157
+ tools: ['webpack-bundle-analyzer', 'next-bundle-analyzer'],
158
+ },
159
+ compression: {
160
+ enabled: true,
161
+ description: 'Gzip/Brotli compression',
162
+ requirement: 'Enabled in production',
163
+ },
164
+ },
165
+ sizeLimits: {
166
+ totalBundle: '2MB',
167
+ initialBundle: '500KB',
168
+ asyncChunks: '200KB each',
169
+ images: '100KB (use WebP)',
170
+ },
171
+ },
172
+ // ============================================================================
173
+ // 5. STATELESS CORE FOR CONCURRENCY
174
+ // ============================================================================
175
+ statelessCore: {
176
+ enabled: true,
177
+ required: true,
178
+ description: 'Stateless Core enables easy concurrency and load distribution',
179
+ benefits: {
180
+ concurrency: 'Functions can run in parallel without conflicts',
181
+ caching: 'Same input = same output, highly cacheable',
182
+ testing: 'Easy to test without mocking state',
183
+ distribution: 'Can distribute load across workers',
184
+ },
185
+ rules: [
186
+ {
187
+ id: 'PERF-STATE-001',
188
+ name: 'Pure Functions Only',
189
+ description: 'Core functions must be pure',
190
+ pattern: 'function analyze(input): output',
191
+ forbidden: ['global variables', 'closures with state', 'side effects'],
192
+ },
193
+ {
194
+ id: 'PERF-STATE-002',
195
+ name: 'No Singletons in Core',
196
+ description: 'Core must not use singleton pattern',
197
+ forbidden: ['export const service = new Service()', 'global state'],
198
+ },
199
+ ],
200
+ },
201
+ // ============================================================================
202
+ // 6. RENDER OPTIMIZATION
203
+ // ============================================================================
204
+ renderOptimization: {
205
+ enabled: true,
206
+ required: true,
207
+ description: 'React rendering optimizations',
208
+ patterns: {
209
+ memoization: {
210
+ useMemo: 'For expensive computations',
211
+ useCallback: 'For function props',
212
+ ReactMemo: 'For component memoization',
213
+ },
214
+ virtualization: {
215
+ description: 'For long lists',
216
+ libraries: ['react-window', 'react-virtualized'],
217
+ },
218
+ suspense: {
219
+ description: 'For async boundaries',
220
+ pattern: '<Suspense fallback={<Loading />}><AsyncComponent /></Suspense>',
221
+ },
222
+ },
223
+ rules: [
224
+ {
225
+ id: 'PERF-RENDER-001',
226
+ name: 'Avoid Unnecessary Rerenders',
227
+ description: 'Use memoization for expensive components',
228
+ },
229
+ {
230
+ id: 'PERF-RENDER-002',
231
+ name: 'Virtualize Long Lists',
232
+ description: 'Lists > 100 items must be virtualized',
233
+ },
234
+ ],
235
+ },
236
+ // ============================================================================
237
+ // 7. API PERFORMANCE
238
+ // ============================================================================
239
+ apiPerformance: {
240
+ enabled: true,
241
+ required: true,
242
+ description: 'API endpoint performance targets',
243
+ targets: {
244
+ p50: '100ms',
245
+ p95: '300ms',
246
+ p99: '500ms',
247
+ timeout: '30 seconds',
248
+ },
249
+ optimizations: {
250
+ pagination: {
251
+ required: true,
252
+ description: 'All list endpoints must support pagination',
253
+ default: '20 items per page',
254
+ max: '100 items per page',
255
+ },
256
+ compression: {
257
+ required: true,
258
+ description: 'Response compression for large payloads',
259
+ algorithm: 'gzip or brotli',
260
+ },
261
+ caching: {
262
+ required: true,
263
+ description: 'ETag and Cache-Control headers',
264
+ },
265
+ },
266
+ },
267
+ };
268
+ // =============================================================================
269
+ // VALIDATION HELPERS
270
+ // =============================================================================
271
+ export function validatePerformanceCompliance(bundleAnalysis) {
272
+ const violations = [];
273
+ let score = 100;
274
+ // Check bundle size
275
+ if (bundleAnalysis.initial > 500) {
276
+ violations.push(`PERF-BUNDLE-001: Initial bundle ${bundleAnalysis.initial}KB exceeds 500KB limit`);
277
+ score -= 20;
278
+ }
279
+ if (bundleAnalysis.total > 2048) {
280
+ violations.push(`PERF-BUNDLE-002: Total bundle ${bundleAnalysis.total}KB exceeds 2MB limit`);
281
+ score -= 15;
282
+ }
283
+ // Check async chunk size
284
+ if (bundleAnalysis.asyncChunk > 200) {
285
+ violations.push(`PERF-BUNDLE-003: Async chunk ${bundleAnalysis.asyncChunk}KB exceeds 200KB limit`);
286
+ score -= 10;
287
+ }
288
+ return {
289
+ compliant: violations.length === 0,
290
+ violations,
291
+ score: Math.max(0, score),
292
+ };
293
+ }
294
+ export function calculatePerformanceScore(metrics) {
295
+ const maxScore = 100;
296
+ let score = 0;
297
+ // Lazy loading (20 points)
298
+ if (metrics.hasLazyLoading)
299
+ score += 20;
300
+ // Code splitting (15 points)
301
+ if (metrics.hasCodeSplitting)
302
+ score += 15;
303
+ // Caching (20 points)
304
+ if (metrics.hasCaching)
305
+ score += 15;
306
+ if (metrics.hasMultiLayerCache)
307
+ score += 5;
308
+ // Bundle optimization (20 points)
309
+ if (metrics.bundleSize < 500)
310
+ score += 15;
311
+ if (metrics.hasTreeShaking)
312
+ score += 5;
313
+ // Stateless core (15 points)
314
+ if (metrics.hasPureFunctions)
315
+ score += 15;
316
+ // Render optimization (10 points)
317
+ if (metrics.hasMemoization)
318
+ score += 5;
319
+ if (metrics.hasVirtualization)
320
+ score += 5;
321
+ const grade = score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F';
322
+ return { score, maxScore, grade };
323
+ }
324
+ export default PerformanceRules;
325
+ //# sourceMappingURL=ts.rules.js.map
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Delta Constitution - Security Rules Index
3
+ * @description Security rules for all supported languages
4
+ * @version 1.0.0
5
+ */
6
+ // TypeScript / Node.js Rules
7
+ export { default as ts, SecurityRules as TSSecurityRules } from './ts.rules';
8
+ // Future language support:
9
+ // export { default as py } from './py.rules';
10
+ // export { default as java } from './java.rules';
11
+ // export { default as cs } from './cs.rules';
12
+ // export { default as go } from './go.rules';
13
+ // Language-agnostic exports
14
+ export const SecurityAxis = {
15
+ name: 'Security',
16
+ description: 'Policy-driven, Fail-Closed, Audit, Rate Limiting',
17
+ weight: 25, // Percentage in overall score
18
+ // Supported languages
19
+ languages: ['typescript', 'javascript', 'node'],
20
+ // Key principles (language-agnostic)
21
+ principles: [
22
+ {
23
+ id: 'SEC-001',
24
+ name: 'Policy-Driven',
25
+ description: 'All constraints defined in Policies, not hardcoded',
26
+ },
27
+ {
28
+ id: 'SEC-002',
29
+ name: 'Fail-Closed',
30
+ description: 'Default deny - anything not explicitly allowed is forbidden',
31
+ },
32
+ {
33
+ id: 'SEC-003',
34
+ name: 'Audit Logging',
35
+ description: 'Complete audit trail for every operation',
36
+ },
37
+ {
38
+ id: 'SEC-004',
39
+ name: 'Rate Limiting',
40
+ description: 'Distributed + Centralized rate limiting',
41
+ },
42
+ {
43
+ id: 'SEC-005',
44
+ name: 'Input Validation',
45
+ description: 'Strict validation at every layer',
46
+ },
47
+ ],
48
+ };
49
+ export default SecurityAxis;
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Delta Constitution - Security Rules
3
+ * @description Security standards and rules for Delta Architecture
4
+ * @version 1.0.0
5
+ * @see docs/architecture/CONSTITUTION.md
6
+ */
7
+ // =============================================================================
8
+ // SECURITY RULE DEFINITIONS
9
+ // =============================================================================
10
+ export const SecurityRules = {
11
+ version: '1.0.0',
12
+ lastUpdated: '2026-02-10',
13
+ // ============================================================================
14
+ // 1. POLICY-DRIVEN ARCHITECTURE
15
+ // ============================================================================
16
+ policyDriven: {
17
+ enabled: true,
18
+ required: true,
19
+ description: 'All system constraints must be defined in Policies, not hardcoded',
20
+ rules: [
21
+ {
22
+ id: 'SEC-POL-001',
23
+ name: 'No Hardcoded Limits',
24
+ description: 'No magic numbers or hardcoded limits in business logic',
25
+ severity: 'error',
26
+ examples: {
27
+ forbidden: [
28
+ 'if (file.size > 52428800) throw new Error()',
29
+ 'if (code.includes("eval")) reportIssue()',
30
+ 'const MAX_SIZE = 1000000',
31
+ ],
32
+ correct: [
33
+ 'const policy = policies.get("file-size")',
34
+ 'if (file.size > policy.maxSize) reportIssue(policy)',
35
+ ],
36
+ },
37
+ },
38
+ {
39
+ id: 'SEC-POL-002',
40
+ name: 'Policy Registry Required',
41
+ description: 'Every module must have a policies/ directory with definitions',
42
+ severity: 'error',
43
+ check: {
44
+ pathPattern: 'src/modules/*/policies/',
45
+ requiredFiles: ['index.ts'],
46
+ },
47
+ },
48
+ ],
49
+ },
50
+ // ============================================================================
51
+ // 2. FAIL-CLOSED PRINCIPLE
52
+ // ============================================================================
53
+ failClosed: {
54
+ enabled: true,
55
+ required: true,
56
+ description: 'Default deny - anything not explicitly allowed is forbidden',
57
+ rules: [
58
+ {
59
+ id: 'SEC-FAIL-001',
60
+ name: 'Default Deny Pattern',
61
+ description: 'All authorization checks must use default deny',
62
+ severity: 'critical',
63
+ pattern: {
64
+ forbidden: 'if (isBlocked) return deny()',
65
+ required: 'if (!isAllowed) return deny()',
66
+ },
67
+ },
68
+ {
69
+ id: 'SEC-FAIL-002',
70
+ name: 'Error Handling',
71
+ description: 'On error, default to denial, not allowance',
72
+ severity: 'critical',
73
+ examples: {
74
+ forbidden: [
75
+ 'try { risky() } catch (e) { return { allowed: true } }',
76
+ 'catch (e) { return { allowed: true, reason: "fallback" } }',
77
+ ],
78
+ correct: [
79
+ 'try { risky() } catch (e) { return deny(e) }',
80
+ 'catch (e) { auditLog(e); return { allowed: false } }',
81
+ ],
82
+ },
83
+ },
84
+ ],
85
+ },
86
+ // ============================================================================
87
+ // 3. AUDIT LOGGING
88
+ // ============================================================================
89
+ auditLogging: {
90
+ enabled: true,
91
+ required: true,
92
+ description: 'Complete audit trail for every operation across all layers',
93
+ requirements: {
94
+ coverage: '100%',
95
+ layers: ['features', 'modules', 'core', 'security'],
96
+ events: [
97
+ { action: 'auth:login', level: 'info', required: true },
98
+ { action: 'auth:logout', level: 'info', required: true },
99
+ { action: 'auth:failed', level: 'warning', required: true },
100
+ { action: 'upload:init', level: 'info', required: true },
101
+ { action: 'upload:complete', level: 'info', required: true },
102
+ { action: 'upload:failed', level: 'error', required: true },
103
+ { action: 'analysis:start', level: 'info', required: true },
104
+ { action: 'analysis:complete', level: 'info', required: true },
105
+ { action: 'policy:violation', level: 'warning', required: true },
106
+ { action: 'permission:denied', level: 'warning', required: true },
107
+ ],
108
+ },
109
+ schema: {
110
+ required: ['action', 'userId', 'timestamp', 'success'],
111
+ optional: ['metadata', 'severity', 'ip', 'userAgent'],
112
+ },
113
+ },
114
+ // ============================================================================
115
+ // 4. RATE LIMITING
116
+ // ============================================================================
117
+ rateLimiting: {
118
+ enabled: true,
119
+ required: true,
120
+ description: 'Distributed + Centralized rate limiting (Memory + Redis)',
121
+ strategies: {
122
+ memory: {
123
+ enabled: true,
124
+ useCase: 'single-instance deployments',
125
+ storage: 'in-memory Map',
126
+ ttl: 'configurable',
127
+ },
128
+ redis: {
129
+ enabled: true,
130
+ useCase: 'multi-instance deployments',
131
+ storage: 'redis',
132
+ distributed: true,
133
+ },
134
+ },
135
+ endpoints: [
136
+ { path: '/api/auth/*', limit: '5 requests per minute', burst: 10 },
137
+ { path: '/api/upload/*', limit: '10 requests per minute', burst: 20 },
138
+ { path: '/api/analysis/*', limit: '20 requests per minute', burst: 50 },
139
+ ],
140
+ },
141
+ // ============================================================================
142
+ // 5. INPUT VALIDATION
143
+ // ============================================================================
144
+ inputValidation: {
145
+ enabled: true,
146
+ required: true,
147
+ description: 'Strict validation at every layer using schemas',
148
+ layers: {
149
+ features: {
150
+ validation: 'Zod schemas',
151
+ location: 'hooks and services',
152
+ example: 'useUpload.ts validates input before service call',
153
+ },
154
+ modules: {
155
+ validation: 'TypeScript + runtime checks',
156
+ location: 'business logic entry points',
157
+ },
158
+ contracts: {
159
+ validation: 'Contract schema definitions',
160
+ location: 'contract interfaces',
161
+ },
162
+ },
163
+ schemas: [
164
+ { name: 'UploadInput', required: true, file: 'src/contracts/upload.contract.ts' },
165
+ { name: 'AuthInput', required: true, file: 'src/contracts/auth.contract.ts' },
166
+ { name: 'AnalysisInput', required: true, file: 'src/contracts/analysis.contract.ts' },
167
+ ],
168
+ },
169
+ // ============================================================================
170
+ // 6. ENVIRONMENT VALIDATION
171
+ // ============================================================================
172
+ envValidation: {
173
+ enabled: true,
174
+ required: true,
175
+ description: 'All environment variables validated at startup',
176
+ requiredVars: ['SUPABASE_URL', 'SUPABASE_ANON_KEY', 'JWT_SECRET', 'ENCRYPTION_KEY'],
177
+ optional: ['REDIS_URL', 'SENTRY_DSN', 'FEATURE_FLAGS_URL'],
178
+ validation: {
179
+ atStartup: true,
180
+ strict: true,
181
+ failOnMissing: true,
182
+ },
183
+ },
184
+ // ============================================================================
185
+ // 7. PERMISSION GUARDS
186
+ // ============================================================================
187
+ permissionGuards: {
188
+ enabled: true,
189
+ required: true,
190
+ description: 'RBAC + Policy guards at every entry point',
191
+ locations: [
192
+ 'src/security/policy-enforcement/guard.ts',
193
+ 'src/auth/guards.ts',
194
+ 'src/features/*/hooks/usePermissions.ts',
195
+ ],
196
+ patterns: {
197
+ required: [
198
+ 'requirePermission()',
199
+ 'requireAnyPermission()',
200
+ 'requireAllPermissions()',
201
+ 'withPermission()',
202
+ ],
203
+ hooks: ['usePermission()', 'useAuth()'],
204
+ },
205
+ },
206
+ };
207
+ // =============================================================================
208
+ // VALIDATION HELPERS
209
+ // =============================================================================
210
+ export function validateSecurityCompliance(projectStructure) {
211
+ const violations = [];
212
+ // Check policy-driven architecture
213
+ if (!projectStructure.hasPolicyRegistry) {
214
+ violations.push('SEC-POL-002: Missing policies/ directory in modules');
215
+ }
216
+ // Check audit logging
217
+ if (!projectStructure.hasAuditLogging) {
218
+ violations.push('SEC-AUDIT-001: Missing audit logging implementation');
219
+ }
220
+ // Check rate limiting
221
+ if (!projectStructure.hasRateLimiting) {
222
+ violations.push('SEC-RATE-001: Missing rate limiting implementation');
223
+ }
224
+ // Check fail-closed patterns
225
+ if (projectStructure.hasFailOpenPatterns) {
226
+ violations.push('SEC-FAIL-001: Found fail-open patterns in code');
227
+ }
228
+ return {
229
+ compliant: violations.length === 0,
230
+ violations,
231
+ };
232
+ }
233
+ // =============================================================================
234
+ // SCORING
235
+ // =============================================================================
236
+ export function calculateSecurityScore(checks) {
237
+ const maxScore = 100;
238
+ let score = 0;
239
+ // Policy-driven (25 points)
240
+ if (checks.hasPolicyRegistry)
241
+ score += 15;
242
+ if (checks.hasNoHardcodedLimits)
243
+ score += 10;
244
+ // Fail-closed (25 points)
245
+ if (checks.hasDefaultDeny)
246
+ score += 15;
247
+ if (checks.hasProperErrorHandling)
248
+ score += 10;
249
+ // Audit logging (20 points)
250
+ if (checks.hasAuditLogging)
251
+ score += 20;
252
+ // Rate limiting (15 points)
253
+ if (checks.hasRateLimiting)
254
+ score += 15;
255
+ // Input validation (15 points)
256
+ if (checks.hasInputValidation)
257
+ score += 10;
258
+ if (checks.hasEnvValidation)
259
+ score += 5;
260
+ return {
261
+ score,
262
+ maxScore,
263
+ percentage: Math.round((score / maxScore) * 100),
264
+ };
265
+ }
266
+ export default SecurityRules;
267
+ //# sourceMappingURL=ts.rules.js.map