PHPackages                             zxch/indexlens - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. zxch/indexlens

ActiveLibrary[Database &amp; ORM](/categories/database)

zxch/indexlens
==============

Intelligent database query observability and optimization package for Laravel.

v1.0.4(2mo ago)146MITPHPPHP ^8.2CI passing

Since Apr 1Pushed 2mo agoCompare

[ Source](https://github.com/RizkyZaki/IndexLens)[ Packagist](https://packagist.org/packages/zxch/indexlens)[ RSS](/packages/zxch-indexlens/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (12)Versions (6)Used By (0)

IndexLens
=========

[](#indexlens)

[![IndexLens Banner](banner.png)](banner.png)

Intelligent query observability and optimization engine for Laravel.

IndexLens is built for teams that want to move beyond basic query logs. It captures runtime SQL behavior, explains performance bottlenecks, recommends practical fixes, and guards performance budgets in CI.

Why IndexLens
-------------

[](#why-indexlens)

Most tooling can tell you what query ran. IndexLens tells you why it is expensive, where it hurts in your routes, and what to do next.

It is designed to detect:

- N+1 query patterns and duplicate query storms
- missing indexes across WHERE, JOIN, ORDER BY, GROUP BY
- full table scans and filesort risks from EXPLAIN plans
- route-level bottlenecks and memory-heavy hydration patterns
- performance regressions across deployments

Core Intelligence
-----------------

[](#core-intelligence)

### Query Interceptor Engine

[](#query-interceptor-engine)

- Captures SQL, bindings, timing, connection, route name, URL, action, user ID
- Tracks memory before and after each query
- Tracks request duration and query fingerprint per request

### N+1 + Duplicate Detection

[](#n1--duplicate-detection)

- Groups normalized SQL and flags repeated patterns
- Returns severity, explanation, and eager loading recommendation
- Generates suggested code snippets when relation/model candidates are detected

### Missing Index Recommendation

[](#missing-index-recommendation)

- Extracts candidate columns from WHERE/JOIN/ORDER BY/GROUP BY usage
- Checks existing index metadata (MySQL and PostgreSQL paths)
- Outputs actionable SQL suggestions with reason and severity

### SQL EXPLAIN Intelligence

[](#sql-explain-intelligence)

- Runs EXPLAIN for slow queries
- Interprets scan type, filesort, temporary table, missing keys, row estimates
- Produces optimization score, severity, and human-readable strategy

### Route Performance Heatmap

[](#route-performance-heatmap)

- Aggregates average query count, SQL time, memory, request count per route
- Assigns route score and severity ranking
- Makes worst endpoints visible immediately

### Regression Detection

[](#regression-detection)

- Compares latest route baseline against previous baseline
- Flags significant growth in query count and route SQL latency
- Stores regression snapshots for team visibility

### CI Performance Budget

[](#ci-performance-budget)

- Fails pipeline when route performance exceeds configured thresholds
- Intended for pull request enforcement and deployment safety

Installation
------------

[](#installation)

```
composer require zxch/indexlens
php artisan vendor:publish --tag=indexlens-config
php artisan vendor:publish --tag=indexlens-migrations
php artisan migrate
```

Optional debug view publish:

```
php artisan vendor:publish --tag=indexlens-views
```

Configuration
-------------

[](#configuration)

```
return [
  'mode' => env('INDEXLENS_MODE', 'balanced'), // off|safe|balanced|investigate
    'enabled' => true,
    'slow_query_ms' => 100,
    'detect_n_plus_one' => true,
    'detect_missing_indexes' => true,
    'run_explain' => true,
    'store_profiles' => true,
  'capture_cli' => env('INDEXLENS_CAPTURE_CLI', false),
  'sample_rate' => (float) env('INDEXLENS_SAMPLE_RATE', 1.0),
  'max_queries_per_request' => (int) env('INDEXLENS_MAX_QUERIES_PER_REQUEST', 250),
  'persist_only_slow_requests' => env('INDEXLENS_PERSIST_ONLY_SLOW', false),
    'memory_spike_kb' => 1024,
    'n_plus_one_repeat_threshold' => 5,
    'duplicate_query_threshold' => 3,
  'regression_ignore_cli' => env('INDEXLENS_REGRESSION_IGNORE_CLI', true),
  'regression_min_delta_ms' => (float) env('INDEXLENS_REGRESSION_MIN_DELTA_MS', 50),
    'ci_budget' => [
        'max_queries' => 50,
        'max_sql_time' => 200,
    ],
];
```

Facade API
----------

[](#facade-api)

```
use IndexLens\IndexLens\Facades\IndexLens;

IndexLens::enable();
IndexLens::scan();
IndexLens::routes();
IndexLens::recommendIndexes();
IndexLens::explainSlowQueries();
IndexLens::regressions();
IndexLens::report('json');
IndexLens::report('markdown');
IndexLens::report('html');
```

Artisan Commands
----------------

[](#artisan-commands)

```
php artisan indexlens:scan
php artisan indexlens:routes
php artisan indexlens:regression
php artisan indexlens:ci --max-query=50 --max-time=200
php artisan indexlens:report --format=markdown --output=storage/app/indexlens-report.md
php artisan indexlens:report --format=html --output=storage/app/indexlens-report.html
php artisan indexlens:status
```

Production Mode Presets
-----------------------

[](#production-mode-presets)

- `off`: fully disabled
- `safe`: production low-overhead mode (sampling on, no explain, no profile persistence)
- `balanced`: default behavior
- `investigate`: capture-rich mode for short investigations

Recommended production `.env` baseline:

```
INDEXLENS_MODE=safe
INDEXLENS_ENABLED=true
INDEXLENS_CAPTURE_CLI=false
INDEXLENS_SAMPLE_RATE=0.25
INDEXLENS_SLOW_QUERY_MS=300
INDEXLENS_RUN_EXPLAIN=false
INDEXLENS_STORE_PROFILES=false
INDEXLENS_REGRESSION_IGNORE_CLI=true
INDEXLENS_REGRESSION_MIN_DELTA_MS=50
```

Example Findings
----------------

[](#example-findings)

N+1 finding:

```
{
  "type": "n_plus_one",
  "severity": "high",
  "message": "Repeated query detected 50 times",
  "suggestion": "Use Post::with('user') before iterating"
}
```

Index recommendation:

```
{
  "table": "orders",
  "column": "user_id",
  "reason": "frequent WHERE usage",
  "suggestion": "CREATE INDEX idx_orders_user_id ON orders(user_id)",
  "severity": "high"
}
```

Regression output:

```
{
  "route": "/dashboard",
  "before_ms": 120,
  "after_ms": 520,
  "regression": "4.3x slower"
}
```

Route heatmap snapshot:

```
/dashboard -> 142 queries -> HIGH
/reports/export -> 600 queries -> CRITICAL
/users -> 12 queries -> GOOD

```

CI Usage (GitHub Actions)
-------------------------

[](#ci-usage-github-actions)

Important:

- For this package repository, run package tests only.
- Run IndexLens runtime budgets in the host Laravel application repository where an artisan file and real route/query traffic exist.

```
name: indexlens-performance

on:
  pull_request:
  push:
    branches: [main]

jobs:
  package-tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          tools: composer

      - run: composer install --no-interaction --prefer-dist
      - run: php artisan test
```

Debug View
----------

[](#debug-view)

```
return view('indexlens::debug', [
    'routes' => app('indexlens')->routes(),
]);
```

Architecture
------------

[](#architecture)

```
src/
 ├── Console/
 ├── Facades/
 ├── Services/
 ├── Analyzers/
 ├── DTOs/
 ├── Models/
 ├── Repositories/
 ├── Commands/
 ├── Contracts/
 └── IndexLensServiceProvider.php

```

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance83

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

85d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8af4c65f6c85a664ce91e93cc696717dc82f549e3bb8615d09fdd2264d9641ad?d=identicon)[RizkyZaki](/maintainers/RizkyZaki)

---

Top Contributors

[![RizkyZaki](https://avatars.githubusercontent.com/u/95119754?v=4)](https://github.com/RizkyZaki "RizkyZaki (8 commits)")

---

Tags

laraveldatabaseperformancequeryindexobservability

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zxch-indexlens/health.svg)

```
[![Health](https://phpackages.com/badges/zxch-indexlens/health.svg)](https://phpackages.com/packages/zxch-indexlens)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M612](/packages/spatie-laravel-medialibrary)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M341](/packages/psalm-plugin-laravel)[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.2k](/packages/laravel-sail)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M128](/packages/laravel-pulse)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M172](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M23](/packages/yajra-laravel-oci8)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
