@nexus-ioc/graph-analyzer 0.1.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +21 -0
  3. package/README.md +742 -0
  4. package/dist/analyzer/circular-dependency-detector.d.ts +94 -0
  5. package/dist/analyzer/circular-dependency-detector.js +203 -0
  6. package/dist/analyzer/circular-dependency-detector.js.map +1 -0
  7. package/dist/analyzer/module-depth-analyzer.d.ts +117 -0
  8. package/dist/analyzer/module-depth-analyzer.js +221 -0
  9. package/dist/analyzer/module-depth-analyzer.js.map +1 -0
  10. package/dist/analyzer/provider-scope-analyzer.d.ts +91 -0
  11. package/dist/analyzer/provider-scope-analyzer.js +137 -0
  12. package/dist/analyzer/provider-scope-analyzer.js.map +1 -0
  13. package/dist/analyzer/unused-provider-detector.d.ts +73 -0
  14. package/dist/analyzer/unused-provider-detector.js +147 -0
  15. package/dist/analyzer/unused-provider-detector.js.map +1 -0
  16. package/dist/cli.d.ts +2 -0
  17. package/dist/cli.js +537 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/config/config-loader.d.ts +27 -0
  20. package/dist/config/config-loader.js +205 -0
  21. package/dist/config/config-loader.js.map +1 -0
  22. package/dist/config/config-schema.d.ts +83 -0
  23. package/dist/config/config-schema.js +97 -0
  24. package/dist/config/config-schema.js.map +1 -0
  25. package/dist/index.d.ts +41 -0
  26. package/dist/index.js +50 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/interfaces/graph-output.interface.d.ts +126 -0
  29. package/dist/interfaces/graph-output.interface.js +3 -0
  30. package/dist/interfaces/graph-output.interface.js.map +1 -0
  31. package/dist/interfaces/providers.interface.d.ts +10 -0
  32. package/dist/interfaces/providers.interface.js +3 -0
  33. package/dist/interfaces/providers.interface.js.map +1 -0
  34. package/dist/parser/dependency-extractor.d.ts +88 -0
  35. package/dist/parser/dependency-extractor.js +334 -0
  36. package/dist/parser/dependency-extractor.js.map +1 -0
  37. package/dist/parser/parse-entry-file.d.ts +15 -0
  38. package/dist/parser/parse-entry-file.js +46 -0
  39. package/dist/parser/parse-entry-file.js.map +1 -0
  40. package/dist/parser/parse-imports.d.ts +15 -0
  41. package/dist/parser/parse-imports.js +65 -0
  42. package/dist/parser/parse-imports.js.map +1 -0
  43. package/dist/parser/parse-ns-module.d.ts +39 -0
  44. package/dist/parser/parse-ns-module.js +122 -0
  45. package/dist/parser/parse-ns-module.js.map +1 -0
  46. package/dist/parser/parse-provider.d.ts +2 -0
  47. package/dist/parser/parse-provider.js +7 -0
  48. package/dist/parser/parse-provider.js.map +1 -0
  49. package/dist/parser/parse-ts-config.d.ts +10 -0
  50. package/dist/parser/parse-ts-config.js +40 -0
  51. package/dist/parser/parse-ts-config.js.map +1 -0
  52. package/dist/parser/parser-rec.d.ts +1 -0
  53. package/dist/parser/parser-rec.js +52 -0
  54. package/dist/parser/parser-rec.js.map +1 -0
  55. package/dist/parser/parser.d.ts +1 -0
  56. package/dist/parser/parser.js +61 -0
  57. package/dist/parser/parser.js.map +1 -0
  58. package/dist/parser/provider/class-parser.d.ts +20 -0
  59. package/dist/parser/provider/class-parser.js +137 -0
  60. package/dist/parser/provider/class-parser.js.map +1 -0
  61. package/dist/parser/provider/providers-parser.d.ts +9 -0
  62. package/dist/parser/provider/providers-parser.js +32 -0
  63. package/dist/parser/provider/providers-parser.js.map +1 -0
  64. package/dist/parser/provider/use-class-parser.d.ts +25 -0
  65. package/dist/parser/provider/use-class-parser.js +161 -0
  66. package/dist/parser/provider/use-class-parser.js.map +1 -0
  67. package/dist/parser/provider/use-factory-parser.d.ts +15 -0
  68. package/dist/parser/provider/use-factory-parser.js +53 -0
  69. package/dist/parser/provider/use-factory-parser.js.map +1 -0
  70. package/dist/parser/provider/use-value-parser.d.ts +13 -0
  71. package/dist/parser/provider/use-value-parser.js +41 -0
  72. package/dist/parser/provider/use-value-parser.js.map +1 -0
  73. package/dist/parser/rules.d.ts +10 -0
  74. package/dist/parser/rules.js +37 -0
  75. package/dist/parser/rules.js.map +1 -0
  76. package/dist/utils/error-formatter.d.ts +27 -0
  77. package/dist/utils/error-formatter.js +177 -0
  78. package/dist/utils/error-formatter.js.map +1 -0
  79. package/dist/utils/validator.d.ts +45 -0
  80. package/dist/utils/validator.js +252 -0
  81. package/dist/utils/validator.js.map +1 -0
  82. package/dist/visualize/generator.d.ts +26 -0
  83. package/dist/visualize/generator.js +75 -0
  84. package/dist/visualize/generator.js.map +1 -0
  85. package/dist/visualize/graph-analyzer.d.ts +126 -0
  86. package/dist/visualize/graph-analyzer.js +199 -0
  87. package/dist/visualize/graph-analyzer.js.map +1 -0
  88. package/dist/visualize/html-generator.d.ts +71 -0
  89. package/dist/visualize/html-generator.js +1312 -0
  90. package/dist/visualize/html-generator.js.map +1 -0
  91. package/dist/visualize/json-formatter.d.ts +106 -0
  92. package/dist/visualize/json-formatter.js +252 -0
  93. package/dist/visualize/json-formatter.js.map +1 -0
  94. package/docs/API_REFERENCE.md +747 -0
  95. package/docs/ARCHITECTURE.md +486 -0
  96. package/docs/CLI_GUIDE.md +576 -0
  97. package/docs/HTML_VISUALIZATION.md +365 -0
  98. package/package.json +85 -0
