Analyze TypeScript/JavaScript dependencies, build a directed graph (imports/exports/require/dynamic import), compute metrics (fan-in/out, density, mutual pairs, complexity), find cycles (Tarjan SCC), and generate a heuristic (LLM-free) analysis. Optionally add LLM insights (Gemini) while never sending file contents — only graph metadata.
- Supports:
import,export from,require,import(),import = require(), with warnings for non-literal specifiers. - TypeScript-aware resolution (honors
tsconfig.json:paths,baseUrl,rootDirs, extensions). - Metrics: fan-in / fan-out, density, mutual pairs, normalized coupling score, complexity score.
- Cycle detection via Tarjan SCCs and an LLM-free heuristic narrative.
- Optional Gemini insights (on metadata only; no source code).
- CLI and HTTP API (the server is in
server/server.ts). - Vitest test suite with ≥80% coverage.
- Node.js 18+ (20+ recommended)
- pnpm / npm / yarn
- (optional) GEMINI_API_KEY if you plan to use
--llm gemini
ai-api
├─ app/
│ ├─ ApplicationService.ts
│ └─ ports.ts
├─ analyzer/
│ ├─ depsExtractor.ts
│ ├─ fileScanner.ts
│ ├─ graph.ts
│ ├─ heuristics.ts
│ ├─ metrics.ts
│ ├─ narrative.ts
│ ├─ rules.ts
│ └─ tsResolver.ts
├─ composition/
│ ├─ makeAnalyzer.ts
│ ├─ makeRenderer.ts
│ └─ makeWriter.ts
├─ core/
│ └─ types.ts
├─ formats/
│ ├─ renderers.ts
│ ├─ reportGenerator.ts
│ └─ reportTypes.ts
├─ llm/
│ ├─ geminiProvider.ts
│ ├─ prompts.ts
│ └─ provider.ts
├─ server/
│ └─ server.ts ← HTTP API server
├─ utils/
│ ├─ fsUtils.ts
│ └─ logger.ts
├─ test/ ← Vitest tests (≥80% coverage)
├─ index.ts ← CLI entry
├─ package.json
├─ tsconfig.json
├─ vite.config.ts ← for Vitest
├─ .gitignore
└─ .env.example
cd ./ai-apipnpm install
pnpm build # compile to dist/npm install
npm run buildyarn
yarn buildRequires
tsxorts-node. Example withtsx:
pnpm add -D tsx
npx tsx index.ts --root ./src --llm none
# or the server:
npx tsx server/server.tsnode dist/index.js --root ./../src --llm nonenode dist/index.js --root ./../src --llm none --json analysis.report.jsonnode dist/index.js --root ./../src --includeJS --includeTypeImports --llm none --json analysis.report.jsonnode dist/index.js --root ../src --llm none --json analysis.report.json# macOS/Linux (bash/zsh)
export GEMINI_API_KEY=YOUR_KEY
# optional:
# export GEMINI_MODEL=gemini-2.5-flash
node dist/index.js --root ./../src --llm gemini --json analysis.report.jsonSecurity: only metadata (edge endpoints, SCCs, aggregate metrics) is sent to the LLM. Never source code.
The server lives in server/server.ts.
# 1) build
npm build
# 2) run (PORT=5050 by default)
node dist/server/server.jsnpx tsx server/server.ts
# or: npx ts-node server/server.ts- Open in a browser:
http://localhost:5050/→ quick help - Example JSON analysis:
curl "http://localhost:5050/analyze?root=./../src&llm=none" | jq .
# available query params:
# &includeJS=true
# &includeTypeImports=true
# &llm=none|geminiYou can set the port via env:
macOS/Linux:export PORT=5050
PowerShell:$env:PORT=5050
node dist/index.js --root <path> [--includeJS] [--includeTypeImports] [--json <file>] [--llm <none|gemini>]| Flag | Type | Default | Description |
|---|---|---|---|
--root |
string | ./../src |
Root directory to analyze. |
--includeJS |
boolean | false |
Include .js/.jsx (in addition to .ts/.tsx). |
--includeTypeImports |
boolean | false |
Include import type edges. |
--json |
string | "" |
Write the report to a JSON file. |
--llm |
enum | none |
none or gemini. Adds LLM insights if configured. |
See .env.example. Common settings:
LOG_LEVEL=info # debug|info|warn|error
PORT=5050 # HTTP server port
GEMINI_API_KEY=... # only if you use --llm gemini
# GEMINI_MODEL=gemini-2.5-flash # optional overrideAdd/verify:
{
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js --root ./../src --llm none",
"serve": "node dist/server/server.js",
"test": "vitest --run",
"coverage": "vitest run --coverage"
}
}npm test
npm coverage- Coverage target: ≥80% lines/functions/branches.
- The suite covers: import extraction, resolver, graph algorithms, metrics, heuristics, composition, application flow, logger, and Gemini provider (mocked).
fast-globimport/type errors → ensure yourtsconfig.jsonincludes:{ "compilerOptions": { "esModuleInterop": true, "allowSyntheticDefaultImports": true } }- Windows paths → the report normalizes to POSIX-style paths.
- Gemini 404/model → set a valid
GEMINI_MODELand correctGEMINI_API_KEY. - No files found → confirm
--rootpoints to the folder containing your sources.