--- title: "Svelte Kit Frontend Architecture" description: "How resources/js is organised in the Svelte kit: folder map, page and layout resolution, shared props, permission checks and translations with Inertia." --- # Architecture All the Svelte-specific code is in `resources/js`. For the Laravel side (modules, tenancy, auth), see [Core architecture](/docs/core/architecture). ## Overview Here's the path a request takes from a Laravel controller to a Svelte page: ```text Controller: Inertia::render('users/Index', $props) → @inertiajs/vite resolves resources/js/pages/users/Index.svelte → app.ts picks the default layout from the page name → page reads its own props with $props() and shared props from `page` ``` The app is created in `resources/js/app.ts`. You won't find a `resolve` callback there, because the `@inertiajs/vite` plugin in `vite.config.ts` handles page resolution. What `app.ts` does have is a `layout` callback, which picks a default layout based on the page name: | Page name starts with | Default layout | | --- | --- | | `auth/` | `AuthLayout` | | `settings/` | `AppLayout` wrapping `settings/Layout.svelte` | | anything else | `AppLayout` | Any page can override that default from its ` ``` Because `types/global.d.ts` registers `SharedData` with Inertia, `page.props` is typed in every file. The same file declares a global `PageProps` type (`T & SharedData`). ## Permissions on the frontend Rather than digging through `page.props.auth` yourself, call `usePermission()` from `lib/permission.ts`. - `can(...names)` returns `true` for a super admin, or when the user holds **any** of the permissions you pass. - The same page runs on central and tenant domains, so pass both permission names together. ```svelte {#if can('Create User', 'Create Tenant User')} … {/if} ``` ::: info Hiding a button just keeps the UI tidy. The real protection is the `permission:` middleware on the server routes. See [Users, roles & permissions](/docs/core/users-roles-permissions). ::: Language works the same way. `useLanguage()` from `lib/language.ts` gives you getters (`language.languages`, `language.userLocale`) and `changeLanguage()`. Read the reactive values through the object and don't destructure them. ## Translations Always import the helper from the Svelte subpath, `@erag/lang-sync-inertia/svelte`. Importing from the package root breaks the build. ```svelte ``` - Each key points to `lang//modules/.php`. - Running `php artisan erag:generate-lang` exports them to `resources/js/lang//modules/.json`. - Placeholders behave just like they do in Laravel: `__('modules.user.index.delete_confirm.message', { name: user.name })`. - You also get `trans`, `transChoice` and `trans_choice` from `svelteLang()`. [Localization](/docs/core/localization) has the full story. ## Related files - `resources/js/app.ts`: app entry, default layouts - `vite.config.ts`: Inertia, Svelte, Tailwind and Wayfinder (`formVariants: true`) plugins - `resources/js/types/global.d.ts`: `SharedData`, `PageProps` - `app/Http/Middleware/HandleInertiaRequests.php`: shared props - `resources/js/lib/`: shared logic - `eslint.config.js`: lint rules ::: info When `svelte-check` loads `vite.config.ts`, the config sets `LARAVEL_BYPASS_ENV_CHECK`. This lets you type check without a running Laravel environment. :::