# How the Code-Review-Graph Handles PHP Laravel Framework-Specific Edges

> Discover how the code-review-graph adds Laravel-specific edges by scanning Route definitions and Eloquent relationships post-parsing. Learn about DEPENDS_ON edges with concrete framework evidence only.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: deep-dive
- Published: 2026-07-25

---

**The graph adds Laravel-specific edges through an evidence-gated post-processing step that scans for Route definitions and Eloquent relationships after generic PHP parsing, creating `DEPENDS_ON` edges only when concrete Laravel framework evidence is detected.**

The tirth8205/code-review-graph repository constructs a universal code-dependency model across multiple programming languages, but PHP Laravel framework-specific edges require specialized handling beyond standard PHP analysis. These framework-aware dependencies are captured through a dedicated post-processing pass that inspects Laravel-specific patterns in the Abstract Syntax Tree (AST), ensuring accurate representation of routing and ORM relationships.

## Generic PHP Parsing Foundation

The parser first extracts language-agnostic nodes and edges from PHP source files. In [`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py), the section marked by the comment "PHP / Laravel semantic constructs" (lines 10179-10180) handles the base PHP constructs including files, classes, functions, and tests. This initial stage creates generic edges such as `CALLS`, `IMPORTS_FROM`, `INHERITS`, and `IMPLEMENTS` that apply to any PHP codebase regardless of framework.

## Laravel-Specific Post-Processing Pass

After the generic parsing completes, a dedicated Laravel-focused pass scans the PHP AST for framework-specific architectural patterns. This secondary analysis targets two primary Laravel constructs that define application structure and data flow.

### Route Definition Detection

The parser identifies static method calls to `Route::get()`, `Route::post()`, `Route::resource()`, and other routing facade methods. When detected, the system creates a `DEPENDS_ON` edge connecting the route definition node to its corresponding controller action.

```php
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

// This generates a DEPENDS_ON edge to UserController@index
Route::get('/users', [UserController::class, 'index']);

// This generates edges for all resource methods (index, store, show, etc.)
Route::resource('posts', PostController::class);

```

### Eloquent Relationship Mapping

For model relationships, the parser examines class methods returning `$this->belongsTo()`, `$this->hasMany()`, `$this->morphTo()`, and similar Eloquent relationship methods. These patterns generate edges between the defining model and the related model classes.

```php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    // This generates a DEPENDS_ON edge to the User model
    public function author()
    {
        return $this->belongsTo(User::class);
    }
    
    // This generates a DEPENDS_ON edge to the Comment model
    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

```

## Evidence Gating Mechanism

To prevent false positives in plain PHP code that might coincidentally use similar method names, Laravel-specific edges employ strict evidence gating. The `resolve_target` helper in [`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py) (lines 10122-10171) validates specific evidence types before creating edges.

### Import Analysis

The parser checks for explicit `use` statements importing `Illuminate\Routing\Route` or Eloquent base classes. The presence of these imports serves as primary evidence that the code operates within the Laravel framework ecosystem.

### Fully-Qualified Names and Conventions

Secondary evidence includes fully-qualified class names such as `\App\Http\Controllers\...` or method names following Laravel REST conventions including `index`, `store`, `show`, `update`, and `destroy`. The parser stores specific evidence strings including `"import"`, `"fully_qualified"`, and `"same_namespace"` alongside resolved targets to justify edge creation.

## Integration with the Graph Visualization

Once created, `DEPENDS_ON` edges integrate seamlessly into the visualization layer. The [`graph.ts`](https://github.com/tirth8205/code-review-graph/blob/main/graph.ts) file in the VS Code extension ([`code-review-graph-vscode/src/webview/graph.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/webview/graph.ts), lines 14-22) includes these edges in the `ALL_EDGE_KINDS` array, allowing the webview to render them alongside standard dependency edges. Users can toggle Laravel-specific dependencies using the toolbar interface.

The repository documentation explicitly acknowledges this capability in the README (lines 148-152), noting that Blade template references and Laravel Route/Eloquent semantic edges appear only when the parser detects the required framework evidence.

## Summary

- The graph processes PHP code through a generic parser first, then executes a Laravel-specific post-pass for framework patterns
- Route definitions such as `Route::get()` and `Route::resource()` generate `DEPENDS_ON` edges linking to their target controllers
- Eloquent relationship methods including `belongsTo()` and `hasMany()` create edges between related models
- Evidence gating requires specific imports, fully-qualified namespace patterns, or Laravel naming conventions to prevent false positives in non-Laravel code
- These framework edges appear in the visualization layer through the standard `ALL_EDGE_KINDS` configuration and can be toggled via the UI toolbar

## Frequently Asked Questions

### What edge type represents Laravel framework dependencies in the graph?

The system uses the `DEPENDS_ON` edge kind, defined in the global `EdgeKind` enum, to represent high-level Laravel framework dependencies such as routes and Eloquent relationships. This distinguishes framework-level connections from language-level edges like `CALLS` or `IMPLEMENTS` while maintaining compatibility with the visualization system.

### How does the parser distinguish real Laravel code from plain PHP with similar method names?

The parser implements evidence gating through the `resolve_target` helper in [`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py) (lines 10122-10171), which checks for concrete Laravel evidence such as `use Illuminate\Routing\Route` imports, fully-qualified class names like `\App\Http\Controllers`, or standard REST method names before creating edges. This prevents plain PHP code with coincidentally similar method names from triggering false Laravel dependencies.

### Can developers toggle Laravel-specific edges in the visualization interface?

Yes. The VS Code extension's webview ([`code-review-graph-vscode/src/webview/graph.ts`](https://github.com/tirth8205/code-review-graph/blob/main/code-review-graph-vscode/src/webview/graph.ts), lines 14-22) includes `DEPENDS_ON` in the `ALL_EDGE_KINDS` array, allowing users to show or hide Laravel framework edges using the toolbar pills interface alongside other dependency types. This provides flexibility when analyzing projects that mix Laravel and non-Laravel PHP code.

### Where in the codebase is the Laravel-specific parsing logic implemented?

Laravel-specific logic resides in [`code_review_graph/parser.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/parser.py), specifically within the section marked "PHP / Laravel semantic constructs" (lines 10179-10180) for the initial PHP parsing, and the `resolve_target` helper (lines 10122-10171) for evidence-gated edge creation during the post-processing pass. The README (lines 148-152) documents this feature as an explicit capability of the graph system.