PHPackages                             naimul/db-visualizer - 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. naimul/db-visualizer

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

naimul/db-visualizer
====================

Laravel Database &amp; Code Intelligence Visualizer (N+1, Relations, Performance Analyzer)

v1.0.6(2mo ago)7792[2 issues](https://github.com/Naimcse56/db-visualizer/issues)MITPHPPHP ^8.1

Since Apr 6Pushed 1mo agoCompare

[ Source](https://github.com/Naimcse56/db-visualizer)[ Packagist](https://packagist.org/packages/naimul/db-visualizer)[ RSS](/packages/naimul-db-visualizer/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (5)Versions (8)Used By (0)

🔍 Laravel DB Visualizer
=======================

[](#-laravel-db-visualizer)

A powerful Laravel package to analyze your application models, relationships, database usage, and detect performance issues like **N+1 queries, unused columns, and missing eager loading**.

---

🚀 Features
----------

[](#-features)

- 📊 Scan all Eloquent Models (App + Modules support)
- 🔗 Auto-detect relationships
- 🧠 Detect N+1 query risks probability
- ❌ Find unused columns
- ⚡ Detect missing eager loading
- 📈 Performance scoring system (0–100)
- 🧹 Code usage analysis
- 🧩 Supports Laravel Modules (nwidart style)

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require naimul/db-visualizer
```

---

⚙️ Auto Service Provider
------------------------

[](#️-auto-service-provider)

If you are using Laravel 10+, the package will auto-register.

If not, add manually:

```
Naimul\DbVisualizer\DbVisualizerServiceProvider::class,
```

---

🗂 Publishing Configuration
--------------------------

[](#-publishing-configuration)

To customize the package's configuration, publish the config file with:

```
php artisan vendor:publish --provider="Naimul\DbVisualizer\DbVisualizerServiceProvider" --tag="dbv-config"
```

This will create a `db-visualizer.php` config file in your `config` directory.

🗃 Publishing Assets (Views, JS, CSS)
------------------------------------

[](#-publishing-assets-views-js-css)

To publish the package's frontend resources (views, JS, CSS), run:

```
php artisan vendor:publish --provider="Naimul\DbVisualizer\DbVisualizerServiceProvider" --tag="dbv-resources"
```

This will copy the package's resources into your application's `resources/vendor/db-visualizer` directory for customization.

🔐 Authorization
---------------

[](#-authorization)

Access to DB Visualizer is controlled via a `viewDbVisualizer` gate. By default, access is **only granted in the `local` environment**.

To allow access in other environments, override the gate in your `AppServiceProvider`:

```
use Illuminate\Support\Facades\Gate;

public function boot(): void
{
    // Allow authenticated admins only
    Gate::define('viewDbVisualizer', fn (?User $user) => $user?->is_admin);

    // Allow specific emails
    Gate::define('viewDbVisualizer', fn (?User $user) => in_array($user?->email, [
        'admin@example.com',
    ]));

    // Allow everyone (including unauthenticated users)
    Gate::define('viewDbVisualizer', fn (?User $user) => true);
}
```

Requests that fail the gate receive a `403` response. Unauthenticated users are redirected to the login page.

> **Important:** Always declare a nullable `?User $user` parameter in your gate callback. Laravel uses this to determine whether the gate supports unauthenticated (guest) access. A callback without any parameter — such as `fn () => true` — will **not** be called for guests and will redirect them to login instead.

---

🌐 Routes
--------

[](#-routes)

After installation, visit:

```
/dbv
/dbv/data
/dbv/detail/{model}

```

Example:

```
http://your-app.test/dbv/data

```

---

📊 API Endpoints
---------------

[](#-api-endpoints)

### Get all models analysis

[](#get-all-models-analysis)

```
GET /dbv/data
```

### Search models

[](#search-models)

```
GET /dbv/data?search=User
```

### Model details

[](#model-details)

```
GET /dbv/detail/User
```

---

🧠 What It Analyzes
------------------

[](#-what-it-analyzes)

### ✔ Models

[](#-models)

- Table name
- Columns
- Relations
- Soft deletes

### ✔ Relations

[](#-relations)

- Used / unused detection
- N+1 query detection probability
- Missing eager loading

### ✔ Columns

[](#-columns)

- Used / unused detection

### ✔ Performance Score

[](#-performance-score)

- Calculates score (0–100)
- Quality labels:

    - Excellent
    - Good
    - Average
    - Poor

---

📈 Example Response
------------------

[](#-example-response)

```
{
  "model": "User",
  "table": "users",
  "performance_score": 85,
  "quality_label": "Good Quality",
  "unused_columns_count": 2,
  "n_plus_one_issues": 1,
  "relations": [
    {
      "method": "posts",
      "type": "HasMany",
      "used": true,
      "n_plus_one": false
    }
  ]
}
```

---

⚡ Performance Scoring Rules
---------------------------

[](#-performance-scoring-rules)

IssuePenaltyUnused relation-10Unused column-2N+1 issue-15Missing eager load-10Bonus:

- Soft deletes: +5
- Cache usage: +5
- API Resource usage: +5

---

🛠 Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel 10, 11, 12, 13 supported

---

📁 Supported Structure
---------------------

[](#-supported-structure)

- `app/Models`
- `Modules/*/Entities`
- `Modules/*/Models`
- Blade Views scanning

---

🔥 Use Case
----------

[](#-use-case)

This package is useful for:

- Optimizing large Laravel applications
- Detecting hidden performance issues
- Code quality auditing
- Refactoring legacy systems
- Interview/demo projects

---

🧩 Future Plans
--------------

[](#-future-plans)

- N+1 Query file locate
- eagerloading File locate
- Performance booster

---

🤝 Contributing
--------------

[](#-contributing)

Pull requests are welcome. For major changes, please open an issue first.

---

📜 License
---------

[](#-license)

MIT License © Open Source

---

⭐ Support
---------

[](#-support)

If you like this package, give it a ⭐ on GitHub.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance82

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 67.4% 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 ~0 days

Total

7

Last Release

63d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/26866670?v=4)[Naimul Islam](/maintainers/Naimcse56)[@Naimcse56](https://github.com/Naimcse56)

---

Top Contributors

[![Robiussani152](https://avatars.githubusercontent.com/u/19356585?v=4)](https://github.com/Robiussani152 "Robiussani152 (29 commits)")[![Naimcse56](https://avatars.githubusercontent.com/u/26866670?v=4)](https://github.com/Naimcse56 "Naimcse56 (14 commits)")

### Embed Badge

![Health badge](/badges/naimul-db-visualizer/health.svg)

```
[![Health](https://phpackages.com/badges/naimul-db-visualizer/health.svg)](https://phpackages.com/packages/naimul-db-visualizer)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M84](/packages/mongodb-laravel-mongodb)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[laragear/populate

Populate your database with a supercharged, continuable seeder

8713.1k](/packages/laragear-populate)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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