Skip to content

SrDev93/laravel-guardian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛡️ Laravel Guardian

Laravel Guardian is an all-in-one package for enhancing the security and performance of Laravel applications.
This package automatically scans your application for security and performance issues, generates reports, and even resolves some issues automatically.


🚀 Features

🔒 Security Module

  • Checks the permissions of sensitive files and directories (.env, storage, bootstrap/cache)
  • Detects insecure file permissions (e.g., 777, 775)
  • Scans for dangerous files like phpinfo.php, .git, composer.lock
  • Validates CSRF protection, APP_KEY, and Debug Mode settings
  • Option to automatically remove unsafe files with artisan commands

⚡ Performance Module

  • Analyzes slow database queries from logs
  • Detects large or inefficient Blade views (e.g., excessive loops or includes)
  • Recommends enabling caching where appropriate
  • Checks for the usage of eager loading in models
  • Provides an automatic optimization command:
    php artisan guardian:optimize

📊 Monitoring & Notification Module

  • Monitors Laravel logs for new errors and sends alerts (via Telegram, Email, etc.)
  • Saves logs in storage/logs/guardian.log
  • Sends alerts about detected issues in real-time
  • Supports sending alerts via Telegram and Email
  • Can be run continuously with guardian:watch command to monitor logs and notify in real-time

🧩 Installation

Install the package via Composer:

composer require srdev93/laravel-guardian

To publish the configuration file:

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

⚙️ Configuration

Once installed, the configuration file will be available at:

config/guardian.php

Example config:

return [
    'check_security' => true,
    'check_performance' => true,
    'auto_fix' => false,
    'telegram_bot_token' => env('GUARDIAN_TELEGRAM_BOT_TOKEN', null),
    'telegram_chat_id' => env('GUARDIAN_TELEGRAM_CHAT_ID', null),
];

You can enable or disable different modules based on your needs (e.g., security, performance).


🧠 Artisan Commands

Command Description
php artisan guardian:scan-security Scan for security and performance issues in the application.
php artisan guardian:optimize Automatically optimize the application by clearing caches, optimizing routes, views, and configs.
php artisan guardian:report Generate a report of security and performance status in either JSON or HTML format.
php artisan guardian:watch Continuously monitor Laravel logs for new errors and send notifications.

📄 Example Report Output

After running the guardian:report command, the generated report will show results similar to this:

Guardian Report
========================
✅ Secure: No issues found.
⚠️ Performance: 3 potential slow queries detected.

In HTML format, it will look like this:

<h1>Guardian Report</h1>
<h2>Security</h2>
<ul>
  <li>No issues found.</li>
</ul>
<h2>Performance</h2>
<ul>
  <li>3 slow queries detected (>200ms)</li>
</ul>

🛠 Future Development

  • Web dashboard to view security and performance reports
  • Integration with Reverb for live monitoring and real-time alerts
  • Support for email notifications
  • Periodic report generation (daily, weekly)

🤝 Contributing

We welcome contributions! If you have ideas for enhancing Laravel Guardian, feel free to submit a Pull Request or open an Issue.


🪪 License

This package is open-sourced software licensed under the MIT license.


Developed with ❤️ by SrDev93

About

Laravel Guardian - Security & Performance Suite for Laravel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages