Python dependency graph analyzer, architecture enforcer, and MCP server for AI coding agents
Project description
๐ฆ Hawkeye
Python architectural intelligence engine โ dependency analysis, symbol-level impact tracking, and MCP server for AI coding agents.
Hawkeye gives AI editors (Claude Code, Cursor, Windsurf) full architectural awareness before they edit your code โ preventing broken imports, hidden coupling, and circular dependencies.
Installation
# From source (recommended during beta)
git clone https://github.com/AlexxBenny/Hawkeye-analyze-your-codebase.git
cd Hawkeye-analyze-your-codebase
pip install -e .
# With MCP server for AI editors
pip install -e ".[mcp]"
Quick Start
# 1. Analyze any Python project
hawkeye analyze /path/to/project
# 2. Get full architectural context for a file
hawkeye context /path/to/project src/core/engine.py
# 3. Check symbol-level impact before refactoring
hawkeye impact /path/to/project src/core/engine.py -s Engine
# 4. Find coupling hotspots
hawkeye impact /path/to/project src/core/engine.py --hotspots
# 5. Find dead code
hawkeye impact /path/to/project src/core/engine.py --unused
# 6. Open interactive dependency graph
hawkeye show /path/to/project
# 7. Enforce architecture rules in CI
hawkeye check /path/to/project --no-cycles
Why Hawkeye?
| Problem | How Hawkeye Solves It |
|---|---|
| "I changed a class and 5 tests broke" | hawkeye impact shows blast radius before you edit |
| "This codebase has spaghetti imports" | hawkeye analyze maps the entire dependency graph |
| "Which module is the riskiest?" | hawkeye metrics ranks by instability + complexity |
| "Are there circular imports?" | hawkeye check --no-cycles detects and suggests fixes |
| "AI editor made a bad import" | MCP server gives the AI full context before it writes |
CLI Commands (7)
| Command | Description |
|---|---|
hawkeye analyze <path> |
Full project analysis (text/json/dot/html output) |
hawkeye context <path> <file...> |
Architectural context for one or more files |
hawkeye impact <path> <file> |
Symbol-level impact analysis, hotspots, dead code |
hawkeye show <path> |
Open interactive D3.js graph in browser |
hawkeye check <path> |
Enforce architecture rules (CI/CD exit codes) |
hawkeye metrics <path> |
Coupling + complexity metrics table |
hawkeye serve |
Start MCP server for AI editors |
Example: hawkeye analyze
=== PROJECT SUMMARY: MyApp ===
Modules: 20
Dependencies: 40
Total LOC: 2696
Graph density: 0.1053
Avg instability: 0.444
Has cycles: No โ
Health breakdown:
โ
Healthy: 9
โ ๏ธ Warning: 5
๐ด Critical: 6
โโ Module Metrics โโ
Module Ca Ce I LOC Health
MyApp.core.graph 8 2 0.200 251 ๐ด
MyApp.core.metrics 5 1 0.167 144 โ ๏ธ
MyApp.core.analyzer 3 1 0.250 328 ๐ด
MyApp.config 4 0 0.000 102 โ
Example: hawkeye impact --hotspots
๐ฅ Symbol Hotspots (imported by โฅ2 modules):
DependencyGraph (core.graph) โ 16 importers
ModuleMetrics (core.metrics) โ 10 importers
HawkeyeEngine (engine) โ 6 importers
Example: hawkeye impact --unused
๐ Unused Symbols (5 found):
EdgeInfo (core.graph) โ safe to make private
analyze_file (core.analyzer) โ superseded by analyze_project
AI Editor Integration (MCP)
Hawkeye exposes 10 MCP tools designed for AI coding agents. Add to your editor's MCP config:
{
"mcpServers": {
"hawkeye": {
"command": "hawkeye-mcp",
"args": ["--project", "/path/to/your/project"]
}
}
}
MCP Tools
| Tool | Purpose |
|---|---|
hawkeye_analyze(path) |
Scan project โ call this first |
hawkeye_file_context(file) |
Everything about a file in one call โ deps, dependents, impact, cycles, health |
hawkeye_context(files) |
Combined context for multi-file editing sessions |
hawkeye_impact(file, symbol, mode) |
Symbol-level blast radius, hotspots, dead code |
hawkeye_symbols(file) |
List all classes/functions with usage counts |
hawkeye_find(pattern) |
Search for modules by name |
hawkeye_cycles() |
Import cycles with severity and break suggestions |
hawkeye_metrics(sort_by) |
Coupling + complexity metrics for all modules |
hawkeye_path(source, target) |
Shortest dependency path between modules |
hawkeye_graph(max_depth) |
Full graph as structured JSON |
Example: hawkeye_file_context
One call gives the AI agent everything it needs:
{
"module": "myapp.core.engine",
"file": "core/engine.py",
"loc": 340,
"dependency_count": 3,
"dependent_count": 8,
"dependencies": [
{"module": "myapp.core.scanner", "file": "core/scanner.py"},
{"module": "myapp.core.analyzer", "file": "core/analyzer.py"}
],
"dependents": [
{"module": "myapp.cli", "file": "cli.py"},
{"module": "myapp.server.mcp", "file": "server/mcp.py"}
],
"impact": {"direct": 8, "transitive": 12},
"metrics": {
"ca": 8, "ce": 3, "instability": 0.273,
"health": "critical",
"cyclomatic_complexity": 45,
"cognitive_complexity": 32
}
}
Architecture Rules
Define rules in hawkeye.toml and enforce them with hawkeye check:
[project]
name = "MyApp"
[scan]
exclude_dirs = ["venv", "__pycache__", ".git"]
# Enforce layered architecture (lower layers can't import higher ones)
[rules.layers]
order = ["models", "services", "api", "cli"]
direction = "downward"
# Block specific import patterns
[[rules.forbidden]]
from = "api.*"
to = ["cli.*", "scripts.*"]
# Ensure module groups are independent
[[rules.independence]]
modules = ["auth", "billing", "notifications"]
# CI/CD integration โ exits non-zero on violations
hawkeye check /path/to/project --no-cycles
Core Analysis Features
Dependency Graph
- AST-based import resolution (relative, absolute, symbol-level)
- Directed graph with transitive closure, shortest path, neighborhood extraction
- Topological sort, depth filtering, subgraph extraction
Coupling Metrics (Robert C. Martin)
- Ca โ Afferent coupling (who depends on me)
- Ce โ Efferent coupling (who do I depend on)
- I โ Instability (Ce / (Ca + Ce)) โ 0.0 = stable, 1.0 = unstable
Complexity Metrics
- Cyclomatic complexity โ decision branches per function
- Cognitive complexity โ nesting-weighted (SonarSource specification)
- Per-function, per-class, and per-module aggregation
Cycle Detection
- Tarjan's Strongly Connected Components (SCC) algorithm
- Severity scoring (low โ critical based on cycle size + coupling)
- Break suggestions with specific edge recommendations
Symbol Resolution
- Cross-file symbol registry (class X defined in module Y)
- Import โ definition matching
- Hotspot detection (most-imported symbols)
- Dead code detection (defined but never imported)
- Symbol-level impact analysis (blast radius per class/function)
Health Scoring
- Composite of coupling + complexity โ healthy / warning / critical
- Per-module and project-level aggregation
Visualization
Interactive HTML (D3.js)
hawkeye show /path/to/project # Opens in browser
hawkeye analyze /path/to/project -f html -o graph.html
Force-directed graph with search, zoom, drag, click-to-inspect. Color-coded by health status.
Graphviz DOT
hawkeye analyze /path/to/project -f dot -o deps.dot
dot -Tpng deps.dot -o deps.png
JSON
hawkeye analyze /path/to/project -f json
Project Structure
Hawkeye/
โโโ src/hawkeye/
โ โโโ engine.py # Central orchestrator (9-step pipeline)
โ โโโ config.py # TOML config with walk-up discovery
โ โโโ cli.py # 7 CLI commands
โ โโโ core/ # Analysis pipeline
โ โ โโโ scanner.py # File discovery + LOC counting
โ โ โโโ analyzer.py # AST imports + symbols + complexity
โ โ โโโ graph.py # Directed graph + algorithms
โ โ โโโ metrics.py # Coupling + complexity metrics
โ โ โโโ cycles.py # Tarjan's SCC + severity scoring
โ โ โโโ rules.py # Architecture rule enforcement
โ โ โโโ symbols.py # Cross-file symbol resolution
โ โโโ server/ # AI editor integration
โ โ โโโ mcp.py # 10 MCP tools
โ โโโ visualizer/ # Output renderers
โ โโโ html_renderer.py # Interactive D3.js graph
โ โโโ dot_renderer.py # Graphviz DOT format
โ โโโ text_renderer.py # Terminal tables + summaries
โ โโโ json_renderer.py # Structured JSON
โโโ tests/ # 195 tests (pytest)
โ โโโ conftest.py # Shared fixtures
โ โโโ test_scanner.py # 17 tests
โ โโโ test_analyzer.py # 22 tests
โ โโโ test_graph.py # 16 tests
โ โโโ test_metrics.py # 15 tests
โ โโโ test_cycles.py # 14 tests
โ โโโ test_rules.py # 16 tests
โ โโโ test_symbols.py # 27 tests
โ โโโ test_engine.py # 22 tests
โโโ examples/ # Usage examples
โโโ hawkeye.toml # Example config
โโโ pyproject.toml # pip install ready
โโโ LICENSE # MIT
Zero required dependencies. Core analysis runs on Python stdlib only. MCP server requires pip install mcp.
Requirements
- Python 3.10+
- No dependencies for core analysis
mcppackage for AI editor integration (optional)
License
MIT โ see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hawkeye_analyzer-0.1.2.tar.gz.
File metadata
- Download URL: hawkeye_analyzer-0.1.2.tar.gz
- Upload date:
- Size: 64.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb4ae7cb6b3d4e3d89c0bbf4591517270c0d55f583e11b10f973425f87ec75b2
|
|
| MD5 |
68314800bf562a10102e683cdae54c50
|
|
| BLAKE2b-256 |
4430e2c7e26086cc6825dad7b64d1a28385f2d133cc8ec27a1dc65c131b081bf
|
Provenance
The following attestation bundles were made for hawkeye_analyzer-0.1.2.tar.gz:
Publisher:
ci.yml on AlexxBenny/Hawkeye-analyze-your-codebase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hawkeye_analyzer-0.1.2.tar.gz -
Subject digest:
bb4ae7cb6b3d4e3d89c0bbf4591517270c0d55f583e11b10f973425f87ec75b2 - Sigstore transparency entry: 1395176264
- Sigstore integration time:
-
Permalink:
AlexxBenny/Hawkeye-analyze-your-codebase@3f91dc0d829d762a40682551b9868a52e6e5dd6a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/AlexxBenny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3f91dc0d829d762a40682551b9868a52e6e5dd6a -
Trigger Event:
push
-
Statement type:
File details
Details for the file hawkeye_analyzer-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hawkeye_analyzer-0.1.2-py3-none-any.whl
- Upload date:
- Size: 54.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0eb62a279d81cbb0d4c24b9ac735669916a78f27d561f5451e176cf6fb224b1
|
|
| MD5 |
b646d6a916c282a41668ed94c54aa44a
|
|
| BLAKE2b-256 |
18c3d031b744523c385d2dc2c622a5e245afdee5715045d41f7326a9cba93f0c
|
Provenance
The following attestation bundles were made for hawkeye_analyzer-0.1.2-py3-none-any.whl:
Publisher:
ci.yml on AlexxBenny/Hawkeye-analyze-your-codebase
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hawkeye_analyzer-0.1.2-py3-none-any.whl -
Subject digest:
f0eb62a279d81cbb0d4c24b9ac735669916a78f27d561f5451e176cf6fb224b1 - Sigstore transparency entry: 1395176374
- Sigstore integration time:
-
Permalink:
AlexxBenny/Hawkeye-analyze-your-codebase@3f91dc0d829d762a40682551b9868a52e6e5dd6a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/AlexxBenny
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@3f91dc0d829d762a40682551b9868a52e6e5dd6a -
Trigger Event:
push
-
Statement type: