Skip to content
Projets

À propos

⚡ Laravel and Nuxt.js boilerplate designed for development with maximum API performance, ready-made authorization methods, image uploading with optimization, user roles, device management

Développement web et applicatif

Comment ces chiffres sont mesurés

What you can do

  • Laravel 13 and Nuxt 4
  • Laravel Octane supercharges your application's performance by serving your application using high-powered application servers.
  • Laravel Socialite OAuth providers
  • Laravel Sail Light-weight command-line interface for interacting with Laravel's default Docker development environment.

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

preview

⚡ Laravel Nuxt Boilerplate

FOSSA Status GitHub Workflow Status CodeQL

The goal of the project is to create a template for development on Laravel and Nuxt with maximum API performance, ready-made authorization methods, image uploading with optimization and ready-made user roles.

Features

  • Laravel 13 and Nuxt 4
  • Laravel Octane supercharges your application's performance by serving your application using high-powered application servers.
  • Laravel Socialite OAuth providers
  • Laravel Sail Light-weight command-line interface for interacting with Laravel's default Docker development environment.
  • Spatie Laravel Permissions This package allows you to manage user permissions and roles in a database.
  • Pest Elegant testing framework with expressive syntax and zero-config Laravel integration.
  • UI library Nuxt UI 4 based on TailwindCSS 4 and Reka UI.
  • Pinia The intuitive store for Vue.js
  • Integrated pages: login, registration, password recovery, email confirmation, account information update, password change.
  • Temporary uploads with image optimization and signed URLs via imgproxy.
  • Device management
  • Enhanced Fetch Wrappers : Utilizes $http and useHttp, which extend the capabilities of Nuxt's standard $fetch and useFetch.
  • Monorepo layout (apps/api + apps/web) with just task runner.

Requirements

Installation

Standalone

Show standalone instructions
  1. cd apps/api && composer install && cd ../web && bun install && cd ../..
  2. cp apps/api/.env.example apps/api/.env
  3. cd apps/api && php artisan key:generate && php artisan storage:link, then php artisan imgproxy:key and copy the pair into .env
  4. php artisan migrate && php artisan db:seed
  5. php artisan octane:install --server=swoole && php artisan octane:start --host=127.0.0.1 --port=8000
  6. In another terminal: cd apps/web && bun run dev

Docker

Single docker-compose.yml: API runs on Laravel Sail with Octane in watch mode, web runs on oven/bun:1, plus a redis:8-alpine service for cache / queue / session / throttling. Orchestrated via just. just sail ... wraps the upstream vendor/bin/sail for those who want it.

Installing just

brew install just                          # macOS
apt install just                           # Debian / Ubuntu
winget install --id Casey.Just --exact     # Windows

Other systems: see the full list of packages.

Lifecycle

just up -d                 # start full app (api + web) — :8000 / :3000
just prod -d               # production mode (Octane no-watch, web .output/)
just api -d                # api only — :8000
just web                   # web foreground, ephemeral — :3000
just stop                  # pause containers
just down                  # remove containers

Quick start:

just init                  # copies .env files, composer install, builds api image, bun install, key:generate, imgproxy keys, storage:link
just up -d
just a migrate --seed

Common commands:

just                       # show all recipes
just build                 # rebuild the api image
just a migrate             # `php artisan migrate` in ephemeral container
just sail ...              # invoke Laravel Sail directly (e.g. `just sail tinker`)
just composer require ...
just bun add @vueuse/core
just pint                  # PHP linter
just test                  # Pest
just down -v               # stop and remove volumes

Usage

Fetch wrapper

To integrate with the API, enhanced $http and useHttp wrappers are used, expanding the functionality of Nuxt's standard $fetch and useFetch. The $http wrapper includes custom interceptors to replace the originals:

  • onFetch instead of onRequest
  • onFetchError instead of onRequestError
  • onFetchResponse instead of onResponse
  • onFetchResponseError instead of onResponseError

