Search by

kdr-dev / dissect

kdr_dev

Visualise your Eloquent models and their relationships as an interactive graph. Keep track of what route is exposed and how it's requests & responses are build.

Package info

github.com/kadirtikil/dissect

pkg:composer/kdr-dev/dissect

Statistics

Installs: 161

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0


README

Keep sight of your Laravel application, in the age of agentic development.

dissect is a dev-only page inside your Laravel app that draws what your code actually is: your models and how they relate, every endpoint and what it takes and returns, every job and what dispatches it, what is on your queue right now, what each service provider wires up, and which domain (bounded context) all of it belongs to.

It reads your source and your framework's own metadata. It never runs your code to find out. Everything it shows comes from what is in the repository right now, so it stays correct while you, your team or your coding agents keep changing things.

The model graph: every model with its columns, and each relation drawn from the column that links it

πŸ€” What it's for

Laravel apps grow sideways. A model gains a relation, a controller starts queueing a job, a provider swaps an implementation, a "Billing" folder slowly fills up with things that aren't billing. Each change is small and makes sense in its diff. Nobody sees the whole picture, and when an agent writes half the code, the picture moves faster than anybody can follow.

dissect gives you that picture with one composer require:

  • 🧭 Onboarding. Open one page and see the schema, the HTTP surface and the background work. No grepping, no out-of-date diagram on a wiki.
  • πŸ” Reviewing. Check after a change, yours or an agent's, that the relation points where you meant, the endpoint validates what you expected, and the job lands on the right queue.
  • 🧱 Architecture. See which domain every class is in, spot the classes that sit in the wrong folder, and filter every list down to one domain.
  • πŸš‘ Debugging. See what is waiting, running, delayed and failed on your queue, next to the code that put it there.

✨ What you get

The sidebar has one page for each question:

Page Answers
🏠 Overview How big is this app? Model, relation and view counts, plus a way into every other page.
πŸ“¦ Models What does my data look like? Every Eloquent model with its columns, and each relation drawn between the columns that link it (posts.author_id β†’ authors.id).
πŸ›£οΈ Routes How is it reached? Every endpoint, its middleware, the request it validates and the response it returns.
⏱️ Jobs What happens in the background? Every job, queued listener, mailable and notification: its queue, retries, payload, and the endpoint that dispatches it.
πŸ“‘ Queue What is happening right now? Waiting, running, delayed and failed jobs, plus batches. Live and polled.
🌲 Provider-Trees What is wired to what? Each service provider's bindings, what they resolve to, and the constructors behind them, drawn as a tree.
🧭 Domains How is this app split up? Every domain, how it was found, its classes, and anything that looks out of place.
πŸ•°οΈ Changes What did I (or an agent) just change? Every model, route, job and provider that's new, gone or different since you started watching or since the committed snapshot, and how risky each change is.

Each page has its own address (/dissect#/routes, /dissect#/domains, …), so you can bookmark one or link a colleague to it.

And the parts that make it easy to live with:

  • πŸ“¦ No build step in your app. The compiled frontend ships with the package.
  • πŸ”Œ Nothing to publish. The service provider is auto-discovered.
  • πŸ”’ Local-only by default, behind a viewDissect gate everywhere else.
  • 🀝 Shared state you commit. Node positions, saved views and hand-written domains live in .dissect/ in your project, so your whole team sees the same picture.
  • ♻️ Live updates. Edit a model, controller, job or provider and the page refreshes on its own, with no file watcher to run.
  • πŸ’» Works without the page too. php artisan dissect:export prints any of it as JSON, a Markdown digest, or a Mermaid diagram of the models.
  • 🚧 Guardrails between domains. Write down which domain may use which, and php artisan dissect:check fails CI when the code disagrees.
  • πŸ€– An MCP server for agents. php artisan mcp:start dissect answers questions about one model, route, job or provider at a time.

πŸš€ Quick start

dissect is not on Packagist yet, so install it straight from GitHub. From your application's root:

composer config repositories.dissect vcs https://github.com/kadirtikil/dissect.git
composer require kdr-dev/dissect --dev

Then open /dissect in your local environment. That's it. πŸŽ‰

πŸ’‘ Composer resolves packages by tag. To track the unreleased tip instead, or if no tag has been pushed yet, ask for the branch: composer require kdr-dev/dissect:dev-main --dev.

πŸ”‘ SSH works too: swap the URL for git@github.com:kadirtikil/dissect.git.

Adding the repository by hand instead

composer config writes the repository entry for you. To do it yourself, add this to your application's composer.json:

{
    "repositories": [
        { "type": "vcs", "url": "https://github.com/kadirtikil/dissect.git" }
    ]
}

Then run composer require kdr-dev/dissect --dev.

Publishing the config file is optional, since almost everything can be set from .env:

php artisan vendor:publish --tag=dissect-config

βœ… Requirements

  • PHP 8.3+
  • Laravel 13.x

Laravel 13 is a hard minimum, on purpose. Columns and relations come from the framework's own ModelInspector (the class behind artisan model:show), and the endpoint list reads laravel-json-api schemas, whose current release supports nothing earlier. Supporting one framework version well is worth more here than supporting three thinly.

πŸ“¦ Models

The graph is the heart of dissect. Every model in your models directory becomes a card with its table and columns. Every relation becomes an edge from the column that holds the key to the column it points at, so you read posts.author_id β†’ authors.id, not just "Post β†’ Author".

  • 🎨 Relation families. Eloquent's eleven relation types fold into four colours (has, belongs to, many-to-many, polymorphic), and polymorphic edges are dashed too, so colour is never the only signal. A legend is always on screen.
  • πŸ”Ž Expand a card to see every column with its key, unique, nullable, guarded, hidden and cast flags. From there, Jobs shows every job that carries this model.
  • πŸ‘» Models outside the scan, such as a vendor's DatabaseNotification, show as dashed "not in scan" placeholders instead of being dropped.
  • βœ‹ Drag cards into an arrangement that makes sense. Positions are saved to .dissect/layout.json, which you commit, so the team gets the same layout. Reset layout puts everything back on the grid.

πŸ—‚οΈ Views

A large schema is easier to read one slice at a time. Pick the models you want (shift-drag on the canvas, or tick them in the View menu's model list), name the selection, and it is saved as a view in .dissect/views.json.

  • βž• Tick a model to add it to the open view, untick it to take it out. Changes save as you go.
  • 🧭 A model keeps the same position in every view, so switching views hides models instead of rearranging the board.
  • 🀝 The file is plain JSON and meant to be committed. Which view you have open is remembered per browser, not in the file.

πŸ“ Models outside app/Models

One other directory is one variable:

DISSECT_MODELS_PATH=src/Domain

Models in several places, such as a Models folder per domain, go in the published config. A * stands for one directory name:

'models' => [
    'paths' => [
        'app/Domain/*/Models',
        'packages/billing/src/Models',
    ],
],

No namespace is needed, because each model's class name is read from its own file. Two models with the same class name in different namespaces are two cards. (DISSECT_MODELS_NAMESPACE is no longer read.)

🧭 Domains

If your app is split into domains (bounded contexts), dissect works out which domain every class belongs to and shows the app through that lens. Most apps need no configuration at all: domains are read from the folder layout you already use.

The Domains page: each domain with how it was found, its folders and classes, plus findings and unassigned classes

How domains are found

dissect recognises these layouts:

Layout Each domain is
nwidart/laravel-modules Modules/{Name}
InterNACHI/modular app-modules/{name}
Spatie's Laravel Beyond CRUD app/Domain/{Name}, src/Domain/{Name} (or Domains)
Local packages packages/{name} or packages/{vendor}/{name}, a folder with a composer.json
Hexagonal src/{Name} or app/{Name} with at least two of Domain/, Application/, Infrastructure/
Layer-first sub-folders app/Models/{Name} plus the same name under another layer, e.g. app/Http/Controllers/{Name}

An app that follows none of these has no domains, and dissect looks exactly as it does without them. A starter kit's Auth folders don't count as a domain, which is why the layer-first rule needs a matching app/Models/{Name}.

Writing domains down

For anything the folders don't express, list the domains in .dissect/domains.json. Commit it, like the layout and the views:

{
    "version": 1,
    "domains": [
        { "name": "Identity", "paths": ["app/Models/User.php", "app/Http/Controllers/Auth"] }
    ]
}

Paths are relative to the app root, a * stands for one directory name, and a path may name a single file. Add "conventions": false to ignore the folder layouts and use only this file.

Moving a single class

A class that sits in the wrong folder can say where it belongs with an attribute:

#[Domain('Identity')]
class User extends Authenticatable {}

You declare the Domain attribute class yourself, in any namespace. dissect matches it by its short name and reads it from the file without loading the class, so nothing from this dev dependency ends up in your production code.

Who wins

The attribute first, then domains.json, then the folder layout. A class none of them claims is listed as unassigned. It is never guessed into a domain.

Two things are reported as findings so they get noticed instead of quietly believed: an attribute that disagrees with the folder the class sits in, and an attribute that names a domain nothing else defines.

Where domains show up

  • 🧭 The Domains page lists every domain with how it was found (folder, domains.json, attribute, …), its folders and its classes grouped by namespace, followed by the findings and the unassigned classes. An app with no domains gets an empty state that lists the layouts that would count.
  • 🚧 Boundary rules, once you write some: each domain's rule on its card, links that break one in red, and every violation listed with its file and line.
  • πŸ”— What each domain depends on, and what uses it. Under each domain, one chip per other domain its classes name, and one per domain whose classes name its own, with how many references there are. A ⇄ marks two domains that name each other. Click a chip to see every reference behind it: which class, which class it names, how (relation, dispatch, type, …), and the file and line.
  • 🏷️ Every model, route, job and provider carries its domain, so the other pages can use it. A route belongs to its controller's domain, and a closure route to the domain of the file it is written in. A provider belongs to the domain of its own class, not to what it binds.
  • πŸŽ›οΈ Domain filters. The Routes, Jobs and Provider-Trees lists show a row of domain chips under their other filters: one per domain that has rows in that list, plus unassigned. Click one to see just that domain's endpoints, jobs or providers. An app with no domains sees no chips.
  • 🎨 One colour per domain, the same on every page, so Billing is recognisably Billing wherever it appears.
  • πŸ“„ /dissect/domains.json serves the same data as JSON, for scripts and agents.

Which class uses which

dissect also reads every class, interface, trait and enum in your source folders, and every other one of them it names. The Domains page uses it to show how domains depend on each other. You can ask for it from the terminal or an agent too:

php artisan dissect:export classes --format=md
## Between domains
- Billing β†’ Sales: 1 (relation 1)
- Sales β†’ Billing: 1 (relation 1)

Each reference says how one class names the other. Most kinds are what the syntax says: extends, implements, trait, new, static, type, instanceof, catch and attribute. Four are what the syntax means in a Laravel app, which a generic dependency tool can't see:

  • relation: $this->belongsTo(Customer::class) and the other relation builders.
  • dispatch: SendInvoice::dispatch(), dispatch(new SendInvoice), Bus::dispatch(...).
  • event: event(new InvoicePaid), Event::dispatch(...).
  • binding: $this->app->bind(Gateway::class, StripeGateway::class), and when()->needs()->give().

Each name is counted once, with its most specific kind, so a dispatched job is a dispatch and not also a new. Only references between your own classes are listed. Everything is read as syntax, so nothing is loaded or run, and a file that doesn't parse is listed as such rather than skipped silently.

Boundary rules

Once you know which domain uses which, you can say which ones may. Add a rules object to .dissect/domains.json, keyed by domain:

{
    "version": 1,
    "rules": {
        "Billing": { "may_use": ["Shared"], "must_not_use": ["Illuminate\\Http"] },
        "Sales": { "may_use": ["Billing", "Shared"] }
    }
}
  • may_use lists the other domains this one's classes may name. Anything else is a violation. Leave the key out to allow every domain, or give an empty list to allow none. A domain may always use itself, and a class in no domain is never a violation.
  • must_not_use lists namespaces (or single classes) this domain must not name at all, the framework's and packages' included. Illuminate\Http keeps requests out of a domain layer.

A domain with no rule isn't checked, so you can start with one domain and add the rest when they're ready. An app with no rules never builds the class index for it. Every reference kind counts, the Laravel ones included: a relation, a dispatched job or a container binding across a boundary is a violation like any new or type hint.

A rule that can't be read, or that names a domain that doesn't exist, is reported rather than ignored. A typo in an allow-list would otherwise be a check that never fires.

php artisan dissect:export boundaries --format=md
2 rules, 1 violation.

## Sales (1)
- Sales may not use Billing: Customer β†’ Invoice (relation, line 19). `app/Domain/Sales/Models/Customer.php:19`

Failing the build

dissect:check exits with 1 when a rule is broken, so CI or a pre-commit hook can stop on it:

php artisan dissect:check
app/Domain/Sales/Models/Customer.php:19 Sales may not use Billing: Customer β†’ Invoice (relation, line 19).

   ERROR  1 violation of 2 rules.
  • --files=app/Domain/Sales/Models/Customer.php reports only what those files break. The whole app is still read, since whether a class may be named depends on which domain it is in, but you only hear about the files you gave it. Repeat the option or separate paths with commas.
  • --format=github writes workflow annotations, so a violation shows up on its line in the pull request.
  • --format=json gives a script the verdict (passed) and everything behind it.

It also fails when .dissect/domains.json has a problem, such as invalid JSON, an unknown key or a rule naming a domain that doesn't exist. Otherwise a broken rules file would pass as "no rules". With no rules at all it passes and says there was nothing to check. A file that doesn't parse is listed as not checked, and doesn't fail on its own.

# .github/workflows/ci.yml
- run: php artisan dissect:check --format=github

Catching an agent as it edits

dissect:check --hook runs as a Claude Code hook. After every Edit or Write it checks the file that was just changed. When the edit breaks a rule, it tells the agent at once, with the file, the line and the rule. Add this to .claude/settings.json and commit it:

{
    "hooks": {
        "PostToolUse": [
            {
                "matcher": "Edit|MultiEdit|Write",
                "hooks": [{ "type": "command", "command": "php artisan dissect:check --hook" }]
            }
        ]
    }
}

What the agent sees after an edit that breaks a rule:

dissect: this breaks a boundary rule in .dissect/domains.json:
- `app/Domain/Sales/Models/Customer.php:19` Sales may not use Billing: Customer β†’ Invoice (relation, line 19).

The rule:
- **Sales** may use no other domain

Change the code so it keeps to the rule. The rule says where this team wants the boundary;
only change .dissect/domains.json if you were asked to move it.
  • It stays silent when the edit keeps to the rules, and for any file that isn't PHP. An agent only hears from it when there's something to fix.
  • Editing .dissect/domains.json itself checks the whole app, and a rules file that can't be read is reported whatever was edited.
  • If the check can't run at all (the app doesn't boot, say), you see the error and the agent carries on. A broken tool never blocks an edit.
  • The command is relative to the session's directory, so it checks the checkout the agent is working in, a git worktree included.

The MCP server has the same check as dissect_check, for an agent to ask before it edits rather than be told after.

On the Domains page

Each domain card shows its rule. A link into another domain that breaks a rule turns red, under both domains, and opening it says which rule every reference across it breaks. The page header counts the violations, and a Broken rules list below the domains has each one with its file and line: what dissect:check fails on. A rule naming a domain that doesn't exist is listed with the other domains.json problems at the top.

🚧 Coming next: the domain map. A graph with one node per domain and the dependencies between domains as edges, so you can see the shape of the whole app at the domain level and click through to the classes behind each dependency. It's being built now and will be documented here when it lands.

On the Models graph, each card names its domain beside the table, and its left edge takes the domain's colour. A relation from a model in one domain to a model in another is drawn thicker, and its label says which domain it goes into (invoices β†’ Billing). Relations to a model in no domain are not counted as crossings.

Every domain is also a view in the view menu, under Domains. A domain view shows that domain's models and follows its folders, so it can't be edited. Copy to a saved view turns it into an ordinary view in .dissect/views.json, which you can then change.

πŸ›£οΈ Routes

The graph says what your data looks like. The Routes page says how you reach it: every endpoint, what a request must carry, and what comes back.

POST api/invoices                      Request   StoreInvoiceRequest
auth:sanctum Β· throttle:60,1             customer_id  integer  req
                                           exists:customers,id
Response  resource Β· 201                 lines[].sku  string   req
  id          scalar
  customer    object  sometimes
  lines[]     array
  • πŸ”€ Web and API. The list splits into the routes your own frontend calls and the API you offer to others, based on the middleware group each route file applies. An API served from somewhere other than /api still lands in the right half.
  • 🌐 Hosts. Routes on different domains (hosts) are kept apart, and the host is shown before the path.
  • πŸ”Ž Filter by path, route name, controller or verb, and narrow by method, by domain, and by whose code it is (app, vendor or framework). A path-repository package counts as your own code.
  • πŸ‘€ Nothing is hidden. Whatever you have selected elsewhere, the endpoint list shows every route until you filter it here.

🎯 Where the shapes come from

Requests are read from a FormRequest's rules() when one is type-hinted, and from inline validation otherwise: $request->validate([…]), $this->validate($request, […]), Validator::make($data, […]) or validator($data, […]). Responses are read from the return type and the toArray() of whatever JsonResource it names, nested resources included. A Resource::collection(…) in the body is a list even when the method declares no return type.

  • ❔ sometimes|required is optional: the field may be left out, and only has to be filled when it's sent.
  • πŸ™ˆ A key behind when(), whenLoaded(), whenCounted() and the rest is marked as only sometimes present.
  • 🧾 Validation whose rules are built elsewhere, such as $request->validate($this->rules()), is shown as validation dissect couldn't read, not as an endpoint that accepts anything.

Nothing in Laravel can be asked what an endpoint returns, so some of this is read from your source rather than run. Each shape says which:

Confidence Meaning
certain The framework produced it: rules() ran, or the resource declared its model with @mixin.
inferred Read from the source. Usually rules() could not run outside a request, or the resource never said what it wraps.
unknown The class was found but its shape could not be read. Treat it as incomplete.

A confidently wrong API description is worse than none, so this is shown, not smoothed over.

🧩 JSON:API

Apps built on laravel-json-api get their shapes from their schemas, since every route that package registers runs the same generic controller and a return type would say nothing.

POST v1/documents                      Request   JSON:API document
                                         data          object  req
Response  JSON:API document  201           type        string  req
  data        object                       attributes  object
    type                                     title
    id                                       slug
    attributes  object                    relationships object
      title       sometimes                  owner       object
    relationships object                       data      object
  • πŸ“¦ The envelope is shown, not the bare fields: you write data.attributes.title, so that is what the page says.
  • πŸ”— posts/{post}/author is described with the author's schema, and a relationships/… endpoint promises a type and an id and nothing else.
  • 🚫 A DELETE says it answers 204 instead of reporting an empty body as a failure.
  • βœ… Rules from the resource's ResourceRequest are shown where the value actually sits, at data.attributes.title.
  • 🩹 Update fields stay optional, because a JSON:API update is a patch: the rules say what a value must look like if you send it.
  • πŸ› οΈ A custom action ($actions->withId()->post('publish')) runs your own method, so it's read from that method like any other route, not described as a post document.

⏱️ Jobs

The Jobs page answers the question a 202 Accepted leaves behind: what happens next, where, and carrying what. Jobs, queued listeners, mailables and queued notifications all end up on the same worker, so they are all here, found by the ShouldQueue interface instead of by which folder they sit in.

SendInvoice                            Queue     invoices
Job                                      set in the constructor
                                       Retries   3 tries Β· 10, 60s Β· 120s timeout
Payload                                Handling  batchable Β· after commit
  invoice   App\Models\Invoice
            carries Invoice            Dispatched by                          2
                                         InvoiceController@store  dispatch()
Carries                                  app/Http/…/InvoiceController.php:61
  Invoice β†—                              POST:api/invoices β†—
  • πŸ”— Dispatched by links to the endpoint that queues the job, and Carries jumps to the model on the graph.
  • 🧭 Grouped by queue, because the queue is what you point a worker at.
  • βŒ€ Never dispatched? A job nothing dispatches is flagged: it is either dead code or dispatched dynamically. That's something queue:work can't tell you. A queued listener isn't flagged, since its event is what queues it.
  • πŸ”Ž Filter by name, class, queue or dispatcher, and narrow by kind, queue and domain.

🎯 Where the queue name comes from

A job using Laravel's Queueable trait cannot declare a public $queue property (PHP rejects the redefinition), so most jobs name their queue somewhere else. dissect reads all of those places and says which one answered:

Source Meaning
property A declared $queue. The usual form for a queued listener.
constructor $this->onQueue('…') among the constructor's own statements. One inside an if doesn't count, since it depends on the arguments.
dispatch The class named none, and every dispatch site chained the same ->onQueue('…'), including onto dispatch(new …) or Bus::batch([…]).
mixed Dispatch sites name different queues, or one names a queue and another names none (which is the default queue). Picking one would invent a fact.
default Nothing named one.

Nothing is executed to find this out. backoff() and middleware() are read from source too. Describing your code must never be able to break it.

πŸ“‘ Queue

Every other page describes your code. This one describes your queue, right now. It is polled every few seconds while open, never cached, and stops polling when you leave the page or hide the browser tab.

database                         LISTENERS 1   MAIL 1   PUBLISHING 2

Now      Waiting   4    PublishPost      publishing   0/3   6m ago
         Reserved  1    PublishPost      publishing   1/3   taken 6m ago
Next     Delayed   2    PruneComments    maintenance  0/3   in 13m
Past     Failed    2    WeeklyDigest     mail         3/3   4h ago
                        TransportException: Connection refused
         Batches   2    Republish every post   86/120   2 failed   running
  • πŸ”— Every row links to its job class on the Jobs page.
  • 🚦 The database and redis drivers can be listed. SQS, sync, null and a missing jobs table each say why they can't be, instead of showing an empty queue.
  • πŸ”€ An app with several queue connections gets a switcher. Failed jobs are readable even when the queue itself is not.
  • πŸ”’ Counts are always exact. A queue 40,000 deep reports 40,000 and lists the first page.

πŸ•³οΈ Laravel keeps no record of a job that succeeded. It is queued, it runs, it is deleted. So the history here means what failed and what was batched, and an empty history means nothing failed, not that nothing ran. That gap is why Horizon exists.

πŸ”’ Payloads are never unserialised. The queue payload holds a serialised instance of your job. Unserialising it would construct your objects, run their __wakeup, and load every model a SerializesModels job carries. dissect reads only the JSON envelope, and the payload is never put on the page.

🌲 Provider-Trees

The Provider-Trees page reads each of your service providers and draws what it decides: the contracts it binds, what they resolve to, and, following constructor type-hints, what those classes need in turn.

DocumentServiceProvider ── singleton ──▢ TextExtractor ── singleton ──▢ TikaTextExtractor
        β”‚                                                                     β”‚ injects
        β”œβ”€β”€ bind ────────▢ ImageRenderer ── bind ──▢ ImagickRenderer          β–Ό
        β”‚                        β”‚                                      VersionStore
        └── contextual β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”€β”€ contextual Β· when RenderThumbnail ──▢ VipsImageRenderer
  • 🧩 Contracts and the classes they resolve to are separate boxes. What somebody asks for versus what they get is the whole point of a binding.
  • 🎯 when()->needs()->give() is drawn next to the default it overrides, labelled with who is asking.
  • πŸ”— A provider that registers another continues into that provider's bindings.
  • 🏷️ Side effects (events, gates, config, publishes, migrations, routes, views, commands) are counted as badges on the provider, so they don't bury the dependencies.
  • 〰️ Line style says how sure it is: solid for what is written literally, dashed for what a constructor implied, dotted for what couldn't be read.
  • πŸ”Ž Search matches a class anywhere in any tree, so "which provider wires up the transcoder?" is one word. Narrow by domain with the chips.

πŸ•³οΈ What it cannot see

Nothing is booted to find this out, since registering a provider would connect whatever its singletons connect to. So only what is written literally can be named. A binding built in a loop, a class name in a variable, or a binding inside a helper method shows up as a dotted "unresolved" box with the code as written, under a banner saying the tree is not fully analysed. A tree cut short by max_depth or max_nodes says so too.

The walk stops at framework and package code: Illuminate\Filesystem\Filesystem gets a box, but its constructor isn't followed. A contract your provider type-hints but doesn't bind is a leaf, because some other provider decides it.

Only your own providers are listed. The ones in bootstrap/providers.php and those packages register run into the hundreds and are almost all vendor code.

πŸ’» From the terminal

Everything the page shows can be printed without opening it. That's useful for a script, for a CI step, and for handing an agent a map of the app.

php artisan dissect:export                                # every surface, as JSON
php artisan dissect:export routes                         # one surface
php artisan dissect:export classes --format=md            # which class uses which
php artisan dissect:export boundaries --format=md         # where a domain breaks its rule
php artisan dissect:export jobs --format=md               # a digest to read
php artisan dissect:export schema --format=mermaid        # the models as an ER diagram
php artisan dissect:export routes --format=openapi        # the API as an OpenAPI 3.1 document
php artisan dissect:export --format=md --output=docs/app.md
php artisan dissect:check                                 # exit 1 if a domain breaks its rule
php artisan dissect:snapshot                              # write down what the app looks like now
php artisan dissect:diff                                  # what changed since then
  • json is exactly the payload the page reads (see the endpoints under How it works), so anything built on one works on the other.
  • md is a digest of the same payload: one line per model, route, job or binding, with the details people look them up for underneath. It comes out at about a tenth the size of the JSON, which matters when it goes into a prompt. Anything dissect only inferred is marked as inferred, and a long field list ends in +N more instead of stopping silently.
  • mermaid draws the models as an erDiagram, which GitHub, GitLab and most docs sites render as-is. Keys are marked PK, FK and UK, and a relation and its inverse are one line named by both ends (invoices / customer). It's for the schema only.
  • openapi describes the API routes as an OpenAPI 3.1 document. See OpenAPI below. It's for the routes only.
- `POST api/documents` documents.store β†’ DocumentController@store Β· api
  - middleware: api, auth:sanctum
  - request (form-request StoreDocumentRequest): title* string; document_type_id* integer; tags[].name* string
  - response 201 (resource DocumentResource): id; title

πŸ“œ OpenAPI

php artisan dissect:export routes --format=openapi --output=openapi.json

This writes your API as an OpenAPI 3.1 document, read from the same routes, form requests and API resources the Routes page shows. Nothing is annotated by hand, so it can't drift from the code. Commit it and a pull request that changes an endpoint shows the change. Or hand it to Swagger UI, Redoc, Postman, or a client generator.

The workbench's API, exported and opened in Redoc: posts.store with its request body read from StorePostRequest

From the code In the document
Each verb of an api route An operation, with the route name as its summary and operationId.
{post}, {post:slug}, where('id', '[0-9]+') A path parameter, with the constraint as a pattern.
{category?} Two paths, with it and without: OpenAPI has no optional path parameter.
Route::domain('{account}.example.com') The operation's own servers, with account as a variable. The same path on two domains can't be two operations in OpenAPI, so the first keeps it and its description names the other.
A form request or $request->validate() The body (or the query string, for a GET), each field with its type, bounds, in: values and nullable, and its rules as written. A form request becomes a component. A file (file, image, mimes:, File::types()) makes the body multipart/form-data.
An API resource A component, wrapped in data the way Laravel wraps it (or not, after withoutWrapping()). A collection is a list under data.
auth:sanctum, auth, auth.basic A security scheme per guard, of the kind its driver takes, plus a 401.
Validation A 422 in Laravel's {message, errors} shape.
JSON:API (laravel-json-api) application/vnd.api+json documents, and 204 where there's no body.

What the code doesn't say, the document doesn't say either. A resource field's type isn't in the code ('title' => $this->title), so it has none, rather than a guessed one a client would trust. When dissect only inferred a shape, the operation's description says so. When it couldn't work out a response, the operation has a default response that says that instead.

The Routes page offers the same file: OpenAPI in its header saves openapi.json, byte for byte what the command writes.

It passes Redocly's linter with no structural problems. Three of its recommended style rules will still flag it, on purpose:

  • security-defined for an operation with no auth middleware. dissect can't tell a public endpoint from one guarded by middleware it doesn't recognise, so it doesn't claim either.
  • operation-4xx-response for an operation with neither auth nor validation. dissect won't guess a 404 from a route parameter.
  • info-license, since there's no license to read from the code.

Its title, version, description, servers, and which route stacks it covers (api by default) are under openapi in config/dissect.php.

The command works whether or not the page is enabled. It only reads your code, and an Artisan command can't be reached from the web, so it doesn't need the dissect.enabled switch or the viewDissect gate. The queue isn't exported: it's runtime state, and a file of it would be stale before anyone opened it.

πŸ•°οΈ Snapshots

dissect:snapshot writes .dissect/snapshot.json. It holds every model, route, job and provider as it is now, each one under the id the page uses for it, and reduced to what a change to the code can move:

  • Models: table, columns and relations.
  • Routes: name, action, middleware, parameters, request fields and response.
  • Jobs: queue, retries, traits, payload, and what dispatches them.
  • Providers: what each one binds.

Commit it. It's the "before" for reading a change against. When a change is accepted, take a new one, and the snapshot's own diff in the pull request says what was accepted:

     "App\\Models\\Invoice": {
         "table": "invoices",
         "columns": {
+            "refunded_at": {"type": "datetime", "nullable": true, "unique": false, …},

Taking a snapshot twice gives the same bytes, and a run that finds nothing new leaves the file alone. Nothing in it moves unless the code does: there's no timestamp, no absolute path, no line a closure or a dispatch happens to sit on. Each column, field or setting is one line, so the file's diff is one line per changed thing. --output= writes it somewhere else.

A snapshot taken on your laptop is compared in CI, on another machine, so what the machine decides is kept out of the comparison:

  • The database. Each model records the driver its columns were read from. On the same driver the native types are compared, so int to bigint shows. Across two, only each column's kind is (string, integer, datetime, …), so MySQL's bigint unsigned and SQLite's integer are the same column. A model's connection is the one it names, not this machine's default.
  • Columns that couldn't be read. If a model's table isn't there or its connection is down, its columns are left out and not compared, rather than read as every column removed. dissect:snapshot names those models. Run your migrations before taking a snapshot or diffing in CI.
  • Local-only tools. Telescope, Horizon, Pulse, Boost, Debugbar, Ignition and Testbench's workbench register routes on a laptop that CI doesn't have. snapshot_ignore_routes lists the patterns left out: each is matched against a route's controller class, name and URI. Other package routes stay in. An app's JSON:API routes run on the package's controller, and they're its API.

What changed since

dissect:diff reads the app as it is now and compares it with the snapshot. Here it is after an agent added a required slug to the post form, made body required, dropped excerpt from PostResource, and gave SendInvoice a retry count and a new constructor argument:

  breaking ~ route GET api/posts
  breaking     - response field excerpt
  breaking ~ route POST api/posts
  breaking     ~ request field body: now required
  risky        - rule nullable on request field body
  breaking     + request field slug (string, required)
  breaking     - response field excerpt
  …
  risky    ~ job SendInvoice
  risky        + argument reminder (bool)
  risky        ~ tries none β†’ 5

   INFO  6 changes since .dissect/snapshot.json: 5 breaking, 1 risky.

Each change is judged for whoever already depends on the thing changed:

Means For example
breaking Something that worked stops working. A route, column, relation or binding gone; a request field now required; a response field gone; a route renamed, so route('old.name') throws.
risky It may well be fine, but someone should look. A column's type changed; middleware added or taken off; a rule changed; a job's queue, retries or payload changed.
additive Nothing that worked stops. Anything new, or a field no longer required.
  • --format=md writes the same report as Markdown, for a pull request comment or a prompt. --format=json is for a script.
  • --fail-on=breaking exits 1 when there's a breaking change (or risky for risky or worse, any for any change). Without it, a diff is a report and exits 0.
  • --against= compares with another snapshot file, for example one taken on main.

In CI, keep the committed snapshot honest. A pull request that changes an endpoint has to update the snapshot too, so the change shows up in review:

- run: php artisan dissect:diff --fail-on=any

Or let breaking changes through only on purpose:

- run: php artisan dissect:diff --fail-on=breaking --format=md >> "$GITHUB_STEP_SUMMARY"

A snapshot in another format (written by a different dissect version) is refused rather than compared: every item would look changed. Take a new one.

Watching

The committed snapshot answers "what changed since the team last agreed on it". Watching answers "what changed since I sat down", or since you let an agent loose:

php artisan dissect:snapshot --watch       # start watching
php artisan dissect:diff --against=watch   # what changed since

It's a snapshot in storage/dissect/watch.json (watch_path), never committed, so it's yours and not the team's. Starting again restarts the clock.

An agent with the MCP server can ask dissect_changes before it finishes. It compares against watching if you started to, and the committed snapshot otherwise. The server's instructions ask the agent to tell you about anything breaking. The tool only reads, so it can't start watching itself. With nothing to compare against, it says so and tells the agent who can.

On the Changes page

The Changes page after an agent's edit: a model, three routes and a job, each with what changed and how bad it is

The same report, live. Start watching there instead of in the terminal. Restart forgets what changed so far, and Stop goes back to the committed snapshot. Changes arrive as you edit, with no reload, like the rest of the page. Each item can be opened on its own page, except one that was removed. The switch at the top picks the baseline, and the chips hide a severity.

The page can start and stop watching, but it never writes or removes the committed snapshot. That's taken in the terminal, and reviewed in a pull request.

πŸ€– For agents (MCP)

dissect ships an MCP server, so a coding agent can ask about the one model or route it's working on instead of reading the whole app into its context. It's built on the official laravel/mcp package and registered for you as a local server:

php artisan mcp:start dissect

To add it to Claude Code, run this from your project root:

claude mcp add dissect -- php artisan mcp:start dissect

Or commit it for the team in .mcp.json at the project root, which other MCP clients read too:

{
  "mcpServers": {
    "dissect": {
      "command": "php",
      "args": ["artisan", "mcp:start", "dissect"]
    }
  }
}
Tool Answers
dissect_search Where does a name appear? Models, tables, columns, routes, request fields, jobs, classes anywhere in a provider tree, domains.
dissect_model A model's table, columns, relations with their key columns, and who points at it.
dissect_route A route's action, middleware, request fields and response shape, found by name, URI, verb and URI, or controller.
dissect_job A queued class's queue, retries, payload, and every place that dispatches it.
dissect_provider What a provider binds, what that resolves to, and what those classes need.
dissect_domain The domains, or every class in one.
dissect_class What a class uses and what uses it, by kind and line, with crossings between domains marked.
dissect_check Whether the code keeps to the boundary rules, for the files given or the whole app, with every violation and the rule it breaks.
dissect_changes What changed in models, routes, jobs and bindings since the user started watching, or since the committed snapshot, each marked breaking, risky or additive.

Every tool is read-only and answers in the same Markdown as dissect:export --format=md. Called with no name, a tool lists everything in one line each; with a name, short (Invoice) or full, it gives the entry. An exact name beats a partial one.

Each call reads the app fresh through dissect:export, so an answer reflects the code as it is now, not as it was when the agent's session started. (A long-running PHP process can't forget a class it has already loaded, so asking in-process would keep serving a model's old relations after you edit it.) The exporters' caches keep that fast when nothing has changed. .env is read fresh too: an edit to DB_DATABASE or a DISSECT_ setting applies to the next call. Anything set in the server's real environment, such as env in .mcp.json, still wins over the file.

Like the export command, the server is a local process and doesn't depend on dissect.enabled or the viewDissect gate. It's never served over HTTP.

🀝 Files you commit

dissect keeps the things people author in a .dissect/ folder at your project root. It's deliberately not in storage/ (gitignored) or vendor/ (wiped by composer install): these are worth agreeing on once and reviewing in a pull request.

File Written by Holds
.dissect/layout.json the page, when you drag a card Where each model sits on the graph.
.dissect/views.json the page, when you save a view Named subsets of the graph.
.dissect/domains.json you, by hand Domains the folder layout doesn't express, and the boundary rules between them. Never written by dissect.
.dissect/snapshot.json php artisan dissect:snapshot The models, routes, jobs and providers as they were when it was taken.

🧷 Upgrades and your files

composer update can't touch these files. Each one records the format version it was written in, and dissect won't rewrite a file written by a newer version than the one you're running. It reads it, renders what it understands, and refuses the save with a message, instead of replacing your layout with the subset it recognised. So "layout not saved" on a machine with an older dissect is a version mismatch, not a bug.

When a release changes the format, your file is copied to .dissect/layout.json.v1.bak before the first migrating write. An unparseable file is copied to .dissect/layout.json.corrupt.bak (then .corrupt.2.bak and so on) before being replaced, so no broken hand edit is lost.

Format 2 identifies models by full class name (App\Models\Invoice) instead of short name. Older files are upgraded automatically. A short name that two models share stays in a view as both, and loses its position in the layout, since there's no telling which one was dragged there.

βš™οΈ Configuration

Most settings can be changed through environment variables, so you rarely need the published config file.

Variable Default Purpose
DISSECT_ENABLED unset Unset means "on in local only". Set true or false to decide explicitly.
DISSECT_PATH dissect URL prefix the page is served from.
DISSECT_MODELS_PATH app/Models Directory scanned for models. Relative paths resolve from the base path. For several directories, use models.paths.
DISSECT_DOMAINS true false turns domain detection off entirely.

The rest live in config/dissect.php:

General
  • middleware: default ['web']. Add your auth middleware here if you enable the page outside local. The viewDissect gate check is always added after this list.
  • local_hosts: default []. Extra names the page answers to without the gate in local, on top of localhost, *.localhost, *.test, loopback addresses and APP_URL's host. See Security.
  • layout_path: default base_path('.dissect/layout.json').
  • views_path: default base_path('.dissect/views.json').
  • snapshot_path: default base_path('.dissect/snapshot.json'), where dissect:snapshot writes.
  • snapshot_ignore_routes: routes a snapshot leaves out, as patterns matched against the controller class, name and URI (* for anything). It defaults to the tools a laptop runs and CI doesn't, such as Laravel\Telescope\* and Barryvdh\Debugbar\*.
  • watch_path: default storage_path('dissect/watch.json'), where watching keeps its snapshot.
  • openapi: what --format=openapi puts around the operations. title (default: the app's name), version (default 1.0.0), description, servers (URLs or OpenAPI server objects; / by default), and stacks (default ['api']: web routes answer with pages).
Models
  • models.paths: default [], which means "use models_path". A list of directories holding models, where * stands for one directory name.
Domains
  • domains.file: default base_path('.dissect/domains.json'). Domains written down by hand.
  • domains.root: default base_path(). Where folder layouts are looked for.
  • domains.paths: default ['app', 'src', 'Modules', 'app-modules', 'packages']. Where classes are looked for when listing every domain's members. Each domain's own folders are always included.
Routes
  • routes.watch_paths: default ['app', 'routes']. Directories watched to notice the endpoint list has changed. Narrow it to where your HTTP code lives if app/ is large.
Jobs
  • jobs.paths: default ['app/Jobs', 'app/Listeners', 'app/Mail', 'app/Notifications']. Where queueable classes are looked for. Each class name is read from its own file, so an unusual layout just needs its directory added.
  • jobs.watch_paths: default ['app', 'routes']. Where dispatch sites are looked for. This is the widest scan dissect does (every file is parsed), so narrowing it helps most here.
Providers
  • providers.paths: default ['app/Providers']. Any concrete ServiceProvider subclass in here counts.
  • providers.max_depth: default 4. How many constructor hops a tree follows before it stops and says so.
  • providers.max_nodes: default 150. A hard cap per tree, to bound the cost on a large app.
  • providers.watch_paths: default ['app']. Wider than providers.paths on purpose: a tree changes when any constructor down it does.
Queue
  • queue.rows: default 50. How many jobs each section lists. Counts are always exact.
  • queue.poll_interval: default 5000 (ms). How often the Queue page re-reads while it is open.

πŸ” Security: what keeps this off production

It's easy to assume more protection than there is, so here's exactly how it works. The service provider is auto-discovered and boots on every request in every environment where the package is installed. One check decides whether the routes register:

config('dissect.enabled') === null
    ? app()->environment('local')   // the default
    : (bool) config('dissect.enabled');

So the switch is APP_ENV, and two things have to hold that dissect can't enforce:

  1. Production deploys with composer install --no-dev, so a --dev install isn't there at all.
  2. APP_ENV isn't local there, and nobody left DISSECT_ENABLED=true on after debugging.

Break either (a staging box left at APP_ENV=local, a deploy that installs dev dependencies) and the routes are live. That's why registering them isn't the same as letting anybody in.

In local, only your machine's own names skip the gate: localhost, *.localhost, *.test, loopback addresses (127.x, [::1]) and the host in APP_URL. A request for any other name goes to the viewDissect gate like everywhere else. That also covers DNS rebinding, where a page on some other site points its own name at 127.0.0.1 to read dissect from your browser: the browser reaches your server, but the request still carries the other site's name. To open the page from a phone or another machine, list the name or address it uses:

'local_hosts' => ['192.168.1.20'],

Outside local, every dissect route checks the viewDissect gate, the way Telescope checks viewTelescope. No gate defined means a 403. The check is added after your middleware list, so editing that list can't remove it. To use dissect on staging, enable it and say who may see it, for example in AppServiceProvider::boot():

use Illuminate\Support\Facades\Gate;

Gate::define('viewDissect', fn ($user) => in_array($user->email, [
    'you@example.com',
]));

Give the closure a nullable user (fn (?User $user = null) => …) if the box is already behind a VPN or basic auth and guests should get in.

Anyone who passes the gate sees:

  • your full schema, every route, every validation rule, every job, every provider and every domain;
  • what is on your queues right now: which jobs, on which queue, with their attempts and timings (never their arguments);
  • failed jobs, including the first line of each exception. SQL is cut out of database errors, but other exception messages are shown as written, and apps do put user data in those;
  • two POST endpoints that write .dissect/layout.json and .dissect/views.json into your project root.

πŸ” How it works

  • Read, never run. Models come from Laravel's ModelInspector, routes from the router, and everything else (request and response shapes, dispatch sites, queue names, provider bindings, #[Domain] attributes) is parsed from your source with nikic/php-parser or read by reflection. No job is constructed, no provider is booted, no container binding is resolved.
  • Cached against fingerprints. Each surface caches its result against a fingerprint of the files it depends on, so the expensive work runs once per change, not once per request. Editing .dissect/domains.json invalidates the surfaces that carry a domain.
  • Fast first paint. The schema, layout and views are inlined into the initial HTML, so the page makes no requests on boot. Routes, jobs, providers and domains are fetched the first time you open their page.
  • Live by polling. The page polls those fingerprints, so editing a model, a controller, a dispatch or a constructor refreshes the right page without a file watcher.
  • The queue is the exception. It's runtime state, not source, so it's never cached and is polled only while its page is open.
  • Assets are served from the package's dist/ by a route with an allow-list, so there's nothing to publish or re-publish after an upgrade.

Every page is backed by a JSON endpoint under your DISSECT_PATH, and every one but the queue can also be printed with dissect:export:

Endpoint Contents
/dissect/schema.json Models, columns and relations.
/dissect/routes.json Endpoints with request and response shapes.
/dissect/jobs.json Queueables, their queues and dispatch sites.
/dissect/providers.json Provider trees.
/dissect/domains.json Domains, their classes, findings and unassigned classes.
/dissect/classes.json Every class and the app classes it uses.
/dissect/boundaries.json The boundary rules, what's wrong with them, and every violation.
/dissect/queue.json The live queue.

See ARCHITECTURE.md for the full design and every payload format.

πŸ—ΊοΈ Roadmap

  • 🧭 Domain map. Domains as nodes and the dependencies between them as edges. In progress.
  • βœ… Contract compliance: checking that endpoints return what they promise.

πŸ› οΈ Contributing

The package is developed against Orchestra Testbench, with a Workbench application in workbench/.

composer install
pnpm install

composer serve      # build the workbench app and serve it
composer test       # PHPUnit
pnpm test:unit      # Vitest
pnpm test:e2e       # Playwright
pnpm build          # type-check and compile the frontend into dist/
pnpm lint           # oxlint + eslint

πŸ§ͺ Fixtures

  • workbench/app is small on purpose. It covers every relation family and column kind, a form request whose rules() can't run, a resource with no model behind it, a closure route and an invokable controller. The tests assert against it. It has no domains, to prove an app without them is left alone.

  • workbench/domains is a second app that does have domains: Billing and Sales under app/Domain, an Identity domain built from a domains.json entry and a #[Domain] attribute, a stale attribute that disagrees with its folder, and a class no domain claims.

    touch .workbench-domains   # serve the domain fixture instead
    composer serve
    rm .workbench-domains      # back to the plain app
  • composer serve:huge generates a 122-model schema, to see what layout, the minimap and saved views do under load. composer huge:clean removes it.

⚑ Frontend hot reload

Run composer serve:hmr in one terminal and pnpm dev in another. You get the real Laravel host with the frontend served from Vite, so frontend edits hot-reload while the PHP side stays real.

🏷️ Releasing

dist/ is committed on purpose. It's the compiled bundle the Composer package serves, and the whole promise is one composer require with no build step in your app. So every release must rebuild it:

pnpm build
git add dist && git commit -m "build: dist for vX.Y.Z"
git tag vX.Y.Z && git push --tags

⚠️ A tag that ships a stale dist/ ships a stale UI to everyone who installs it.

πŸ“„ License

MIT. See LICENSE.