docs: add project overview
This commit is contained in:
parent
0f017e6e2f
commit
60fdbf5eff
177
docs/PROJECT_OVERVIEW.md
Normal file
177
docs/PROJECT_OVERVIEW.md
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
# AR-Test — Project Overview
|
||||||
|
|
||||||
|
AR-Test ("AR Studio") is thob.studio's AR service for client companies. Each client is a **project** with its own logo; admins add the client's 3D models to it, and each model gets a QR code. When a customer scans it, a mobile page opens with the **client's logo** (thob's mark stays top-right) and shows the model in Augmented Reality (AR) in their room.
|
||||||
|
|
||||||
|
- **Frontend:** React Router v7 (framework mode), React 19, Tailwind CSS v4, served by `react-router-serve` on port 3000
|
||||||
|
- **Backend:** PocketBase (auth, database, and file storage). There is no custom server code.
|
||||||
|
- **3D/AR rendering:** Google `<model-viewer>` 4.0.0, loaded from a CDN
|
||||||
|
- **Production:** `ar.thob.studio` (app) and `pb.ar.thob.studio` (PocketBase), behind Traefik with Let's Encrypt, on a DigitalOcean droplet
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. How it works
|
||||||
|
|
||||||
|
```
|
||||||
|
Admin (browser) PocketBase Customer (phone)
|
||||||
|
─────────────── ────────── ────────────────
|
||||||
|
/login ── authWithPassword ──▶ users
|
||||||
|
/ (dashboard)
|
||||||
|
create asset ──────────────▶ ar_assets (glb / usdz)
|
||||||
|
generate QR (client-side)
|
||||||
|
upload QR PNG ─────────────▶ ar_assets.qr_image
|
||||||
|
scan QR ─▶ /ar/:id
|
||||||
|
ar_assets.getOne ◀──────────── (public)
|
||||||
|
GLB / USDZ files ─────────────▶ <model-viewer>
|
||||||
|
→ WebXR / Scene Viewer / Quick Look
|
||||||
|
```
|
||||||
|
|
||||||
|
All data loading runs **in the browser** (`clientLoader` / `clientAction`). The PocketBase SDK talks to PocketBase directly from the browser. The server only renders the HTML shell.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Routes
|
||||||
|
|
||||||
|
Registered in [app/routes.ts](../app/routes.ts). File names follow the URL ([FRONTEND_RULES.md §4](FRONTEND_RULES.md)).
|
||||||
|
|
||||||
|
| Path | File | Purpose |
|
||||||
|
|---|---|---|
|
||||||
|
| (layout) | `routes/admin/layout.tsx` | Sign-in guard; loads projects + counts + settings; sidebar; shared dialogs |
|
||||||
|
| `/` | `routes/admin/index.tsx` | Redirects to `/projects` |
|
||||||
|
| `/projects` | `routes/admin/projects/index.tsx` | Client grid with Active/Archived tabs; project create/update action |
|
||||||
|
| `/projects/:id` | `routes/admin/projects/$id.tsx` | Client header (logo, details) + its assets |
|
||||||
|
| `/assets` | `routes/admin/assets/index.tsx` | All assets with filter chips (`?filter=all\|unassigned\|<projectId>`); asset create/update/delete action |
|
||||||
|
| `/assets/:id` | `routes/admin/assets/$id.tsx` | QR (PNG/SVG download, link), details, live customer view |
|
||||||
|
| `/settings` | `routes/admin/settings.tsx` | Branding toggles |
|
||||||
|
| `/preview/:id` | `routes/admin/preview.$id.tsx` | Old links → `/assets/:id` |
|
||||||
|
| `/login` | `routes/login.tsx` | Sign-in (guests only) |
|
||||||
|
| `/ar/:id` | `routes/ar.$id.tsx` | **Public** AR page that QR codes open |
|
||||||
|
|
||||||
|
### 2.1 Projects (client companies)
|
||||||
|
- A project has a company name, an optional or required logo (see Settings), a **logo background** (Light / Dark preset or any custom colour, so white logos stay visible on the light AR page), the AR **button style** (colour, text colour, label and size: Small, Medium, Large, Full width, or Custom with exact height, width, side padding, corner radius and border), the **AR page layout** (see 2.4), a description and a status (active/archived).
|
||||||
|
- Colours are chosen with presets, the system colour picker, or a typed hex code. A custom logo background is classed as light or dark automatically so a missing logo's fallback text stays readable.
|
||||||
|
- The project dialog shows a **live AR page preview** that updates as you type, upload or pick colours. Only the form column scrolls; the title, preview and buttons stay in place.
|
||||||
|
- Logos: PNG/WebP up to 2 MB. With "Accept SVG logos" on, SVGs are converted to PNG in the browser before upload, so SVG files (which can contain scripts) are never stored.
|
||||||
|
- Projects without a logo show the company name instead.
|
||||||
|
|
||||||
|
### 2.2 Assets
|
||||||
|
- Every asset belongs to one project, or is **unassigned** (older assets). Moving an asset into a project never changes its URL, so printed QR codes keep working and start showing the client logo.
|
||||||
|
- The asset dialog has a project picker and, when the project has a logo, a **"Client logo on QR code"** switch (default from Settings).
|
||||||
|
- QR codes are generated in the browser from the asset's AR URL: error correction **H** when branded, **M** otherwise. A branded code clears a square of modules in the centre and places the logo inside it (on the project's logo background colour), so it is part of the code rather than a card laid over it. The screen and both downloads (PNG about 1000 px, or SVG with the logo embedded) are drawn from the same SVG in `lib/assets/qr.ts`.
|
||||||
|
|
||||||
|
### 2.3 Settings (toggles)
|
||||||
|
|
||||||
|
| Toggle | Effect |
|
||||||
|
|---|---|
|
||||||
|
| Require a company logo | Projects can't be saved without a logo |
|
||||||
|
| Accept SVG logos | SVG uploads allowed (converted to PNG) |
|
||||||
|
| Client logo on QR codes | Default for new assets' branded QR switch |
|
||||||
|
| Per-project button style | Projects can set the button's colour, text colour, label and size |
|
||||||
|
|
||||||
|
### 2.4 AR page (public)
|
||||||
|
- Client logo top-left in its backing chip (client's backing colour), the model name under it, thob's "t." top-right, the 3D model, and the button: "View in your space" in thob orange unless the project sets its own colour, text colour, label and size.
|
||||||
|
- Each project can change the layout (project dialog → "AR page"): **top and bottom bars** (off lets the model fill the whole screen, with the logo and button over it), **model name**, **logo backing** (off shows the logo on its own) and **thob logo**. All are on by default, which is the look above.
|
||||||
|
- Unassigned assets show only the thob logo. Missing assets show "Model not found".
|
||||||
|
|
||||||
|
### 2.5 Login (public)
|
||||||
|
- Split layout: an animated showcase on the left and the sign-in form in a fixed column on the right. The showcase tells a three-step story (scan the tag → open the AR page → place it in the room) on a phone whose screen changes with each step. Steps move on every 3.6 s and can be clicked; with reduced motion they wait for clicks.
|
||||||
|
- Responsive: side by side from 960 px (text beside a tilted phone from 1200 px), form above the showcase from 640 px, form only on phones.
|
||||||
|
- The illustration uses a made-up client, "Oakline Interiors", and a sofa photo with its background removed (`public/images/demo/`). Its QR code is a fixed image (`public/images/demo/qr-code.svg`) that opens thob.studio. The phone screens use plain backgrounds.
|
||||||
|
- Form: email, password (Show/Hide, Caps Lock warning), "Keep me signed in for 30 days" (on by default). Off ends the session when the browser closes. Wrong credentials show one banner and mark both fields, without saying which was wrong. Typing clears the banner and that field's error. The button shows "Signing in…" and then a green "Signed in. Opening AR Studio" while the admin loads.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Code layout
|
||||||
|
|
||||||
|
```
|
||||||
|
app/
|
||||||
|
routes/ login, ar.$id, not-found, admin/{layout, index, settings, preview.$id, projects/*, assets/*}
|
||||||
|
components/
|
||||||
|
ui/ primitives (Text, Button, Input, Field, Dialog, Select, Sheet, Switch, …) and
|
||||||
|
cross-feature pieces: ClientLogo, LogoTile, ArPage, ArPagePreview, PhoneFrame
|
||||||
|
admin/ sidebar/*, admin-dialogs-provider
|
||||||
|
projects/ list/ (card, header, unassigned banner), detail/ (header, meta), form/ (dialog, fields, logo, colour, preview)
|
||||||
|
assets/ asset-qr, delete-asset-dialog, list/ (card, list, filters, pagination), form/ (dialog, project select,
|
||||||
|
branded switch, model source), detail/ (header, QR panel, details, customer view)
|
||||||
|
ar-viewer/ ar-scene
|
||||||
|
settings/ setting-toggle
|
||||||
|
auth/ form/ (panel, form, password input, sign-in button, access note),
|
||||||
|
showcase/ (showcase, story steps, phone, scan/open/place screens, armchair)
|
||||||
|
services/ pocketbase, auth, assets, projects, settings, asset-media (file URLs, brand, button colour)
|
||||||
|
schemas/ assets/asset-form, projects/project-form, auth/login (email, password, remember)
|
||||||
|
hooks/ admin/ (data, dialogs, active nav), assets/use-qr-svg, projects/use-project-form-brand, …
|
||||||
|
lib/ qr, qr-export, form-data (assets, projects), logo-file, pagination, format, browser, errors
|
||||||
|
data/ routes, brand, assets/, projects/, settings/, ar-viewer/, auth/ (login story, demo client, errors)
|
||||||
|
types/ asset, project, settings, action, auth
|
||||||
|
pb_migrations/ Tracked PocketBase migrations (local `yarn pb` and production both read this folder)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Configuration
|
||||||
|
|
||||||
|
| Variable | Used for | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `VITE_POCKETBASE_URL` | PocketBase client base URL | **Baked in at build time.** Falls back to `http://127.0.0.1:8099` when unset. A localhost/127.0.0.1 value is swapped for the address the page was opened with (`lib/local-url.ts`), so a phone on the same network reaches the laptop. The same applies to `VITE_FRONTEND_URL` in QR codes. |
|
||||||
|
| `VITE_FRONTEND_URL` | URL encoded in QR codes | **Baked in at build time.** Falls back to the current site origin when unset. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. PocketBase data model
|
||||||
|
|
||||||
|
Created by [pb_migrations/1791850000_projects_and_settings.js](../pb_migrations/1791850000_projects_and_settings.js) and [1791860000_project_button_style.js](../pb_migrations/1791860000_project_button_style.js), the AR page layout in [1791880000_project_ar_page.js](../pb_migrations/1791880000_project_ar_page.js), with the login token length in [1791870000_users_token_30_days.js](../pb_migrations/1791870000_users_token_30_days.js) (except `ar_assets`, which predates tracked migrations).
|
||||||
|
|
||||||
|
**`projects`** — list: signed-in; view: public (the AR page expands it); create/update: signed-in; delete: superusers only. `ar_page` (JSON) holds the AR page layout and button size; missing keys use the defaults in `data/projects/constants.ts`, so new options need no migration.
|
||||||
|
|
||||||
|
| Field | Type | Notes |
|
||||||
|
|---|---|---|
|
||||||
|
| `name` | text, required | Company name |
|
||||||
|
| `logo` | file | PNG/WebP, ≤ 2 MB |
|
||||||
|
| `logo_bg` | select `light`/`dark`, required | Preset, or the contrast class of a custom colour |
|
||||||
|
| `logo_bg_color` | text `#rrggbb` | Custom backing colour; empty = the preset |
|
||||||
|
| `brand_color` | text `#rrggbb` | Button colour; empty = thob orange |
|
||||||
|
| `button_text_color` | text `#rrggbb` | Empty = white |
|
||||||
|
| `button_label` | text ≤ 32 | Empty = "View in your space" |
|
||||||
|
| `description` | text | Internal note |
|
||||||
|
| `status` | select `active`/`archived`, required | |
|
||||||
|
|
||||||
|
**`ar_assets`** — as before, plus `project` (relation → projects, optional; empty = unassigned) and `branded_qr` (bool). `qr_url` is still written on create; `qr_image`/`qr_file` are no longer used (QR codes are generated on the fly).
|
||||||
|
|
||||||
|
**`app_settings`** — one record: `logo_required`, `allow_svg_logos`, `branded_qr_default`, `brand_button`. Read: public (the AR page needs `brand_button`); update: signed-in.
|
||||||
|
|
||||||
|
**`project_asset_counts`** — view collection (`id`, `asset_count`) for the sidebar and project cards; signed-in only.
|
||||||
|
|
||||||
|
**`users`** — auth collection for admin login. Sessions last 30 days ([1791870000_users_token_30_days.js](../pb_migrations/1791870000_users_token_30_days.js)). With "Keep me signed in" off, `services/auth.ts` ends the session when the browser closes, using a cookie with no expiry date.
|
||||||
|
|
||||||
|
**Asset URL rule:** an uploaded file wins over an external URL (`services/asset-media.ts`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Build and deploy
|
||||||
|
|
||||||
|
| Command | What it does |
|
||||||
|
|---|---|
|
||||||
|
| `yarn dev` | Vite dev server on `:5173`, `host: true` |
|
||||||
|
| `yarn pb` | This project's local PocketBase on port `8099`, reachable from the local network (admin UI at `/_/`), applying `pb_migrations/` |
|
||||||
|
| `yarn build` | Production build to `build/client` and `build/server` |
|
||||||
|
| `yarn start` | `react-router-serve ./build/server/index.js` on `:3000` |
|
||||||
|
| `yarn typecheck` | `react-router typegen && tsc` |
|
||||||
|
|
||||||
|
- **Docker:** a multi-stage `node:20-alpine` build. `VITE_*` values are passed as build `ARG`s with no defaults, so export them before running `build-and-push.sh`.
|
||||||
|
- **`build-and-push.sh`:** runs `doctl registry login`, then builds `linux/amd64` and pushes `registry.digitalocean.com/thob-blr1/ar:<sha>` and `:latest`.
|
||||||
|
- **`docker-compose.yml`** runs three services:
|
||||||
|
- `traefik`: TLS through Let's Encrypt, and redirects HTTP to HTTPS
|
||||||
|
- `app`: the `ar:latest` image, with `pull_policy: always`
|
||||||
|
- `pocketbase`: `ghcr.io/muchobien/pocketbase`, with the volume `pb_data` and `./pb_migrations` mounted
|
||||||
|
- Hostnames: `ar.thob.studio`, `pb.ar.thob.studio`, `traefik.ar.thob.studio`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Known issues
|
||||||
|
|
||||||
|
- **`ar_assets` writes are open.** Its API rules are empty (`''`), so anyone can create, edit or delete assets through the REST API. Recommended: list/view public, create/update/delete `@request.auth.id != ""`. (The new `projects` and `app_settings` collections are already locked down.)
|
||||||
|
- **Traefik dashboard is exposed without authentication** (`--api.insecure=true`, port 8080).
|
||||||
|
- **`ar_assets` itself isn't in a tracked migration** (it was created before `pb_migrations/` was used). New schema changes go in `pb_migrations/`; changes made in the PocketBase dashboard while `yarn pb` runs are written there automatically.
|
||||||
|
- **`pocketbase/pocketbase` binary is committed** even though `.gitignore` lists it.
|
||||||
|
- **`.env` is not in `.dockerignore`,** so it is copied into the image (shell build args still take priority).
|
||||||
|
- **Compose sets `VITE_*` as runtime env,** which has no effect because the values are baked in at build.
|
||||||
|
- **No automated tests.**
|
||||||
Loading…
x
Reference in New Issue
Block a user