@dailephd/my-dev-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,649 @@
1
+ # Architecture
2
+
3
+ ## System goal
4
+
5
+ my-dev-kit provides deterministic, offline code graph indexing and retrieval for TypeScript, JavaScript, and Python projects.
6
+
7
+ The system produces file-based JSON artifacts that can be inspected, searched, sliced, and reused by developers or coding agents. It does not run a server, maintain a runtime graph, call LLMs, call external APIs, or modify user source files.
8
+
9
+ The core workflow is:
10
+
11
+ index a project
12
+ search or lookup graph nodes
13
+ slice the relevant graph neighborhood
14
+ retrieve bounded source context
15
+ optionally render the graph for inspection
16
+
17
+ ## High-level architecture
18
+
19
+ CLI entry: src/cli.ts
20
+ |
21
+ +-- index command -> Indexing layer -> manifest.json, symbol-index.json, code-graph.json, optional call-graph.json
22
+ +-- search command -> Search layer -> ranked keyword matches over index artifacts
23
+ +-- lookup command -> Lookup layer -> exact node lookup and bounded neighbor traversal
24
+ +-- source command -> Source retrieval -> bounded source slices
25
+ +-- slice command -> Graph slicing layer -> bounded graph-neighborhood artifacts
26
+ +-- view command -> Graph view layer -> DOT, SVG, or PNG graph output
27
+
28
+ The `index` command creates the artifact set. All other commands read from that artifact set.
29
+
30
+ ## Artifact model
31
+
32
+ The index command writes artifacts into the selected output directory.
33
+
34
+ Core artifacts:
35
+
36
+ - `manifest.json`
37
+ - `symbol-index.json`
38
+ - `code-graph.json`
39
+
40
+ Optional artifacts:
41
+
42
+ - `call-graph.json`, written when `--call-graph` is requested and call graph data is available
43
+
44
+ Artifact flow:
45
+
46
+ index --root <project> --src <src>
47
+ |
48
+ +-> manifest.json
49
+ +-> symbol-index.json
50
+ +-> code-graph.json
51
+ +-> call-graph.json, optional
52
+
53
+ search / lookup / source / slice / view
54
+ |
55
+ +<- manifest.json
56
+ +<- symbol-index.json
57
+ +<- code-graph.json
58
+ +<- call-graph.json, when requested by a command or workflow
59
+
60
+ The artifacts are local files. They can be committed, ignored, deleted, regenerated, inspected manually, or passed into other tools.
61
+
62
+ ## CLI layer
63
+
64
+ Files:
65
+
66
+ - `src/cli.ts`
67
+ - `src/commands/`
68
+
69
+ The CLI layer registers the public command surface with `commander`.
70
+
71
+ Public commands:
72
+
73
+ - `index`
74
+ - `search`
75
+ - `lookup`
76
+ - `source`
77
+ - `slice`
78
+ - `view`
79
+
80
+ Command files:
81
+
82
+ - `indexCommand.ts`
83
+ - `searchCommand.ts`
84
+ - `lookupCommand.ts`
85
+ - `sourceCommand.ts`
86
+ - `sliceCommand.ts`
87
+ - `viewCommand.ts`
88
+
89
+ The CLI layer owns:
90
+
91
+ - command registration
92
+ - option parsing
93
+ - input validation
94
+ - output-format selection
95
+ - error presentation
96
+ - process exit behavior
97
+
98
+ The CLI layer does not own indexing, graph traversal, source retrieval, search scoring, or rendering logic.
99
+
100
+ ## Indexing layer
101
+
102
+ Files:
103
+
104
+ - `src/indexing/`
105
+
106
+ The indexing layer owns the full index run.
107
+
108
+ Responsibilities:
109
+
110
+ - resolve the project root
111
+ - resolve source roots
112
+ - discover source files
113
+ - apply default ignored directories
114
+ - apply repeated `--exclude` rules
115
+ - support `--dry-run`
116
+ - support progress diagnostics
117
+ - dispatch files to language adapters
118
+ - assemble the symbol index
119
+ - build the code graph
120
+ - optionally build the call graph
121
+ - write index artifacts
122
+
123
+ Source discovery is centralized in `discoverSourceFiles.ts`. Normal indexing, dry-run mode, default ignores, repeated excludes, and progress counters use the same discovery path before symbol extraction.
124
+
125
+ The indexer skips common dependency, generated, build, and cache directories before reading files from those directories.
126
+
127
+ Examples of skipped directories include:
128
+
129
+ - `node_modules`
130
+ - `.next`
131
+ - `dist`
132
+ - `build`
133
+ - `coverage`
134
+ - `playwright-report`
135
+ - `test-results`
136
+ - `.cache`
137
+ - `.turbo`
138
+ - `.vercel`
139
+ - `.git`
140
+ - `.pytest_cache`
141
+ - `__pycache__`
142
+ - `.venv`
143
+ - `venv`
144
+
145
+ The indexing layer validates source roots and supported languages before running extraction.
146
+
147
+ ## Language adapter layer
148
+
149
+ Files:
150
+
151
+ - `src/languages/`
152
+
153
+ The language adapter layer owns language-specific extraction.
154
+
155
+ Main files:
156
+
157
+ - `types.ts`
158
+ - `registry.ts`
159
+ - `typescript/adapter.ts`
160
+ - `python/adapter.ts`
161
+
162
+ The `LanguageAdapter` interface defines the adapter contract:
163
+
164
+ - supported file extensions
165
+ - whether the adapter supports call graph extraction
166
+ - source extraction
167
+ - optional call graph extraction
168
+ - optional import resolution
169
+
170
+ The default registry registers:
171
+
172
+ - TypeScript adapter for `.ts`, `.tsx`, `.js`, and `.jsx`
173
+ - Python adapter for `.py`
174
+
175
+ The builder uses the registry to select the correct adapter per file. Language-specific logic stays inside adapters instead of being hardcoded throughout the indexing pipeline.
176
+
177
+ ## TypeScript and JavaScript adapter
178
+
179
+ Files:
180
+
181
+ - `src/languages/typescript/adapter.ts`
182
+
183
+ The TypeScript adapter handles:
184
+
185
+ - TypeScript files
186
+ - TSX files
187
+ - JavaScript files
188
+ - JSX files
189
+
190
+ It uses TypeScript compiler-based parsing for symbol extraction and conservative call graph extraction.
191
+
192
+ Extracted structures include:
193
+
194
+ - imports
195
+ - exports
196
+ - top-level symbols
197
+ - symbol names
198
+ - symbol kinds
199
+ - symbol start lines
200
+ - language metadata
201
+ - static call relationships where supported
202
+
203
+ The adapter is conservative. It does not attempt to fully resolve runtime dispatch, dynamic imports, generated code, or framework-specific behavior beyond what is statically available.
204
+
205
+ ## Python adapter
206
+
207
+ Files:
208
+
209
+ - `src/languages/python/adapter.ts`
210
+
211
+ The Python adapter handles `.py` files.
212
+
213
+ Python indexing requires Python 3.8 or later on `PATH` as `python` or `python3`.
214
+
215
+ The adapter uses a Python subprocess with AST extraction scripts. It does not execute user source files.
216
+
217
+ Extracted structures include:
218
+
219
+ - top-level functions
220
+ - async top-level functions
221
+ - top-level classes
222
+ - imports
223
+ - `ALL_CAPS` constants
224
+ - `Final`-annotated constants
225
+ - `__all__` exports when defined as a plain list
226
+ - conservative syntactic call edges for straightforward calls
227
+
228
+ Python symbols are considered exported unless their names start with `_`, unless `__all__` provides a more specific export list.
229
+
230
+ The Python call graph is static and conservative. It records direct syntactic calls such as:
231
+
232
+ - `foo()`
233
+ - `self.foo()`
234
+ - `module.foo()`
235
+ - `ClassName.method()`
236
+
237
+ It does not execute Python code or infer dynamic runtime behavior.
238
+
239
+ ## Symbol index layer
240
+
241
+ Files:
242
+
243
+ - `src/symbol-index/`
244
+
245
+ The symbol index layer builds per-file symbol tables.
246
+
247
+ For each indexed source file, it records:
248
+
249
+ - relative file path
250
+ - language
251
+ - imported module paths
252
+ - exported symbol names
253
+ - dependency paths when resolvable
254
+ - symbol records
255
+ - symbol names
256
+ - symbol kinds
257
+ - symbol start lines
258
+
259
+ The symbol index is written to `symbol-index.json`.
260
+
261
+ Consumers:
262
+
263
+ - `source` uses the symbol index to resolve symbol-name retrieval.
264
+ - `search` uses the symbol index to match symbol names, imports, exports, and dependency metadata.
265
+ - downstream workflows can use the symbol index as a compact file summary.
266
+
267
+ Current limitation:
268
+
269
+ - Symbol records include start lines, but not full symbol end-line bounds.
270
+ - Symbol retrieval may return a bounded preview from the symbol start line.
271
+ - Exact retrieval should use line-range mode when precise bounds are required.
272
+
273
+ ## Code graph layer
274
+
275
+ Files:
276
+
277
+ - `src/graph/codeGraphTypes.ts`
278
+ - `src/indexing/`
279
+
280
+ The code graph is a typed directed graph.
281
+
282
+ Node types include:
283
+
284
+ - file nodes
285
+ - symbol nodes
286
+
287
+ Core edge kinds include:
288
+
289
+ - `defines`
290
+ - `imports`
291
+ - `exports`
292
+ - `calls`
293
+ - `depends-on`
294
+ - `related-to`
295
+
296
+ Edge meanings:
297
+
298
+ - `defines` means a file defines a symbol.
299
+ - `imports` means a file imports from another module or dependency.
300
+ - `exports` means a file exports a symbol.
301
+ - `calls` means a symbol calls another symbol when statically detected.
302
+ - `depends-on` means a file or symbol depends on another node.
303
+ - `related-to` means a general structural relationship that is useful but not represented by a narrower edge kind.
304
+
305
+ The code graph is written to `code-graph.json`.
306
+
307
+ Consumers:
308
+
309
+ - `lookup`
310
+ - `slice`
311
+ - `view`
312
+ - `search`
313
+
314
+ The code graph describes code structure. It is not a runtime execution graph and does not claim complete semantic understanding of a program.
315
+
316
+ ## Call graph layer
317
+
318
+ The call graph is optional and generated only when `--call-graph` is requested.
319
+
320
+ Artifact:
321
+
322
+ - `call-graph.json`
323
+
324
+ The call graph stores conservative static call edges extracted from supported language adapters.
325
+
326
+ The call graph is useful for:
327
+
328
+ - finding direct call relationships
329
+ - inspecting local call structure
330
+ - expanding graph context around a symbol
331
+ - supporting deeper retrieval workflows when call relationships are relevant
332
+
333
+ Limitations:
334
+
335
+ - dynamic dispatch is not fully resolved
336
+ - runtime control flow is not modeled
337
+ - generated runtime behavior is not inferred
338
+ - unsupported call patterns are skipped rather than guessed
339
+
340
+ ## Search layer
341
+
342
+ Files:
343
+
344
+ - `src/search/`
345
+
346
+ The search layer performs deterministic keyword search over index artifacts.
347
+
348
+ Search reads:
349
+
350
+ - `manifest.json`
351
+ - `symbol-index.json`
352
+ - `code-graph.json`
353
+
354
+ Search targets include:
355
+
356
+ - file paths
357
+ - file node IDs
358
+ - symbol node IDs
359
+ - symbol names
360
+ - symbol kinds
361
+ - imported module paths
362
+ - exported symbol names
363
+ - dependency paths
364
+ - edge kinds
365
+ - edge endpoints
366
+ - neighboring node labels
367
+
368
+ Search behavior:
369
+
370
+ - local only
371
+ - deterministic
372
+ - keyword-based
373
+ - field-weighted
374
+ - no embeddings
375
+ - no semantic similarity service
376
+ - no LLM calls
377
+ - no source-file modification
378
+
379
+ Search scores are ranking integers. They are not probabilities or model confidence values.
380
+
381
+ ## Lookup layer
382
+
383
+ Files:
384
+
385
+ - `src/lookup/lookupNode.ts`
386
+
387
+ The lookup layer resolves an exact graph node ID and returns bounded graph context around that node.
388
+
389
+ Lookup supports:
390
+
391
+ - exact node ID lookup
392
+ - depth 0 through 3
393
+ - incoming edge traversal
394
+ - outgoing edge traversal
395
+ - neighboring node collection
396
+
397
+ Lookup is exact-match only. Partial or fuzzy node lookup belongs to `search`.
398
+
399
+ Node ID examples:
400
+
401
+ - `file:src/index.ts`
402
+ - `symbol:src/index.ts#describeUser`
403
+
404
+ ## Source retrieval layer
405
+
406
+ Files:
407
+
408
+ - `src/lookup/getSourceSlice.ts`
409
+ - `src/lookup/resolveSourceTarget.ts`
410
+ - `src/lookup/sourceSliceTypes.ts`
411
+ - `src/source/renderSourceOutput.ts`
412
+
413
+ The source retrieval layer reads bounded source ranges from the indexed project.
414
+
415
+ Supported retrieval modes:
416
+
417
+ - file node retrieval
418
+ - symbol node retrieval
419
+ - file plus symbol-name retrieval
420
+ - file plus explicit line range retrieval
421
+
422
+ The source layer enforces:
423
+
424
+ - project-root containment
425
+ - path traversal protection
426
+ - valid line ranges
427
+ - max-line limits
428
+ - output-format selection
429
+
430
+ Output formats:
431
+
432
+ - `json`
433
+ - `plain`
434
+ - `numbered`
435
+
436
+ Source retrieval never modifies source files. It only reads source content and renders bounded output.
437
+
438
+ ## Graph slicing layer
439
+
440
+ Files:
441
+
442
+ - `src/graph/`
443
+ - `src/lookup/`
444
+
445
+ The graph slicing layer builds a bounded graph neighborhood around a focus node.
446
+
447
+ Slice inputs:
448
+
449
+ - index directory
450
+ - focus node ID
451
+ - traversal depth
452
+ - traversal direction
453
+
454
+ Supported directions:
455
+
456
+ - `incoming`
457
+ - `outgoing`
458
+ - `both`
459
+
460
+ Traversal depth is capped. The current public command supports depth 0 through 3.
461
+
462
+ Slice output includes:
463
+
464
+ - focus node
465
+ - included nodes
466
+ - included edges
467
+ - summary counts
468
+
469
+ Graph slicing reads graph artifacts only. It does not read source files and does not require Graphviz.
470
+
471
+ The result is written as a graph-slice artifact.
472
+
473
+ ## Graph view layer
474
+
475
+ Files:
476
+
477
+ - `src/graph/`
478
+
479
+ The graph view layer converts `code-graph.json` into visual graph output.
480
+
481
+ Main responsibilities:
482
+
483
+ - build DOT text
484
+ - apply edge-style conventions
485
+ - optionally invoke Graphviz
486
+ - write DOT, SVG, or PNG output
487
+
488
+ Main files:
489
+
490
+ - `buildDotGraph.ts`
491
+ - `edgeStyleConvention.ts`
492
+ - `dotTypes.ts`
493
+ - `renderGraphviz.ts`
494
+ - `writeGraphView.ts`
495
+
496
+ Supported output formats:
497
+
498
+ - `dot`
499
+ - `svg`
500
+ - `png`
501
+
502
+ Supported edge styles:
503
+
504
+ - `semantic`
505
+ - `labeled`
506
+ - `minimal`
507
+
508
+ Edge style behavior:
509
+
510
+ - `semantic` uses DOT marker and line-style attributes per edge kind and emits a legend.
511
+ - `labeled` emits inline edge labels.
512
+ - `minimal` emits edges without labels or extra attributes.
513
+
514
+ DOT output does not require Graphviz. SVG and PNG rendering require the Graphviz `dot` executable.
515
+
516
+ Graphviz is invoked with `shell: false`, and DOT content is passed through stdin.
517
+
518
+ ## I/O and shared helpers
519
+
520
+ Files:
521
+
522
+ - `src/io/`
523
+ - `src/version.ts`
524
+
525
+ The shared I/O layer supports:
526
+
527
+ - reading JSON artifacts
528
+ - writing JSON artifacts
529
+ - writing rendered output
530
+ - validating paths
531
+ - shared filesystem behavior
532
+
533
+ `src/version.ts` stores the package version constant used by the CLI.
534
+
535
+ ## Test structure
536
+
537
+ Tests are in `tests/`, organized by subsystem.
538
+
539
+ Main test groups:
540
+
541
+ - `tests/cli/`
542
+ - `tests/index/`
543
+ - `tests/lookup/`
544
+ - `tests/view/`
545
+ - `tests/search/`
546
+ - `tests/security/`
547
+
548
+ Security tests cover:
549
+
550
+ - path traversal protection
551
+ - malformed artifact handling
552
+ - artifact path validation
553
+ - DOT escaping
554
+ - output path behavior
555
+ - graph traversal limits
556
+ - output-size limits
557
+
558
+ Most integration tests invoke the built CLI through child processes against fixture projects in `examples/`. Unit tests operate directly on exported functions.
559
+
560
+ ## Security boundaries
561
+
562
+ my-dev-kit is designed as a local, offline CLI.
563
+
564
+ Security boundaries:
565
+
566
+ - no LLM calls
567
+ - no external API calls
568
+ - no server process
569
+ - no runtime agent execution
570
+ - no source-file modification
571
+ - no shell-based Graphviz invocation
572
+ - no execution of user Python source during Python indexing
573
+ - source retrieval is read-only
574
+ - graph traversal is bounded
575
+ - source retrieval is bounded
576
+ - artifact paths are validated
577
+ - project-root containment is enforced for source retrieval
578
+ - DOT node IDs, labels, and edge labels are escaped
579
+
580
+ Important implementation constraints:
581
+
582
+ - The CLI layer does not own retrieval or graph logic.
583
+ - The graph and lookup layers do not own CLI parsing.
584
+ - Source retrieval rejects paths outside `manifest.projectRoot`.
585
+ - Artifact paths in `manifest.json` are validated to stay inside the index directory.
586
+ - DOT generation escapes node IDs, labels, and edge labels.
587
+ - Graphviz receives DOT through stdin and is invoked without shell expansion.
588
+ - Graph traversal depth is capped for `lookup` and `slice`.
589
+
590
+ ## Design boundaries
591
+
592
+ my-dev-kit uses conservative static analysis.
593
+
594
+ Current boundaries:
595
+
596
+ - It does not execute user project code.
597
+ - It does not infer complete runtime behavior.
598
+ - It does not resolve all dynamic imports.
599
+ - It does not fully resolve dynamic dispatch.
600
+ - It does not perform semantic similarity search.
601
+ - It does not use embeddings.
602
+ - It does not call LLMs.
603
+ - It does not provide an orchestrator.
604
+ - It does not provide backend agent execution.
605
+ - It does not provide evaluation workflows.
606
+ - It does not publish packages automatically.
607
+ - It does not create GitHub releases automatically.
608
+
609
+ The graph schema is stable within one index run. Re-indexing may produce different node IDs if file paths or symbol names change.
610
+
611
+ The `alpha-import/` directory in the source repository contains reference material. It is excluded from TypeScript compilation and is not part of the published package or runtime.
612
+
613
+ ## Extension points
614
+
615
+ The architecture is intended to support additive downstream layers.
616
+
617
+ Potential future layers include:
618
+
619
+ - data-model graph extraction
620
+ - richer React and TSX indexing
621
+ - test-title and locator indexing
622
+ - route-aware indexing
623
+ - browser storage key tracing
624
+ - source continuation retrieval
625
+ - local dependency source bundles
626
+ - incremental indexing
627
+ - graph diffing
628
+ - additional language adapters
629
+
630
+ These features should build on the current artifact model instead of replacing the indexer or creating a parallel scanning pipeline.
631
+
632
+ A future data-model extraction layer may consume `symbol-index.json` and `code-graph.json` to produce separate data-model artifacts. That feature is not implemented in version 1.0.0.
633
+
634
+ ## Practical summary
635
+
636
+ my-dev-kit has a small layered architecture:
637
+
638
+ - the CLI parses commands
639
+ - the indexing layer writes artifacts
640
+ - language adapters extract source structure
641
+ - the symbol index stores compact per-file symbol data
642
+ - the code graph stores file and symbol relationships
643
+ - search ranks artifact matches
644
+ - lookup traverses exact graph nodes
645
+ - source retrieves bounded source content
646
+ - slice extracts bounded graph neighborhoods
647
+ - view renders the graph
648
+
649
+ The main design rule is to keep indexing deterministic, artifacts inspectable, and retrieval bounded.