Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Wayfinder Laravel Package

laravel/wayfinder

Generates fully typed, importable TypeScript functions from your Laravel routes and controllers. Call backend endpoints like normal TS functions—no hardcoded URLs or manual syncing. Includes an Artisan generator and Vite plugin for auto-regeneration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Seamless Laravel-TS Integration: Wayfinder bridges Laravel’s backend routes/controllers with TypeScript frontend by auto-generating typed functions, eliminating manual URL management and reducing API drift risk. This aligns perfectly with modern full-stack Laravel applications (e.g., Inertia.js, Livewire, or vanilla TS).
  • Type Safety: Generates TypeScript definitions for routes/actions, enabling IDE autocompletion, runtime validation, and compile-time error detection (e.g., invalid route params).
  • Convention Over Configuration: Leverages Laravel’s existing routing system (e.g., named routes, controller actions) without requiring custom annotations or metadata.
  • Inertia.js Synergy: Native support for Inertia’s useForm.submit() and Link components, reducing boilerplate for form submissions and navigation.

Integration Feasibility

  • Low Friction: Requires minimal setup—Composer/NPM install + Vite plugin configuration. No changes to existing Laravel routes or controllers.
  • Build-Time Generation: TypeScript definitions are generated during Vite builds (dev/prod), ensuring consistency between frontend and backend.
  • Backward Compatibility: Works with existing Laravel apps without breaking changes (though API is in beta; v1.0.0 will stabilize it).
  • Tooling Ecosystem: Integrates with Laravel’s route:cache and Vite’s HMR, fitting into standard deploy pipelines.

Technical Risk

  • Beta Status: API subject to change pre-v1.0.0 (monitor changelog for breaking changes). Mitigation: Pin to a specific beta version in composer.json and package.json.
  • Route Caching Pitfalls: Stale cached routes can cause missing generated files. Requires route:clear pre-deploy (automatable in CI/CD).
  • Complex Route Scenarios: Ambiguous routes (multiple routes → same action) force manual URI selection in TS. Mitigation: Prefer named routes or refactor overlapping routes.
  • Performance Overhead: Generates files during builds. For large apps, consider:
    • Excluding unused controllers/routes via --skip-actions/--skip-routes.
    • Customizing output paths to avoid bloating the JS bundle.
  • Reserved Word Handling: JS reserved words (e.g., delete) are renamed to [method]Method in TS, which may require frontend adjustments.

Key Questions

  1. Team Adoption:
    • Will frontend devs embrace TypeScript-first workflows (vs. manual API clients)?
    • How will the team handle beta API changes? (e.g., feature flags, migration scripts)
  2. Scalability:
    • For apps with 100+ routes/controllers, will generated files bloat the bundle? Test with --skip-actions for unused controllers.
    • How will Wayfinder handle dynamic routes (e.g., locale prefixes, tenant IDs)?
  3. CI/CD Impact:
    • Can route:clear + wayfinder:generate be automated in deploy scripts?
    • Will Vite’s HMR handle regenerated files smoothly during dev?
  4. Edge Cases:
    • How will Wayfinder handle middleware-affected routes (e.g., auth, rate-limiting)?
    • Does it support Laravel’s API resources (e.g., ResourceController) or only traditional controllers?
  5. Alternatives:
    • Compare with manual API clients (e.g., OpenAPI/Swagger) or other tools like Laravel Scout for route generation.

Integration Approach

Stack Fit

  • Primary Use Case: Laravel + TypeScript/Vite stacks (e.g., Inertia.js, Livewire with Alpine.js, or vanilla TS).
  • Compatibility:
    • Laravel: Works with Laravel 10+ (tested with latest). Assumes standard routing (no custom route resolvers unless Wayfinder supports them).
    • Frontend: Requires Vite (or compatible bundler) for the plugin. Supports React, Vue, Svelte, etc., via Inertia or direct TS usage.
    • Other Tools:
      • Inertia.js: Native integration for forms/links.
      • Livewire: Can use Wayfinder for non-Livewire routes (e.g., API endpoints).
      • API Testing: Generated TS types can feed into tools like Vitest or Jest for frontend API tests.
  • Anti-Patterns:
    • Avoid for apps with heavy dynamic routing (e.g., SPAs with client-side routing like Next.js).
    • Not ideal if frontend uses a separate API backend (Wayfinder ties to Laravel routes).

