Laravel React Starter Kit

repository·main·Indexed 21 days ago

https://github.com/laravel/react-starter-kit

A starter kit for building full-stack applications using Laravel, React 19, TypeScript, and Inertia.js. It features Tailwind CSS, shadcn/ui, and radix-ui for styling, and Vite as the build tool. The kit includes a customizable installation process via the `install:features` command and a pre-configured ESLint setup for React and TypeScript.

Tokens
1.9K
Snippets
8
Records
12
Agent score
73%

What's inside laravel-react-starter-kit

  1. Overview of the Laravel + React Starter Kit

    main

    The Laravel + React Starter Kit is a modern foundation for building full-stack applications. It uses Inertia.js to bridge the gap between a Laravel backend and a React frontend, allowing you to build single-page applications (SPAs) using classic server-side routing and controllers instead of building a separate API.

    Key Technologies:

    • Frontend Framework: React 19
    • Language: TypeScript
    • Styling: Tailwind CSS
    • Component Libraries: shadcn/ui and radix-ui
    • Build Tool: Vite
    • Glue Layer: Inertia.js
  2. Configure core application settings via APP_ environment variables

    main

    The application's core behavior is controlled through the config/app.php file, which primarily pulls values from the .env file using the env() helper. You can configure the application name, environment, debug mode, URL, and localization settings by setting the corresponding environment variables.

    APP_NAME=MyApplication
    APP_ENV=local
    APP_DEBUG=true
    APP_URL=http://localhost
    APP_LOCALE=en
    APP_FALLBACK_LOCALE=en
    APP_FAKER_LOCALE=en_US
  3. Configure maintenance mode drivers

    main

    You can manage the application's maintenance mode status using different drivers. The maintenance.driver setting determines how the status is tracked, and maintenance.store determines where it is stored.

    Supported drivers for driver:

    • file (default)
    • cache (recommended for multi-machine setups)
    • array
    APP_MAINTENANCE_DRIVER=cache
    APP_MAINTENANCE_STORE=database
  4. Skip Node.js processes during feature installation

    main

    You can prevent the command from installing Node dependencies or building assets by setting specific environment variables. This is useful if you manage dependencies or asset compilation through a different pipeline.

    • To skip npm install and npm run build: Set LARAVEL_INSTALLER_NO_NODE=true in your environment.
    • To defer installer hooks: Set LARAVEL_INSTALLER_DEFER_HOOKS=true (Note: providing the --answers flag will override this and prevent deferral).
  5. ESLint configuration for React and TypeScript

    main

    The project uses a flat ESLint configuration that integrates several plugins to enforce code quality and style for React, TypeScript, and modern JavaScript.

    Key features include:

    • React & Hooks: Uses eslint-plugin-react and eslint-plugin-react-hooks with recommended settings. It is configured for the modern JSX runtime (no React import required).
    • TypeScript: Uses typescript-eslint recommended rules. It enforces consistent-type-imports with a preference for type-imports and separate-type-imports style.
    • Import Management: Uses eslint-plugin-import with a TypeScript resolver. It enforces a specific import order (builtin, external, internal, parent, sibling, index) and prefers top-level type specifiers.
    • Stylistic Rules: Uses @stylistic/eslint-plugin to enforce 1tbs brace styles and mandatory blank lines around control statements (if, return, for, while, do, switch, try, throw).
    • Prettier Integration: Includes eslint-config-prettier to ensure ESLint rules do not conflict with Prettier formatting.
  6. Configure TypeScript import resolution in ESLint

    main

    The ESLint configuration uses eslint-plugin-import with a TypeScript resolver to correctly handle module resolution. If you modify the project structure, ensure the project key in the import/resolver settings points to your tsconfig.json.

    // Current configuration in eslint.config.js
    settings: {
        'import/resolver': {
            typescript: {
                alwaysTryTypes: true,
                project: './tsconfig.json',
            },
            node: true,
        },
    }
    settings: {
        'import/resolver': {
            typescript: {
                alwaysTryTypes: true,
                project: './tsconfig.json',
            },
            node: true,
        },
    }
  7. Configure application encryption and keys

    main

    Laravel uses an encryption key to secure data. The key configuration is loaded from APP_KEY. For seamless key rotation, you can provide multiple keys via a comma-separated list in the APP_PREVIOUS_KEYS environment variable. The default cipher used is AES-256-CBC.

    APP_KEY=base64:your-random-32-character-string
    APP_PREVIOUS_KEYS=base64:old-key-1,base64:old-key-2
  8. Merge Tailwind CSS classes with cn()

    main

    Use the cn utility function to conditionally merge CSS classes. It combines the functionality of clsx (for conditional logic) and tailwind-merge (to resolve Tailwind class conflicts). This is the standard way to handle dynamic class names in this project while ensuring that conflicting Tailwind classes are correctly overridden.

    import { cn } from '@/lib/utils';
    
    // Example usage with conditional classes and Tailwind conflict resolution
    const className = cn('px-2 py-1 text-sm', isPrimary && 'bg-blue-500', isLarge && 'text-lg');
  9. Extract a string URL from InertiaLinkProps with toUrl()

    main

    The toUrl function normalizes Inertia link destinations. Since InertiaLinkProps['href'] can be either a plain string or an object containing a url property, toUrl ensures you always receive a consistent string representation of the URL.

    import { toUrl } from '@/lib/utils';
    import type { InertiaLinkProps } from '@inertiajs/react';
    
    const href: InertiaLinkProps['href'] = { url: '/dashboard' };
    const urlString = toUrl(href); // Returns '/dashboard'
  10. ESLint ignored files and directories

    main

    The following paths are explicitly ignored by ESLint in this project:

    • vendor (PHP dependencies)
    • node_modules
    • public
    • bootstrap/ssr
    • tailwind.config.js
    • vite.config.ts
    • resources/js/actions/**
    • resources/js/components/ui/*
    • resources/js/routes/**
    • resources/js/wayfinder/**
  11. Install starter kit features via install:features

    main

    The install:features command allows you to customize your starter kit installation by choosing which features to keep or remove. It uses a configuration file located at chisel.php in your project root to determine available options and execution logic.

    By default, the command is interactive and uses Laravel Prompts to let you select features via a multiselect interface. If you are running this in a non-interactive environment (like a CI/CD pipeline), you can provide answers as a JSON string to skip prompts.

    When running the command, the following lifecycle occurs:

    1. Node Dependencies: If not skipped, npm install is executed.
    2. Feature Execution: The logic defined in chisel.php is executed based on your selections.
    3. Asset Building: If not skipped, npm run build is executed to compile assets.
    php artisan install:features
    
    # To skip interactive prompts in automated environments:
    php artisan install:features --answers='["feature-one", "feature-two"]'