abdur-rahaman / laravel-ai-review
AI-powered Laravel code review package — detect bugs, security vulnerabilities, suggest refactoring, generate PHPUnit tests, and review GitHub pull requests.
Package info
github.com/abdurrahamanbabu/laravel-ai-review
pkg:composer/abdur-rahaman/laravel-ai-review
Requires
- php: ^8.1|^8.2|^8.3|^8.4
- guzzlehttp/guzzle: ^7.5
- illuminate/console: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
- openai-php/client: ^0.8|^0.10
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^9.5|^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
AI-powered code review for Laravel applications
abdur-rahaman/laravel-ai-review analyzes your Laravel code with modern LLMs (OpenAI, Azure OpenAI, Anthropic Claude, or local Ollama models). It detects bugs, security vulnerabilities, performance issues, suggests refactorings, generates PHPUnit/Pest tests, and can automatically review GitHub pull requests.
Features
| Feature | Description |
|---|---|
| Code Analysis | Deep review of PHP/Laravel code for bugs, logic errors, and style issues |
| Security Scanning | Detects mass assignment, SQL injection, XSS, hardcoded secrets, missing auth, etc. |
| Refactoring Suggestions | SOLID, clean code, and Laravel-idiomatic improvements |
| Test Generation | Auto-generate PHPUnit or Pest tests for any class |
| GitHub PR Reviews | Comment on pull requests with AI findings (CLI + webhook) |
| Multi-provider | OpenAI, Azure OpenAI, Anthropic, Ollama |
| Artisan Commands | Simple CLI interface |
| Facade API | Use AiReview::analyze() anywhere in your app |
Requirements
- PHP 8.1+
- Laravel 9, 10, 11, 12, or 13
- An API key for at least one supported AI provider
Installation
composer require abdur-rahaman/laravel-ai-review
Publish the config:
php artisan vendor:publish --tag=ai-review-config
Add your API key to .env:
# Required for OpenAI (default) OPENAI_API_KEY=sk-... # Optional overrides AI_REVIEW_PROVIDER=openai # openai | azure | anthropic | ollama AI_REVIEW_MODEL=gpt-4o AI_REVIEW_MAX_TOKENS=4096 AI_REVIEW_TEMPERATURE=0.2 # GitHub integration (for PR reviews) GITHUB_TOKEN=ghp_... GITHUB_WEBHOOK_SECRET=your-webhook-secret
Usage
1. Analyze a single file
php artisan ai-review:analyze app/Models/User.php php artisan ai-review:analyze app/Http/Controllers/PostController.php --format=markdown --save
2. Scan a directory / whole app
php artisan ai-review:scan php artisan ai-review:scan app/Http/Controllers --save php artisan ai-review:scan app --exclude=vendor --exclude=storage
3. Generate tests
php artisan ai-review:generate-tests app/Services/OrderService.php php artisan ai-review:generate-tests app/Models/User.php --framework=pest --save
4. Review a GitHub Pull Request
php artisan ai-review:review-pr your-org your-repo 42 php artisan ai-review:review-pr your-org your-repo 42 --comment php artisan ai-review:review-pr your-org your-repo 42 --request-changes
5. GitHub Webhook (automatic PR reviews)
- In your GitHub repository go to Settings → Webhooks → Add webhook
- Payload URL:
https://your-app.com/ai-review/webhook/github - Content type:
application/json - Secret: the value of
GITHUB_WEBHOOK_SECRET - Events: select Pull requests
The package will automatically analyze opened/updated PRs and post a review comment.
Programmatic API
use AbdurRahaman\LaravelAiReview\Facades\AiReview; use AbdurRahaman\LaravelAiReview\Services\CodeAnalyzer; use AbdurRahaman\LaravelAiReview\Services\TestGenerator; // Via Facade $result = AiReview::analyze(file_get_contents('app/Models/User.php'), 'User.php'); $result = AiReview::analyzeFile(app_path('Models/User.php')); $scan = AiReview::scan(app_path()); // Via dependency injection public function __construct( private CodeAnalyzer $analyzer, private TestGenerator $tests, ) {} public function review() { $analysis = $this->analyzer->analyzeFile(app_path('Http/Controllers/OrderController.php')); // $analysis structure: // [ // 'summary' => '...', // 'score' => 78, // 'issues' => [ ['type' => 'bug', 'severity' => 'high', ...], ... ], // 'refactoring' => [ ... ], // 'security' => [ ... ], // ] $generated = $this->tests->generateForFile(app_path('Services/PaymentService.php'), 'pest'); }
Configuration
See config/ai-review.php for all options. Key sections:
- provider – which AI backend to use
- analysis – max tokens, file size limits, excluded directories, severity filters
- github – token, webhook secret, auto-comment behaviour
- prompts – fully customizable system & user prompts
Output Formats
| Format | Flag | Description |
|---|---|---|
| console | --format=console |
Colored terminal output (default) |
| markdown | --format=markdown |
GitHub-flavored Markdown |
| json | --format=json |
Machine-readable JSON |
| html | --format=html |
Standalone HTML report |
Reports can be saved under storage/app/ai-reviews/ with --save.
Supported AI Providers
| Provider | Env vars | Notes |
|---|---|---|
| OpenAI | OPENAI_API_KEY, AI_REVIEW_MODEL |
Default, best quality |
| Azure | AZURE_OPENAI_* |
Enterprise deployments |
| Anthropic | ANTHROPIC_API_KEY |
Claude 3.5 Sonnet recommended |
| Ollama | OLLAMA_BASE_URL, AI_REVIEW_OLLAMA_MODEL |
Fully local / offline |
Testing the Package
composer test
Security
If you discover any security-related issues in the package itself, please email the maintainer. Never commit real API keys or GitHub tokens.
License
The MIT License (MIT). See LICENSE for details.
Credits
- Abdur Rahaman
- Built with ❤️ for the Laravel community