Migration Path

  1. Pilot Phase:
    • Start with a single feature/module (e.g., a blog’s PostController).
    • Compare generated TS types with existing manual API clients for accuracy.
  2. Incremental Rollout:
    • Generate types for critical routes first (--skip-actions for others).
    • Replace hardcoded URLs in frontend with Wayfinder imports.
  3. Tooling Updates:
    • Update vite.config.js to include the Wayfinder plugin.
    • Add wayfinder:generate to build scripts (dev/prod).
  4. Deprecation:
    • Phase out manual API clients (e.g., OpenAPI-generated files) in favor of Wayfinder.
    • Use --skip-actions to exclude legacy clients during transition.

Compatibility

  • Laravel Features:
    • ✅ Named routes, controller actions, middleware, route model binding.
    • ✅ Invokable controllers, resource controllers (with caveats).
    • ⚠️ Custom route resolvers (untested; may require Wayfinder updates).
    • ❌ API resources (unless manually mapped to routes).
  • Frontend Patterns:
    • ✅ Inertia.js forms/links, React/Vue/Svelte components.
    • ✅ Query params, form submissions, HTTP method overrides.
    • ⚠️ Complex nested routes (e.g., {user}/{post} with optional params).
  • Build Systems:
    • ✅ Vite (primary), Webpack (via Vite compatibility layer).
    • ❌ Non-JS bundlers (e.g., Parcel, esbuild without TS support).

Sequencing

  1. Pre-requisites:
    • Laravel app with Vite configured.
    • TypeScript set up in the frontend.
  2. Core Setup:
    composer require laravel/wayfinder
    npm install -D @laravel/vite-plugin-wayfinder
    
  3. Configuration:
    • Update vite.config.js with the Wayfinder plugin.
    • Configure wayfinder:generate in package.json scripts:
      "scripts": {
        "dev": "vite --plugins",
        "build": "php artisan route:clear && npm run build:vite",
        "build:vite": "vite build"
      }
      
  4. Testing:
    • Generate types and verify imports in TS files.
    • Test edge cases (e.g., optional params, query strings).
  5. Deployment:
    • Add route:clear pre-build in CI/CD (e.g., GitHub Actions, Laravel Forge).

Operational Impact

Maintenance

  • Pros:
    • Reduced Drift: TypeScript definitions stay in sync with Laravel routes, eliminating manual URL updates.
    • Self-Documenting: Generated files serve as living documentation for the API.
    • Refactoring Safety: Renaming routes/controllers updates TS imports automatically.
  • Cons:
    • Generated Code: Files are auto-generated (.gitignore recommended), but errors require debugging Wayfinder’s logic (e.g., route resolution).
    • Beta Support: May need to patch Wayfinder for critical bugs until v1.0.0.
  • Best Practices:
    • Document Wayfinder-specific conventions (e.g., route naming, param binding).
    • Use --with-form for conventional forms to reduce manual form attribute management.

Support

  • Debugging:
    • Route Issues: Verify route:list matches generated TS files. Use php artisan wayfinder:generate --verbose for logs.
    • TS Errors: Check for reserved word collisions or ambiguous routes.
    • Build Failures: Ensure route:clear runs pre-build to avoid stale routes.
  • Troubleshooting Workflow:
    1. Clear cached routes: php artisan route:clear.
    2. Regenerate types: php artisan wayfinder:generate.
    3. Restart Vite dev server or rebuild.
  • Community:
    • Active Laravel Slack/Discord channels for Wayfinder.
    • GitHub issues for beta-specific bugs.

Scaling

  • Performance:
    • Build Time: Generation adds ~1–5s to Vite builds (depends on route complexity). Mitigate by:
      • Skipping unused controllers/actions.
      • Running in parallel with other build steps.
    • Bundle Size: Generated files are tree-shakable. Use dynamic imports for lazy-loaded routes.
  • Large Apps:
    • Modularization: Split routes/controllers into microservices or monorepo modules, each with their own Wayfinder config.
    • Selective Generation: Use --skip-actions for non-critical controllers.
  • Multi-Tenant/Environments:
    • Wayfinder respects APP_URL for base
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai