specialist-agent 2.9.0 → 2.10.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.
@@ -0,0 +1,713 @@
1
+ /**
2
+ * Architecture Pattern Registry
3
+ *
4
+ * Comprehensive catalog of software architecture patterns with:
5
+ * - Detection heuristics (directory structure, file patterns, code patterns)
6
+ * - Full and simplified (lite) variants
7
+ * - Framework-specific adaptations
8
+ * - Migration paths between patterns
9
+ * - Team size and project size recommendations
10
+ */
11
+
12
+ // ── Architecture Pattern Definitions ───────────────────
13
+
14
+ export const ARCHITECTURE_PATTERNS = {
15
+ // ── Frontend Architectures ──────────────────────────
16
+
17
+ 'modular': {
18
+ id: 'modular',
19
+ name: 'Modular (Feature-Based)',
20
+ category: 'frontend',
21
+ description: 'Vertical slicing by feature/domain. Each module is a bounded context with its own components, services, types.',
22
+ bestFor: {
23
+ teamSize: '2-15',
24
+ projectSize: 'medium-large',
25
+ description: 'Teams that want clear ownership per feature, good module isolation without heavy ceremony.',
26
+ },
27
+ detection: {
28
+ requiredDirs: ['modules', 'shared'],
29
+ optionalDirs: ['app', 'assets', 'config'],
30
+ moduleSubDirs: ['components', 'services', 'types'],
31
+ optionalModuleSubDirs: ['adapters', 'hooks', 'composables', 'stores', 'actions', 'views', 'pages', '__tests__'],
32
+ filePatterns: ['**/modules/*/index.ts', '**/modules/*/index.tsx'],
33
+ antiPatterns: ['controllers', 'models', 'views', 'atoms', 'molecules', 'organisms'],
34
+ codePatterns: [],
35
+ minScore: 5,
36
+ },
37
+ migrationPaths: ['clean', 'hexagonal', 'fsd', 'ddd', 'modular-monolith'],
38
+ },
39
+
40
+ 'fsd': {
41
+ id: 'fsd',
42
+ name: 'Feature-Sliced Design (FSD)',
43
+ category: 'frontend',
44
+ description: 'Layered architecture with strict import rules: app > pages > widgets > features > entities > shared.',
45
+ bestFor: {
46
+ teamSize: '5-30',
47
+ projectSize: 'large',
48
+ description: 'Large teams needing strict import discipline and clear layer boundaries.',
49
+ },
50
+ detection: {
51
+ requiredDirs: [],
52
+ optionalDirs: ['app', 'processes', 'pages', 'widgets', 'features', 'entities', 'shared'],
53
+ moduleSubDirs: [],
54
+ optionalModuleSubDirs: ['ui', 'model', 'api', 'lib', 'config'],
55
+ filePatterns: [],
56
+ antiPatterns: ['controllers', 'models'],
57
+ codePatterns: [],
58
+ minScore: 6,
59
+ // Special: needs at least 3 of the FSD layers
60
+ customRule: 'fsd-layers',
61
+ },
62
+ migrationPaths: ['modular', 'clean', 'hexagonal'],
63
+ },
64
+
65
+ 'atomic': {
66
+ id: 'atomic',
67
+ name: 'Atomic Design',
68
+ category: 'frontend',
69
+ description: 'Components organized by granularity: atoms > molecules > organisms > templates > pages.',
70
+ bestFor: {
71
+ teamSize: '2-10',
72
+ projectSize: 'medium',
73
+ description: 'Design-system-heavy projects with strong designer-developer collaboration.',
74
+ },
75
+ detection: {
76
+ requiredDirs: [],
77
+ optionalDirs: ['atoms', 'molecules', 'organisms', 'templates', 'pages'],
78
+ moduleSubDirs: [],
79
+ optionalModuleSubDirs: [],
80
+ filePatterns: ['**/atoms/**', '**/molecules/**', '**/organisms/**'],
81
+ antiPatterns: ['modules', 'features', 'domain', 'use-cases'],
82
+ codePatterns: [],
83
+ minScore: 4,
84
+ customRule: 'atomic-layers',
85
+ },
86
+ migrationPaths: ['modular', 'fsd'],
87
+ },
88
+
89
+ 'mvc': {
90
+ id: 'mvc',
91
+ name: 'MVC / MVVM / Layered',
92
+ category: 'fullstack',
93
+ description: 'Horizontal slicing by technical layer: controllers, models, views/components.',
94
+ bestFor: {
95
+ teamSize: '1-5',
96
+ projectSize: 'small-medium',
97
+ description: 'Small teams familiar with server-side MVC. Simple CRUD applications.',
98
+ },
99
+ detection: {
100
+ requiredDirs: [],
101
+ optionalDirs: ['controllers', 'models', 'views', 'middlewares', 'middleware', 'routes', 'repositories', 'services', 'viewmodels', 'view-models', 'presenters'],
102
+ moduleSubDirs: [],
103
+ optionalModuleSubDirs: [],
104
+ filePatterns: ['**/*-controller.*', '**/*-model.*', '**/*.controller.*', '**/*.model.*', '**/*.service.*'],
105
+ antiPatterns: ['modules', 'features', 'domain', 'use-cases', 'ports', 'adapters'],
106
+ codePatterns: [],
107
+ minScore: 4,
108
+ },
109
+ migrationPaths: ['modular', 'clean', 'modular-monolith'],
110
+ },
111
+
112
+ 'clean': {
113
+ id: 'clean',
114
+ name: 'Clean Architecture',
115
+ category: 'fullstack',
116
+ description: 'Concentric layers with dependency rule: Entities > Use Cases > Adapters > Frameworks.',
117
+ bestFor: {
118
+ teamSize: '5-30',
119
+ projectSize: 'large',
120
+ description: 'Complex business domains needing strict separation of concerns and testability.',
121
+ },
122
+ detection: {
123
+ requiredDirs: [],
124
+ optionalDirs: ['domain', 'entities', 'use-cases', 'usecases', 'application', 'infrastructure', 'presentation', 'interfaces', 'frameworks'],
125
+ moduleSubDirs: [],
126
+ optionalModuleSubDirs: ['value-objects', 'repositories', 'dtos'],
127
+ filePatterns: ['**/use-cases/**', '**/usecases/**', '**/domain/entities/**'],
128
+ antiPatterns: ['controllers', 'models', 'views'],
129
+ codePatterns: [],
130
+ minScore: 5,
131
+ },
132
+ migrationPaths: ['hexagonal', 'ddd', 'microservices'],
133
+ },
134
+
135
+ 'hexagonal': {
136
+ id: 'hexagonal',
137
+ name: 'Hexagonal (Ports & Adapters)',
138
+ category: 'fullstack',
139
+ description: 'Core domain isolated by ports (interfaces) and adapters (implementations). Infrastructure swappable.',
140
+ bestFor: {
141
+ teamSize: '5-20',
142
+ projectSize: 'large',
143
+ description: 'Projects needing multiple entry points or infrastructure flexibility.',
144
+ },
145
+ detection: {
146
+ requiredDirs: [],
147
+ optionalDirs: ['ports', 'adapters', 'domain', 'core', 'infrastructure'],
148
+ moduleSubDirs: [],
149
+ optionalModuleSubDirs: ['in', 'out', 'primary', 'secondary', 'driving', 'driven'],
150
+ filePatterns: ['**/ports/**/*Port*', '**/ports/**/*port*', '**/adapters/**/*Adapter*', '**/adapters/**/*adapter*'],
151
+ antiPatterns: ['controllers', 'models', 'views'],
152
+ codePatterns: ['Port', 'Adapter'],
153
+ minScore: 5,
154
+ },
155
+ migrationPaths: ['ddd', 'microservices', 'clean'],
156
+ },
157
+
158
+ 'flat': {
159
+ id: 'flat',
160
+ name: 'Flat / Component-Driven',
161
+ category: 'frontend',
162
+ description: 'Single components directory with minimal structure. Typical starting point for small projects.',
163
+ bestFor: {
164
+ teamSize: '1-3',
165
+ projectSize: 'small',
166
+ description: 'Solo developers, prototypes, small projects with < 20 components.',
167
+ },
168
+ detection: {
169
+ requiredDirs: ['components'],
170
+ optionalDirs: ['pages', 'api', 'utils', 'lib', 'hooks', 'styles'],
171
+ moduleSubDirs: [],
172
+ optionalModuleSubDirs: [],
173
+ filePatterns: [],
174
+ antiPatterns: ['modules', 'features', 'domain', 'entities', 'atoms', 'molecules', 'ports', 'adapters'],
175
+ codePatterns: [],
176
+ minScore: 2,
177
+ customRule: 'flat-components',
178
+ },
179
+ migrationPaths: ['modular', 'atomic', 'fsd'],
180
+ },
181
+
182
+ 'screaming': {
183
+ id: 'screaming',
184
+ name: 'Screaming Architecture',
185
+ category: 'frontend',
186
+ description: 'Top-level directories named after business domains. The structure "screams" what the app does.',
187
+ bestFor: {
188
+ teamSize: '3-10',
189
+ projectSize: 'medium',
190
+ description: 'DDD-influenced teams wanting immediate domain visibility.',
191
+ },
192
+ detection: {
193
+ requiredDirs: [],
194
+ optionalDirs: [],
195
+ moduleSubDirs: [],
196
+ optionalModuleSubDirs: [],
197
+ filePatterns: [],
198
+ antiPatterns: ['components', 'controllers', 'models', 'views', 'modules', 'features'],
199
+ codePatterns: [],
200
+ minScore: 3,
201
+ customRule: 'screaming-domains',
202
+ },
203
+ migrationPaths: ['modular', 'ddd', 'clean'],
204
+ },
205
+
206
+ // ── Backend / Fullstack Architectures ──────────────
207
+
208
+ 'ddd': {
209
+ id: 'ddd',
210
+ name: 'Domain-Driven Design (DDD)',
211
+ category: 'backend',
212
+ description: 'Bounded contexts with aggregates, value objects, domain events. Business language drives structure.',
213
+ bestFor: {
214
+ teamSize: '10-50',
215
+ projectSize: 'large-enterprise',
216
+ description: 'Complex business domains with domain experts. Projects where the model IS the product.',
217
+ },
218
+ detection: {
219
+ requiredDirs: [],
220
+ optionalDirs: ['aggregates', 'value-objects', 'domain-events', 'bounded-contexts', 'domain', 'shared-kernel'],
221
+ moduleSubDirs: [],
222
+ optionalModuleSubDirs: ['aggregates', 'value-objects', 'domain-events', 'repositories', 'services'],
223
+ filePatterns: ['**/*Aggregate*', '**/*ValueObject*', '**/*DomainEvent*', '**/aggregates/**', '**/value-objects/**'],
224
+ antiPatterns: [],
225
+ codePatterns: ['AggregateRoot', 'ValueObject', 'DomainEvent'],
226
+ minScore: 5,
227
+ },
228
+ migrationPaths: ['cqrs', 'microservices', 'event-driven'],
229
+ },
230
+
231
+ 'cqrs': {
232
+ id: 'cqrs',
233
+ name: 'CQRS (Command Query Separation)',
234
+ category: 'backend',
235
+ description: 'Separate command (write) and query (read) paths with dedicated models for each.',
236
+ bestFor: {
237
+ teamSize: '5-30',
238
+ projectSize: 'large',
239
+ description: 'Systems with asymmetric read/write loads, audit trail requirements.',
240
+ },
241
+ detection: {
242
+ requiredDirs: [],
243
+ optionalDirs: ['commands', 'queries', 'command-handlers', 'query-handlers', 'read-models', 'projections', 'write-models'],
244
+ moduleSubDirs: [],
245
+ optionalModuleSubDirs: ['commands', 'queries', 'handlers'],
246
+ filePatterns: ['**/*Command*', '**/*Query*', '**/*Handler*', '**/commands/**', '**/queries/**'],
247
+ antiPatterns: [],
248
+ codePatterns: ['CommandHandler', 'QueryHandler', 'Command', 'Query'],
249
+ minScore: 5,
250
+ },
251
+ migrationPaths: ['event-driven', 'microservices'],
252
+ },
253
+
254
+ 'event-driven': {
255
+ id: 'event-driven',
256
+ name: 'Event-Driven',
257
+ category: 'backend',
258
+ description: 'Asynchronous communication via events. Decoupled producers and consumers.',
259
+ bestFor: {
260
+ teamSize: '5-30',
261
+ projectSize: 'large',
262
+ description: 'Asynchronous workflows, microservices communication, eventual consistency.',
263
+ },
264
+ detection: {
265
+ requiredDirs: [],
266
+ optionalDirs: ['events', 'handlers', 'subscribers', 'listeners', 'publishers', 'sagas', 'domain-events', 'event-handlers'],
267
+ moduleSubDirs: [],
268
+ optionalModuleSubDirs: [],
269
+ filePatterns: ['**/*EventHandler*', '**/*Subscriber*', '**/*Listener*', '**/*Publisher*', '**/*Saga*'],
270
+ antiPatterns: [],
271
+ codePatterns: ['EventEmitter', 'EventBus', 'publish', 'subscribe', 'EventHandler'],
272
+ minScore: 4,
273
+ },
274
+ migrationPaths: ['cqrs', 'microservices'],
275
+ },
276
+
277
+ 'microservices': {
278
+ id: 'microservices',
279
+ name: 'Microservices',
280
+ category: 'backend',
281
+ description: 'Independent services with own databases, deployed separately. Communication via APIs or events.',
282
+ bestFor: {
283
+ teamSize: '15-100+',
284
+ projectSize: 'enterprise',
285
+ description: 'Large teams needing independent deployment, different scaling per domain.',
286
+ },
287
+ detection: {
288
+ requiredDirs: [],
289
+ optionalDirs: ['services', 'gateway', 'api-gateway', 'shared', 'proto', 'contracts'],
290
+ moduleSubDirs: [],
291
+ optionalModuleSubDirs: [],
292
+ filePatterns: ['**/services/*/package.json', '**/services/*/Dockerfile', '**/apps/*/package.json'],
293
+ antiPatterns: [],
294
+ codePatterns: [],
295
+ minScore: 4,
296
+ customRule: 'microservices-check',
297
+ },
298
+ migrationPaths: ['serverless'],
299
+ },
300
+
301
+ 'modular-monolith': {
302
+ id: 'modular-monolith',
303
+ name: 'Modular Monolith',
304
+ category: 'fullstack',
305
+ description: 'Single deployment with enforced module boundaries. Best of both: isolation without distributed complexity.',
306
+ bestFor: {
307
+ teamSize: '3-20',
308
+ projectSize: 'medium-large',
309
+ description: 'Projects that may become microservices later. Module isolation without distributed overhead.',
310
+ },
311
+ detection: {
312
+ requiredDirs: ['modules'],
313
+ optionalDirs: ['shared', 'infrastructure', 'core'],
314
+ moduleSubDirs: ['domain', 'application', 'infrastructure'],
315
+ optionalModuleSubDirs: ['ports', 'adapters', 'events'],
316
+ filePatterns: ['**/modules/*/index.ts', '**/modules/*/module.ts'],
317
+ antiPatterns: [],
318
+ codePatterns: [],
319
+ minScore: 6,
320
+ customRule: 'modular-monolith-check',
321
+ },
322
+ migrationPaths: ['microservices', 'ddd', 'hexagonal'],
323
+ },
324
+
325
+ 'serverless': {
326
+ id: 'serverless',
327
+ name: 'Serverless / Functions',
328
+ category: 'backend',
329
+ description: 'Function-based architecture with event triggers. Stateless execution units.',
330
+ bestFor: {
331
+ teamSize: '1-10',
332
+ projectSize: 'small-medium',
333
+ description: 'Event-driven workloads, variable traffic, cost-optimized for low-traffic APIs.',
334
+ },
335
+ detection: {
336
+ requiredDirs: [],
337
+ optionalDirs: ['functions', 'lambdas', 'handlers', 'api'],
338
+ moduleSubDirs: [],
339
+ optionalModuleSubDirs: [],
340
+ filePatterns: ['serverless.yml', 'serverless.ts', 'netlify.toml', 'vercel.json', 'firebase.json', 'amplify.yml', 'sam-template.yaml', 'template.yaml'],
341
+ antiPatterns: [],
342
+ codePatterns: ['exports.handler', 'module.exports.handler'],
343
+ minScore: 3,
344
+ },
345
+ migrationPaths: ['microservices', 'modular'],
346
+ },
347
+
348
+ 'unstructured': {
349
+ id: 'unstructured',
350
+ name: 'Unstructured / Ad-hoc',
351
+ category: 'any',
352
+ description: 'No clear architecture pattern. Files organized loosely or by convenience.',
353
+ bestFor: {
354
+ teamSize: '1',
355
+ projectSize: 'prototype',
356
+ description: 'Quick prototypes, experiments. Should evolve into a proper architecture.',
357
+ },
358
+ detection: {
359
+ requiredDirs: [],
360
+ optionalDirs: [],
361
+ moduleSubDirs: [],
362
+ optionalModuleSubDirs: [],
363
+ filePatterns: [],
364
+ antiPatterns: [],
365
+ codePatterns: [],
366
+ minScore: 0,
367
+ customRule: 'unstructured-fallback',
368
+ },
369
+ migrationPaths: ['flat', 'modular', 'mvc'],
370
+ },
371
+ }
372
+
373
+ // ── Monorepo Pattern Definitions ──────────────────────
374
+
375
+ export const MONOREPO_PATTERNS = {
376
+ 'turborepo': {
377
+ id: 'turborepo',
378
+ name: 'Turborepo',
379
+ detectFiles: ['turbo.json'],
380
+ detectDirs: ['apps', 'packages'],
381
+ workspaceConfig: 'turbo.json',
382
+ },
383
+ 'nx': {
384
+ id: 'nx',
385
+ name: 'Nx',
386
+ detectFiles: ['nx.json'],
387
+ detectDirs: ['apps', 'libs'],
388
+ workspaceConfig: 'nx.json',
389
+ detectDeps: ['@nx/workspace', '@nrwl/workspace', 'nx'],
390
+ },
391
+ 'lerna': {
392
+ id: 'lerna',
393
+ name: 'Lerna',
394
+ detectFiles: ['lerna.json'],
395
+ detectDirs: ['packages'],
396
+ workspaceConfig: 'lerna.json',
397
+ },
398
+ 'pnpm': {
399
+ id: 'pnpm',
400
+ name: 'pnpm Workspaces',
401
+ detectFiles: ['pnpm-workspace.yaml'],
402
+ detectDirs: [],
403
+ workspaceConfig: 'pnpm-workspace.yaml',
404
+ },
405
+ 'workspaces': {
406
+ id: 'workspaces',
407
+ name: 'npm/yarn Workspaces',
408
+ detectFiles: [],
409
+ detectDirs: [],
410
+ workspaceConfig: 'package.json',
411
+ customRule: 'package-json-workspaces',
412
+ },
413
+ }
414
+
415
+ // ── Framework-Specific Architecture Adaptations ───────
416
+
417
+ export const FRAMEWORK_ADAPTATIONS = {
418
+ // For each framework, maps architecture patterns to their specific adaptations
419
+ nextjs: {
420
+ routerType: null, // detected dynamically: 'app-router' | 'pages-router'
421
+ adaptations: {
422
+ modular: {
423
+ srcRoot: 'src',
424
+ routeDir: 'app',
425
+ moduleDir: 'modules',
426
+ sharedDir: 'shared',
427
+ stateManagement: { client: 'zustand', server: 'tanstack-react-query' },
428
+ layers: ['components', 'hooks', 'services', 'adapters', 'stores', 'actions', 'types', '__tests__'],
429
+ liteLayers: ['components', 'hooks', 'services', 'types'],
430
+ specialDirs: { actions: 'Server Actions', stores: 'Zustand stores' },
431
+ },
432
+ clean: {
433
+ srcRoot: 'src',
434
+ layers: { domain: 'domain', application: 'application', infrastructure: 'infrastructure', presentation: 'app' },
435
+ liteLayers: { core: 'core', infra: 'infra', presentation: 'app' },
436
+ },
437
+ hexagonal: {
438
+ srcRoot: 'src',
439
+ layers: { core: { domain: true, ports: { in: true, out: true }, useCases: true }, adapters: { in: { web: 'app' }, out: { api: true, storage: true } } },
440
+ liteLayers: { core: { domain: true, ports: true }, adapters: true },
441
+ },
442
+ },
443
+ },
444
+
445
+ react: {
446
+ adaptations: {
447
+ modular: {
448
+ srcRoot: 'src',
449
+ routeDir: 'app/router',
450
+ moduleDir: 'modules',
451
+ sharedDir: 'shared',
452
+ stateManagement: { client: 'zustand', server: 'tanstack-react-query' },
453
+ layers: ['components', 'hooks', 'services', 'adapters', 'stores', 'types', 'pages', '__tests__'],
454
+ liteLayers: ['components', 'hooks', 'services', 'types'],
455
+ specialDirs: { stores: 'Zustand stores', pages: 'Route pages' },
456
+ },
457
+ clean: {
458
+ srcRoot: 'src',
459
+ layers: { domain: 'domain', application: 'application', infrastructure: 'infrastructure', presentation: 'presentation' },
460
+ liteLayers: { core: 'core', infra: 'infra', presentation: 'presentation' },
461
+ },
462
+ hexagonal: {
463
+ srcRoot: 'src',
464
+ layers: { core: { domain: true, ports: { in: true, out: true }, useCases: true }, adapters: { in: { web: 'presentation' }, out: { api: true, storage: true } } },
465
+ liteLayers: { core: { domain: true, ports: true }, adapters: true },
466
+ },
467
+ },
468
+ },
469
+
470
+ vue: {
471
+ adaptations: {
472
+ modular: {
473
+ srcRoot: 'src',
474
+ routeDir: 'app/router',
475
+ moduleDir: 'modules',
476
+ sharedDir: 'shared',
477
+ stateManagement: { client: 'pinia', server: 'tanstack-vue-query' },
478
+ layers: ['components', 'composables', 'services', 'adapters', 'stores', 'types', 'views', '__tests__'],
479
+ liteLayers: ['components', 'composables', 'services', 'types'],
480
+ specialDirs: { stores: 'Pinia stores', views: 'Route views', composables: 'Vue composables' },
481
+ },
482
+ clean: {
483
+ srcRoot: 'src',
484
+ layers: { domain: 'domain', application: 'application', infrastructure: 'infrastructure', presentation: 'presentation' },
485
+ liteLayers: { core: 'core', infra: 'infra', presentation: 'presentation' },
486
+ },
487
+ hexagonal: {
488
+ srcRoot: 'src',
489
+ layers: { core: { domain: true, ports: { in: true, out: true }, useCases: true }, adapters: { in: { web: 'presentation' }, out: { api: true, storage: true } } },
490
+ liteLayers: { core: { domain: true, ports: true }, adapters: true },
491
+ },
492
+ },
493
+ },
494
+
495
+ nuxt: {
496
+ adaptations: {
497
+ modular: {
498
+ srcRoot: '',
499
+ routeDir: 'pages',
500
+ moduleDir: 'modules',
501
+ sharedDir: 'shared',
502
+ stateManagement: { client: 'pinia', server: 'tanstack-vue-query' },
503
+ layers: ['components', 'composables', 'services', 'adapters', 'stores', 'types', '__tests__'],
504
+ liteLayers: ['components', 'composables', 'services', 'types'],
505
+ specialDirs: { stores: 'Pinia stores', composables: 'Auto-imported composables' },
506
+ nuxtDirs: ['server/api', 'server/utils', 'plugins', 'middleware', 'layouts'],
507
+ },
508
+ clean: {
509
+ srcRoot: '',
510
+ layers: { domain: 'domain', application: 'application', infrastructure: 'server', presentation: 'pages' },
511
+ liteLayers: { core: 'core', infra: 'server', presentation: 'pages' },
512
+ },
513
+ },
514
+ },
515
+
516
+ svelte: {
517
+ adaptations: {
518
+ modular: {
519
+ srcRoot: 'src',
520
+ routeDir: 'routes',
521
+ moduleDir: 'lib/modules',
522
+ sharedDir: 'lib/shared',
523
+ stateManagement: { client: 'svelte-stores', server: 'tanstack-svelte-query' },
524
+ layers: ['components', 'stores', 'services', 'adapters', 'types', '__tests__'],
525
+ liteLayers: ['components', 'stores', 'services', 'types'],
526
+ specialDirs: { stores: 'Svelte stores ($lib)' },
527
+ },
528
+ clean: {
529
+ srcRoot: 'src',
530
+ layers: { domain: 'lib/domain', application: 'lib/application', infrastructure: 'lib/infrastructure', presentation: 'routes' },
531
+ liteLayers: { core: 'lib/core', infra: 'lib/infra', presentation: 'routes' },
532
+ },
533
+ },
534
+ },
535
+
536
+ angular: {
537
+ adaptations: {
538
+ modular: {
539
+ srcRoot: 'src',
540
+ routeDir: 'app',
541
+ moduleDir: 'app/modules',
542
+ sharedDir: 'app/shared',
543
+ stateManagement: { client: 'ngrx-signals', server: 'tanstack-angular-query' },
544
+ layers: ['components', 'services', 'models', 'guards', 'pipes', 'directives', 'types', '__tests__'],
545
+ liteLayers: ['components', 'services', 'models', 'types'],
546
+ specialDirs: { guards: 'Route guards', pipes: 'Angular pipes' },
547
+ },
548
+ clean: {
549
+ srcRoot: 'src',
550
+ layers: { domain: 'app/domain', application: 'app/application', infrastructure: 'app/infrastructure', presentation: 'app/presentation' },
551
+ liteLayers: { core: 'app/core', infra: 'app/infra', presentation: 'app/presentation' },
552
+ },
553
+ },
554
+ },
555
+
556
+ astro: {
557
+ adaptations: {
558
+ modular: {
559
+ srcRoot: 'src',
560
+ routeDir: 'pages',
561
+ moduleDir: 'modules',
562
+ sharedDir: 'shared',
563
+ stateManagement: { client: 'nanostores', server: 'astro-data' },
564
+ layers: ['components', 'services', 'types', 'islands', '__tests__'],
565
+ liteLayers: ['components', 'services', 'types'],
566
+ specialDirs: { islands: 'Interactive framework islands', content: 'Content collections' },
567
+ astroDirs: ['content', 'layouts', 'islands'],
568
+ },
569
+ clean: {
570
+ srcRoot: 'src',
571
+ layers: { domain: 'domain', application: 'application', infrastructure: 'infrastructure', presentation: 'pages' },
572
+ liteLayers: { core: 'core', infra: 'infra', presentation: 'pages' },
573
+ },
574
+ },
575
+ },
576
+ }
577
+
578
+ // ── Migration Map ─────────────────────────────────────
579
+
580
+ export const MIGRATION_MAP = {
581
+ // From -> To: effort + description
582
+ 'unstructured->flat': { effort: 'low', description: 'Organize files into components/pages/utils folders' },
583
+ 'unstructured->modular': { effort: 'medium', description: 'Group files by feature into modules with barrel exports' },
584
+ 'unstructured->mvc': { effort: 'low', description: 'Organize by technical layer (controllers, models, services)' },
585
+
586
+ 'flat->modular': { effort: 'medium', description: 'Group components by domain into modules, add services/types layers' },
587
+ 'flat->atomic': { effort: 'medium', description: 'Reorganize components by granularity (atoms, molecules, organisms)' },
588
+ 'flat->fsd': { effort: 'high', description: 'Restructure into FSD layers with strict import rules' },
589
+
590
+ 'mvc->modular': { effort: 'medium', description: 'Shift from horizontal to vertical slicing, group by feature' },
591
+ 'mvc->clean': { effort: 'high', description: 'Extract domain layer, define use cases, invert dependencies' },
592
+ 'mvc->modular-monolith': { effort: 'high', description: 'Extract modules with enforced boundaries, add domain layers' },
593
+
594
+ 'modular->clean': { effort: 'medium', description: 'Add domain/application/infrastructure layers inside each module' },
595
+ 'modular->hexagonal': { effort: 'medium', description: 'Define ports and adapters, isolate domain from infrastructure' },
596
+ 'modular->fsd': { effort: 'medium', description: 'Reorganize modules into FSD layers (features, entities, shared)' },
597
+ 'modular->ddd': { effort: 'high', description: 'Add aggregates, value objects, domain events within bounded contexts' },
598
+ 'modular->modular-monolith': { effort: 'low', description: 'Enforce strict module boundaries, add internal layering' },
599
+
600
+ 'atomic->modular': { effort: 'medium', description: 'Regroup by domain instead of granularity, preserve design system' },
601
+ 'atomic->fsd': { effort: 'medium', description: 'Map atoms/molecules to shared, organisms to features/entities' },
602
+
603
+ 'clean->hexagonal': { effort: 'low', description: 'Rename layers, formalize ports/adapters, same dependency direction' },
604
+ 'clean->ddd': { effort: 'medium', description: 'Add aggregates, bounded contexts, domain events' },
605
+ 'clean->microservices': { effort: 'high', description: 'Extract bounded contexts into independent services' },
606
+
607
+ 'hexagonal->ddd': { effort: 'medium', description: 'Add DDD tactical patterns (aggregates, value objects) to domain' },
608
+ 'hexagonal->microservices': { effort: 'medium', description: 'Extract adapters into standalone services' },
609
+
610
+ 'ddd->cqrs': { effort: 'medium', description: 'Separate command and query paths, add read models' },
611
+ 'ddd->microservices': { effort: 'high', description: 'Extract bounded contexts into independent deployable services' },
612
+ 'ddd->event-driven': { effort: 'medium', description: 'Add event bus, publish domain events between contexts' },
613
+
614
+ 'modular-monolith->microservices': { effort: 'high', description: 'Extract modules into independent services (Strangler Fig)' },
615
+ 'modular-monolith->ddd': { effort: 'medium', description: 'Add DDD patterns within module boundaries' },
616
+ 'modular-monolith->hexagonal': { effort: 'medium', description: 'Add ports/adapters structure within each module' },
617
+
618
+ 'fsd->modular': { effort: 'medium', description: 'Merge FSD layers into feature modules, simplify import rules' },
619
+ 'fsd->clean': { effort: 'high', description: 'Map FSD layers to Clean Architecture concentric layers' },
620
+
621
+ 'screaming->modular': { effort: 'low', description: 'Add internal structure (services, types, index.ts) to domain dirs' },
622
+ 'screaming->ddd': { effort: 'medium', description: 'Formalize domain dirs into bounded contexts with DDD patterns' },
623
+
624
+ 'event-driven->cqrs': { effort: 'medium', description: 'Separate command/query handlers, add read model projections' },
625
+ 'event-driven->microservices': { effort: 'medium', description: 'Each event consumer becomes its own service' },
626
+
627
+ 'cqrs->microservices': { effort: 'medium', description: 'Split command/query services, separate deployments' },
628
+
629
+ 'serverless->microservices': { effort: 'medium', description: 'Group functions into services, add service boundaries' },
630
+ 'serverless->modular': { effort: 'medium', description: 'Organize functions into modules with shared infrastructure' },
631
+ }
632
+
633
+ // ── Architecture Suggestion Engine ────────────────────
634
+
635
+ export function getSuggestedArchitectures(currentArch, framework, projectInfo) {
636
+ const suggestions = []
637
+ const pattern = ARCHITECTURE_PATTERNS[currentArch]
638
+ if (!pattern) return suggestions
639
+
640
+ const frameworkAdaptations = FRAMEWORK_ADAPTATIONS[framework] || {}
641
+
642
+ for (const targetId of pattern.migrationPaths) {
643
+ const target = ARCHITECTURE_PATTERNS[targetId]
644
+ if (!target) continue
645
+
646
+ const migrationKey = `${currentArch}->${targetId}`
647
+ const migration = MIGRATION_MAP[migrationKey]
648
+ if (!migration) continue
649
+
650
+ // Check if framework has adaptation for this target
651
+ const hasFrameworkSupport = frameworkAdaptations.adaptations?.[targetId] || targetId === 'modular'
652
+
653
+ const suggestion = {
654
+ id: targetId,
655
+ name: target.name,
656
+ description: target.description,
657
+ effort: migration.effort,
658
+ migrationDescription: migration.description,
659
+ bestFor: target.bestFor,
660
+ hasFrameworkSupport: !!hasFrameworkSupport,
661
+ variants: [],
662
+ }
663
+
664
+ // Add Full variant
665
+ suggestion.variants.push({
666
+ id: 'full',
667
+ name: `${target.name} (Full)`,
668
+ description: `Complete implementation with all layers and patterns. ${target.bestFor.description}`,
669
+ teamSize: target.bestFor.teamSize,
670
+ complexity: 'high',
671
+ })
672
+
673
+ // Add Lite variant
674
+ suggestion.variants.push({
675
+ id: 'lite',
676
+ name: `${target.name} (Simplified)`,
677
+ description: `Streamlined version with fewer layers. Same core principles, less ceremony. Good for smaller teams.`,
678
+ teamSize: reducedTeamSize(target.bestFor.teamSize),
679
+ complexity: 'medium',
680
+ })
681
+
682
+ // Add monorepo variant if applicable
683
+ if (projectInfo?.isMonorepo && ['modular', 'clean', 'hexagonal', 'modular-monolith', 'microservices'].includes(targetId)) {
684
+ suggestion.variants.push({
685
+ id: 'monorepo',
686
+ name: `${target.name} (Monorepo)`,
687
+ description: `Adapted for monorepo with shared packages. Each app/service follows the architecture independently.`,
688
+ teamSize: target.bestFor.teamSize,
689
+ complexity: 'high',
690
+ })
691
+ }
692
+
693
+ suggestions.push(suggestion)
694
+ }
695
+
696
+ // Sort by effort (low first), then by framework support
697
+ suggestions.sort((a, b) => {
698
+ const effortOrder = { low: 0, medium: 1, high: 2 }
699
+ if (a.hasFrameworkSupport !== b.hasFrameworkSupport) return a.hasFrameworkSupport ? -1 : 1
700
+ return (effortOrder[a.effort] || 2) - (effortOrder[b.effort] || 2)
701
+ })
702
+
703
+ return suggestions
704
+ }
705
+
706
+ function reducedTeamSize(teamSize) {
707
+ const match = teamSize.match(/(\d+)-(\d+)/)
708
+ if (!match) return '1-5'
709
+ const min = Math.max(1, Math.floor(parseInt(match[1]) / 2))
710
+ const max = Math.max(min + 2, Math.floor(parseInt(match[2]) / 2))
711
+ return `${min}-${max}`
712
+ }
713
+