package/README.md ADDED
@@ -0,0 +1,742 @@
1
+ # @nexus-ioc/graph-analyzer
2
+
3
+ > Static analysis and visualization tool for Nexus IoC dependency injection graphs
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@nexus-ioc/graph-analyzer.svg)](https://www.npmjs.com/package/@nexus-ioc/graph-analyzer)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
8
+ [![Tests](https://img.shields.io/badge/tests-443%20passing-brightgreen.svg)](./src)
9
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen.svg)](https://nodejs.org/)
10
+
11
+ Analyze and visualize dependency injection graphs in [Nexus IoC](https://github.com/Isqanderm/ioc) applications. Extract complete metadata about modules, providers, and dependencies **without running your application**. Detect circular dependencies, unused providers, scope mismatches, and visualize your architecture with interactive HTML graphs.
12
+
13
+ ## ✨ Features
14
+
15
+ ### Core Analysis
16
+ - 🔍 **Static Analysis** - Analyze DI graphs without executing code using TypeScript AST
17
+ - 🎯 **Complete Dependency Extraction** - Constructor and property injection with full metadata
18
+ - 🔧 **CLI & Programmatic API** - Use as a command-line tool or integrate into your build pipeline
19
+ - 🎨 **Modern Decorator Support** - Both legacy and TC39 Stage 3 decorators
20
+ - 📦 **TypeScript Path Aliases** - Resolves tsconfig.json path mappings automatically
21
+ - 🌳 **Module Graph Traversal** - Follows imports to build complete dependency graph
22
+
23
+ ### Advanced Analysis Features
24
+ - 🔄 **Circular Dependency Detection** - Detect circular imports and provider dependencies
25
+ - 🗑️ **Unused Provider Detection** - Find providers that are registered but never injected
26
+ - 📊 **Module Depth Analysis** - Analyze module hierarchy depth and complexity metrics
27
+ - 🎯 **Provider Scope Analysis** - Detect scope mismatches (Singleton depending on Request-scoped)
28
+ - ⚠️ **Missing Decorator Detection** - Identify dependencies without explicit `@Inject` decorators
29
+
30
+ ### Visualization & Output
31
+ - 📊 **Multiple Output Formats** - JSON data, interactive HTML, and PNG visualizations
32
+ - 🎨 **Interactive HTML Graphs** - Click nodes to explore, pan/zoom, dark theme support
33
+ - 🔗 **IDE Integration** - Clickable links to source code (VSCode, WebStorm, IntelliJ IDEA)
34
+ - ⚡ **Progress Indicators** - Real-time feedback with spinners and statistics
35
+ - 🎛️ **Flexible Output Control** - Verbose and quiet modes for different use cases
36
+
37
+ ## 📦 Installation
38
+
39
+ Install as a development dependency in your project:
40
+
41
+ ```bash
42
+ npm install --save-dev @nexus-ioc/graph-analyzer
43
+ ```
44
+
45
+ Or install globally:
46
+
47
+ ```bash
48
+ npm install -g @nexus-ioc/graph-analyzer
49
+ ```
50
+
51
+ **Requirements:**
52
+ - Node.js >= 14.0.0
53
+ - TypeScript project with Nexus IoC
54
+
55
+ ## 🚀 Quick Start
56
+
57
+ ### CLI Usage
58
+
59
+ Analyze your application's entry point:
60
+
61
+ ```bash
62
+ # Generate interactive HTML visualization (recommended)
63
+ npx graph-analyzer -f html -o graph.html src/main.ts
64
+
65
+ # Generate JSON data
66
+ npx graph-analyzer -f json -o graph.json src/main.ts
67
+
68
+ # Run all analysis checks
69
+ npx graph-analyzer --check-circular --check-unused --check-scope --check-depth src/main.ts
70
+
71
+ # Specify custom tsconfig.json
72
+ npx graph-analyzer -c tsconfig.app.json src/main.ts
73
+ ```
74
+
75
+ ### Programmatic Usage
76
+
77
+ ```typescript
78
+ import { GraphAnalyzer, ParseEntryFile, ParseTsConfig } from '@nexus-ioc/graph-analyzer';
79
+ import * as fs from 'fs';
80
+ import * as ts from 'typescript';
81
+
82
+ // Load TypeScript configuration
83
+ const tsConfigContent = fs.readFileSync('tsconfig.json', 'utf8');
84
+ const tsConfig = new ParseTsConfig(tsConfigContent, process.cwd());
85
+
86
+ // Parse entry file
87
+ const entryContent = fs.readFileSync('src/main.ts', 'utf8');
88
+ const sourceFile = ts.createSourceFile('src/main.ts', entryContent, ts.ScriptTarget.Latest, true);
89
+ const entryFile = new ParseEntryFile(sourceFile, 'src/main.ts', tsConfig);
90
+ entryFile.parse();
91
+
92
+ // Build module graph (simplified - see full example in docs)
93
+ const modulesGraph = new Map();
94
+ modulesGraph.set('entry', entryFile);
95
+ // ... traverse and add all modules
96
+
97
+ // Analyze with all features enabled
98
+ const analyzer = new GraphAnalyzer(modulesGraph, 'src/main.ts', {
99
+ outputFormat: 'json',
100
+ jsonOutputPath: './graph.json',
101
+ checkCircular: true,
102
+ checkUnused: true,
103
+ checkDepth: true,
104
+ checkScope: true
105
+ });
106
+
107
+ const output = analyzer.parse();
108
+ console.log(`Analyzed ${output.metadata.totalModules} modules`);
109
+ console.log(`Found ${output.metadata.totalProviders} providers`);
110
+
111
+ // Check for issues
112
+ if (output.analysis?.circularDependencies?.length > 0) {
113
+ console.error('Circular dependencies detected!');
114
+ }
115
+ ```
116
+
117
+ ## 📖 CLI Reference
118
+
119
+ ### Command Syntax
120
+
121
+ ```
122
+ graph-analyzer [options] <entry-file>
123
+ ```
124
+
125
+ ### Arguments
126
+
127
+ - `<entry-file>` - Path to your application's entry point file (e.g., `src/main.ts`)
128
+
129
+ ### Options
130
+
131
+ #### Output Options
132
+ | Option | Alias | Description | Default |
133
+ |--------|-------|-------------|---------|
134
+ | `--config <path>` | `-c` | Path to tsconfig.json | `./tsconfig.json` |
135
+ | `--output <path>` | `-o` | Output file path | `./graph.json`, `./graph.png`, or `./graph.html` |
136
+ | `--format <format>` | `-f` | Output format: `json`, `png`, `html`, or `both` | `both` |
137
+
138
+ #### Analysis Options
139
+ | Option | Description | Default |
140
+ |--------|-------------|---------|
141
+ | `--check-circular` | Detect circular dependencies in modules and providers | `false` |
142
+ | `--check-unused` | Detect providers that are registered but never injected | `false` |
143
+ | `--check-depth` | Analyze module hierarchy depth and complexity | `false` |
144
+ | `--check-scope` | Detect provider scope mismatches | `false` |
145
+ | `--check-ci` | Enable all checks (circular, unused, depth, scope) | `false` |
146
+ | `--deep-module-threshold <n>` | Threshold for identifying deep modules | `5` |
147
+
148
+ #### Visualization Options
149
+ | Option | Description | Default |
150
+ |--------|-------------|---------|
151
+ | `--ide <protocol>` | IDE protocol for clickable links: `vscode`, `webstorm`, `idea` | `vscode` |
152
+ | `--dark` | Use dark theme for HTML output | `false` |
153
+
154
+ #### General Options
155
+ | Option | Alias | Description |
156
+ |--------|-------|-------------|
157
+ | `--verbose` | - | Show detailed progress information |
158
+ | `--quiet` | - | Suppress all output except errors |
159
+ | `--help` | `-h` | Display help message |
160
+ | `--version` | `-v` | Display version number |
161
+
162
+ ### Examples
163
+
164
+ ```bash
165
+ # Basic usage - generates interactive HTML
166
+ npx graph-analyzer -f html -o graph.html src/main.ts
167
+
168
+ # Run all analysis checks (recommended for CI/CD)
169
+ npx graph-analyzer --check-ci -f json -o graph.json src/main.ts
170
+
171
+ # Detect circular dependencies only
172
+ npx graph-analyzer --check-circular src/main.ts
173
+
174
+ # Detect unused providers
175
+ npx graph-analyzer --check-unused -f html src/main.ts
176
+
177
+ # Analyze module depth and complexity
178
+ npx graph-analyzer --check-depth --deep-module-threshold 3 src/main.ts
179
+
180
+ # Detect scope mismatches (Singleton depending on Request-scoped)
181
+ npx graph-analyzer --check-scope src/main.ts
182
+
183
+ # HTML with dark theme and WebStorm links
184
+ npx graph-analyzer -f html --ide webstorm --dark src/main.ts
185
+
186
+ # Custom tsconfig location
187
+ npx graph-analyzer -c config/tsconfig.build.json src/main.ts
188
+
189
+ # Verbose output for debugging
190
+ npx graph-analyzer --verbose --check-ci src/main.ts
191
+
192
+ # Quiet mode for CI/CD pipelines (exit code 1 if issues found)
193
+ npx graph-analyzer --quiet --check-ci -f json -o build/graph.json src/main.ts
194
+
195
+ # Complete example with all options
196
+ npx graph-analyzer \
197
+ -c tsconfig.json \
198
+ -f html \
199
+ -o docs/architecture.html \
200
+ --check-circular \
201
+ --check-unused \
202
+ --check-scope \
203
+ --check-depth \
204
+ --ide vscode \
205
+ --dark \
206
+ src/main.ts
207
+ ```
208
+
209
+ ## 📊 Analysis Features
210
+
211
+ ### Circular Dependency Detection
212
+
213
+ Detects circular dependencies in both module imports and provider dependencies using depth-first search (DFS).
214
+
215
+ ```bash
216
+ npx graph-analyzer --check-circular src/main.ts
217
+ ```
218
+
219
+ **Detects:**
220
+ - Module-level circular imports (ModuleA → ModuleB → ModuleA)
221
+ - Provider-level circular dependencies (ServiceA → ServiceB → ServiceA)
222
+
223
+ **Example Output:**
224
+ ```json
225
+ {
226
+ "analysis": {
227
+ "circularDependencies": [
228
+ {
229
+ "type": "module",
230
+ "cycle": ["UserModule", "AuthModule", "UserModule"],
231
+ "severity": "error",
232
+ "message": "Circular module import detected: UserModule -> AuthModule -> UserModule"
233
+ }
234
+ ]
235
+ }
236
+ }
237
+ ```
238
+
239
+ ### Unused Provider Detection
240
+
241
+ Finds providers that are registered but never injected as dependencies.
242
+
243
+ ```bash
244
+ npx graph-analyzer --check-unused src/main.ts
245
+ ```
246
+
247
+ **Identifies:**
248
+ - Providers registered in modules but not used anywhere
249
+ - Potential dead code that can be removed
250
+ - Providers that might be missing from exports
251
+
252
+ **Example Output:**
253
+ ```json
254
+ {
255
+ "analysis": {
256
+ "unusedProviders": [
257
+ {
258
+ "token": "LegacyService",
259
+ "module": "CoreModule",
260
+ "type": "Class",
261
+ "reason": "Not injected in any provider"
262
+ }
263
+ ]
264
+ }
265
+ }
266
+ ```
267
+
268
+ ### Module Depth Analysis
269
+
270
+ Analyzes module hierarchy depth and complexity metrics using breadth-first search (BFS).
271
+
272
+ ```bash
273
+ npx graph-analyzer --check-depth --deep-module-threshold 5 src/main.ts
274
+ ```
275
+
276
+ **Calculates:**
277
+ - Maximum depth in module hierarchy
278
+ - Average depth across all modules
279
+ - Modules exceeding depth threshold
280
+ - Fan-in and fan-out metrics
281
+
282
+ **Example Output:**
283
+ ```json
284
+ {
285
+ "analysis": {
286
+ "depthAnalysis": {
287
+ "maxDepth": 4,
288
+ "averageDepth": 2.3,
289
+ "totalModules": 15,
290
+ "deepModules": [
291
+ {
292
+ "name": "FeatureModule",
293
+ "depth": 5,
294
+ "fanIn": 3,
295
+ "fanOut": 7
296
+ }
297
+ ]
298
+ }
299
+ }
300
+ }
301
+ ```
302
+
303
+ ### Provider Scope Analysis
304
+
305
+ Detects scope mismatches where Singleton providers depend on Request-scoped providers.
306
+
307
+ ```bash
308
+ npx graph-analyzer --check-scope src/main.ts
309
+ ```
310
+
311
+ **Detects:**
312
+ - Singleton providers depending on Request-scoped providers (memory leak risk)
313
+ - Scope inconsistencies that can cause unexpected behavior
314
+ - Provides suggestions for fixing scope issues
315
+
316
+ **Example Output:**
317
+ ```json
318
+ {
319
+ "analysis": {
320
+ "scopeAnalysis": {
321
+ "scopeMismatches": [
322
+ {
323
+ "provider": "UserService",
324
+ "providerScope": "Singleton",
325
+ "dependency": "RequestContext",
326
+ "dependencyScope": "Request",
327
+ "severity": "error",
328
+ "message": "Singleton provider 'UserService' depends on Request-scoped provider 'RequestContext'",
329
+ "suggestions": [
330
+ "Change 'UserService' to Request scope",
331
+ "Change 'RequestContext' to Singleton scope if it doesn't need request-specific state"
332
+ ]
333
+ }
334
+ ]
335
+ }
336
+ }
337
+ }
338
+ ```
339
+
340
+ ### Missing Decorator Detection
341
+
342
+ Identifies dependencies that lack explicit `@Inject` decorators.
343
+
344
+ **Automatically detected in all analysis modes**
345
+
346
+ **Example Output:**
347
+ ```json
348
+ {
349
+ "providers": [
350
+ {
351
+ "token": "UserService",
352
+ "dependencies": [
353
+ {
354
+ "type": "constructor",
355
+ "index": 0,
356
+ "token": "UserRepository",
357
+ "hasExplicitDecorator": false,
358
+ "raw": "private repo: UserRepository"
359
+ }
360
+ ]
361
+ }
362
+ ]
363
+ }
364
+ ```
365
+
366
+ ## 📊 Output Formats
367
+
368
+ ### JSON Output
369
+
370
+ The JSON output provides a structured representation of your dependency graph with complete analysis results:
371
+
372
+ ```json
373
+ {
374
+ "modules": [
375
+ {
376
+ "name": "UserModule",
377
+ "path": "/path/to/user.module.ts",
378
+ "imports": ["DatabaseModule"],
379
+ "exports": ["UserService"],
380
+ "providers": ["UserService", "UserRepository"],
381
+ "isGlobal": false
382
+ }
383
+ ],
384
+ "providers": [
385
+ {
386
+ "token": "UserService",
387
+ "type": "Class",
388
+ "module": "UserModule",
389
+ "scope": "Singleton",
390
+ "dependencies": [
391
+ {
392
+ "type": "constructor",
393
+ "index": 0,
394
+ "token": "UserRepository",
395
+ "tokenType": "class",
396
+ "optional": false,
397
+ "hasExplicitDecorator": true
398
+ }
399
+ ]
400
+ }
401
+ ],
402
+ "analysis": {
403
+ "circularDependencies": [],
404
+ "unusedProviders": [],
405
+ "depthAnalysis": { "maxDepth": 3, "averageDepth": 2.1 },
406
+ "scopeAnalysis": { "scopeMismatches": [] }
407
+ },
408
+ "metadata": {
409
+ "entryPoint": "/path/to/main.ts",
410
+ "rootModule": "AppModule",
411
+ "analyzedAt": "2025-01-18T12:00:00.000Z",
412
+ "version": "0.1.0",
413
+ "totalModules": 5,
414
+ "totalProviders": 12
415
+ }
416
+ }
417
+ ```
418
+
419
+ ### HTML Output (Interactive Visualization)
420
+
421
+ The HTML output provides an interactive graph visualization with:
422
+
423
+ **Features:**
424
+ - 🖱️ **Interactive Graph** - Click nodes to explore dependencies, pan and zoom
425
+ - 🎨 **Visual Hierarchy** - Modules as containers, providers as nodes
426
+ - 🔍 **Search** - Find modules and providers quickly
427
+ - 🎯 **Filtering** - View modules only, providers only, or all
428
+ - 🔗 **IDE Links** - Click to open source files in your IDE
429
+ - ⚠️ **Error Highlighting** - Visual indicators for circular dependencies, missing decorators
430
+ - 🌓 **Dark Theme** - Easy on the eyes
431
+ - 📊 **Statistics** - Module count, provider count, dependency count
432
+
433
+ **Example:**
434
+ ```bash
435
+ npx graph-analyzer -f html --dark --ide vscode -o graph.html src/main.ts
436
+ ```
437
+
438
+ Open `graph.html` in your browser to explore your dependency graph interactively.
439
+
440
+ ### PNG Output
441
+
442
+ The PNG output is a static graph visualization showing:
443
+ - Modules as nodes
444
+ - Dependencies as directed edges
445
+ - Global modules highlighted
446
+ - Provider relationships
447
+
448
+ **Note:** Requires Graphviz to be installed on your system.
449
+
450
+ ## 🎯 What Gets Analyzed
451
+
452
+ ### Supported Patterns
453
+
454
+ ✅ **Constructor Injection**
455
+ ```typescript
456
+ @Injectable()
457
+ class UserService {
458
+ constructor(
459
+ @Inject(UserRepository) private repo: UserRepository,
460
+ @Inject('CONFIG') private config: Config
461
+ ) {}
462
+ }
463
+ ```
464
+
465
+ ✅ **Property Injection**
466
+ ```typescript
467
+ @Injectable()
468
+ class UserService {
469
+ @Inject(Logger)
470
+ private logger: Logger;
471
+ }
472
+ ```
473
+
474
+ ✅ **Optional Dependencies**
475
+ ```typescript
476
+ @Injectable()
477
+ class UserService {
478
+ constructor(
479
+ @Optional() @Inject(CacheService) private cache?: CacheService
480
+ ) {}
481
+ }
482
+ ```
483
+
484
+ ✅ **TC39 Stage 3 Decorators**
485
+ ```typescript
486
+ @Injectable()
487
+ class UserService {
488
+ static dependencies = [
489
+ { index: 0, token: UserRepository, optional: false }
490
+ ];
491
+ }
492
+ ```
493
+
494
+ ✅ **Different Provider Types**
495
+ ```typescript
496
+ @NsModule({
497
+ providers: [
498
+ UserService, // Class
499
+ { provide: 'CONFIG', useValue: config }, // UseValue
500
+ { provide: 'FACTORY', useFactory: factory }, // UseFactory
501
+ { provide: IService, useClass: ServiceImpl } // UseClass
502
+ ]
503
+ })
504
+ ```
505
+
506
+ ### Token Types
507
+
508
+ The analyzer detects three types of injection tokens:
509
+
510
+ - **Class tokens**: `@Inject(UserService)`
511
+ - **String tokens**: `@Inject('CONFIG')`
512
+ - **Symbol tokens**: `@Inject(Symbol.for('key'))`
513
+
514
+ ## 🏗️ Architecture
515
+
516
+ The graph analyzer works in several phases:
517
+
518
+ 1. **Entry Point Parsing** - Finds the root module from your entry file
519
+ 2. **Module Traversal** - Recursively follows module imports
520
+ 3. **Provider Analysis** - Extracts provider metadata from each module
521
+ 4. **Dependency Extraction** - Analyzes decorators to find dependencies
522
+ 5. **Graph Building** - Constructs the complete dependency graph
523
+ 6. **Output Generation** - Produces JSON and/or PNG visualization
524
+
525
+ For detailed architecture documentation, see [ARCHITECTURE.md](./docs/ARCHITECTURE.md).
526
+
527
+ ## 📚 API Reference
528
+
529
+ For complete API documentation, see [API_REFERENCE.md](./docs/API_REFERENCE.md).
530
+
531
+ ### Key Classes
532
+
533
+ - `GraphAnalyzer` - Main analyzer class
534
+ - `JsonFormatter` - JSON output formatter
535
+ - `DependencyExtractor` - Dependency metadata extraction
536
+ - `ParseNsModule` - Module parser
537
+ - `ParseEntryFile` - Entry point parser
538
+
539
+ ## 🧪 Testing
540
+
541
+ The package includes comprehensive tests covering all features:
542
+
543
+ ```bash
544
+ # Run all tests
545
+ npm test
546
+
547
+ # Run tests with coverage
548
+ npm run test:coverage
549
+
550
+ # Run tests in watch mode
551
+ npm run test:watch
552
+ ```
553
+
554
+ **Test Coverage**: 443 tests across 26 test files, covering:
555
+ - Parser components (entry file, modules, providers)
556
+ - Dependency extraction (constructor, property, TC39 decorators)
557
+ - Analysis features (circular, unused, depth, scope)
558
+ - Output formatters (JSON, HTML)
559
+ - Configuration and validation
560
+ - Error handling and edge cases
561
+
562
+ ## 🔧 Troubleshooting
563
+
564
+ ### Common Issues
565
+
566
+ #### "Cannot find module" errors
567
+
568
+ **Problem:** The analyzer can't resolve module imports.
569
+
570
+ **Solution:**
571
+ - Ensure your `tsconfig.json` has correct `paths` configuration
572
+ - Use the `-c` flag to specify the correct tsconfig file
573
+ - Check that all imported modules exist
574
+
575
+ ```bash
576
+ npx graph-analyzer -c tsconfig.json src/main.ts
577
+ ```
578
+
579
+ #### "No root module found" error
580
+
581
+ **Problem:** The entry file doesn't bootstrap a module.
582
+
583
+ **Solution:**
584
+ - Ensure your entry file calls `NsApplicationFactory.create()` or similar
585
+ - The entry file should import and bootstrap your root module
586
+
587
+ ```typescript
588
+ // src/main.ts
589
+ import { NsApplicationFactory } from 'nexus-ioc';
590
+ import { AppModule } from './app.module';
591
+
592
+ async function bootstrap() {
593
+ const app = await NsApplicationFactory.create(AppModule);
594
+ await app.listen(3000);
595
+ }
596
+ bootstrap();
597
+ ```
598
+
599
+ #### Circular dependency false positives
600
+
601
+ **Problem:** Circular dependencies reported for valid patterns.
602
+
603
+ **Solution:**
604
+ - Some circular dependencies are intentional (e.g., forwardRef)
605
+ - Review the reported cycles to determine if they're problematic
606
+ - Consider refactoring to break the cycle if it's causing issues
607
+
608
+ #### Missing decorators warnings
609
+
610
+ **Problem:** Warnings about missing `@Inject` decorators.
611
+
612
+ **Solution:**
613
+ - Add explicit `@Inject` decorators to all constructor parameters
614
+ - This is recommended for production code to avoid reflection issues
615
+
616
+ ```typescript
617
+ // Before (may cause issues)
618
+ constructor(private service: MyService) {}
619
+
620
+ // After (recommended)
621
+ constructor(@Inject(MyService) private service: MyService) {}
622
+ ```
623
+
624
+ #### HTML visualization not loading
625
+
626
+ **Problem:** HTML file opens but graph doesn't render.
627
+
628
+ **Solution:**
629
+ - Check browser console for errors
630
+ - Ensure the HTML file is opened from a local file or web server
631
+ - Try a different browser (Chrome, Firefox, Safari all supported)
632
+
633
+ #### Performance issues with large projects
634
+
635
+ **Problem:** Analysis takes too long or runs out of memory.
636
+
637
+ **Solution:**
638
+ - Analyze specific modules instead of the entire application
639
+ - Disable unnecessary analysis checks
640
+ - Increase Node.js memory limit:
641
+
642
+ ```bash
643
+ NODE_OPTIONS="--max-old-space-size=4096" npx graph-analyzer src/main.ts
644
+ ```
645
+
646
+ ### Getting Help
647
+
648
+ If you encounter issues not covered here:
649
+
650
+ 1. Check the [documentation](./docs)
651
+ 2. Search [existing issues](https://github.com/Isqanderm/ioc/issues)
652
+ 3. Create a [new issue](https://github.com/Isqanderm/ioc/issues/new) with:
653
+ - Your environment (Node.js version, OS)
654
+ - Complete error message
655
+ - Minimal reproduction example
656
+
657
+ ## 🤝 Contributing
658
+
659
+ Contributions are welcome! Here's how you can help:
660
+
661
+ ### Reporting Issues
662
+
663
+ - Use the [issue tracker](https://github.com/Isqanderm/ioc/issues)
664
+ - Include reproduction steps and environment details
665
+ - Check if the issue already exists before creating a new one
666
+
667
+ ### Submitting Pull Requests
668
+
669
+ 1. Fork the repository
670
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
671
+ 3. Make your changes
672
+ 4. Add tests for new functionality
673
+ 5. Ensure all tests pass (`npm test`)
674
+ 6. Run linter (`npm run code:check`)
675
+ 7. Commit your changes (`git commit -m 'feat: add amazing feature'`)
676
+ 8. Push to the branch (`git push origin feature/amazing-feature`)
677
+ 9. Open a Pull Request
678
+
679
+ ### Development Setup
680
+
681
+ ```bash
682
+ # Clone the repository
683
+ git clone https://github.com/Isqanderm/ioc.git
684
+ cd ioc/packages/graph-analyzer
685
+
686
+ # Install dependencies
687
+ npm install
688
+
689
+ # Build the package
690
+ npm run build
691
+
692
+ # Run tests
693
+ npm test
694
+
695
+ # Run tests in watch mode
696
+ npm run test:watch
697
+
698
+ # Run linter
699
+ npm run code:check
700
+ ```
701
+
702
+ ### Commit Convention
703
+
704
+ We use [Conventional Commits](https://www.conventionalcommits.org/):
705
+
706
+ - `feat:` - New features
707
+ - `fix:` - Bug fixes
708
+ - `docs:` - Documentation changes
709
+ - `test:` - Test additions or changes
710
+ - `chore:` - Maintenance tasks
711
+ - `refactor:` - Code refactoring
712
+
713
+ ## 📄 License
714
+
715
+ MIT © 2024 [Aleksandr Melnik](https://github.com/Isqanderm)
716
+
717
+ See [LICENSE](./LICENSE) file for details.
718
+
719
+ ## 🔗 Related Projects
720
+
721
+ - **[Nexus IoC](https://github.com/Isqanderm/ioc)** - The dependency injection framework this tool analyzes
722
+ - **[TypeScript](https://www.typescriptlang.org/)** - Language and compiler API used for static analysis
723
+ - **[Cytoscape.js](https://js.cytoscape.org/)** - Graph visualization library for HTML output
724
+ - **[Graphviz](https://graphviz.org/)** - Graph visualization engine for PNG output
725
+
726
+ ## 📞 Support
727
+
728
+ - 🐛 **[Report a bug](https://github.com/Isqanderm/ioc/issues/new?labels=bug&template=bug_report.md)**
729
+ - 💡 **[Request a feature](https://github.com/Isqanderm/ioc/issues/new?labels=enhancement&template=feature_request.md)**
730
+ - 📖 **[Documentation](https://github.com/Isqanderm/ioc/tree/main/packages/graph-analyzer#readme)**
731
+ - 💬 **[Discussions](https://github.com/Isqanderm/ioc/discussions)**
732
+
733
+ ## 🙏 Acknowledgments
734
+
735
+ - Built with [TypeScript Compiler API](https://github.com/microsoft/TypeScript)
736
+ - Inspired by [NestJS](https://nestjs.com/) and [Angular](https://angular.io/) dependency injection patterns
737
+ - Graph visualization powered by [Cytoscape.js](https://js.cytoscape.org/)
738
+
739
+ ---
740
+
741
+ **Made with ❤️ by [Aleksandr Melnik](https://github.com/Isqanderm)**
742
+