code-tree-graph 0.1.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.
Files changed (2) hide show
  1. package/README.md +295 -0
  2. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,295 @@
1
+ <p align="center">
2
+ <img width="300px" src="https://i.imgur.com/jg49HQ8.png" />
3
+ <p align="center">
4
+ <a href="https://discord.gg/SJdBqBz3tV">
5
+ <img src="https://img.shields.io/discord/1110227955554209923.svg?label=Chat&logo=Discord&colorB=7289da&style=flat"
6
+ alt="Join Discord" />
7
+ </a>
8
+ <a href="https://github.com/OpenSourceAGI/appdemo-dev-tools/discussions">
9
+ <img alt="GitHub Stars" src="https://img.shields.io/github/stars/OpenSourceAGI/appdemo-dev-tools" /></a>
10
+ <a href="https://github.com/OpenSourceAGI/appdemo-dev-tools/discussions">
11
+ <img alt="GitHub Discussions"
12
+ src="https://img.shields.io/github/discussions/OpenSourceAGI/appdemo-dev-tools" />
13
+ </a>
14
+ <br />
15
+ <a href="https://github.com/OpenSourceAGI/appdemo-dev-tools/pulse" alt="Activity">
16
+ <img src="https://img.shields.io/github/commit-activity/m/OpenSourceAGI/appdemo-dev-tools" />
17
+ </a>
18
+ <img src="https://img.shields.io/github/last-commit/OpenSourceAGI/appdemo-dev-tools.svg" alt="GitHub last commit" />
19
+ <br />
20
+ <img src="https://img.shields.io/badge/Next.js-16-black" alt="Next.js" />
21
+ <a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request">
22
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"
23
+ alt="PRs Welcome" />
24
+ </a>
25
+ <a href="https://codespaces.new/OpenSourceAGI/appdemo-dev-tools">
26
+ <img src="https://github.com/codespaces/badge.svg" width="150" height="20" />
27
+ </a>
28
+ </p>
29
+
30
+ # code-graph
31
+
32
+ Interactive code dependency graph and file tree visualization components for [Fumadocs](https://fumadocs.vercel.app/) + Next.js. Drop them into any MDX page to generate live, navigable views of your codebase — no external service required.
33
+
34
+ **What's included:**
35
+ - **`DependencyGraph`** — Mermaid flowchart built from full AST analysis, with pan/zoom, search, hover tooltips, and remote repo ZIP support
36
+ - **`FileTreeView`** — searchable, filterable file table with export/import/JSDoc metadata and GitHub deep links
37
+ - **`TypeTable`** — collapsible property tables for type documentation
38
+ - **AST engine** — TypeScript/JS parser extracting imports, exports, functions, types, and signatures
39
+
40
+ ---
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ npm install code-graph
46
+ ```
47
+
48
+ Import the CSS once in your app root (e.g. `app/layout.tsx`):
49
+
50
+ ```ts
51
+ import "code-graph/dist/index.css";
52
+ ```
53
+
54
+ ### Peer dependencies
55
+
56
+ ```bash
57
+ npm install react react-dom next fumadocs-core
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Components
63
+
64
+ ### DependencyGraph
65
+
66
+ Server component. Scans directories with the AST engine and renders an interactive Mermaid flowchart.
67
+
68
+ ```tsx
69
+ import { DependencyGraph } from "code-graph";
70
+
71
+ export default function Page() {
72
+ return (
73
+ <DependencyGraph
74
+ paths={["../packages/core", "../packages/utils"]}
75
+ ignore={["node_modules", "dist", "*.test.ts"]}
76
+ ignoreFile="../.treeignore"
77
+ showLegend={true}
78
+ showNpmImports={false}
79
+ showTypes={false}
80
+ showPrivateFunctions={false}
81
+ showExportedFunctions={false}
82
+ />
83
+ );
84
+ }
85
+ ```
86
+
87
+ | Prop | Type | Default | Description |
88
+ |------|------|---------|-------------|
89
+ | `paths` | `string[]` | required | Directories to analyze (absolute or relative to `cwd`) |
90
+ | `descriptions` | `Record<string, string>` | `{}` | Manual descriptions keyed by relative path |
91
+ | `ignore` | `string[]` | `[]` | File/folder names or patterns to exclude |
92
+ | `ignoreFile` | `string` | — | Path to a `.treeignore` file (gitignore-style) |
93
+ | `showLegend` | `boolean` | `true` | Show toggle control buttons |
94
+ | `showNpmImports` | `boolean` | `false` | Display external npm dependency nodes |
95
+ | `showTypes` | `boolean` | `false` | Display type definition nodes |
96
+ | `showPrivateFunctions` | `boolean` | `false` | Display internal (non-exported) function nodes |
97
+ | `showExportedFunctions` | `boolean` | `false` | Display exported function nodes |
98
+ | `instructions` | `React.ReactNode` | built-in help | Custom help panel content |
99
+
100
+ **Features:**
101
+ - Color-coded nodes: entry points (green), core modules (blue), types (purple), utils (gray), npm deps (orange)
102
+ - Pan & zoom with drag and Ctrl+scroll
103
+ - Click a node to scroll to its file tree entry
104
+ - Hover tooltips with JSDoc, exports, and signatures
105
+ - Real-time search with node highlight
106
+ - Toggle visibility of npm / types / private / exported nodes
107
+ - Remote repo analysis: paste a GitHub URL or ZIP to analyze any repo without cloning
108
+
109
+ ---
110
+
111
+ ### FileTreeView
112
+
113
+ Server component. Generates a filterable table of your file tree with code-analysis metadata.
114
+
115
+ ```tsx
116
+ import { FileTreeView } from "code-graph";
117
+
118
+ export default function Page() {
119
+ return (
120
+ <FileTreeView
121
+ paths={["../packages/my-lib"]}
122
+ ghBase="https://github.com/user/repo/tree/master/packages/my-lib"
123
+ descriptions={{
124
+ "my-lib": "Core library",
125
+ "my-lib/index.ts": "Main entry point",
126
+ }}
127
+ ignore={["node_modules", "dist"]}
128
+ inferDescriptions={true}
129
+ defaultImportFilter="all"
130
+ defaultInternalFilter="all"
131
+ defaultExportFilter="functions"
132
+ defaultCollapseDepth={4}
133
+ />
134
+ );
135
+ }
136
+ ```
137
+
138
+ | Prop | Type | Default | Description |
139
+ |------|------|---------|-------------|
140
+ | `paths` | `string[]` | required | Directories or files to scan |
141
+ | `ghBase` | `string` | required | GitHub base URL for file deep-links |
142
+ | `descriptions` | `Record<string, string>` | `{}` | Manual descriptions keyed by relative path |
143
+ | `ignore` | `string[]` | `[]` | File/folder names or patterns to exclude |
144
+ | `ignoreFile` | `string` | — | Path to a `.treeignore` file |
145
+ | `inferDescriptions` | `boolean` | `true` | Auto-extract descriptions from leading JSDoc/comments |
146
+ | `defaultImportFilter` | `"all" \| "local" \| "npm"` | — | Initial import filter |
147
+ | `defaultInternalFilter` | `"all" \| "declared-types" \| "exported-types" \| "functions" \| "classes"` | — | Initial internals filter |
148
+ | `defaultExportFilter` | `"all" \| "functions" \| "classes" \| "constants"` | — | Initial export filter |
149
+ | `defaultCollapseDepth` | `number` | — | Initial tree collapse depth |
150
+
151
+ **Features:**
152
+ - Fuzzy search (Fuse.js) across names, imports, exports, JSDoc, and signatures
153
+ - 3 independent filter dropdowns (imports, types/internals, exports)
154
+ - Sort by import / type / export count
155
+ - Collapse depth slider
156
+ - Rich badge tooltips with Markdown-parsed descriptions, signatures, and type properties
157
+ - Clickable file badges linking to GitHub source lines
158
+ - `package.json` detection with dependency listing
159
+
160
+ ---
161
+
162
+ ### TypeTable
163
+
164
+ Client component for rendering collapsible type/property tables in documentation pages.
165
+
166
+ ```tsx
167
+ import { TypeTable } from "code-graph";
168
+
169
+ export default function Page() {
170
+ return (
171
+ <TypeTable
172
+ type={{
173
+ name: { type: "string", description: "The node name", required: true },
174
+ children: { type: "TypeNode[]", description: "Nested children", required: false },
175
+ }}
176
+ />
177
+ );
178
+ }
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Programmatic API
184
+
185
+ The AST engine is available as a standalone Node.js API:
186
+
187
+ ```ts
188
+ import {
189
+ generateFileTree,
190
+ analyzeFileContent,
191
+ parseIgnoreFile,
192
+ } from "code-graph";
193
+ ```
194
+
195
+ ### `generateFileTree`
196
+
197
+ Scans a directory and returns a tree of [`FileTreeNode`](#filetreenode) objects.
198
+
199
+ ```ts
200
+ const tree = generateFileTree(
201
+ "/absolute/path/to/src",
202
+ { "index.ts": "Main entry" }, // descriptions
203
+ new Set(["node_modules", "dist"]), // ignorePatterns
204
+ true // inferDescriptions from JSDoc
205
+ );
206
+ ```
207
+
208
+ | Parameter | Type | Default | Description |
209
+ |-----------|------|---------|-------------|
210
+ | `packagesDir` | `string` | required | Root directory to scan |
211
+ | `descriptions` | `Record<string, string>` | `{}` | Manual descriptions by relative path |
212
+ | `ignorePatterns` | `Set<string>` | `new Set()` | File/folder names to skip |
213
+ | `inferDescriptions` | `boolean` | `false` | Extract descriptions from source comments |
214
+
215
+ ### `analyzeFileContent`
216
+
217
+ Analyzes source text in memory — no filesystem read needed.
218
+
219
+ ```ts
220
+ import { analyzeFileContent } from "code-graph";
221
+
222
+ const analysis = analyzeFileContent("index.ts", sourceText);
223
+ // { localImports, npmImports, exports, functions, types, ... }
224
+ ```
225
+
226
+ ### `parseIgnoreFile`
227
+
228
+ Parses a `.gitignore`-style file into a `Set<string>` of patterns.
229
+
230
+ ```ts
231
+ import { parseIgnoreFile } from "code-graph";
232
+
233
+ const patterns = parseIgnoreFile("/path/to/.treeignore");
234
+ const tree = generateFileTree("/path/to/src", {}, patterns);
235
+ ```
236
+
237
+ ---
238
+
239
+ ## Types
240
+
241
+ ### `FileTreeNode`
242
+
243
+ ```ts
244
+ interface FileTreeNode {
245
+ name: string;
246
+ type: "file" | "folder";
247
+ path: string; // relative to scanned root
248
+ description?: string;
249
+ analysis?: FileAnalysis;
250
+ children?: FileTreeNode[];
251
+ packageDependencies?: string[]; // from package.json
252
+ packageExports?: AnalysisItem[];
253
+ }
254
+ ```
255
+
256
+ ### `FileAnalysis`
257
+
258
+ ```ts
259
+ interface FileAnalysis {
260
+ localImports: string[];
261
+ localImportSymbols: { source: string; valueNames: string[]; typeNames: string[] }[];
262
+ npmImports: string[];
263
+ exports: AnalysisItem[];
264
+ functions: AnalysisItem[];
265
+ types: AnalysisItem[];
266
+ }
267
+ ```
268
+
269
+ ### `AnalysisItem`
270
+
271
+ ```ts
272
+ interface AnalysisItem {
273
+ name: string;
274
+ kind?: "function" | "class" | "constant" | "type";
275
+ line?: number;
276
+ jsdoc?: string;
277
+ signature?: string;
278
+ properties?: TypeProperty[];
279
+ }
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Dependencies
285
+
286
+ | Package | Purpose |
287
+ |---------|---------|
288
+ | `@typescript-eslint/typescript-estree` | AST parsing for TS/JS |
289
+ | `mermaid` | Graph rendering |
290
+ | `fuse.js` | Fuzzy search |
291
+ | `jszip` | Remote ZIP repo analysis |
292
+ | `marked` | JSDoc → Markdown in tooltips |
293
+ | `@radix-ui/react-tooltip` | Badge tooltips |
294
+ | `lucide-react` | Icons |
295
+ | `svg-toolbelt` | SVG pan/zoom |
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "code-tree-graph",
3
+ "version": "0.1.2",
4
+ "description": "Code dependency graph and file tree visualization components",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./dist/index.css": "./dist/index.css"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "vite build",
21
+ "dev": "vite build --watch"
22
+ },
23
+ "dependencies": {
24
+ "@radix-ui/react-tooltip": "^1.2.8",
25
+ "@typescript-eslint/typescript-estree": "^8.56.1",
26
+ "class-variance-authority": "^0.7.1",
27
+ "clsx": "^2.1.1",
28
+ "fuse.js": "^7.1.0",
29
+ "jszip": "^3.10.1",
30
+ "lucide-react": "^0.555.0",
31
+ "marked": "^17.0.4",
32
+ "mermaid": "^11.12.3",
33
+ "svg-toolbelt": "^0.6.1",
34
+ "tailwind-merge": "^3.5.0",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "devDependencies": {
38
+ "@vitejs/plugin-react": "^4.3.4",
39
+ "vite": "^6.3.5",
40
+ "vite-plugin-dts": "^4.5.4"
41
+ },
42
+ "peerDependencies": {
43
+ "fumadocs-core": "*",
44
+ "next": "*",
45
+ "react": "*",
46
+ "react-dom": "*"
47
+ }
48
+ }