sarfraznawaz2005/aiqueryoptimizer

A Laravel development tool that leverages the intelligence of AI to analyze and optimize your application's SQL queries. This package provides real-time, actionable feedback directly in your browser, helping you identify performance bottlenecks and improve your database efficiency.
SELECT queries with the click of a button.You can install the package via Composer:
composer require sarfraznawaz2005/aiqueryoptimizer --dev
Next, publish the configuration and assets using the vendor:publish command. This will create the config/ai-query-optimizer.php file and publish the necessary CSS/JS assets to your public directory.
php artisan vendor:publish --provider="AIQueryOptimizer\AIQueryOptimizerServiceProvider"
After publishing, open config/ai-query-optimizer.php to configure the package.
By default, the package is enabled. You can disable it by setting the enabled option to false or by using the AI_QUERY_OPTIMIZER_ENABLED environment variable.
'enabled' => env('AI_QUERY_OPTIMIZER_ENABLED', true),
To prevent the package from running in a production environment, it is restricted to specific environments. By default, it only runs in local, development, and staging.
'allowed_environments' => ['local', 'development', 'staging'],
The package supports both Gemini and OpenAI. You need to configure your chosen provider with the appropriate API key and model.
Update your .env file, example with Gemini:
AI_QUERY_OPTIMIZER_ENABLED=true
AI_PROVIDER=gemini
GEMINI_API_KEY=your_gemini_api_key
GEMINI_MODEL="gemini-2.5-flash"
Caching is enabled by default to reduce API costs. The analysis for each unique query will be cached for a day. You can disable it or change the duration.
'cache' => [
'enabled' => true,
'duration_in_minutes' => 60 * 24, // Cache for one day
],
Once installed and configured, the package works automatically in your specified environments.
SELECT queries in the background.The package hooks into Laravel's query execution event to collect all SELECT queries. It then injects a small UI component into your application's frontend. When you trigger the analysis, it sends the queries, along with your database table and index metadata, to the AI. The AI, acting as a database expert, returns detailed suggestions which are then displayed in a user-friendly format.
This is a development tool and should not be used in a production environment. Always ensure your API keys are stored securely in your .env file and are not committed to version control.
Please see the license file for more information.
How can I help you explore Laravel packages today?