|
| 1 | +# ObjectQL Demo |
| 2 | + |
| 3 | +A standalone, deployable demo application for the ObjectQL platform. |
| 4 | +Runs locally with `@objectstack/cli` and deploys to **Vercel** as a serverless function. |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +- **In-memory driver** — zero external database required; data persists across warm Vercel invocations. |
| 9 | +- **Console UI** — full ObjectStack Console available at `/console/`. |
| 10 | +- **Studio UI** — ObjectStack Studio available at `/_studio/`. |
| 11 | +- **Project-Tracker showcase** — ships with the `examples/showcase/project-tracker` metadata (objects, views, permissions) so the demo has real data structures out of the box. |
| 12 | +- **Auth** — Better-Auth based authentication via `@objectstack/plugin-auth`. |
| 13 | + |
| 14 | +## Local Development |
| 15 | + |
| 16 | +```bash |
| 17 | +# From the monorepo root: |
| 18 | +pnpm install |
| 19 | + |
| 20 | +# Start the demo in dev mode: |
| 21 | +pnpm --filter @objectql/demo dev |
| 22 | + |
| 23 | +# Or from the apps/demo directory: |
| 24 | +cd apps/demo |
| 25 | +pnpm dev |
| 26 | +``` |
| 27 | + |
| 28 | +The development server starts on `http://localhost:3000`. |
| 29 | + |
| 30 | +## Vercel Deployment |
| 31 | + |
| 32 | +### Prerequisites |
| 33 | + |
| 34 | +1. A [Vercel account](https://vercel.com). |
| 35 | +2. The [Vercel CLI](https://vercel.com/docs/cli) installed (`npm i -g vercel`). |
| 36 | + |
| 37 | +### Setup |
| 38 | + |
| 39 | +1. **Create a new Vercel project** pointing to this repository. |
| 40 | +2. In **Project Settings → General**, set the **Root Directory** to `apps/demo`. |
| 41 | +3. Configure the following **Environment Variables**: |
| 42 | + |
| 43 | +| Variable | Required | Description | |
| 44 | +|---|---|---| |
| 45 | +| `AUTH_SECRET` | **Yes** (production) | Secret key for signing auth tokens. Generate with `openssl rand -base64 32`. | |
| 46 | +| `AUTH_TRUSTED_ORIGINS` | No | Comma-separated list of additional trusted origins (e.g. `https://myapp.example.com`). | |
| 47 | + |
| 48 | +4. Deploy: |
| 49 | + |
| 50 | +```bash |
| 51 | +# From the monorepo root: |
| 52 | +vercel --cwd apps/demo |
| 53 | + |
| 54 | +# Or for production: |
| 55 | +vercel --cwd apps/demo --prod |
| 56 | +``` |
| 57 | + |
| 58 | +### How It Works |
| 59 | + |
| 60 | +- **`vercel.json`** — Configures Vercel to use a custom build command, allocate 1 GiB memory to the serverless function, and rewrite all requests to the catch-all `api/[[...route]].ts` handler. |
| 61 | +- **`api/[[...route]].ts`** — Bootstraps the full ObjectStack kernel with ObjectQL plugins, the in-memory driver, auth, Console, and Studio. Uses `@hono/node-server`'s `getRequestListener()` to bridge the Vercel serverless runtime with the Hono HTTP framework. |
| 62 | +- **`scripts/build-vercel.sh`** — Builds all required workspace packages (foundation, drivers, plugins, protocols, examples) in the correct dependency order. |
| 63 | +- **`scripts/patch-symlinks.cjs`** — Replaces pnpm workspace symlinks with real copies so Vercel can bundle the function without symlink errors. |
| 64 | + |
| 65 | +### Monorepo Multi-Project |
| 66 | + |
| 67 | +This repository contains two independent Vercel projects: |
| 68 | + |
| 69 | +| Project | Root Directory | Framework | |
| 70 | +|---|---|---| |
| 71 | +| **`apps/site`** | `apps/site` | Next.js (fumadocs) | |
| 72 | +| **`apps/demo`** | `apps/demo` | `null` (custom serverless) | |
| 73 | + |
| 74 | +Each project is configured independently and deployed separately. Changes to one do not affect the other. |
| 75 | + |
| 76 | +## Project Structure |
| 77 | + |
| 78 | +``` |
| 79 | +apps/demo/ |
| 80 | +├── api/ |
| 81 | +│ └── [[...route]].ts # Vercel serverless entry point |
| 82 | +├── scripts/ |
| 83 | +│ ├── build-vercel.sh # Vercel build script |
| 84 | +│ └── patch-symlinks.cjs # pnpm symlink dereference for Vercel |
| 85 | +├── objectstack.config.ts # Local dev configuration |
| 86 | +├── package.json |
| 87 | +├── tsconfig.json |
| 88 | +├── vercel.json |
| 89 | +└── README.md |
| 90 | +``` |
| 91 | + |
| 92 | +## Architecture |
| 93 | + |
| 94 | +``` |
| 95 | + Vercel Edge Network |
| 96 | + │ |
| 97 | + ▼ |
| 98 | + ┌──────────────────┐ |
| 99 | + │ api/[[...route]] │ ← catch-all serverless function |
| 100 | + └────────┬─────────┘ |
| 101 | + │ |
| 102 | + ┌───────────┼───────────┐ |
| 103 | + ▼ ▼ ▼ |
| 104 | + ┌──────────┐ ┌────────┐ ┌──────────┐ |
| 105 | + │ Console │ │ Studio │ │ REST/RPC │ |
| 106 | + │ SPA (/) │ │/_studio│ │ /api/* │ |
| 107 | + └──────────┘ └────────┘ └──────────┘ |
| 108 | + │ │ │ |
| 109 | + └───────────┴───────────┘ |
| 110 | + │ |
| 111 | + ObjectStack Kernel |
| 112 | + (ObjectQL + Auth + |
| 113 | + InMemoryDriver) |
| 114 | +``` |
0 commit comments