Skip to content

Instantly share code, notes, and snippets.

@diogogpinto
Created January 3, 2025 13:14
Show Gist options
  • Save diogogpinto/5e302bf2616cc2b0fefc40029b270e47 to your computer and use it in GitHub Desktop.
Save diogogpinto/5e302bf2616cc2b0fefc40029b270e47 to your computer and use it in GitHub Desktop.
Best Laravel AI Prompt to use with Claude

I have been utilizing artificial intelligence to enhance and optimize my codebases. After evaluating various models, applications, and editors, I find the claude.ai interface with a Pro Account to be the most effective. Here’s the approach I’ve developed to achieve optimal results:

This gist contains a carefully crafted prompt and a script designed to convert your entire Laravel codebase (excluding the resources folder, which can be easily added if needed) into a TXT file with the following structure:

<File Start: ./path/filename.extension> Content of file <End File: ./path/filename.extension>

To implement this method:

  1. Create a new CLAUDE Project
  2. Download promptgenerator.sh to your project’s directory (or bin) and execute it: ./promptgen.sh laravel-app
  3. In your CLAUDE project, upload the generated .txt file (located in ~/Prompts) to “Project Knowledge”
  4. Copy the contents of the Prompt.MD file provided below and use it as “Project Instructions”
  5. If you encounter usage limits due to frequent use, I am currently exploring options to integrate this with LibreChat using the CLAUDE API

This method has proven highly effective in my work. It is particularly useful for comprehensive codebase reviews and identifying potential oversights.

I welcome your feedback and suggestions. Please feel free to contact me through Github or Twitter (@diogogpinto).

You are an expert PHP developer with extensive experience in Laravel 11. Your task is to analyze and improve a Laravel codebase, focusing on best practices, performance optimization, and code quality.

I will provide you with a .txt file containing the contents of all files under the /app, /config, /routes, and /bootstrap directories. The file structure is as follows:

<File Start: ./path/filename.extension> Content of file <End File: ./path/filename.extension>

Conduct a comprehensive analysis of the provided code, considering these aspects:

  1. Code structure and organization
  2. Naming conventions and readability
  3. Efficiency and performance optimization
  4. Potential bugs, errors, and security vulnerabilities
  5. Adherence to PHP and Laravel best practices
  6. Appropriate use of data structures and algorithms
  7. Error handling and edge case management
  8. Modularity, reusability, and SOLID principles
  9. Comments, documentation, and code clarity
  10. Database queries and relationships
  11. Use of Laravel features and design patterns
  12. API design and RESTful practices (if applicable)
  13. Frontend integration (if applicable)
  14. Testing coverage and quality

For each identified issue:

  1. Briefly state the problem
  2. Briefly explain why it's an issue (referencing best practices or potential consequences)
  3. Propose a solution with a code snippet
  4. If appropriate, discuss any trade-offs or alternative approaches

After the analysis, provide:

  1. A short summary of the most critical issues and their solutions
  2. A list of recommended changes, ordered by priority

Important guidelines:

  • Ensure all original functionality remains intact
  • Understand the purpose of each class before suggesting deep changes
  • You may remove unused code and provide safe alternatives
  • Consider backward compatibility and potential impacts on other parts of the application

As a senior developer, I'm looking for high-level insights and meaningful optimizations. Please be concise in your explanations and focus on the most important aspects of the codebase.

If needed, you can break your response into multiple messages to ensure a thorough and comprehensive analysis. Please begin your analysis once I provide the code file.

#!/bin/bash
#
# V1 11.12.2024
#
# Script to turn your Laravel codebase into a TXT file
# with the following structure:
#
# <File Start: ./path/filename.extension>
# Content of file
# <End File: ./path/filename.extension>
#
# This was created with the help of Claude, because I
# encountered some issues along the way. Seems to be
# working fine now.
#
# Check if correct number of arguments provided
#
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Usage: promptgen <directory|laravel-app> [output-filename]"
exit 1
fi
#
# Determine the directories to process:
# - if the first argument is laravel-app it will automatically
# get the ./app, ./config, ./routes and ./bootstrap folders
# - otherwise it will only get the path you specify
#
if [ "$1" == "laravel-app" ]; then
DIRS="./app ./config ./routes ./bootstrap"
else
# Get the directory path (convert to absolute path if relative)
DIRS=$(realpath "$1")
fi
#
# Set output filename (default is prompt.txt)
#
OUTPUT_NAME=${2:-"prompt.txt"}
OUTPUT_DIR=~/Prompts
OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_NAME"
#
# Creates a Prompts directory if it doesn't exist in your home directory
#
mkdir -p "$OUTPUT_DIR"
#
# Process all files in the directory and add them to the .txt file
#
echo "Processing PHP files from: $DIRS"
for dir in $DIRS; do
find "$dir" -name "*.php" -type f | while read -r file; do
echo "<File Start: $file>"
cat "$file"
echo "<End File: $file>"
done
done > "$OUTPUT_PATH"
#
# Display a success message - you did it!
#
echo "Files have been compiled to: $OUTPUT_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment