In-app SQL DevTools HUD, automatic N+1 burst detector, and interactive EXPLAIN plan inspector for React and Node.js.
Powered by @culpritsql/plans WebAssembly and @culpritsql/plan-viewer.
Quickstart · Integrations · React HUD · Server Collector · API
- Floating SQL HUD (
⚡ SQL · 12 · 1 N+1): Live query counter with green/amber/coral health dot and docked drawer (Queries·N+1 Bursts·Plan Inspector). - Automatic N+1 burst detection: Canonical SQL fingerprinting strips comments, literals,
$1/?/:param, andIN (?, ?, ...)lists to group repeated queries per HTTP request and suggestJOINorWHERE id = ANY($1)batching fixes. - Request correlation (
AsyncLocalStorage): Tags every SQL query executed inside a route handler with its HTTP route badge (GET /api/orders). - Zero-dependency driver &
diagnostics_channelhooks: Native support for Reylo (reylo:query),pg,mysql2,better-sqlite3/node:sqlite, Prisma, and Drizzle. - Safe auto-
EXPLAIN+ instant paste: Runs read-onlyEXPLAINon slow single-statementSELECTqueries via@culpritsql/plansWasm, or paste any PostgreSQL, MySQL, MariaDB, SQLite, YugabyteDB, or SQL Server.sqlplanoutput directly inside the drawer. - Strict CSS & bundler isolation: Scoped to
.culprit-dt(never mutates hostbodyor<button>styles), and Node builtins live strictly behind@culpritsql/devtools/server.
npm install @culpritsql/devtools// lib/devtools.ts (Node.js server)
import { Pool } from "pg";
import {
CulpritCollector,
createDevtoolsHandler,
instrumentPg,
} from "@culpritsql/devtools/server";
export const sqlCollector = new CulpritCollector({
slowThresholdMs: 20,
nPlusOneThreshold: 5,
});
// Optional: capture Reylo, pg, and mysql2 diagnostics_channel events automatically
sqlCollector.subscribeDiagnosticsChannels();
export const pool = instrumentPg(new Pool({ connectionString: process.env.DATABASE_URL }), {
collector: sqlCollector,
autoExplain: true,
});
export const devtoolsHandler = createDevtoolsHandler(sqlCollector);// app/layout.tsx or src/App.tsx
import { CulpritDevtools } from "@culpritsql/devtools/react";
import "@culpritsql/devtools/styles.css";
export function DevOverlay() {
if (process.env.NODE_ENV === "production") return null;
return <CulpritDevtools endpoint="/__culprit" position="bottom-right" theme="dark" />;
}Run the zero-Docker SQLite + React 19 + WebAssembly playground in demo/ to trigger live N+1 query bursts, compare batched fixes, emit reylo:query diagnostics_channel telemetry, and inspect interactive EXPLAIN flow graphs:
git clone https://github.com/culpritsql/culprit-devtools.git
cd culprit-devtools && bun install && bun run demo
# Open http://127.0.0.1:4321Reylo emits structured query telemetry on reylo:query. Subscribe once at startup to capture timings, row counts, parameters, and request correlation with zero wrapper code:
import { CulpritCollector } from "@culpritsql/devtools/server";
export const collector = new CulpritCollector();
collector.subscribeDiagnosticsChannels(["reylo:query"]);// app/api/__culprit/[...slug]/route.ts
import { createDevtoolsHandler } from "@culpritsql/devtools/server";
import { sqlCollector } from "@/lib/devtools";
const handler = createDevtoolsHandler(sqlCollector, { basePath: "/api/__culprit" });
export const GET = handler;
export const POST = handler;Wrap Route Handlers or Server Actions with sqlCollector.withRequest("GET /api/orders", () => ...) and point <CulpritDevtools endpoint="/api/__culprit" /> at the route.
import { Hono } from "hono";
import { CulpritCollector, createDevtoolsHandler } from "@culpritsql/devtools/server";
const collector = new CulpritCollector();
const devtools = createDevtoolsHandler(collector);
const app = new Hono();
app.all("/__culprit/*", (c) => devtools(c.req.raw));
app.use("*", (c, next) => collector.withRequest(`${c.req.method} ${c.req.path}`, next));createNodeDevtoolsMiddleware serves /__culprit/* and automatically wraps downstream Express routes in collector.withRequest("METHOD /path", ...):
import express from "express";
import { CulpritCollector, createNodeDevtoolsMiddleware } from "@culpritsql/devtools/server";
const app = express();
const collector = new CulpritCollector();
app.use(createNodeDevtoolsMiddleware(collector));import {
instrumentPg,
instrumentMysql,
instrumentSqlite,
} from "@culpritsql/devtools/server";
const pgPool = instrumentPg(rawPgPool, { autoExplain: true });
const mysqlPool = instrumentMysql(rawMysqlPool, { autoExplain: true });
const sqliteDb = instrumentSqlite(rawBetterSqlite3Db, { autoExplain: true });import { drizzle } from "drizzle-orm/node-postgres";
import { sqlCollector, pool } from "./devtools";
// Passing an instrumented pg pool captures exact execution timings + auto-EXPLAIN:
export const db = drizzle(pool);
// Or attach a lightweight Drizzle logger directly:
export const loggedDb = drizzle(rawPool, {
logger: sqlCollector.createDrizzleLogger("postgres"),
});
// Prisma client query event hook:
prisma.$on("query", (event) => {
sqlCollector.recordQuery({
sql: event.query,
durationMs: event.duration,
params: event.params,
engine: "postgres",
});
});<CulpritDevtools /> works with live polling (endpoint="/__culprit"), SSR (initialSnapshot), or completely offline in Storybook and tests (snapshot={...}).
| Prop | Type | Default | Description |
|---|---|---|---|
endpoint |
string |
"/__culprit" |
Base URL for /snapshot, /clear, and /parse |
snapshot |
DevtoolsSnapshot |
undefined |
Controlled snapshot (disables background polling) |
initialSnapshot |
DevtoolsSnapshot |
undefined |
Initial data for SSR and first client paint |
pollIntervalMs |
number |
1500 |
Polling cadence in ms (<= 0 disables polling) |
position |
"bottom-right" | "bottom-left" | "top-right" | "top-left" |
"bottom-right" |
Corner placement for the floating trigger pill |
theme |
"dark" | "light" | "system" |
"dark" |
Theme applied to the drawer and <PlanViewer /> |
defaultOpen |
boolean |
false |
Render with the drawer open initially |
defaultTab |
"queries" | "bursts" | "plan" |
"queries" |
Initial drawer tab |
- Disabled in production by default:
CulpritCollectorbecomes a zero-allocation no-op whenNODE_ENV === "production", andcreateDevtoolsHandlerreturns403 ForbiddenunlessallowProduction: trueis explicitly configured. - Loopback-only guard:
createDevtoolsHandlerandcreateNodeDevtoolsMiddlewarereject non-loopbackHost,X-Forwarded-For, and socket addresses (403 Forbidden) unlessallowRemote: trueis passed. - Read-only
autoExplainguard: Auto-EXPLAINruns strictly on single-statementSELECT/WITH ... SELECTqueries containing zero data-modifying keywords, tagged with/* culprit */so explain queries never recurse.
| Import Path | Environment | Exports |
|---|---|---|
@culpritsql/devtools |
Browser / SSR / Universal | CulpritDevtools, normalizeSqlForFingerprint, fingerprintSql, detectNPlusOneAdvice, shared types |
@culpritsql/devtools/react |
Browser / SSR | CulpritDevtools and React prop types |
@culpritsql/devtools/server |
Node.js / Bun (>=20) |
CulpritCollector, createDevtoolsHandler, createNodeDevtoolsMiddleware, instrumentPg, instrumentMysql, instrumentSqlite, parseExplainText |
@culpritsql/devtools/styles.css |
CSS | Scoped .culprit-dt + @culpritsql/plan-viewer styles |
MIT