laravel-inertia-react-structure
Frontend structure conventions for Laravel Inertia React applications based on Spatie's production practices. Use when creating, scaffolding, or reviewing frontend code in a Laravel Inertia React project. Triggers on creating React components, pages, modules, organizing frontend directories, setting up Inertia pages, structuring a React frontend within Laravel, or when the user asks about frontend file organization in an Inertia app.
What this skill does
# Laravel Inertia React Frontend Structure
Based on [Spatie's conventions](https://spatie.be/blog/how-to-structure-the-frontend-of-a-laravel-inertia-react-application) for structuring production Laravel Inertia React applications.
## Directory Structure
Four base directories under `resources/js`:
```
resources/js/
├── common/ # Generic, reusable code portable across projects
├── modules/ # Project-specific code shared across multiple pages
├── pages/ # Inertia page components
└── shadcn/ # Auto-generated shadcn/ui components (if used)
```
**common vs modules**: ask "Does it relate to a domain or feature?" If yes → `modules`. If it's generic and project-agnostic → `common`.
## Naming Conventions
- **Components and React contexts**: `PascalCase` (e.g. `Button.tsx`, `AuthContext.tsx`)
- **Other files** (helpers, hooks, constants, stores): `camelCase` (e.g. `useAuth.ts`, `formatDate.ts`)
- **Directories**: `kebab-case` (e.g. `date-picker/`, `user-management/`)
## Module Organization
Small modules have a few top-level files. Larger modules organize by type:
```
modules/agenda/
├── components/
├── contexts/
├── constants/
├── helpers/
├── hooks/
├── stores/
└── types.ts # or types/ directory if large
```
The `common/` directory follows the same structure.
## Pages Directory
Pages mirror the URL structure. Components are suffixed with `Page`.
```
pages/
├── layouts/ # Global layouts
├── admin/
│ ├── layouts/ # Section-specific layouts
│ ├── users/
│ │ ├── components/ # Page-specific partials
│ │ ├── helpers/
│ │ ├── IndexPage.tsx
│ │ └── EditPage.tsx
│ └── DashboardPage.tsx
└── auth/
├── LoginPage.tsx
└── RegisterPage.tsx
```
## React Component Conventions
Use **function declarations** (not `const` arrow functions) and **named exports** exclusively:
```tsx
// Correct
export function Button({ variant, className }: ButtonProps) {
return <button className={cn(variant, className)}>Click</button>;
}
// Wrong: const + default export
const Button = ({ variant }) => { ... };
export default Button;
```
**One component per file. No barrel files (index.ts re-exports).**
### Import Organization
Two blocks separated by a blank line: library imports first, then application imports. Use absolute paths with aliases (`@/`):
```tsx
import { useState } from "react";
import { cn } from "@/common/helpers/cn";
import { useAgenda } from "@/modules/agenda/hooks/useAgenda";
import { AgendaItem } from "@/modules/agenda/components/AgendaItem";
```
### Props
Sort alphabetically, with `className` and `children` last:
```tsx
interface DialogProps {
onClose: () => void;
open: boolean;
title: string;
className?: string;
children: React.ReactNode;
}
```
## Stylesheets
Use Tailwind. Single `app.css` for most projects. Larger projects split into:
```
resources/css/
├── base/
├── components/
└── utilities/
```
## Multi-Zone Applications
For apps with distinct sections (e.g. admin/client), introduce `apps/`:
```
resources/js/
├── common/ # Shared across all zones
├── modules/ # Global modules shared across zones
├── apps/
│ ├── admin/
│ │ ├── modules/ # Admin-specific modules
│ │ ├── pages/
│ │ └── app.tsx
│ └── client/
│ ├── modules/ # Client-specific modules
│ ├── pages/
│ └── app.tsx
└── shadcn/
```
## shadcn/ui Usage
Abstract shadcn components into simpler, project-specific implementations rather than using the low-level API directly in application code. Place abstractions in `common/` or `modules/` as appropriate.
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.