Additionally, $http predefines a base url, authorization headers, and proxy IP for convenient API work in SSR mode. For example, the code for authorizing a user by email and password:

<script lang="ts" setup>
const router = useRouter();
const auth = useAuthStore();
const form = templateRef("form");
const state = reactive({
  email: "",
  password: "",
  remember: false,
});

const submitting = ref(false);

async function onSubmit(): Promise<void> {
  submitting.value = true;

  try {
    const res = await $http<{ ok?: boolean }>("login", {
      method: "POST",
      body: { ...state },
    });

    if (res?.ok) {
      await auth.login();
      await router.push("/");
    }
  } catch (err: any) {
    if (err?.response?.status === 422) {
      form.value?.setErrors(err.response?._data?.errors ?? []);
    }
  } finally {
    submitting.value = false;
  }
}
</script>
<template>
  <UForm ref="form" :state="state" @submit="onSubmit" class="space-y-4">
    <UFormField label="Email" name="email" required>
      <UInput
        v-model="state.email"
        placeholder="[email protected]"
        icon="i-lucide-mail"
        trailing
        type="email"
        autofocus
      />
    </UFormField>

    <UFormField label="Password" name="password" required>
      <UInput v-model="state.password" class="w-full" type="password" />
    </UFormField>

    <UTooltip :delay-duration="0" text="for 1 month" :content="{ side: 'right' }">
      <UCheckbox v-model="state.remember" class="w-full" label="Remember me" />
    </UTooltip>

    <div class="flex items-center justify-end space-x-4">
      <NuxtLink class="text-sm" to="/auth/forgot">Forgot your password?</NuxtLink>
      <UButton type="submit" label="Login" :loading="submitting" />
    </div>
  </UForm>
</template>

In this example, a POST request will be made to the url "/api/v1/login"

Authentication

useAuthStore() has everything you need to work with authorization.

Data returned by useAuthStore:

  • logged: Boolean, whether the user is authorized
  • user: User object, user stored in pinia store
  • fetchCsrf: Function, fetch csrf token
  • fetchUser: Function, fetch user data
  • login: Function, login user
  • logout: Function, remove local data and call API to remove session
  • hasRole: Function, checks the role

Nuxt Middleware

The following middleware is supported:

  • guest: unauthorized users
  • auth: authorized users
  • verified: users who have confirmed their email
  • role-user: users with the 'user' role
  • role-admin: users with the 'admin' role

Laravel Middleware

All built-in middleware from Laravel + middleware based on roles Spatie Laravel Permissions Middleware

Image uploads

Uploads are processed by imgproxy (imgproxy service in docker-compose.yml), PHP never decodes images.

  • POST /api/v1/upload stores the original in storage/app/private/uploads-tmp, imgproxy applies the optimize preset (fit 2560×2560, auto-rotate, strip metadata, WebP q90) and only the result is saved to the public disk.
  • Set UPLOAD_OPTIMIZE=false to store the original file as is. Limits are in config/uploads.php.
  • The API returns signed imgproxy URLs (e.g. avatar_url with the avatar preset), keys never reach the frontend. Presets live in config/laravel-imgproxy.php.
  • IMGPROXY_URL is the public address used in URLs, IMGPROXY_INTERNAL_URL is used by the API to fetch processed uploads.
  • imgproxy does not cache results: in production put a CDN or a caching reverse proxy in front of it (see Deployment).

Deployment

deploy/nginx.conf is an example reverse proxy that serves everything from a single domain: / → Nuxt, /api/ and /storage/ → Laravel, /image/ → imgproxy with response caching.

Set APP_URL and FRONTEND_URL to the same domain and IMGPROXY_URL=https://example.com/image in both .env files. Expose only nginx to the internet.

Examples

Route list

routes

Demo

https://github.com/k2so-dev/laravel-nuxt/assets/15279423/9b134491-1444-4323-a7a3-d87833dcdc67

Links

License

FOSSA Status

Explorer des projets similaires

Chargement…