PHPackages                             refactorlab/ai-code-reviewer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. refactorlab/ai-code-reviewer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

refactorlab/ai-code-reviewer
============================

AI-powered code review tool for Laravel, integrated with GitHub and OpenAI.

v1.0.0(1y ago)15MITPHPPHP ^8.2

Since Apr 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/charoyan88/refactorlab-ai-code-reviewer)[ Packagist](https://packagist.org/packages/refactorlab/ai-code-reviewer)[ Fund](https://refactorlab.dev/sponsor)[ GitHub Sponsors](https://github.com/refactorlab)[ RSS](/packages/refactorlab-ai-code-reviewer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

AI Code Reviewer v1.0.0
=======================

[](#ai-code-reviewer-v100)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c061507110947849d22612a941737cd35b67b71bec494e5ce4a51dbce1dc930e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7265666163746f726c61622f61692d636f64652d72657669657765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/refactorlab/ai-code-reviewer)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a33922f540837325dea572448435059550a001bbda8cbc899a971bdeda51402c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f636861726f79616e38382f7265666163746f726c61622d61692d636f64652d72657669657765722f74657374733f6c6162656c3d7465737473)](https://github.com/charoyan88/refactorlab-ai-code-reviewer/actions?query=workflow%3Atests+branch%3Amain)[![License](https://camo.githubusercontent.com/7c5464fdf38848ae7109ae927a24913da5c6bc01dfae69a6b1e8c9eb7227e369/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636861726f79616e38382f7265666163746f726c61622d61692d636f64652d72657669657765723f7374796c653d666c61742d737175617265)](LICENSE.md)

Introduction
------------

[](#introduction)

AI Code Reviewer is a powerful Laravel package that automatically analyzes GitHub pull requests using OpenAI's GPT-4. It helps improve code quality by identifying potential issues, bugs, and suggesting improvements - all without manual intervention.

The package listens for GitHub webhook events when pull requests are opened or updated, extracts the code changes, sends them to OpenAI for analysis, and then posts the AI-generated review comments directly back to the pull request on GitHub.

This intelligent code review assistant saves developer time, helps maintain coding standards, and can catch issues that might be missed during human review.

Features
--------

[](#features)

- 🤖 Listens to GitHub pull request webhooks
- 🔍 Sends code diffs to OpenAI for analysis
- 💬 Posts AI-generated review comments back to the pull request
- ⚙️ Configurable file filters and settings
- 🔒 Secure webhook handling with signature verification
- 🔄 Batch processing for large pull requests
- 🧠 Customizable AI prompts and response handling
- 🛠️ Extensive configuration options

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require refactorlab/ai-code-reviewer:^1.0
```

The package will automatically register its service provider with Laravel's auto-discovery.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=aicode-config
```

This will create a `config/aicode.php` file where you can configure the package.

### Required Environment Variables

[](#required-environment-variables)

Add the following to your `.env` file:

```
OPENAI_API_KEY=your-openai-api-key
GITHUB_API_TOKEN=your-github-token-with-repo-access
GITHUB_WEBHOOK_SECRET=your-webhook-secret

```

- `OPENAI_API_KEY`: Your OpenAI API key (requires access to GPT-4)
- `GITHUB_API_TOKEN`: A GitHub personal access token with `repo` scope
- `GITHUB_WEBHOOK_SECRET`: A secret string to verify webhook requests

Detailed Configuration
----------------------

[](#detailed-configuration)

The `config/aicode.php` file contains the following sections:

### OpenAI Configuration

[](#openai-configuration)

```
'openai' => [
    'api_key' => env('OPENAI_API_KEY'),
    'model' => env('OPENAI_MODEL', 'gpt-4-turbo'),
    'temperature' => env('OPENAI_TEMPERATURE', 0.1),
    'max_tokens' => env('OPENAI_MAX_TOKENS', 4000),
],
```

- `model`: The OpenAI model to use (default: gpt-4-turbo)
- `temperature`: Controls randomness (0-1, lower = more deterministic)
- `max_tokens`: Maximum token limit for responses

### GitHub Configuration

[](#github-configuration)

```
'github' => [
    'token' => env('GITHUB_API_TOKEN'),
    'webhook_secret' => env('GITHUB_WEBHOOK_SECRET'),
],
```

### File Filters

[](#file-filters)

```
'file_filters' => [
    'include' => [
        '*.php',
        '*.js',
        // etc.
    ],
    'exclude' => [
        'vendor/*',
        'node_modules/*',
        // etc.
    ],
],
```

### Review Settings

[](#review-settings)

```
'settings' => [
    'max_files_per_review' => env('MAX_FILES_PER_REVIEW', 10),
    'max_diff_size' => env('MAX_DIFF_SIZE', 5000),
    'comment_threshold' => env('COMMENT_THRESHOLD', 0.7),
    'batch_processing' => env('BATCH_PROCESSING', true),
],
```

Usage
-----

[](#usage)

### Setting up the GitHub Webhook

[](#setting-up-the-github-webhook)

1. Go to your GitHub repository's settings
2. Click on "Webhooks" → "Add webhook"
3. Set the Payload URL to: ```
    https://your-app.com/github/webhook

    ```
4. Select content type: `application/json`
5. Enter your webhook secret (same as `GITHUB_WEBHOOK_SECRET`)
6. Under "Which events would you like to trigger this webhook?", select "Pull requests"
7. Ensure "Active" is checked and click "Add webhook"

Once set up, the AI Code Reviewer will automatically analyze new pull requests and post its review as comments.

### Example GitHub PR Comments

[](#example-github-pr-comments)

When the AI Code Reviewer analyzes a pull request, it will post comments like these:

#### Example 1: Bug Detection

[](#example-1-bug-detection)

```
**High**: Potential null reference exception in UserController.php on line 42.

The `$user` variable might be null if the user is not found, but it's being accessed without a null check.

**Suggestion**: Add a null check before accessing properties:
```php
if ($user !== null) {
    $user->update($request->validated());
}

```

```

#### Example 2: Code Improvement

```

**Medium**: Inefficient database query in ProductService.php on line 78.

The current implementation runs a separate query for each product, which could lead to N+1 query issues.

**Suggestion**: Use eager loading with the `with()` method:

```
return Product::with('category', 'tags')->get();
```

```

#### Example 3: Security Issue

```

**High**: SQL Injection vulnerability in ReportController.php on line 126.

Raw user input is being directly used in a database query.

**Suggestion**: Use query bindings instead:

```
DB::select("SELECT * FROM reports WHERE status = ?", [$request->status]);
```

```

## Testing

```bash
composer test

```

Security
--------

[](#security)

If you discover any security issues, please contact the author directly instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance46

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

407d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c405bf8873d5cadea280f07393768cbab2a8d0c985bdf652a838231cefb35e1?d=identicon)[charoyan88](/maintainers/charoyan88)

---

Top Contributors

[![charoyan88](https://avatars.githubusercontent.com/u/12574159?v=4)](https://github.com/charoyan88 "charoyan88 (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/refactorlab-ai-code-reviewer/health.svg)

```
[![Health](https://phpackages.com/badges/refactorlab-ai-code-reviewer/health.svg)](https://phpackages.com/packages/refactorlab-ai-code-reviewer)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[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)
