sdd-mcp-server 1.3.0 → 1.3.2

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,825 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ /**
4
+ * Analyzes the project structure and returns comprehensive project information
5
+ */
6
+ export async function analyzeProject(projectPath) {
7
+ const analysis = {
8
+ name: 'Unknown Project',
9
+ description: 'No description available',
10
+ version: '0.0.0',
11
+ type: 'unknown',
12
+ architecture: 'unknown',
13
+ dependencies: [],
14
+ devDependencies: [],
15
+ scripts: {},
16
+ directories: [],
17
+ files: [],
18
+ hasTests: false,
19
+ hasDocker: false,
20
+ hasCI: false,
21
+ framework: null,
22
+ language: 'javascript',
23
+ testFramework: null,
24
+ buildTool: null,
25
+ packageManager: 'npm'
26
+ };
27
+ try {
28
+ // Check for package.json
29
+ const packageJsonPath = path.join(projectPath, 'package.json');
30
+ if (fs.existsSync(packageJsonPath)) {
31
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
32
+ analysis.name = packageJson.name || analysis.name;
33
+ analysis.description = packageJson.description || analysis.description;
34
+ analysis.version = packageJson.version || analysis.version;
35
+ analysis.type = packageJson.type === 'module' ? 'ES Module' : 'CommonJS';
36
+ analysis.dependencies = Object.keys(packageJson.dependencies || {});
37
+ analysis.devDependencies = Object.keys(packageJson.devDependencies || {});
38
+ analysis.scripts = packageJson.scripts || {};
39
+ // Detect framework
40
+ if (analysis.dependencies.includes('express') || analysis.devDependencies.includes('express')) {
41
+ analysis.framework = 'Express.js';
42
+ analysis.architecture = 'REST API Server';
43
+ }
44
+ else if (analysis.dependencies.includes('fastify')) {
45
+ analysis.framework = 'Fastify';
46
+ analysis.architecture = 'High-performance REST API';
47
+ }
48
+ else if (analysis.dependencies.includes('react')) {
49
+ analysis.framework = 'React';
50
+ analysis.architecture = 'Frontend Application';
51
+ }
52
+ else if (analysis.dependencies.includes('vue')) {
53
+ analysis.framework = 'Vue.js';
54
+ analysis.architecture = 'Progressive Web Application';
55
+ }
56
+ else if (analysis.dependencies.includes('@angular/core')) {
57
+ analysis.framework = 'Angular';
58
+ analysis.architecture = 'Enterprise Frontend Application';
59
+ }
60
+ else if (analysis.dependencies.includes('next')) {
61
+ analysis.framework = 'Next.js';
62
+ analysis.architecture = 'Full-stack React Framework';
63
+ }
64
+ else if (analysis.dependencies.includes('@modelcontextprotocol/sdk')) {
65
+ analysis.framework = 'MCP SDK';
66
+ analysis.architecture = 'Model Context Protocol Server';
67
+ }
68
+ // Detect language
69
+ if (analysis.devDependencies.includes('typescript') || fs.existsSync(path.join(projectPath, 'tsconfig.json'))) {
70
+ analysis.language = 'typescript';
71
+ }
72
+ // Detect test framework
73
+ if (analysis.devDependencies.includes('jest')) {
74
+ analysis.testFramework = 'Jest';
75
+ }
76
+ else if (analysis.devDependencies.includes('mocha')) {
77
+ analysis.testFramework = 'Mocha';
78
+ }
79
+ else if (analysis.devDependencies.includes('vitest')) {
80
+ analysis.testFramework = 'Vitest';
81
+ }
82
+ // Detect build tool
83
+ if (analysis.scripts.build?.includes('webpack')) {
84
+ analysis.buildTool = 'Webpack';
85
+ }
86
+ else if (analysis.scripts.build?.includes('vite')) {
87
+ analysis.buildTool = 'Vite';
88
+ }
89
+ else if (analysis.scripts.build?.includes('tsc')) {
90
+ analysis.buildTool = 'TypeScript Compiler';
91
+ }
92
+ else if (analysis.scripts.build?.includes('rollup')) {
93
+ analysis.buildTool = 'Rollup';
94
+ }
95
+ }
96
+ // Check for yarn or pnpm
97
+ if (fs.existsSync(path.join(projectPath, 'yarn.lock'))) {
98
+ analysis.packageManager = 'yarn';
99
+ }
100
+ else if (fs.existsSync(path.join(projectPath, 'pnpm-lock.yaml'))) {
101
+ analysis.packageManager = 'pnpm';
102
+ }
103
+ // Scan directory structure
104
+ const items = fs.readdirSync(projectPath, { withFileTypes: true });
105
+ for (const item of items) {
106
+ if (item.isDirectory() && !item.name.startsWith('.') && item.name !== 'node_modules') {
107
+ analysis.directories.push(item.name);
108
+ // Check for test directories
109
+ if (item.name === 'test' || item.name === 'tests' || item.name === '__tests__' || item.name === 'spec') {
110
+ analysis.hasTests = true;
111
+ }
112
+ }
113
+ else if (item.isFile()) {
114
+ analysis.files.push(item.name);
115
+ // Check for Docker
116
+ if (item.name === 'Dockerfile' || item.name === 'docker-compose.yml') {
117
+ analysis.hasDocker = true;
118
+ }
119
+ // Check for CI/CD
120
+ if (item.name === '.gitlab-ci.yml' || item.name === '.travis.yml' || item.name === 'Jenkinsfile') {
121
+ analysis.hasCI = true;
122
+ }
123
+ }
124
+ }
125
+ // Check for GitHub Actions
126
+ if (fs.existsSync(path.join(projectPath, '.github', 'workflows'))) {
127
+ analysis.hasCI = true;
128
+ }
129
+ // Additional architecture detection based on directory structure
130
+ if (analysis.directories.includes('src')) {
131
+ const srcPath = path.join(projectPath, 'src');
132
+ const srcItems = fs.readdirSync(srcPath, { withFileTypes: true });
133
+ const srcDirs = srcItems.filter(item => item.isDirectory()).map(item => item.name);
134
+ if (srcDirs.includes('domain') && srcDirs.includes('infrastructure')) {
135
+ analysis.architecture = 'Domain-Driven Design (DDD)';
136
+ }
137
+ else if (srcDirs.includes('controllers') && srcDirs.includes('models')) {
138
+ analysis.architecture = 'MVC Architecture';
139
+ }
140
+ else if (srcDirs.includes('components') && srcDirs.includes('pages')) {
141
+ analysis.architecture = 'Component-Based Architecture';
142
+ }
143
+ }
144
+ }
145
+ catch (error) {
146
+ console.error('Error analyzing project:', error);
147
+ }
148
+ return analysis;
149
+ }
150
+ /**
151
+ * Generates dynamic product.md content based on project analysis
152
+ */
153
+ export function generateProductDocument(analysis) {
154
+ const features = extractFeatures(analysis);
155
+ const valueProps = generateValuePropositions(analysis);
156
+ const targetUsers = identifyTargetUsers(analysis);
157
+ return `# Product Overview
158
+
159
+ ## Product Description
160
+ ${analysis.description}
161
+
162
+ **Project**: ${analysis.name}
163
+ **Version**: ${analysis.version}
164
+ **Type**: ${analysis.architecture}
165
+
166
+ ## Core Features
167
+ ${features.map(f => `- ${f}`).join('\n')}
168
+
169
+ ## Target Use Case
170
+ ${generateUseCaseDescription(analysis)}
171
+
172
+ ## Key Value Proposition
173
+ ${valueProps.map(v => `- **${v.title}**: ${v.description}`).join('\n')}
174
+
175
+ ## Target Users
176
+ ${targetUsers.map(u => `- ${u}`).join('\n')}
177
+
178
+ ## Success Metrics
179
+ ${generateSuccessMetrics(analysis).map(m => `- ${m}`).join('\n')}
180
+
181
+ ## Technical Advantages
182
+ ${generateTechnicalAdvantages(analysis).map(a => `- ${a}`).join('\n')}
183
+ `;
184
+ }
185
+ /**
186
+ * Generates dynamic tech.md content based on project analysis
187
+ */
188
+ export function generateTechDocument(analysis) {
189
+ const techStack = buildTechStack(analysis);
190
+ const devCommands = extractDevCommands(analysis);
191
+ const architecture = describeArchitecture(analysis);
192
+ return `# Technology Stack
193
+
194
+ ## Architecture
195
+ **Type**: ${analysis.architecture}
196
+ **Language**: ${analysis.language === 'typescript' ? 'TypeScript' : 'JavaScript'}
197
+ **Module System**: ${analysis.type}
198
+ ${analysis.framework ? `**Framework**: ${analysis.framework}` : ''}
199
+ ${analysis.buildTool ? `**Build Tool**: ${analysis.buildTool}` : ''}
200
+
201
+ ${architecture}
202
+
203
+ ## Technology Stack
204
+ ${techStack.map(t => `- **${t.name}**: ${t.description}`).join('\n')}
205
+
206
+ ## Development Environment
207
+ - **Node Version**: ${getNodeVersion()}
208
+ - **Package Manager**: ${analysis.packageManager}
209
+ - **Language**: ${analysis.language === 'typescript' ? 'TypeScript with type safety' : 'JavaScript'}
210
+ ${analysis.testFramework ? `- **Testing**: ${analysis.testFramework}` : ''}
211
+
212
+ ## Dependencies Analysis
213
+ ### Production Dependencies (${analysis.dependencies.length})
214
+ ${analysis.dependencies.slice(0, 15).map(d => `- \`${d}\`: ${describeDependency(d)}`).join('\n')}
215
+ ${analysis.dependencies.length > 15 ? `\n... and ${analysis.dependencies.length - 15} more` : ''}
216
+
217
+ ### Development Dependencies (${analysis.devDependencies.length})
218
+ ${analysis.devDependencies.slice(0, 10).map(d => `- \`${d}\`: ${describeDependency(d)}`).join('\n')}
219
+ ${analysis.devDependencies.length > 10 ? `\n... and ${analysis.devDependencies.length - 10} more` : ''}
220
+
221
+ ## Development Commands
222
+ ${devCommands}
223
+
224
+ ## Quality Assurance
225
+ ${generateQualityAssurance(analysis)}
226
+
227
+ ## Deployment Configuration
228
+ ${generateDeploymentConfig(analysis)}
229
+ `;
230
+ }
231
+ /**
232
+ * Generates dynamic structure.md content based on project analysis
233
+ */
234
+ export function generateStructureDocument(analysis) {
235
+ const structure = buildDirectoryTree(analysis);
236
+ const patterns = identifyPatterns(analysis);
237
+ const conventions = extractConventions(analysis);
238
+ return `# Project Structure
239
+
240
+ ## Directory Organization
241
+ \`\`\`
242
+ ${structure}
243
+ \`\`\`
244
+
245
+ ## Key Directories
246
+ ${describeKeyDirectories(analysis)}
247
+
248
+ ## Code Organization Patterns
249
+ ${patterns.map(p => `- **${p.pattern}**: ${p.description}`).join('\n')}
250
+
251
+ ## File Naming Conventions
252
+ ${conventions.naming.map(c => `- ${c}`).join('\n')}
253
+
254
+ ## Module Organization
255
+ ${describeModuleOrganization(analysis)}
256
+
257
+ ## Architectural Principles
258
+ ${generateArchitecturalPrinciples(analysis).map(p => `- **${p.principle}**: ${p.description}`).join('\n')}
259
+
260
+ ## Development Patterns
261
+ ${generateDevelopmentPatterns(analysis).map(p => `- ${p}`).join('\n')}
262
+
263
+ ## Testing Structure
264
+ ${describeTestingStructure(analysis)}
265
+
266
+ ## Build Output
267
+ ${describeBuildOutput(analysis)}
268
+ `;
269
+ }
270
+ // Helper functions for dynamic content generation
271
+ function extractFeatures(analysis) {
272
+ const features = [];
273
+ // Based on scripts
274
+ if (analysis.scripts.test)
275
+ features.push('Automated testing framework');
276
+ if (analysis.scripts.build)
277
+ features.push('Build system for production deployment');
278
+ if (analysis.scripts.dev || analysis.scripts.start)
279
+ features.push('Development server with hot reload');
280
+ if (analysis.scripts.lint)
281
+ features.push('Code quality enforcement with linting');
282
+ if (analysis.scripts.typecheck)
283
+ features.push('Type safety validation');
284
+ if (analysis.scripts.coverage)
285
+ features.push('Code coverage analysis');
286
+ // Based on dependencies
287
+ if (analysis.framework)
288
+ features.push(`${analysis.framework} framework integration`);
289
+ if (analysis.hasDocker)
290
+ features.push('Docker containerization support');
291
+ if (analysis.hasCI)
292
+ features.push('Continuous Integration/Deployment pipeline');
293
+ if (analysis.testFramework)
294
+ features.push(`${analysis.testFramework} testing suite`);
295
+ if (analysis.language === 'typescript')
296
+ features.push('TypeScript type safety');
297
+ // MCP specific
298
+ if (analysis.dependencies.includes('@modelcontextprotocol/sdk')) {
299
+ features.push('Model Context Protocol (MCP) server capabilities');
300
+ features.push('AI tool integration support');
301
+ features.push('Spec-driven development workflow');
302
+ }
303
+ return features.length > 0 ? features : ['Core application functionality'];
304
+ }
305
+ function generateValuePropositions(analysis) {
306
+ const props = [];
307
+ if (analysis.language === 'typescript') {
308
+ props.push({
309
+ title: 'Type Safety',
310
+ description: 'Compile-time type checking reduces runtime errors'
311
+ });
312
+ }
313
+ if (analysis.hasTests) {
314
+ props.push({
315
+ title: 'Quality Assurance',
316
+ description: 'Comprehensive test coverage ensures reliability'
317
+ });
318
+ }
319
+ if (analysis.framework === 'MCP SDK') {
320
+ props.push({
321
+ title: 'AI Integration',
322
+ description: 'Seamless integration with AI development tools'
323
+ });
324
+ }
325
+ if (analysis.hasDocker) {
326
+ props.push({
327
+ title: 'Deployment Flexibility',
328
+ description: 'Container-based deployment for any environment'
329
+ });
330
+ }
331
+ return props;
332
+ }
333
+ function identifyTargetUsers(analysis) {
334
+ const users = [];
335
+ if (analysis.framework === 'MCP SDK' || analysis.dependencies.includes('@modelcontextprotocol/sdk')) {
336
+ users.push('AI developers using Claude, Cursor, or similar tools');
337
+ users.push('Development teams implementing spec-driven workflows');
338
+ }
339
+ if (analysis.architecture.includes('API')) {
340
+ users.push('Backend developers building RESTful services');
341
+ users.push('API consumers and third-party integrators');
342
+ }
343
+ if (analysis.framework?.includes('React') || analysis.framework?.includes('Vue') || analysis.framework?.includes('Angular')) {
344
+ users.push('Frontend developers building web applications');
345
+ users.push('End users accessing web interfaces');
346
+ }
347
+ if (users.length === 0) {
348
+ users.push('Software developers');
349
+ users.push('System administrators');
350
+ }
351
+ return users;
352
+ }
353
+ function generateUseCaseDescription(analysis) {
354
+ if (analysis.dependencies.includes('@modelcontextprotocol/sdk')) {
355
+ return 'This product enables AI-powered development teams to follow structured, spec-driven development workflows with comprehensive phase management, quality gates, and AI tool integration.';
356
+ }
357
+ if (analysis.architecture.includes('API')) {
358
+ return `This ${analysis.framework || 'application'} provides RESTful API services for client applications, enabling data exchange and business logic processing.`;
359
+ }
360
+ if (analysis.architecture.includes('Frontend')) {
361
+ return `This ${analysis.framework || 'web'} application delivers interactive user interfaces for ${analysis.description || 'web-based services'}.`;
362
+ }
363
+ return analysis.description || 'General-purpose application for various use cases.';
364
+ }
365
+ function generateSuccessMetrics(analysis) {
366
+ const metrics = [];
367
+ if (analysis.hasTests)
368
+ metrics.push('Test coverage > 80%');
369
+ if (analysis.scripts.lint)
370
+ metrics.push('Zero linting errors in production code');
371
+ if (analysis.language === 'typescript')
372
+ metrics.push('Zero TypeScript compilation errors');
373
+ if (analysis.architecture.includes('API'))
374
+ metrics.push('API response time < 200ms for 95% of requests');
375
+ if (analysis.hasCI)
376
+ metrics.push('Successful CI/CD pipeline execution rate > 95%');
377
+ return metrics.length > 0 ? metrics : ['Successful deployment and operation'];
378
+ }
379
+ function generateTechnicalAdvantages(analysis) {
380
+ const advantages = [];
381
+ if (analysis.language === 'typescript') {
382
+ advantages.push('Strong typing prevents common JavaScript errors');
383
+ }
384
+ if (analysis.buildTool) {
385
+ advantages.push(`Optimized builds with ${analysis.buildTool}`);
386
+ }
387
+ if (analysis.architecture.includes('DDD')) {
388
+ advantages.push('Domain-Driven Design ensures business alignment');
389
+ }
390
+ if (analysis.dependencies.includes('inversify')) {
391
+ advantages.push('Dependency injection for loose coupling and testability');
392
+ }
393
+ return advantages;
394
+ }
395
+ function buildTechStack(analysis) {
396
+ const stack = [];
397
+ // Core runtime
398
+ stack.push({
399
+ name: 'Node.js',
400
+ description: 'JavaScript runtime for server-side execution'
401
+ });
402
+ // Language
403
+ if (analysis.language === 'typescript') {
404
+ stack.push({
405
+ name: 'TypeScript',
406
+ description: 'Typed superset of JavaScript for enhanced developer experience'
407
+ });
408
+ }
409
+ // Framework
410
+ if (analysis.framework) {
411
+ stack.push({
412
+ name: analysis.framework,
413
+ description: getFrameworkDescription(analysis.framework)
414
+ });
415
+ }
416
+ // Testing
417
+ if (analysis.testFramework) {
418
+ stack.push({
419
+ name: analysis.testFramework,
420
+ description: 'Testing framework for unit and integration tests'
421
+ });
422
+ }
423
+ // Build tool
424
+ if (analysis.buildTool) {
425
+ stack.push({
426
+ name: analysis.buildTool,
427
+ description: 'Build and bundling tool for production optimization'
428
+ });
429
+ }
430
+ // Key dependencies
431
+ for (const dep of analysis.dependencies.slice(0, 5)) {
432
+ if (!['react', 'vue', 'express', 'fastify', 'next'].includes(dep)) {
433
+ stack.push({
434
+ name: dep,
435
+ description: describeDependency(dep)
436
+ });
437
+ }
438
+ }
439
+ return stack;
440
+ }
441
+ function extractDevCommands(analysis) {
442
+ if (Object.keys(analysis.scripts).length === 0) {
443
+ return 'No npm scripts defined';
444
+ }
445
+ let commands = '```bash\n';
446
+ // Common commands in order of importance
447
+ const commandOrder = ['dev', 'start', 'build', 'test', 'lint', 'typecheck', 'coverage'];
448
+ for (const cmd of commandOrder) {
449
+ if (analysis.scripts[cmd]) {
450
+ commands += `${analysis.packageManager} run ${cmd} # ${describeCommand(cmd, analysis.scripts[cmd])}\n`;
451
+ }
452
+ }
453
+ // Add other commands
454
+ for (const [cmd, script] of Object.entries(analysis.scripts)) {
455
+ if (!commandOrder.includes(cmd)) {
456
+ commands += `${analysis.packageManager} run ${cmd} # ${script.substring(0, 50)}${script.length > 50 ? '...' : ''}\n`;
457
+ }
458
+ }
459
+ commands += '```';
460
+ return commands;
461
+ }
462
+ function describeArchitecture(analysis) {
463
+ if (analysis.architecture === 'Domain-Driven Design (DDD)') {
464
+ return `
465
+ ### Domain-Driven Design Architecture
466
+ The project follows DDD principles with clear separation between:
467
+ - **Domain Layer**: Business logic and domain models
468
+ - **Application Layer**: Use cases and application services
469
+ - **Infrastructure Layer**: External dependencies and integrations
470
+ - **Presentation Layer**: API endpoints or UI components
471
+ `;
472
+ }
473
+ if (analysis.architecture === 'MVC Architecture') {
474
+ return `
475
+ ### MVC Architecture Pattern
476
+ The project implements Model-View-Controller pattern:
477
+ - **Models**: Data structures and business logic
478
+ - **Views**: Presentation layer and templates
479
+ - **Controllers**: Request handling and routing
480
+ `;
481
+ }
482
+ if (analysis.architecture.includes('API')) {
483
+ return `
484
+ ### RESTful API Architecture
485
+ The project provides REST API services with:
486
+ - **Endpoints**: Resource-based URL structure
487
+ - **Middleware**: Request processing pipeline
488
+ - **Services**: Business logic implementation
489
+ - **Data Access**: Database integration layer
490
+ `;
491
+ }
492
+ return '';
493
+ }
494
+ function describeDependency(dep) {
495
+ const descriptions = {
496
+ '@modelcontextprotocol/sdk': 'MCP SDK for AI tool integration',
497
+ 'express': 'Web application framework',
498
+ 'fastify': 'High-performance web framework',
499
+ 'react': 'UI component library',
500
+ 'vue': 'Progressive JavaScript framework',
501
+ 'typescript': 'TypeScript language support',
502
+ 'inversify': 'Dependency injection container',
503
+ 'handlebars': 'Template engine',
504
+ 'i18next': 'Internationalization framework',
505
+ 'jest': 'JavaScript testing framework',
506
+ 'eslint': 'JavaScript linter',
507
+ 'prettier': 'Code formatter',
508
+ 'webpack': 'Module bundler',
509
+ 'vite': 'Fast build tool',
510
+ 'uuid': 'UUID generation library',
511
+ 'ajv': 'JSON schema validator',
512
+ 'axios': 'HTTP client library',
513
+ 'lodash': 'Utility library',
514
+ 'moment': 'Date manipulation library',
515
+ 'dotenv': 'Environment variable loader'
516
+ };
517
+ return descriptions[dep] || 'Project dependency';
518
+ }
519
+ function getFrameworkDescription(framework) {
520
+ const descriptions = {
521
+ 'Express.js': 'Minimal and flexible Node.js web application framework',
522
+ 'Fastify': 'Fast and low overhead web framework for Node.js',
523
+ 'React': 'JavaScript library for building user interfaces',
524
+ 'Vue.js': 'Progressive framework for building user interfaces',
525
+ 'Angular': 'Platform for building mobile and desktop web applications',
526
+ 'Next.js': 'React framework with server-side rendering and routing',
527
+ 'MCP SDK': 'Model Context Protocol SDK for AI agent integration'
528
+ };
529
+ return descriptions[framework] || 'Application framework';
530
+ }
531
+ function describeCommand(cmd, script) {
532
+ const descriptions = {
533
+ 'dev': 'Start development server with hot reload',
534
+ 'start': 'Start production server',
535
+ 'build': 'Build project for production',
536
+ 'test': 'Run test suite',
537
+ 'lint': 'Check code quality with linter',
538
+ 'typecheck': 'Validate TypeScript types',
539
+ 'coverage': 'Generate test coverage report'
540
+ };
541
+ return descriptions[cmd] || script.substring(0, 50);
542
+ }
543
+ function generateQualityAssurance(analysis) {
544
+ const qa = [];
545
+ if (analysis.scripts.lint) {
546
+ qa.push('- **Linting**: Automated code quality checks');
547
+ }
548
+ if (analysis.scripts.typecheck) {
549
+ qa.push('- **Type Checking**: TypeScript compilation validation');
550
+ }
551
+ if (analysis.hasTests) {
552
+ qa.push(`- **Testing**: ${analysis.testFramework || 'Test'} suite for unit and integration tests`);
553
+ }
554
+ if (analysis.scripts.coverage) {
555
+ qa.push('- **Coverage**: Code coverage reporting and thresholds');
556
+ }
557
+ if (analysis.hasCI) {
558
+ qa.push('- **CI/CD**: Automated quality gates in pipeline');
559
+ }
560
+ return qa.length > 0 ? qa.join('\n') : '- Quality assurance processes to be defined';
561
+ }
562
+ function generateDeploymentConfig(analysis) {
563
+ const config = [];
564
+ if (analysis.hasDocker) {
565
+ config.push('- **Containerization**: Docker support for consistent deployments');
566
+ }
567
+ if (analysis.scripts.build) {
568
+ config.push(`- **Build Process**: \`${analysis.packageManager} run build\` for production artifacts`);
569
+ }
570
+ if (analysis.hasCI) {
571
+ config.push('- **CI/CD Pipeline**: Automated deployment workflows');
572
+ }
573
+ if (analysis.type === 'ES Module') {
574
+ config.push('- **Module System**: ES modules for modern JavaScript');
575
+ }
576
+ return config.length > 0 ? config.join('\n') : '- Deployment configuration to be defined';
577
+ }
578
+ function buildDirectoryTree(analysis) {
579
+ let tree = `├── .kiro/ # SDD workflow files
580
+ │ ├── steering/ # Project steering documents
581
+ │ └── specs/ # Feature specifications\n`;
582
+ for (const dir of analysis.directories.sort()) {
583
+ tree += `├── ${dir}/ # ${describeDirectory(dir)}\n`;
584
+ }
585
+ if (analysis.hasDocker) {
586
+ tree += `├── Dockerfile # Container configuration\n`;
587
+ }
588
+ tree += `├── package.json # Project configuration\n`;
589
+ if (analysis.language === 'typescript') {
590
+ tree += `├── tsconfig.json # TypeScript configuration\n`;
591
+ }
592
+ tree += `└── README.md # Project documentation`;
593
+ return tree;
594
+ }
595
+ function describeDirectory(dir) {
596
+ const descriptions = {
597
+ 'src': 'Source code',
598
+ 'dist': 'Build output',
599
+ 'build': 'Build artifacts',
600
+ 'test': 'Test files',
601
+ 'tests': 'Test suites',
602
+ '__tests__': 'Jest test files',
603
+ 'spec': 'Test specifications',
604
+ 'docs': 'Documentation',
605
+ 'public': 'Static assets',
606
+ 'assets': 'Media and resources',
607
+ 'config': 'Configuration files',
608
+ 'scripts': 'Build and utility scripts',
609
+ 'lib': 'Library code',
610
+ 'bin': 'Executable scripts',
611
+ 'examples': 'Example code',
612
+ 'domain': 'Domain logic (DDD)',
613
+ 'infrastructure': 'External integrations',
614
+ 'application': 'Application services',
615
+ 'presentation': 'UI components',
616
+ 'controllers': 'Request handlers',
617
+ 'models': 'Data models',
618
+ 'views': 'View templates',
619
+ 'services': 'Business services',
620
+ 'utils': 'Utility functions',
621
+ 'helpers': 'Helper functions',
622
+ 'middleware': 'Express middleware',
623
+ 'routes': 'API routes',
624
+ 'api': 'API endpoints'
625
+ };
626
+ return descriptions[dir] || 'Project directory';
627
+ }
628
+ function identifyPatterns(analysis) {
629
+ const patterns = [];
630
+ if (analysis.architecture.includes('DDD')) {
631
+ patterns.push({
632
+ pattern: 'Domain-Driven Design',
633
+ description: 'Business logic isolated in domain layer'
634
+ });
635
+ }
636
+ if (analysis.dependencies.includes('inversify')) {
637
+ patterns.push({
638
+ pattern: 'Dependency Injection',
639
+ description: 'IoC container for managing dependencies'
640
+ });
641
+ }
642
+ if (analysis.architecture.includes('MVC')) {
643
+ patterns.push({
644
+ pattern: 'Model-View-Controller',
645
+ description: 'Separation of concerns between data, presentation, and control'
646
+ });
647
+ }
648
+ if (analysis.directories.includes('middleware')) {
649
+ patterns.push({
650
+ pattern: 'Middleware Pipeline',
651
+ description: 'Request processing through middleware chain'
652
+ });
653
+ }
654
+ if (analysis.hasTests) {
655
+ patterns.push({
656
+ pattern: 'Test-Driven Development',
657
+ description: 'Tests alongside implementation code'
658
+ });
659
+ }
660
+ return patterns;
661
+ }
662
+ function extractConventions(analysis) {
663
+ const naming = [];
664
+ if (analysis.language === 'typescript') {
665
+ naming.push('TypeScript files: `.ts` extension');
666
+ naming.push('Type definition files: `.d.ts` extension');
667
+ }
668
+ else {
669
+ naming.push('JavaScript files: `.js` extension');
670
+ }
671
+ naming.push('Test files: `.test.ts` or `.spec.ts` suffix');
672
+ naming.push('Configuration files: `.json` or `.config.js` format');
673
+ if (analysis.framework?.includes('React')) {
674
+ naming.push('React components: PascalCase (e.g., `UserProfile.tsx`)');
675
+ }
676
+ naming.push('Directories: lowercase with hyphens (e.g., `user-service`)');
677
+ naming.push('Constants: UPPER_SNAKE_CASE');
678
+ naming.push('Functions/Variables: camelCase');
679
+ naming.push('Classes/Types: PascalCase');
680
+ return { naming };
681
+ }
682
+ function describeKeyDirectories(analysis) {
683
+ const descriptions = [];
684
+ if (analysis.directories.includes('src')) {
685
+ descriptions.push('- **src/**: Main source code directory containing application logic');
686
+ }
687
+ if (analysis.directories.includes('dist') || analysis.directories.includes('build')) {
688
+ descriptions.push('- **dist/build/**: Compiled output for production deployment');
689
+ }
690
+ if (analysis.hasTests) {
691
+ const testDir = analysis.directories.find(d => ['test', 'tests', '__tests__'].includes(d));
692
+ if (testDir) {
693
+ descriptions.push(`- **${testDir}/**: Test suites and test utilities`);
694
+ }
695
+ }
696
+ if (analysis.directories.includes('domain')) {
697
+ descriptions.push('- **domain/**: Core business logic and domain models');
698
+ }
699
+ if (analysis.directories.includes('infrastructure')) {
700
+ descriptions.push('- **infrastructure/**: External service integrations and adapters');
701
+ }
702
+ return descriptions.join('\n');
703
+ }
704
+ function describeModuleOrganization(analysis) {
705
+ if (analysis.architecture.includes('DDD')) {
706
+ return `### Domain-Driven Modules
707
+ - Each domain has its own module with models, services, and repositories
708
+ - Clear boundaries between different domains
709
+ - Dependency flow from infrastructure → application → domain`;
710
+ }
711
+ if (analysis.type === 'ES Module') {
712
+ return `### ES Module Organization
713
+ - ES6 module syntax with import/export
714
+ - Barrel exports through index files
715
+ - Tree-shaking enabled for optimized bundles`;
716
+ }
717
+ return `### Module Structure
718
+ - Logical grouping of related functionality
719
+ - Clear import/export boundaries
720
+ - Minimal circular dependencies`;
721
+ }
722
+ function generateArchitecturalPrinciples(analysis) {
723
+ const principles = [];
724
+ principles.push({
725
+ principle: 'Separation of Concerns',
726
+ description: 'Each module handles a specific responsibility'
727
+ });
728
+ if (analysis.language === 'typescript') {
729
+ principles.push({
730
+ principle: 'Type Safety',
731
+ description: 'Leverage TypeScript for compile-time type checking'
732
+ });
733
+ }
734
+ if (analysis.hasTests) {
735
+ principles.push({
736
+ principle: 'Testability',
737
+ description: 'Code designed for easy unit and integration testing'
738
+ });
739
+ }
740
+ if (analysis.dependencies.includes('inversify')) {
741
+ principles.push({
742
+ principle: 'Dependency Inversion',
743
+ description: 'Depend on abstractions, not concrete implementations'
744
+ });
745
+ }
746
+ return principles;
747
+ }
748
+ function generateDevelopmentPatterns(analysis) {
749
+ const patterns = [];
750
+ if (analysis.scripts.dev) {
751
+ patterns.push('Hot module replacement for rapid development');
752
+ }
753
+ if (analysis.scripts.lint) {
754
+ patterns.push('Automated code quality checks on commit');
755
+ }
756
+ if (analysis.language === 'typescript') {
757
+ patterns.push('Strict TypeScript configuration for maximum safety');
758
+ }
759
+ if (analysis.hasTests) {
760
+ patterns.push('Test files co-located with source code');
761
+ }
762
+ return patterns;
763
+ }
764
+ function describeTestingStructure(analysis) {
765
+ if (!analysis.hasTests) {
766
+ return 'Testing structure to be implemented';
767
+ }
768
+ let structure = '';
769
+ if (analysis.testFramework === 'Jest') {
770
+ structure += `### Jest Testing Framework
771
+ - Unit tests: \`*.test.ts\` files alongside source code
772
+ - Integration tests: \`__tests__/integration\` directory
773
+ - Test configuration: \`jest.config.js\`
774
+ - Coverage reports: \`coverage/\` directory`;
775
+ }
776
+ else if (analysis.testFramework) {
777
+ structure += `### ${analysis.testFramework} Testing
778
+ - Test files organized in test directory
779
+ - Unit and integration test separation
780
+ - Test utilities and fixtures`;
781
+ }
782
+ else {
783
+ structure += `### Testing Structure
784
+ - Test files in dedicated test directory
785
+ - Separation between unit and integration tests`;
786
+ }
787
+ return structure;
788
+ }
789
+ function describeBuildOutput(analysis) {
790
+ if (!analysis.scripts.build) {
791
+ return 'No build process configured';
792
+ }
793
+ let output = `### Build Process
794
+ - Command: \`${analysis.packageManager} run build\`\n`;
795
+ if (analysis.directories.includes('dist')) {
796
+ output += '- Output directory: `dist/`\n';
797
+ }
798
+ else if (analysis.directories.includes('build')) {
799
+ output += '- Output directory: `build/`\n';
800
+ }
801
+ if (analysis.buildTool) {
802
+ output += `- Build tool: ${analysis.buildTool}\n`;
803
+ }
804
+ if (analysis.language === 'typescript') {
805
+ output += '- TypeScript compilation to JavaScript\n';
806
+ output += '- Source maps for debugging\n';
807
+ }
808
+ return output;
809
+ }
810
+ function getNodeVersion() {
811
+ try {
812
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
813
+ if (fs.existsSync(packageJsonPath)) {
814
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
815
+ if (packageJson.engines?.node) {
816
+ return packageJson.engines.node;
817
+ }
818
+ }
819
+ }
820
+ catch (error) {
821
+ // Ignore
822
+ }
823
+ return '>= 18.0.0';
824
+ }
825
+ //# sourceMappingURL=documentGenerator.js.map