Tools

analyze_structure

Dependency and coupling analysis for understanding code relationships

The analyze_structure tool helps you understand how different parts of your codebase relate to each other. It analyzes imports and exports to map dependencies, finds connection paths between files, and measures coupling strength between modules.

How It Works

Stellarion builds a dependency graph of your project by analyzing import and export statements. This graph is stored in KuzuDB and can be queried for relationships, paths, and coupling metrics.

When to Use

  • Understanding how files depend on each other: See what a file imports and what imports it
  • Finding dependency chains: Discover how two seemingly unrelated files are connected
  • Measuring coupling between modules: Identify tightly coupled areas that might benefit from refactoring
  • Identifying highly connected files: Find "hub" files that many other files depend on
  • Planning refactoring: Understand the blast radius of changes

Parameters

ParameterTypeRequiredDefaultDescription
typestringNodependenciesAnalysis type: dependencies, paths, or coupling
pathstringNo-File to analyze (required for dependencies)
fromstringNo-Starting file (required for paths)
tostringNo-Target file (required for paths)
depthnumberNo2Maximum traversal depth for dependency chains
directionstringNobothforward (imports), backward (dependents), or both
maxPathsnumberNo5Maximum number of paths to return
thresholdnumberNo0Minimum coupling strength to include

MCP Command Syntax

mcp__stellarion__analyze_structure type:dependencies path:src/index.ts depth:3 direction:both

Analysis Types

Dependencies Analysis

See what a file imports and what files depend on it.

Natural Language:

What files does src/services/userService.ts depend on? What depends on it?

Direct MCP Call:

mcp__stellarion__analyze_structure type:dependencies path:src/services/userService.ts depth:2

Returns:

  • Direct imports (files this file imports)
  • Direct dependents (files that import this file)
  • Transitive dependencies (indirect chains up to depth)

Path Finding

Find all dependency paths connecting two files.

Natural Language:

How is src/api/routes.ts connected to src/db/connection.ts?

Direct MCP Call:

mcp__stellarion__analyze_structure type:paths from:src/api/routes.ts to:src/db/connection.ts maxPaths:10

Returns: All dependency chains connecting the two files, ordered by path length


Coupling Analysis

Measure coupling strength between modules based on shared dependencies.

Natural Language:

Which modules in my project are most tightly coupled?

Direct MCP Call:

mcp__stellarion__analyze_structure type:coupling threshold:5

Returns: Module pairs ranked by coupling strength

Examples

Understand a Core File's Dependencies

Natural Language:

Analyze the dependencies of src/index.ts. What does it import? What imports it?

Direct MCP Call:

mcp__stellarion__analyze_structure type:dependencies path:src/index.ts depth:3 direction:both

Find Forward Dependencies Only

Natural Language:

What files does the auth module import?

Direct MCP Call:

mcp__stellarion__analyze_structure type:dependencies path:src/auth/index.ts direction:forward depth:2

Find What Depends on a File

Natural Language:

What files would be affected if I change src/utils/helpers.ts?

Direct MCP Call:

mcp__stellarion__analyze_structure type:dependencies path:src/utils/helpers.ts direction:backward depth:3

Trace a Dependency Chain

Natural Language:

How does src/components/UserProfile.tsx eventually connect to src/db/models.ts?

Direct MCP Call:

mcp__stellarion__analyze_structure type:paths from:src/components/UserProfile.tsx to:src/db/models.ts

Find Tightly Coupled Modules

Natural Language:

Which parts of my codebase are too tightly coupled?

Direct MCP Call:

mcp__stellarion__analyze_structure type:coupling threshold:10

Output Format

Dependencies Output

FieldDescription
Direct dependenciesFiles imported by the target file
Direct dependentsFiles that import the target file
Transitive dependenciesIndirect dependencies up to depth
Dependency countTotal number of dependencies
Dependent countTotal number of dependents

Paths Output

FieldDescription
PathSequence of files from source to target
Path lengthNumber of hops in the chain
Total paths foundNumber of paths discovered

Coupling Output

FieldDescription
Module pairThe two modules being compared
Coupling strengthScore based on shared dependencies
Shared dependenciesCommon files both modules depend on

Direction Options

DirectionDescriptionUse Case
forwardOnly imports (what this file uses)Understanding dependencies
backwardOnly dependents (what uses this file)Impact analysis
bothBoth directionsComplete picture

Understanding Coupling Scores

ScoreInterpretationAction
0-5Low couplingHealthy modularity
5-15Moderate couplingMonitor during refactoring
15-30High couplingConsider architectural review
30+Very high couplingStrong candidate for refactoring

Tips for Effective Analysis

  1. Start with dependencies: Before modifying a file, check what depends on it
  2. Use depth wisely: Higher depth shows more connections but may be noisy
  3. Check both directions: Understanding imports AND dependents gives the full picture
  4. Monitor coupling: High coupling scores indicate potential architectural issues
  5. Use paths for debugging: When unexpected behavior occurs, trace how modules connect

Combining with Other Tools

  1. Structure + Impact: Use analyze_structure to understand connections, then analyze_impact for risk scores
  2. Structure + Quality: Find coupled modules, then use analyze_quality to check their complexity
  3. Structure + Refactoring: Identify coupling hotspots, then use find_refactoring for improvement suggestions