"If I change this function, what breaks?"
Change impact analysis powered by call graphs + PageRank.
impact-graph statically analyzes your TypeScript/JavaScript and Python codebase to build a call graph. It then answers: "if I refactor this function, what else could break?"
- π Call graph construction β extracts function defs, calls, imports, class methods
- π― Impact analysis β BFS traversal to find all transitively affected functions
- π₯ Risk scoring β PageRank-based risk: highly-depended-on functions = highest risk
- π Circular dep detection β Tarjan's SCC algorithm
- π Orphan detection β functions defined but never called
- π Git diff mode β automatically analyze what changed in your current branch
npm install -g @phoenixaihub/impact-graph
# or
npx @phoenixaihub/impact-graph <command>cd my-project
impact-graph indexπ Indexing project at /my-project ...
β
Indexed in 312ms
Files: 47
Functions: 284
Calls: 891
Graph saved to .impact-graph/graph.json
impact-graph check src/utils.ts:processPaymentβ‘ Impact Analysis β 12 affected function(s)
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββ¬βββββββββββββ¬ββββββββββ
β Function β File β Depth β Risk Score β Callers β
ββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββΌβββββββββββββΌββββββββββ€
β handleCheckout β src/checkout.ts β 1 β 12.45 β 3 β
β processOrder β src/orders.ts β 2 β 9.12 β 2 β
β sendConfirmationEmail β src/notifications.ts β 3 β 4.33 β 1 β
ββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββ΄βββββββββββββ΄ββββββββββ
Flags:
--depth <n>β max traversal depth (default: 10)--format json|table|markdownβ output format
impact-graph check --diffAutomatically detects changed functions in staged + unstaged git diff and runs impact analysis on each.
impact-graph visualize --format mermaid
impact-graph visualize --format dot > graph.dot && dot -Tsvg graph.dot -o graph.svgMermaid output (paste into GitHub/Notion):
graph LR
add["add"]
multiply["multiply"]
multiply --> add
square["square"]
square --> multiply
impact-graph statsπ Codebase Health Stats
Functions: 284
Calls: 891
Files: 47
π₯ Top 10 Riskiest Functions (PageRank)
processPayment 14.23 risk 12 callers src/payments/processor.ts
validateUser 11.87 risk 9 callers src/auth/validate.ts
...
π Circular Dependencies: 2
β processOrder β validateCart β processOrder
β formatDate β parseDate β formatDate
π Orphan Functions (never called, never call): 7
legacyExportCSV (src/export.ts:142)
...
π Most Coupled Modules (by outgoing calls)
src/checkout.ts 34 calls out
| Language | Function defs | Calls | Imports |
|---|---|---|---|
| TypeScript | β | β | β |
| JavaScript | β | β | β |
| Python | β | β | β |
Go support coming soon.
- Call graph construction β regex-based AST extraction (tree-sitter optional)
- PageRank β iterative PageRank (85% damping, 50 iterations). High rank = many callers = risky to change
- Transitive closure β BFS from changed node following reverse call edges
- Circular dep detection β Tarjan's SCC algorithm
- Risk scoring β
PageRank Γ 100 + depth_factor Γ 10
git clone https://github.com/phoenix-assistant/impact-graph
cd impact-graph
npm install --legacy-peer-deps
npm run build
npm testMIT Β© PhoenixAI Hub
impact-graph
βββ src/
β βββ cli.ts # Commander CLI entry point
β βββ parser.ts # AST extraction (TypeScript, JavaScript, Python)
β βββ graph.ts # Call graph construction + adjacency representation
β βββ pagerank.ts # Iterative PageRank + risk scoring
β βββ impact.ts # BFS transitive impact traversal
β βββ stats.ts # Codebase health metrics
β βββ visualize.ts # Mermaid / DOT / JSON output
βββ tests/
Flow: parse files β build call graph β (on query) BFS from changed nodes β rank by PageRank β output
Add impact analysis to your PR workflow:
# .github/workflows/impact.yml
name: Impact Analysis
on: [pull_request]
jobs:
impact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Build impact graph
run: npx @phoenixaihub/impact-graph index
- name: Analyze PR impact
run: npx @phoenixaihub/impact-graph check --diff --format markdown >> $GITHUB_STEP_SUMMARYSee CONTRIBUTING.md.