Skip to content

phoenix-assistant/impact-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

impact-graph

"If I change this function, what breaks?"
Change impact analysis powered by call graphs + PageRank.

CI npm License: MIT

What it does

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

Install

npm install -g @phoenixaihub/impact-graph
# or
npx @phoenixaihub/impact-graph <command>

Usage

1. Index your project

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

2. Check impact of a function change

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

3. Analyze your git diff

impact-graph check --diff

Automatically detects changed functions in staged + unstaged git diff and runs impact analysis on each.

4. Visualize the graph

impact-graph visualize --format mermaid
impact-graph visualize --format dot > graph.dot && dot -Tsvg graph.dot -o graph.svg

Mermaid output (paste into GitHub/Notion):

graph LR
  add["add"]
  multiply["multiply"]
  multiply --> add
  square["square"]
  square --> multiply
Loading

5. Codebase health stats

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

Supported Languages

Language Function defs Calls Imports
TypeScript βœ… βœ… βœ…
JavaScript βœ… βœ… βœ…
Python βœ… βœ… βœ…

Go support coming soon.

Algorithms

  • 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

Development

git clone https://github.com/phoenix-assistant/impact-graph
cd impact-graph
npm install --legacy-peer-deps
npm run build
npm test

License

MIT Β© PhoenixAI Hub


Architecture

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


CI Setup

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_SUMMARY

Contributing

See CONTRIBUTING.md.

About

If I change this function, what breaks? Change impact analysis with call graphs + PageRank.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors