Docs / AR Experiences

Build the app with an AI assistant

Everything an AR app needs is in your Studio experience and the @maravilla/ar SDK. That makes it a good job to hand to a coding assistant — Claude Code, Cursor, or similar — as long as the prompt names the facts the assistant cannot guess.

With the Studio skill the assistant already knows those facts. Without it, the standalone prompt below is written so the result works the first time: it fixes the framework, tells the assistant where the SDK comes from, how to read the experience, what the page must do, and how to check itself.

Before you start

  1. Author and publish your experience (Author an AR experience), and note its path — the name you see in the address bar after /assets/, for example birthday-invitation.
  2. Have your Studio’s API key at hand (RAISINDB_API_KEY) and keep it out of the prompt: it goes into a .env file.
  3. Have Node 22 or newer.

Studio ships a skill for exactly this job, studio-ar-experiences. On a Studio project it is already there: maravilla update re-fetches the studio-* skills along with the Studio package, so there is nothing to download. Run it after enabling Studio and whenever Studio announces a new version.

maravilla update
ls .claude/skills/studio-ar-experiences    # confirm it is installed

The assistant loads the skill when your request matches it (AR, a card with a QR code, placing blocks, embedding in a site) — you can also name it. It knows the content model, how to author a scene as YAML, the QR → page → camera flow, how to embed the viewer in a site and the traps that cost people an afternoon. So the request only has to say what you want, not how.

Example requests

Build the page for an experience you already authored:

Use the studio-ar-experiences skill. My AR experience is /birthday-invitation
in the studio repository, compiled and published. Build the /ar/[name] page in
this SvelteKit app: the printed card has a QR code that opens it, so the first
screen should say "tap Start AR, then look at the card". Show the buttons
from the scene, and check yourself with the skill's checks.

Create the experience content itself as files:

Use the studio-ar-experiences skill. Add an AR scene to the "business-card"
target of /spring-campaign: a heading "Hello" above the card and a purple
spinning cube standing on it, as YAML in raisin-package/content/assets.

Both stay short because the skill carries the facts. If the assistant skips the skill, say its name — or use the standalone prompt below.

The standalone prompt (no skill)

For an assistant that cannot load Studio skills, or for a project that is not a Studio project, this prompt carries the facts itself. It is longer and goes stale faster than the skill, so prefer the skill when you can.

Copy this into your assistant in an empty folder (the skill-using requests above need no copy-paste). Change the three lines marked ← yours.

Build me a small web app that brings a printed birthday invitation to life with augmented reality. When a guest points their phone camera at the printed card, the overlay from my Maravilla Studio AR experience appears on top of it.

## Use the Studio skill
If a `studio-ar-experiences` skill is available, load it before writing code and follow it. It is the source of truth for the content model, placement units, the QR → page → camera flow and the SDK's traps. If it is not available, follow the rules below.

## What already exists in Studio
- An AR experience at path `/birthday-invitation` in the `assets` workspace of the `studio` repository.   ← yours
- It is compiled and published. Its content is delivered by the `@maravilla/ar` SDK. Use that SDK; do not write your own MindAR or A-Frame code.

## Setup
- Framework: SvelteKit (Svelte 5, TypeScript), Node 22+.   ← yours (or "React Router 7 in framework mode")
- `@maravilla/*` packages come from the Maravilla registry. Create `.npmrc` containing exactly:
  `@maravilla:registry=https://solutas.registry.maravilla.cloud/-/npm`
  then install `@maravilla/ar`.
- Environment variables, read from `process.env` at request time, with a `.env.example`: `RAISINDB_URL` (e.g. `https://studio.example.com`), `RAISINDB_API_KEY`, `RAISINDB_REPO` (default `studio`). The API key must never reach the browser.
- Use no database client library: the SDK talks to RaisinDB over plain HTTP.
- `vite dev` does not load `.env` into `process.env`. Make `npm run dev` do it (for example `node --env-file-if-exists=.env ./node_modules/vite/bin/vite.js dev`) and add `@types/node` so `process` type-checks.
- Use relative imports for your own modules; do not rely on the `$lib` alias, which newer SvelteKit versions no longer provide.

## What to build
1. `GET /api/ar/[name]` (server only): call `loadExperience({ path: '/<name>', repository, baseUrl, apiKey, signAsset })` from `@maravilla/ar/server`, with the three environment variables. Return the manifest as JSON. Map an error whose `code` is `AR_NOT_FOUND` or `AR_NOT_COMPILED` to 404 and any other error to 502.
2. `signAsset` returns a URL on this server: `/media/<path>`. *(Optional: if the RaisinDB endpoint already answers `Range` with `206` and CORS for this origin, omit `signAsset` and step 3; the assistant should check with `curl -H 'Range: bytes=0-1'` against a signed video URL first.)*
3. `GET /media/[...path]` (server only): a same-origin media proxy. Get the file's URL from `signAssetUrl({ baseUrl, apiKey, repository, path })` exported by `@maravilla/ar/server`, fetch it, and send it back. It MUST answer `Range` requests with `206` and a `Content-Range` header, and send `Cache-Control: public, max-age=31536000, immutable` for paths under `/.ar-bundles/`.
4. A page at `/ar/[name]`, mobile first. The printed card carries a QR code that opens exactly this URL, so the visitor arrives from a QR scan: the first screen must make clear what to do next (tap Start AR, then look at the card).
   - A welcome screen with a large "Start AR" button. The camera starts only from that tap.
   - Import `@maravilla/ar` only on the client (never at module top level on the server). Call `detectArSupport()`; if unsupported (for example inside an Instagram or WhatsApp in-app browser) show a plain explanation and an "Open in Safari or Chrome" instruction instead of a broken camera.
   - Fetch the manifest, `mountArViewer(host, manifest)`, then `viewer.start()`.
   - Show "Point your camera at the card" until `targetFound`, hide it then, show it again on `targetLost`.
   - Draw `viewer.overlayButtons` as real HTML buttons over the camera (`block.label` is the text, `fire()` runs it), showing only those whose `visible` is true and updating on the `buttonVisible` event (`{ blockId, visible }`; match `blockId` to the button's `id`). Handle `blockAction`: `url` opens the link, `share` uses `navigator.share` when available, `event` is logged.
   - A friendly message with a retry button when the manifest cannot be loaded or the camera is denied.
   - `viewer.destroy()` when the page is left.
5. A `README.md` with the run commands and a note on where the experience name comes from.

## Rules
- Do not guess the SDK's API. After installing, read `node_modules/@maravilla/ar/README.md` and `types/*.d.ts` and use only what they document.
- When you are done, start the dev server and check yourself: request `/api/ar/birthday-invitation` and confirm `targets[0].scenes[0].blocks` exists; request the `bundleUrl` with `Range: bytes=0-99` and confirm `206`; request `/api/ar/does-not-exist` and confirm `404`. Report the results; fix anything that fails before reporting.

Other things to build

Keep the “Setup” and “Rules” sections and replace the story:

A business card. “…a digital business card. Pointing the camera at the printed card shows the person’s name and role floating above it and three buttons — Call, Save contact, Visit website — taken from the experience’s AR Button blocks. Add a /ar/[name]/card fallback page that shows the same details as plain HTML for people whose browser cannot run AR.”

A product label. “…a product experience. Pointing the camera at the label plays the product video on it. The page needs a mute/unmute control, because browsers only autoplay muted video, and a ‘Buy now’ button from the experience.”

A poster that changes by language. “…choose the scene by the visitor’s language: the manifest has several scenes per target, each with a rule; show the first scene whose rule matches, otherwise the first one.” (The viewer shows the first active scene itself; scene rules are evaluated by your app.)

Checking the result on a phone

The checks in the prompt prove the server half. The camera half needs a real device and a secure origin:

  1. Run the app, then expose it over HTTPS (a tunnel such as cloudflared or ngrok, or your staging host) — phones only open the camera on https:// pages.
  2. Open the page in Safari or Chrome, not inside another app.
  3. Tap Start AR, allow the camera, and point it at the printed card or at the artwork on another screen.

If nothing is detected, it is almost always the artwork — see choosing the artwork.

Pilot documentation. Studio is in a partner pilot. Screens and YAML shown here are current as of the version noted on each page; tell your Maravilla contact when something does not match what you see.