From 39da637b6d1c1f2dfe254a5ac49ade8132abba6a Mon Sep 17 00:00:00 2001 From: kingwill101 Date: Fri, 17 Apr 2026 19:13:09 -0500 Subject: [PATCH 1/3] feat(serinus_inertia): serve production assets directly --- .../example/client/package.json | 5 ++- .../example/client/vite.config.js | 3 ++ .../example/lib/app_module.dart | 41 ++++++++++++++++-- .../example/lib/asset_controller.dart | 42 +++++++++++++++++++ packages/serinus_inertia/example/pubspec.yaml | 1 + 5 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 packages/serinus_inertia/example/lib/asset_controller.dart diff --git a/packages/serinus_inertia/example/client/package.json b/packages/serinus_inertia/example/client/package.json index f8f3eea..64e2379 100644 --- a/packages/serinus_inertia/example/client/package.json +++ b/packages/serinus_inertia/example/client/package.json @@ -5,8 +5,9 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build && vite build --ssr src/ssr.jsx", - "build:ssr": "vite build --ssr src/ssr.jsx", + "build:client": "node -e \"const fs=require('node:fs'); try { fs.unlinkSync('public/hot') } catch {}\" && vite build", + "build": "npm run build:client && npm run build:ssr", + "build:ssr": "vite build --ssr src/ssr.jsx --emptyOutDir false --manifest ssr-manifest.json", "lint": "eslint .", "preview": "vite preview" }, diff --git a/packages/serinus_inertia/example/client/vite.config.js b/packages/serinus_inertia/example/client/vite.config.js index 1585770..301875b 100644 --- a/packages/serinus_inertia/example/client/vite.config.js +++ b/packages/serinus_inertia/example/client/vite.config.js @@ -12,5 +12,8 @@ export default defineConfig({ outDir: 'dist', assetsDir: 'assets', manifest: true, + rollupOptions: { + input: 'src/main.jsx', + }, }, }) diff --git a/packages/serinus_inertia/example/lib/app_module.dart b/packages/serinus_inertia/example/lib/app_module.dart index 264b3a5..78a9a70 100644 --- a/packages/serinus_inertia/example/lib/app_module.dart +++ b/packages/serinus_inertia/example/lib/app_module.dart @@ -1,8 +1,42 @@ +import 'dart:io'; + import 'package:serinus/serinus.dart'; import 'package:serinus_inertia/serinus_inertia.dart'; +import 'asset_controller.dart'; import 'app_controller.dart'; +bool _envBool(String name) { + final value = Platform.environment[name]?.trim().toLowerCase(); + return value == '1' || value == 'true' || value == 'yes' || value == 'on'; +} + +String? _envString(String name) { + final value = Platform.environment[name]?.trim(); + if (value == null || value.isEmpty) { + return null; + } + return value; +} + +InertiaSsrOptions _resolveSsrOptions() { + if (!_envBool('SERINUS_INERTIA_ENABLE_SSR')) { + return const InertiaSsrOptions(); + } + + final endpoint = _envString('SERINUS_INERTIA_SSR_ENDPOINT'); + if (endpoint != null) { + return InertiaSsrOptions(enabled: true, endpoint: Uri.parse(endpoint)); + } + + return InertiaSsrOptions( + enabled: true, + manageProcess: true, + runtime: _envString('SERINUS_INERTIA_SSR_RUNTIME') ?? 'node', + bundle: _envString('SERINUS_INERTIA_SSR_BUNDLE') ?? 'client/dist/ssr.js', + ); +} + class AppModule extends Module { AppModule() : super( @@ -15,9 +49,10 @@ class AppModule extends Module { clientDirectory: 'client', includeReactRefresh: true, ), + ssr: _resolveSsrOptions(), // Enable this to have Serinus manage the SSR runtime as a // separate Node or Bun process during app startup: - // ssr: SerinusInertiaSsrOptions( + // ssr: InertiaSsrOptions( // enabled: true, // manageProcess: true, // runtime: 'node', // or 'bun' @@ -28,7 +63,7 @@ class AppModule extends Module { // endpoint started with: // dart run serinus_inertia:ssr start // --bundle client/dist/ssr.js - // ssr: SerinusInertiaSsrOptions( + // ssr: InertiaSsrOptions( // enabled: true, // endpoint: Uri.parse('http://127.0.0.1:13714/render'), // ), @@ -38,6 +73,6 @@ class AppModule extends Module { ), ), ], - controllers: [AppController()], + controllers: [AssetController(), AppController()], ); } diff --git a/packages/serinus_inertia/example/lib/asset_controller.dart b/packages/serinus_inertia/example/lib/asset_controller.dart new file mode 100644 index 0000000..13c6451 --- /dev/null +++ b/packages/serinus_inertia/example/lib/asset_controller.dart @@ -0,0 +1,42 @@ +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:mime/mime.dart'; +import 'package:serinus/serinus.dart'; + +class AssetController extends Controller { + AssetController() : super('/assets') { + on(Route.get('/**'), _serveAsset); + on(Route(path: '/**', method: HttpMethod.head), _serveAsset); + } + + Future _serveAsset(RequestContext context) async { + final relativePath = context.params['**']?.toString() ?? ''; + if (relativePath.isEmpty || _containsUnsafeSegments(relativePath)) { + throw NotFoundException('Asset not found'); + } + + final assetFile = File('client/dist/assets/$relativePath'); + if (!assetFile.existsSync() || + assetFile.statSync().type != FileSystemEntityType.file) { + throw NotFoundException('Asset not found'); + } + + context.res.contentType = ContentType.parse( + lookupMimeType(assetFile.path) ?? 'application/octet-stream', + ); + context.res.contentLength = assetFile.lengthSync(); + context.res.headers[HttpHeaders.cacheControlHeader] = + 'public, max-age=31536000, immutable'; + + if (context.request.method == HttpMethod.head) { + return Uint8List(0); + } + + return assetFile.readAsBytes(); + } + + bool _containsUnsafeSegments(String path) { + return path.split('/').any((segment) => segment == '..' || segment == '.'); + } +} diff --git a/packages/serinus_inertia/example/pubspec.yaml b/packages/serinus_inertia/example/pubspec.yaml index 19951bb..e6b29e6 100644 --- a/packages/serinus_inertia/example/pubspec.yaml +++ b/packages/serinus_inertia/example/pubspec.yaml @@ -5,6 +5,7 @@ environment: sdk: ">=3.10.0 <4.0.0" dependencies: + mime: ^2.0.0 serinus: ^2.1.7 serinus_inertia: path: .. From a13208c8cdeed3bda206aa83804619da1f6c633a Mon Sep 17 00:00:00 2001 From: kingwill101 Date: Fri, 17 Apr 2026 19:13:44 -0500 Subject: [PATCH 2/3] docs(serinus_inertia): add deployment guide and containers --- .dockerignore | 9 + packages/serinus_inertia/example/DEPLOY.md | 402 ++++++++++++++++++ .../serinus_inertia/example/Dockerfile.client | 33 ++ .../serinus_inertia/example/Dockerfile.ssr | 48 +++ packages/serinus_inertia/example/README.md | 56 ++- packages/serinus_inertia/example/compose.yaml | 51 +++ 6 files changed, 592 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 packages/serinus_inertia/example/DEPLOY.md create mode 100644 packages/serinus_inertia/example/Dockerfile.client create mode 100644 packages/serinus_inertia/example/Dockerfile.ssr create mode 100644 packages/serinus_inertia/example/compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4dbf419 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.codex +.dart_tool +**/.dart_tool +**/node_modules +**/dist +**/build +**/public/hot +**/.DS_Store diff --git a/packages/serinus_inertia/example/DEPLOY.md b/packages/serinus_inertia/example/DEPLOY.md new file mode 100644 index 0000000..b675056 --- /dev/null +++ b/packages/serinus_inertia/example/DEPLOY.md @@ -0,0 +1,402 @@ +# Deploying the Serinus Inertia Example + +This guide walks through a production build of the example and the deployment +layout it expects. The example serves `/assets/*` directly from Serinus, so a +reverse proxy is optional rather than required. + +## Overview + +A production deployment has three moving parts: + +1. `client/dist/` for the browser bundle and Vite manifest +2. `client/dist/ssr.js` if SSR is enabled +3. the Dart HTTP server, usually compiled to `build/server` + +The production asset flow in this example is: + +```text +Browser -> Dart server :4000 -> /assets/* served from client/dist/assets/* + -> all page and Inertia requests handled normally +``` + +You can still place nginx, Caddy, or another front door in front for TLS, +host-based routing, or load-balancing, but it does not need to own static file +serving for this example. + +## Prerequisites + +| Tool | Minimum version | Notes | +| --- | --- | --- | +| Dart SDK | 3.10 | `dart --version` | +| Node.js | 18 LTS | `node --version` | +| npm | 9 | bundled with Node | +| Node or Bun | 18 LTS / 1.0 | SSR only | + +Run all commands from `packages/serinus_inertia/example` unless stated +otherwise. + +## Step 1: Install dependencies + +```bash +dart pub get + +cd client +npm install +cd .. +``` + +## Step 2: Build the frontend + +```bash +cd client +npm run build +cd .. +``` + +That produces: + +```text +client/dist/ +├── .vite/ +│ └── manifest.json +├── assets/ +│ ├── main-.js +│ └── main-.css +├── ssr-manifest.json +└── ssr.js +``` + +Verify the required outputs before you deploy: + +```bash +ls client/dist/.vite/manifest.json +ls client/dist/assets +ls client/dist/ssr.js +``` + +`npm run build` clears `client/public/hot` before the browser build. That hot +file must not survive into the deployed layout, or the app will try to use a +Vite dev server in production. + +## Step 3: Compile the Dart server + +The recommended production path is a native executable: + +```bash +mkdir -p build +dart compile exe bin/main.dart -o build/server +``` + +You can also run `dart run bin/main.dart` directly, but that requires deploying +the full monorepo checkout because this example depends on local `path:` +packages. + +## Step 4: Understand the static asset route + +`lib/asset_controller.dart` maps `/assets/**` to `client/dist/assets/**`. +Nothing special is required in front of the app for hashed Vite bundles. + +The controller sets: + +- the response content type based on the asset path +- `Cache-Control: public, max-age=31536000, immutable` + +That cache policy is safe because Vite emits hashed filenames. + +If you only need a minimal Serinus static-file setup, use the official +`serinus_serve_static` package: + +```dart +import 'package:serinus/serinus.dart'; +import 'package:serinus_serve_static/serinus_serve_static.dart'; + +class AppModule extends Module { + AppModule() + : super( + imports: [ + ServeStaticModule( + rootPath: '/public', + renderPath: '*', + serveRoot: '', + exclude: const [], + extensions: const ['.html', '.css', '.js'], + index: const ['index.html'], + redirect: true, + ), + ], + ); +} +``` + +That is the minimal package-backed path for serving files directly from +Serinus. For this Inertia example, we keep the explicit controller because the +production Vite output lives under `client/dist/assets`, while the public URL +must stay `/assets/*`. + +## Step 5: Assemble the deployment root + +For the compiled-binary path, the runtime layout should look like this: + +```text +/opt/serinus-inertia/ +├── server +└── client/ + └── dist/ + ├── .vite/ + │ └── manifest.json + ├── assets/ + │ ├── main-.js + │ └── main-.css + ├── ssr-manifest.json + └── ssr.js +``` + +Copy the outputs into place: + +```bash +mkdir -p /opt/serinus-inertia/client +cp build/server /opt/serinus-inertia/server +cp -r client/dist /opt/serinus-inertia/client/dist +``` + +The server resolves the manifest and asset files relative to its working +directory. Keep the process working directory at `/opt/serinus-inertia`. + +## Step 6: Run the app + +### Client-rendered only + +No extra configuration is required: + +```bash +cd /opt/serinus-inertia +./server +``` + +### SSR managed by Serinus + +If Node or Bun is installed on the host, the app can launch the renderer +itself: + +```bash +cd /opt/serinus-inertia +SERINUS_INERTIA_ENABLE_SSR=true ./server +``` + +Optional overrides: + +```bash +SERINUS_INERTIA_ENABLE_SSR=true \ +SERINUS_INERTIA_SSR_RUNTIME=node \ +SERINUS_INERTIA_SSR_BUNDLE=client/dist/ssr.js \ +./server +``` + +### SSR with an external renderer + +Run the renderer separately: + +```bash +cd /opt/serinus-inertia +node ./client/dist/ssr.js +``` + +Then point the Dart app at it: + +```bash +cd /opt/serinus-inertia +SERINUS_INERTIA_ENABLE_SSR=true \ +SERINUS_INERTIA_SSR_ENDPOINT=http://127.0.0.1:13714/render \ +./server +``` + +## Step 7: systemd units + +### Client-rendered app + +```ini +[Unit] +Description=Serinus Inertia Example +After=network.target + +[Service] +Type=simple +WorkingDirectory=/opt/serinus-inertia +ExecStart=/opt/serinus-inertia/server +Restart=on-failure +User=www-data +Group=www-data + +[Install] +WantedBy=multi-user.target +``` + +### External SSR renderer + +```ini +[Unit] +Description=Serinus Inertia SSR Renderer +After=network.target + +[Service] +Type=simple +WorkingDirectory=/opt/serinus-inertia +ExecStart=/usr/bin/node /opt/serinus-inertia/client/dist/ssr.js +Restart=on-failure +User=www-data +Group=www-data + +[Install] +WantedBy=multi-user.target +``` + +If you use the external renderer unit, add these environment variables to the +app unit: + +```ini +Environment=SERINUS_INERTIA_ENABLE_SSR=true +Environment=SERINUS_INERTIA_SSR_ENDPOINT=http://127.0.0.1:13714/render +``` + +You can then wire the dependencies with `After=` and `Wants=` if you want the +app to wait on the renderer service. + +## Step 8: Optional reverse proxy + +Use a reverse proxy only when you need a front door for TLS termination, +multiple apps, host routing, or similar concerns. + +### Option A: proxy everything to Serinus + +This keeps the deployment simple. Serinus still serves `/assets/*` itself. + +Minimal nginx example: + +```nginx +server { + listen 80; + server_name example.com; + + location / { + proxy_pass http://127.0.0.1:4000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +Minimal Caddy example: + +```caddy +example.com { + reverse_proxy 127.0.0.1:4000 +} +``` + +### Option B: let the proxy serve `/assets/*` directly + +If you want nginx or Caddy to own static asset delivery, point the asset root +at `client/dist` and proxy everything else to the app. The request path +`/assets/main-.js` must resolve to +`/opt/serinus-inertia/client/dist/assets/main-.js` on disk. + +nginx example: + +```nginx +server { + listen 80; + server_name example.com; + + location /assets/ { + root /opt/serinus-inertia/client/dist; + expires 1y; + add_header Cache-Control "public, max-age=31536000, immutable"; + try_files $uri =404; + } + + location / { + proxy_pass http://127.0.0.1:4000; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +Caddy example: + +```caddy +example.com { + handle /assets/* { + root * /opt/serinus-inertia/client/dist + header Cache-Control "public, max-age=31536000, immutable" + file_server + } + + handle { + reverse_proxy 127.0.0.1:4000 + } +} +``` + +If you use this split topology, keep the proxy asset root and the app working +directory aligned with the same `client/dist` build output. + +## Step 9: Docker Compose + +The bundled Compose file exposes two profiles: + +- `client`: one container running the compiled Dart app +- `ssr`: one renderer container plus one compiled Dart app container + +Client-rendered stack: + +```bash +docker compose --profile client up --build +``` + +Open . + +SSR stack: + +```bash +docker compose --profile ssr up --build +``` + +Open . + +The SSR app waits for `ssr-renderer` to report healthy before starting. + +## Smoke checks + +### Client-rendered + +```bash +curl -I http://127.0.0.1:4000/assets/main-.js +curl -H 'X-Inertia: true' -H 'X-Requested-With: XMLHttpRequest' http://127.0.0.1:4000/users +``` + +Expect: + +- `200 OK` for the asset +- `Cache-Control: public, max-age=31536000, immutable` +- JSON from the Inertia request + +If you put nginx or Caddy in front and let it serve assets directly, run the +same checks against the public origin instead of port `4000`. + +### SSR + +Load the page once and confirm the initial HTML already contains rendered app +content inside `#app`. + +## Troubleshooting + +- If the app tries to load assets from a Vite dev server, remove `client/public/hot`. +- If assets 404, confirm the working directory contains `client/dist/assets`. +- If assets 404 behind nginx or Caddy, confirm the proxy root points to `client/dist`, not the deployment root. +- If first visits fail, confirm `client/dist/.vite/manifest.json` exists. +- If SSR is enabled, confirm `client/dist/ssr.js` exists and the renderer is reachable on `/render`. diff --git a/packages/serinus_inertia/example/Dockerfile.client b/packages/serinus_inertia/example/Dockerfile.client new file mode 100644 index 0000000..4dc2e4e --- /dev/null +++ b/packages/serinus_inertia/example/Dockerfile.client @@ -0,0 +1,33 @@ +# syntax=docker/dockerfile:1.7 + +FROM node:24-bookworm-slim AS client-build +WORKDIR /workspace + +COPY . . + +WORKDIR /workspace/packages/serinus_inertia/example/client +RUN npm ci +RUN npm run build + +FROM dart:stable AS server-build +WORKDIR /workspace + +COPY . . + +WORKDIR /workspace/packages/serinus_inertia/example +RUN dart pub get +RUN mkdir -p build && dart compile exe bin/main.dart -o build/server + +FROM debian:bookworm-slim AS app +WORKDIR /opt/serinus-inertia + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=server-build /workspace/packages/serinus_inertia/example/build/server ./server +COPY --from=client-build /workspace/packages/serinus_inertia/example/client/dist ./client/dist + +EXPOSE 4000 + +CMD ["./server"] diff --git a/packages/serinus_inertia/example/Dockerfile.ssr b/packages/serinus_inertia/example/Dockerfile.ssr new file mode 100644 index 0000000..893c6e2 --- /dev/null +++ b/packages/serinus_inertia/example/Dockerfile.ssr @@ -0,0 +1,48 @@ +# syntax=docker/dockerfile:1.7 + +FROM node:24-bookworm-slim AS client-build +WORKDIR /workspace + +COPY . . + +WORKDIR /workspace/packages/serinus_inertia/example/client +RUN npm ci +RUN npm run build + +FROM dart:stable AS server-build +WORKDIR /workspace + +COPY . . + +WORKDIR /workspace/packages/serinus_inertia/example +RUN dart pub get +RUN mkdir -p build && dart compile exe bin/main.dart -o build/server + +FROM debian:bookworm-slim AS app +WORKDIR /opt/serinus-inertia + +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=server-build /workspace/packages/serinus_inertia/example/build/server ./server +COPY --from=client-build /workspace/packages/serinus_inertia/example/client/dist ./client/dist + +EXPOSE 4000 + +CMD ["./server"] + +FROM node:24-bookworm-slim AS ssr +WORKDIR /opt/serinus-inertia/client + +COPY packages/serinus_inertia/example/client/package.json ./package.json +COPY packages/serinus_inertia/example/client/package-lock.json ./package-lock.json +RUN npm ci --omit=dev + +COPY --from=client-build /workspace/packages/serinus_inertia/example/client/dist ./dist + +WORKDIR /opt/serinus-inertia + +EXPOSE 13714 + +CMD ["node", "./client/dist/ssr.js"] diff --git a/packages/serinus_inertia/example/README.md b/packages/serinus_inertia/example/README.md index 79109b1..e6b386c 100644 --- a/packages/serinus_inertia/example/README.md +++ b/packages/serinus_inertia/example/README.md @@ -51,7 +51,7 @@ In development the server resolves client assets in this order: If you run Vite on a custom port and do not want to rely on the hot file, set: ```dart -assets: SerinusInertiaAssetOptions( +assets: InertiaAssetsOptions( entry: 'src/main.jsx', clientDirectory: 'client', devServerUrl: 'http://127.0.0.1:5174', @@ -118,7 +118,7 @@ npm run build:ssr Then enable this in `lib/app_module.dart`: ```dart -ssr: SerinusInertiaSsrOptions( +ssr: InertiaSsrOptions( enabled: true, manageProcess: true, runtime: 'node', // or 'bun' @@ -148,17 +148,59 @@ Then enable the endpoint-based `ssr:` section in `lib/app_module.dart`. ## Production Build -Build the client bundle: +See [DEPLOY.md](DEPLOY.md) for a full walkthrough covering client and SSR +bundle compilation, Dart server compilation, direct static asset serving from +Serinus, optional front-door proxies, alternative nginx/Caddy asset serving, +and a systemd service unit. + +The short version: ```bash cd client -npm run build +npm run build # builds both the browser bundle and client/dist/ssr.js +cd .. +mkdir -p build +dart compile exe bin/main.dart -o build/server ``` -Then start the Serinus server normally: +The server reads the Vite manifest from `client/dist/.vite/manifest.json` +relative to its working directory, and the example serves production assets +from `client/dist/assets` at `/assets/*`. The deploy guide also shows the +alternative layout where nginx or Caddy serves those same built assets +directly. + +## Docker Compose + +If you want containerized production-style setups, the bundled Compose file +defines separate client-rendered and SSR stacks without an nginx sidecar. + +From this directory: ```bash -dart run bin/main.dart +docker compose --profile client up --build ``` -The example server will read the Vite manifest from `client/dist/.vite/manifest.json`. +Then open . + +The client-rendered stack uses: + +- `client-app` — the compiled Dart server with `client/dist/` copied into the + image and `/assets/*` served directly by Serinus + +For SSR with the same Compose file: + +```bash +docker compose --profile ssr up --build +``` + +That starts: + +- `ssr-renderer` — a Node container running `client/dist/ssr.js` +- `ssr-app` — the compiled Dart server configured to call + `http://ssr-renderer:13714/render` + +Compose waits for `ssr-renderer` to report healthy before starting `ssr-app`. + +The SSR stack publishes port `8081` by default so you can run both stacks side +by side. Override the defaults with `SERINUS_INERTIA_CLIENT_PORT` or +`SERINUS_INERTIA_SSR_PORT` if needed. diff --git a/packages/serinus_inertia/example/compose.yaml b/packages/serinus_inertia/example/compose.yaml new file mode 100644 index 0000000..0f70d50 --- /dev/null +++ b/packages/serinus_inertia/example/compose.yaml @@ -0,0 +1,51 @@ +services: + client-app: + profiles: + - client + build: + context: ../../.. + dockerfile: packages/serinus_inertia/example/Dockerfile.client + target: app + ports: + - "${SERINUS_INERTIA_CLIENT_PORT:-8080}:4000" + restart: unless-stopped + + ssr-renderer: + profiles: + - ssr + build: + context: ../../.. + dockerfile: packages/serinus_inertia/example/Dockerfile.ssr + target: ssr + expose: + - "13714" + healthcheck: + test: + [ + "CMD", + "node", + "-e", + "fetch('http://127.0.0.1:13714/health').then((response)=>process.exit(response.ok?0:1)).catch(()=>process.exit(1))", + ] + interval: 5s + timeout: 3s + retries: 12 + start_period: 2s + restart: unless-stopped + + ssr-app: + profiles: + - ssr + build: + context: ../../.. + dockerfile: packages/serinus_inertia/example/Dockerfile.ssr + target: app + environment: + SERINUS_INERTIA_ENABLE_SSR: "true" + SERINUS_INERTIA_SSR_ENDPOINT: "http://ssr-renderer:13714/render" + depends_on: + ssr-renderer: + condition: service_healthy + ports: + - "${SERINUS_INERTIA_SSR_PORT:-8081}:4000" + restart: unless-stopped From 75a778932c8e1b1b666d704968ad26ae3420e9d0 Mon Sep 17 00:00:00 2001 From: kingwill101 Date: Fri, 17 Apr 2026 19:13:58 -0500 Subject: [PATCH 3/3] feat(skills): add portable inertia frontend skill --- skills/inertia-dart-frontend/SKILL.md | 72 +++++++++ .../inertia-dart-frontend/agents/openai.yaml | 4 + .../references/client-patterns.md | 147 ++++++++++++++++++ .../references/dart-io.md | 90 +++++++++++ .../references/deployment.md | 101 ++++++++++++ .../references/docker.md | 138 ++++++++++++++++ .../references/routed.md | 93 +++++++++++ .../references/serinus.md | 146 +++++++++++++++++ 8 files changed, 791 insertions(+) create mode 100644 skills/inertia-dart-frontend/SKILL.md create mode 100644 skills/inertia-dart-frontend/agents/openai.yaml create mode 100644 skills/inertia-dart-frontend/references/client-patterns.md create mode 100644 skills/inertia-dart-frontend/references/dart-io.md create mode 100644 skills/inertia-dart-frontend/references/deployment.md create mode 100644 skills/inertia-dart-frontend/references/docker.md create mode 100644 skills/inertia-dart-frontend/references/routed.md create mode 100644 skills/inertia-dart-frontend/references/serinus.md diff --git a/skills/inertia-dart-frontend/SKILL.md b/skills/inertia-dart-frontend/SKILL.md new file mode 100644 index 0000000..ae12f9f --- /dev/null +++ b/skills/inertia-dart-frontend/SKILL.md @@ -0,0 +1,72 @@ +--- +name: inertia-dart-frontend +description: Guide LLMs to build, extend, and deploy Inertia Dart frontends efficiently across `inertia_dart`, `routed_inertia`, and `serinus_inertia`. Use when requests involve creating pages or components, wiring a Vite client, mapping Dart-side `component` names to frontend files, installing or scaffolding an Inertia client, adding SSR, or preparing Docker, static-serving, reverse-proxy, or production deployment flows for an Inertia-based Dart project. +--- + +# Inertia Dart Frontend + +Build on the package's existing conventions instead of inventing a new Inertia stack. Detect the server integration first, then load only the reference file that matches the current project. + +## Workflow + +1. Detect the server integration before editing frontend files. + +- Inspect `pubspec.yaml`, imports, and existing route handlers. +- If the project uses `package:serinus/serinus.dart`, read `references/serinus.md`. +- If the project uses `package:routed/routed.dart`, read `references/routed.md`. +- Otherwise treat it as a raw `inertia_dart` app and read `references/dart-io.md`. +- For any frontend task, also read `references/client-patterns.md`. +- If the request mentions deployment, manifests, static asset serving, reverse proxies, or production SSR, also read `references/deployment.md`. +- If the request mentions Docker, Dockerfiles, Compose, container images, or container startup flow, also read `references/docker.md`. + +2. Prefer official scaffolding over hand-rolled setup. + +- Use `dart run inertia_dart:inertia create --framework ` for a new client. +- Use `dart run inertia_dart:inertia install --framework --path ` for an existing Vite project. +- Default to React only when the project has no established adapter and the user did not choose one. +- If the project already has `client/src/main.*`, `client/src/ssr.*`, or a pages directory, extend that structure instead of re-scaffolding it. + +3. Preserve the server-to-client component contract exactly. + +- Match `component: 'Home'` to `client/src/Pages/Home.*`. +- Match nested names like `Users/Index` to `client/src/Pages/Users/Index.*`. +- Keep the scaffolded `import.meta.glob('./Pages/**/*.jsx', { eager: true })` style resolver pattern, adapted to the current framework and extension. +- Do not rename component strings on the Dart side without updating the matching frontend file paths. + +4. Keep rendering mode honest. + +- For Inertia requests, return JSON page payloads and do not wrap them in HTML. +- For first visits, either let the integration render HTML or render `renderInertiaBootstrap(page, body: ssr?.body)` plus resolved asset tags. +- Add SSR only when the user asked for it or the project already contains an SSR runtime and entry file. + +5. Use advanced Inertia props only when they change behavior meaningfully. + +- Use plain serializable props by default. +- Use `LazyProp` or `OptionalProp` for expensive partial reload data. +- Use `DeferredProp` for non-critical sections that should load after first paint. +- Use `MergeProp` and `ScrollProp` for append, prepend, and infinite-scroll flows. +- Use `OnceProp` for values that should not keep re-resolving. + +6. Validate the loop before stopping. + +- Check that component names resolve to real page files. +- Check that dev assets come from the Vite hot file in development and the manifest in production. +- If SSR is enabled, check that the runtime endpoint and bundle path both exist. +- When feasible, run the Dart server and the client dev server together and confirm the first visit and one Inertia navigation work. +- For deployment work, confirm the production build outputs exist and that static assets resolve from the deployment target actually in use, whether that is the Dart process or an explicit proxy. +- For deployment and container work, prefer direct commands and declarative config over new bash wrapper scripts. + +## References + +- Read `references/client-patterns.md` for shared frontend rules, file naming, commands, and SSR/client conventions. +- Read `references/dart-io.md` for raw `inertia_dart` apps built on `dart:io`. +- Read `references/routed.md` for `routed_inertia` apps. +- Read `references/serinus.md` for `serinus_inertia` apps. +- Read `references/deployment.md` for production build, static serving, Docker, proxy, and SSR runtime guidance. +- Read `references/docker.md` for Dockerfiles, Compose profiles, native Serinus asset serving, and SSR container startup guidance. + +## Output Expectations + +- State which integration and client adapter you are targeting before making structural changes. +- Reuse the project's existing file names and directory layout where possible. +- Prefer direct code edits and commands over long architectural explanations. diff --git a/skills/inertia-dart-frontend/agents/openai.yaml b/skills/inertia-dart-frontend/agents/openai.yaml new file mode 100644 index 0000000..a1b61ec --- /dev/null +++ b/skills/inertia-dart-frontend/agents/openai.yaml @@ -0,0 +1,4 @@ +interface: + display_name: "Inertia Dart Frontend" + short_description: "Build frontends with Inertia Dart" + default_prompt: "Use $inertia-dart-frontend to build or extend an Inertia Dart frontend in the current project." diff --git a/skills/inertia-dart-frontend/references/client-patterns.md b/skills/inertia-dart-frontend/references/client-patterns.md new file mode 100644 index 0000000..8df1d7f --- /dev/null +++ b/skills/inertia-dart-frontend/references/client-patterns.md @@ -0,0 +1,147 @@ +# Client Patterns + +Use this file for any frontend task, regardless of server integration. + +## Supported Adapters + +The CLI and package templates support three adapters: + +- React + - `src/main.jsx` + - `src/ssr.jsx` + - `src/Pages/**/*.jsx` +- Vue + - `src/main.js` + - `src/ssr.js` + - `src/Pages/**/*.vue` +- Svelte + - `src/main.js` + - `src/ssr.js` + - `src/Pages/**/*.svelte` + +Prefer the adapter already present in the project. If the project is greenfield +and the user did not specify an adapter, default to React because the CLI +defaults there. + +## Fastest Safe Commands + +Use the package CLI instead of recreating Vite + Inertia boilerplate manually. + +New client: + +```bash +dart run inertia_dart:inertia create my-app --framework react +``` + +Existing Vite app: + +```bash +dart run inertia_dart:inertia install --framework react --path ./client +``` + +The CLI wires: + +- `createInertiaApp` +- `import.meta.glob` page resolution +- `src/ssr.*` +- `src/Pages/Home.*` +- `vite.config.js` +- `inertia_hot_file.js` + +## Component Name Mapping + +Treat the Dart-side `component` value as a path under `client/src/Pages` without the extension. + +Examples: + +- `component: 'Home'` -> `client/src/Pages/Home.jsx` +- `component: 'Users/Index'` -> `client/src/Pages/Users/Index.jsx` + +Do not change one side without the other. + +## Resolver Pattern + +Keep the resolver close to the scaffolded pattern: + +```jsx +resolve: (name) => { + const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }) + return pages[`./Pages/${name}.jsx`] +} +``` + +Use the matching extension for Vue or Svelte. Avoid replacing this with custom dynamic import logic unless the app already has a stable alternative. + +## Client and SSR Entry Rules + +Client-only React entry: + +```jsx +createInertiaApp({ + resolve: ..., + setup({ el, App, props }) { + createRoot(el).render() + }, +}) +``` + +SSR React entry: + +```jsx +createServer(page => + createInertiaApp({ + page, + render: ReactDOMServer.renderToString, + resolve: ..., + setup: ({ App, props }) => , + }), +) +``` + +If the server already injects SSR markup into the page, hydrate instead of replacing the DOM. The Serinus docs use: + +```jsx +if (el.hasChildNodes()) { + hydrateRoot(el, ) + return +} +``` + +## Dev and Production Assets + +Preserve these conventions unless the project already uses different paths: + +- hot file: `client/public/hot` +- manifest: `client/dist/.vite/manifest.json` +- generated Vite helper: `client/inertia_hot_file.js` + +The standard Vite config includes `inertiaHotFile()` so the Dart server can discover the dev server URL from the hot file. + +If you need to generate the helper from Dart, use: + +```dart +await writeInertiaViteHotFilePlugin(Directory('client')); +``` + +## Server-Side Asset Resolution + +When rendering first-visit HTML manually, prefer `InertiaViteAssets` or the higher-level integration instead of hard-coded script tags. + +Typical setup: + +```dart +final assets = InertiaViteAssets( + entry: 'index.html', + hotFile: 'client/public/hot', + manifestPath: 'client/dist/.vite/manifest.json', + includeReactRefresh: true, +); +``` + +## Common Mistakes + +- Creating a page file whose path does not match the Dart `component` string. +- Adding SSR on the client side without starting or configuring an SSR runtime. +- Hand-writing Vite asset tags instead of using `InertiaViteAssets` or the integration's asset support. +- Replacing the scaffolded `import.meta.glob` pattern with something incompatible with nested page names. +- Starting Vite without the hot-file plugin, leaving the Dart server unable to discover the dev origin. diff --git a/skills/inertia-dart-frontend/references/dart-io.md b/skills/inertia-dart-frontend/references/dart-io.md new file mode 100644 index 0000000..0eda991 --- /dev/null +++ b/skills/inertia-dart-frontend/references/dart-io.md @@ -0,0 +1,90 @@ +# Raw `inertia_dart` Apps + +Use this path when the app is built directly on `dart:io` instead of Routed or +Serinus. + +## Local Anchors + +If local code is available, search for: + +- `HttpServer.bind` +- `inertiaRequestFromHttp` +- `buildPageDataAsync` +- `renderInertiaBootstrap` +- `InertiaViteAssets` + +Those are the fastest signals that the project is using the low-level +`inertia_dart` flow. + +## Core Request Flow + +For each request: + +1. Parse the request with `inertiaRequestFromHttp(request)`. +2. Build `PropertyContext` from `inertiaRequest.createContext()`. +3. Build page data with `InertiaResponseFactory().buildPageDataAsync(...)`. +4. Return JSON when `inertiaRequest.isInertia` is true. +5. Otherwise render HTML with `renderInertiaBootstrap(page)` and resolved asset tags. + +Typical shape: + +```dart +final inertiaRequest = inertiaRequestFromHttp(request); +final context = inertiaRequest.createContext(); +final page = await InertiaResponseFactory().buildPageDataAsync( + component: 'Home', + props: {'title': 'Hello'}, + url: _requestUrl(request.uri), + context: context, +); +``` + +## Manual HTML Rendering + +For first visits, render HTML with: + +- `renderInertiaBootstrap(page)` for client-only mode +- `renderInertiaBootstrap(page, body: ssr?.body)` for SSR mode +- `InertiaViteAssets` for styles and scripts + +Avoid hard-coded script tags if the helper already covers the case. + +## Static Assets + +If the server owns asset serving in production, serve `client/dist/assets/*` +and keep the manifest and hot-file paths aligned with the frontend build: + +- `client/dist/.vite/manifest.json` +- `client/public/hot` + +If the project uses a different client directory, adapt the paths consistently. + +## SSR + +Use `HttpSsrGateway` when the user explicitly wants SSR or the app already has +an SSR entry. + +Typical flow: + +1. Build the page JSON. +2. Call `gateway.render(jsonEncode(page.toJson()))`. +3. Merge `ssr.head` and `ssr.body` into the final HTML. + +Common local endpoint default: + +- `http://127.0.0.1:13714/render` + +Useful CLI commands: + +```bash +dart run inertia_dart:inertia ssr:start --runtime node +dart run inertia_dart:inertia ssr:check --url http://127.0.0.1:13714 +dart run inertia_dart:inertia ssr:stop --url http://127.0.0.1:13714 +``` + +## Extension Rules + +- Keep existing request parsing and response writing helpers if the app already has them. +- Add new page files under the frontend pages directory the resolver already uses. +- Add new routes by returning a matching `component` string. +- Use advanced props only where partial reloads, deferred sections, or merge behavior are actually needed. diff --git a/skills/inertia-dart-frontend/references/deployment.md b/skills/inertia-dart-frontend/references/deployment.md new file mode 100644 index 0000000..d370e17 --- /dev/null +++ b/skills/inertia-dart-frontend/references/deployment.md @@ -0,0 +1,101 @@ +# Deployment + +Use this file when the request is about productionizing an Inertia Dart app: +deployment guides, Dockerfiles, static asset serving, reverse proxies, SSR +runtime topology, or smoke-checking a release build. + +## Local Anchors + +If local project files exist, inspect equivalents of: + +- `client/dist/.vite/manifest.json` +- the frontend build directory such as `client/dist/` +- deployment docs such as `DEPLOY.md` +- `Dockerfile*`, `Containerfile`, `compose.yaml`, or `compose.yml` +- systemd units, Procfiles, or platform deploy configs + +If package examples are available locally, they can inform details, but the +skill must still work without them. + +## Production Shape + +The stable deployment pattern is: + +- build the browser bundle into a frontend dist directory +- optionally build an SSR bundle such as `client/dist/ssr.js` +- run the Dart app as the dynamic origin +- serve `/assets/*` from the same deployment root, either directly from Dart or through an explicit front-door proxy +- keep a reverse proxy optional for TLS, host routing, or load-balancing rather than treating it as the only way to expose assets + +## Build Outputs To Expect + +For a production build, confirm these files exist before writing deployment +instructions: + +- the Vite manifest, commonly `client/dist/.vite/manifest.json` +- built frontend assets, commonly `client/dist/assets/*` +- an SSR bundle when SSR is enabled + +Do not treat development artefacts as deployable. In particular, the Vite hot +file must not survive into the deployment layout because it forces the server +to look for a dev server. + +## Deployment Rules + +1. Prefer describing the deployment root relative to the frontend dist directory and the compiled server binary. +2. Call out that the manifest path is read relative to the app working directory. +3. Tell the user when `dart run` requires a full workspace checkout because of `path:` dependencies. +4. Prefer `dart compile exe` for standalone deployments unless the project intentionally deploys the full SDK and workspace. +5. Keep SSR optional. Do not require Node or Bun unless SSR is actually enabled. +6. Do not introduce new bash or shell wrapper scripts in deployment guides. Prefer direct commands, systemd units, Docker `CMD`, Compose health checks, or orchestrator-native readiness. +7. Do not require nginx or Caddy just to serve Vite assets when the app already has a native static-file route. +8. When the user asks for the minimal Serinus-native static-file path, show `serinus_serve_static` with `ServeStaticModule(...)` before reaching for custom controllers. + +## SSR Deployment Rules + +Two acceptable SSR topologies exist: + +1. Managed process + - The Dart app starts Node or Bun itself. + - The bundle path must exist inside the app container or deployment root. + +2. External renderer + - A separate process or container serves `/render` and `/health`. + - The Dart app points at that endpoint and should wait for health in orchestrated environments. + +## Docker Guidance + +When editing or creating Docker docs: + +- separate client-build and server-build stages from the runtime stage +- copy only the compiled server binary and frontend dist directory into the runtime image +- prefer one app container for the client-rendered path plus an optional separate SSR renderer container +- keep the renderer separate unless there is a strong reason to bundle it into the app container +- do not recommend extra `.sh` helpers for startup or deployment unless there is no native alternative in the runtime environment + +It is often useful to keep client-rendered and SSR container topologies separate, +but do not force exact service names or profiles unless the project already has +them. + +## Reverse Proxy Expectations + +For optional nginx or Caddy examples: + +- `/assets/*` must resolve under the built frontend assets directory +- hashed assets should keep long-lived immutable cache headers +- the proxy should forward non-asset routes to the Dart app without rewriting the Inertia paths +- when the guide already documents app-served assets, keep the proxy-served asset layout as an explicit alternative instead of replacing it + +Do not force proxy-only guidance when the app already serves the built assets +correctly. + +## Smoke Checks + +When writing or updating deployment instructions, include checks for: + +- first page load +- one Inertia navigation or partial reload +- manifest presence +- absence of the hot file +- SSR-rendered HTML in view source when SSR is enabled +- asset responses with cache headers from the actual serving layer in use diff --git a/skills/inertia-dart-frontend/references/docker.md b/skills/inertia-dart-frontend/references/docker.md new file mode 100644 index 0000000..6f32c94 --- /dev/null +++ b/skills/inertia-dart-frontend/references/docker.md @@ -0,0 +1,138 @@ +# Docker + +Use this file when the request is specifically about Dockerfiles, Compose, +image layout, container startup behavior, or containerized SSR for an Inertia +Dart app. Shell command examples are fine; standalone bash wrapper scripts are +not the preferred deployment pattern. + +## Local Anchors + +If local project files exist, inspect equivalents of: + +- `Dockerfile*` or `Containerfile` +- `compose.yaml` or `compose.yml` +- the frontend dist directory +- SSR runtime commands or health endpoints +- deployment docs for environment variables and working-directory assumptions + +If package examples are available locally, they can inform details, but the +skill must still work without them. + +## Container Model + +A common production shape is: + +- build stages for the client bundle and the Dart server binary +- an app image that runs the compiled Dart server +- for SSR, a dedicated renderer image that runs the SSR bundle + +Keep that split unless the user explicitly wants a simpler single-image setup. + +## Client-Rendered Dockerfile Shape + +A typical client-rendered Dockerfile defines: + +1. `client-build` + - runs `npm ci` + - runs the frontend production build + +2. `server-build` + - runs `dart pub get` + - compiles the app to a server binary + +3. `app` + - copies only the compiled server binary and frontend dist directory + - exposes the app port + +When editing this file: + +- keep the runtime image small +- avoid copying the full source tree into the final runtime stage +- preserve the frontend dist directory as the asset root the app or proxy serves from + +## SSR Dockerfile Shape + +SSR images commonly add: + +1. `app` + - runs the compiled Dart server + - starts with direct `CMD` instead of a shell wrapper + +2. `ssr` + - installs production Node or Bun dependencies + - runs the SSR bundle + - exposes the renderer port if it is a separate container + +When modifying SSR container flow: + +- keep the renderer separate from the Dart app unless the user explicitly wants to merge them +- keep the renderer health endpoint part of the orchestration contract +- keep the app blocked on renderer health before startup in Compose-style environments +- prefer Compose or orchestrator readiness features over adding new shell wrappers + +## Compose Patterns + +It is often useful to define separate client-rendered and SSR topologies: + +- client-only: app container only, or app plus optional proxy +- SSR: renderer plus app, and optionally a proxy + +Preserve an existing split if the project already has one, but do not force +specific service names. + +## Networking Contracts + +Keep these contracts explicit: + +- the app container port +- the SSR renderer port, if any +- the SSR render endpoint such as `/render` +- the SSR health endpoint such as `/health` +- any cross-container hostnames or env vars the app depends on + +If you change service names in Compose, update the SSR endpoint env vars and +readiness wiring consistently. + +## Static Asset Expectations + +The runtime image should include the built frontend assets, and one of these +layers should serve `/assets/*`: + +- the Dart app itself +- a front-door proxy such as nginx or Caddy + +Keep immutable caching on hashed assets regardless of which layer serves them. + +## Readiness + +Prefer, in order: + +1. Compose `healthcheck` plus `depends_on` +2. orchestrator-native readiness and startup ordering +3. app-level retry logic if the integration owns the SSR client +4. a shell wrapper only if the runtime environment provides no cleaner option + +Do not remove the wait step unless the runtime environment provides an +equivalent readiness gate. + +## Safe Editing Rules + +- Update Dockerfiles, Compose, and readiness wiring together when the topology changes. +- Keep the production asset root aligned with the frontend build output. +- Keep SSR optional. Do not force Node into the client-only path. +- Prefer explicit environment variables over hard-coded cross-container hostnames when generalizing a setup. +- Do not add new bash or shell scripts to deployment guides or container flows unless unavoidable. + +## Smoke Checks + +For client-rendered setups: + +- build and start the container stack +- confirm the first page loads +- confirm `/assets/*` is served correctly + +For SSR setups: + +- confirm the renderer becomes healthy +- confirm the app waits successfully, then starts +- confirm view source shows SSR-rendered markup on first load diff --git a/skills/inertia-dart-frontend/references/routed.md b/skills/inertia-dart-frontend/references/routed.md new file mode 100644 index 0000000..33007f5 --- /dev/null +++ b/skills/inertia-dart-frontend/references/routed.md @@ -0,0 +1,93 @@ +# `routed_inertia` + +Use this path when the project is built on Routed. + +## Local Anchors + +If local code is available, search for: + +- `ctx.inertia(` +- `RoutedInertiaMiddleware` +- `registerRoutedInertiaProvider` +- `InertiaServiceProvider` +- `config/inertia.yaml` + +## Integration Shape + +The main server-side entrypoint is usually `ctx.inertia(...)`. + +Typical route: + +```dart +engine.get('/', (ctx) { + return ctx.inertia( + 'Home', + props: {'title': 'Hello'}, + htmlBuilder: htmlBuilder, + ); +}); +``` + +Use `ctx.inertia(...)` instead of manually recreating the raw `inertia_dart` +request flow unless the app already chose a lower-level path. + +## Setup Choices + +Two common setups exist: + +1. Middleware-first setup + - `RoutedInertiaMiddleware(versionResolver: () => '1.0.0').call` + +2. Config/provider setup + - `registerRoutedInertiaProvider(...)` + - `InertiaServiceProvider(...)` + - config files for HTTP and Inertia options + +Prefer whichever style the project already uses. + +## Assets and HTML + +Projects commonly support both: + +- dev mode from a hot file or explicit dev URL +- production mode from the Vite manifest + +If the app uses custom HTML rendering, keep the `htmlBuilder` aligned with +these rules: + +- inject `ssr.head` when SSR is enabled +- render `renderInertiaBootstrap(page, body: ssr?.body)` +- inject manifest or dev-server tags + +If the app uses a template engine, keep asset injection and the Inertia +bootstrap container in the template instead of duplicating them in code. + +## Config Expectations + +An Inertia config file may carry: + +- `version` +- `root_view` +- history settings +- `ssr.enabled` +- `ssr.url` +- asset paths such as `manifest_path`, `entry`, `base_url`, and `hot_file` + +Prefer adjusting config over scattering those values through route handlers. + +## SSR + +Only add SSR hooks when the user asked for first-visit SSR or the app already +has the runtime in place. + +Keep the project's existing runtime model: + +- separate SSR process +- managed child process +- external SSR endpoint + +## Extension Rules + +- Add frontend pages under the frontend pages directory the resolver already uses. +- Match route component names to page file paths exactly. +- Reuse shared props, flash data, and error-bag helpers like `ctx.inertiaShare`, `ctx.inertiaFlash`, and `ctx.inertiaErrors` instead of inventing ad hoc response metadata. diff --git a/skills/inertia-dart-frontend/references/serinus.md b/skills/inertia-dart-frontend/references/serinus.md new file mode 100644 index 0000000..ce54fb3 --- /dev/null +++ b/skills/inertia-dart-frontend/references/serinus.md @@ -0,0 +1,146 @@ +# `serinus_inertia` + +Use this path when the project is built on Serinus. + +## Local Anchors + +If local code is available, search for: + +- `InertiaModule(` +- `InertiaOptions(` +- `InertiaAssetsOptions(` +- `context.inertia(` +- `InertiaSsrOptions(` + +## Integration Shape + +Register `InertiaModule` once in the root module, then render pages with +`context.inertia(...)`. + +Module setup: + +```dart +InertiaModule( + options: InertiaOptions( + version: '1.0.0', + assets: InertiaAssetsOptions( + entry: 'src/main.jsx', + clientDirectory: 'client', + includeReactRefresh: true, + ), + ), +) +``` + +Controller route: + +```dart +on(Route.get('/'), (context) async { + return context.inertia( + component: 'Home', + props: {'title': 'Hello from Serinus'}, + ); +}); +``` + +Use that high-level path unless the project explicitly wants lower-level +request and response handling. + +## Client Bootstrapping + +The React client usually uses `createInertiaApp` with `import.meta.glob`. + +If SSR markup may already exist, hydrate instead of always replacing the root: + +```jsx +if (el.hasChildNodes()) { + hydrateRoot(el, ) + return +} +``` + +That is the right default for Serinus projects that may switch between +client-only and SSR modes. + +## Asset Handling + +`InertiaAssetsOptions` lets the package inject dev or production assets for +first visits. + +Use: + +- `entry: 'src/main.jsx'` +- `clientDirectory: 'client'` +- optional overrides for `manifestPath`, `hotFile`, `devServerUrl`, and `baseUrl` + +Prefer configuring assets in `InertiaOptions` instead of hand-writing HTML +wrappers unless the project already has a custom `htmlBuilder`. + +For a minimal Serinus static-file setup, prefer the official package: + +```dart +import 'package:serinus_serve_static/serinus_serve_static.dart'; + +ServeStaticModule( + rootPath: '/public', + renderPath: '*', + serveRoot: '', + exclude: const [], + extensions: const ['.html', '.css', '.js'], + index: const ['index.html'], + redirect: true, +) +``` + +Use that when the project just needs a straightforward static directory exposed +by Serinus. + +For production bundles, Serinus can also serve Vite assets itself. One common +pattern is a dedicated controller that exposes `/assets/**` from the built +frontend assets directory and sets content type plus immutable cache headers. +Do not assume nginx is required just to serve hashed frontend assets. Also do +not assume `ServeStaticModule` is always a drop-in replacement for Vite output +layouts where the URL prefix and on-disk directory need different mappings. + +## SSR Choices + +Serinus supports both managed and external SSR runtimes. + +Managed process: + +```dart +ssr: InertiaSsrOptions( + enabled: true, + manageProcess: true, + runtime: 'node', + bundle: 'client/dist/ssr.js', +), +``` + +External endpoint: + +```dart +ssr: InertiaSsrOptions( + enabled: true, + endpoint: Uri.parse('http://127.0.0.1:13714/render'), +), +``` + +CLI helpers for a separate runtime: + +```bash +dart run serinus_inertia:ssr start --bundle client/dist/ssr.js +dart run serinus_inertia:ssr check +dart run serinus_inertia:ssr stop +``` + +Only add SSR when the user asked for it or the project already has the entry +file and runtime workflow. + +## Extension Rules + +- Keep shared defaults in `InertiaOptions` rather than duplicating them in every controller. +- Add frontend pages under the frontend pages directory the resolver already uses. +- Match controller `component` names to those page file paths exactly. +- Use `LazyProp`, `DeferredProp`, `MergeProp`, `ScrollProp`, and `OnceProp` only when their behavior is needed. +- Use `context.inertiaLocation(...)` for location redirects instead of inventing a custom `409` response.