Skip to content

Commit 7d14af9

Browse files
committed
Merge branch 'jack/cloud2'
2 parents f1a7b3d + 5de2d08 commit 7d14af9

44 files changed

Lines changed: 1063 additions & 1115 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/server/.env.example

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# Turso Database Configuration (control-plane DB)
2-
# Required for Vercel deployment
3-
TURSO_DATABASE_URL=libsql://your-database.turso.io
4-
TURSO_AUTH_TOKEN=your-auth-token-here
1+
# Control-plane database (owns sys_*, projects, auth)
2+
#
3+
# unset → file:./.objectstack/data/control.db (local SQLite)
4+
# file:<path> → SQLite at that path
5+
# libsql://host → libSQL / Turso
6+
# http(s)://host → libSQL / sqld over HTTP
7+
#
8+
# OBJECTSTACK_DATABASE_URL=libsql://your-database.turso.io
9+
# OBJECTSTACK_DATABASE_AUTH_TOKEN=your-auth-token-here
510

6-
# Turso Platform API (environment provisioning)
7-
# When set, new environments are provisioned as real Turso cloud databases.
8-
# When unset, each environment gets a local SQLite file under .objectstack/data/environments/.
11+
# Turso Platform API (per-project database provisioning)
12+
# When set, new projects are provisioned as real Turso cloud databases.
13+
# When unset, each project gets a local SQLite file under .objectstack/data/environments/.
914
TURSO_ORG_NAME=your-org-slug
1015
TURSO_API_TOKEN=your-platform-api-token

apps/server/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ EXPOSE 3000
6868
VOLUME ["/data"]
6969

7070
# The container talks to the control plane (local SQLite at /data or remote
71-
# Turso) via env. Override any of these in fly.toml / `docker run -e …`.
72-
ENV OBJECTSTACK_CONTROL_DB=/data/control.db
71+
# libSQL/Turso) via env. Override in fly.toml / `docker run -e …`.
72+
ENV OBJECTSTACK_DATABASE_URL=file:/data/control.db
7373

7474
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
7575
CMD wget -qO- "http://127.0.0.1:${PORT}/api/v1/health" >/dev/null 2>&1 || exit 1

apps/server/README.md

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,69 +17,42 @@ See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed deployment instructions.
1717
- **Zero-Code Backend**: No creating routes or controllers per object.
1818
- **Preview Mode**: Run in demo mode — bypass login, auto-simulate admin identity.
1919
- **Vercel Deployment**: Ready-to-deploy to Vercel with Hono adapter.
20-
- **Dual-mode bootstrap**: single self-hosted kernel *or* per-project kernels fronting a cloud control plane (see below).
20+
- **Control-plane + per-project kernels**: the control plane owns `sys_*` (projects, auth, members); each project gets its own kernel minted on demand by `KernelManager`.
2121

22-
## Bootstrap shapes
22+
## Control-plane database
2323

24-
A single `apps/server` process can run in three shapes, selected by env vars.
25-
See the [Cloud vs Self-Hosted guide](../../content/docs/guides/cloud-deployment.mdx) for the full walkthrough.
26-
27-
### `single` (default)
28-
29-
One `ObjectKernel`, one database, every plugin from `objectstack.config.ts`.
30-
No control plane, no per-project routing. Ideal for local development and
31-
single-project deployments.
32-
33-
```bash
34-
OBJECTSTACK_DATABASE_URL=file:./local.db \
35-
AUTH_SECRET=$(openssl rand -hex 32) \
36-
pnpm dev
37-
# → http://localhost:3000
38-
```
39-
40-
### `multi-project-local`
41-
42-
Control-plane sys_* tables live in a local SQLite file. Projects are created
43-
via Studio / the `/api/v1/cloud/projects` REST endpoint; each project binds
44-
its own driver (sqlite / Turso / postgres). Hostname-based routing delivers
45-
each request to the matching project's kernel.
24+
One env var picks where `sys_*` lives. Everything else (per-project kernels,
25+
Studio routing, template seeding) is the same regardless of the choice.
4626

4727
```bash
48-
OBJECTSTACK_MULTI_PROJECT=true \
49-
OBJECTSTACK_CONTROL_DB=/data/control.db \
50-
AUTH_SECRET=$(openssl rand -hex 32) \
28+
# Default: unset → file:./.objectstack/data/control.db (local SQLite)
5129
pnpm dev
52-
# → http://localhost:3000, routes by Host header → sys_project.hostname
53-
```
5430

55-
### `multi-project-remote`
56-
57-
Same path as `multi-project-local` but the control-plane driver points at a
58-
remote Turso database. Used for SaaS deployments where many replicas share
59-
one sys_* schema.
60-
61-
```bash
62-
OBJECTSTACK_CONTROL_PLANE_URL=https://control.example.com \
63-
TURSO_DATABASE_URL=libsql://control.turso.io \
64-
TURSO_AUTH_TOKEN=... \
31+
# Remote libSQL / Turso:
32+
OBJECTSTACK_DATABASE_URL=libsql://control.turso.io \
33+
OBJECTSTACK_DATABASE_AUTH_TOKEN=... \
6534
AUTH_SECRET=$(openssl rand -hex 32) \
6635
pnpm dev
6736
```
6837

69-
| Env var | Purpose |
70-
| --------------------------------- | ------------------------------------------------------------------------ |
71-
| `OBJECTSTACK_MULTI_PROJECT` | Set to `true` to enable local multi-project mode. |
72-
| `OBJECTSTACK_CONTROL_DB` | Path to the local SQLite control DB (default `./.objectstack/data/control.db`). |
73-
| `OBJECTSTACK_CONTROL_PLANE_URL` | Set to enable remote multi-project mode (value identifies the control plane). |
74-
| `TURSO_DATABASE_URL` | Turso URL for the control DB (required with `OBJECTSTACK_CONTROL_PLANE_URL`). |
75-
| `TURSO_AUTH_TOKEN` | Auth token for the control DB. |
76-
| `OBJECTSTACK_KERNEL_CACHE_SIZE` | LRU size for per-project kernels (default 32). |
77-
| `OBJECTSTACK_KERNEL_TTL_MS` | Idle eviction TTL in ms (default 900000). |
78-
| `AUTH_SECRET` | Better Auth session secret (≥ 32 chars). |
79-
80-
In both multi-project shapes, `OBJECTSTACK_DATABASE_URL` is **not** read on
81-
the data plane — project database URLs and credentials come from sys_project
82-
rows.
38+
| `OBJECTSTACK_DATABASE_URL` value | Resolved driver |
39+
|:---|:---|
40+
| unset | `file:./.objectstack/data/control.db` (SQLite) |
41+
| `file:<path>` / `file:///<path>` / bare path | SQLite at that path |
42+
| `libsql://host` | libSQL / Turso |
43+
| `http(s)://host` | libSQL / sqld over HTTP |
44+
45+
| Env var | Purpose |
46+
|:---|:---|
47+
| `OBJECTSTACK_DATABASE_URL` | Control-plane DB URL. Default: local SQLite. |
48+
| `OBJECTSTACK_DATABASE_AUTH_TOKEN` | Auth token forwarded to libSQL/Turso. Optional. |
49+
| `OBJECTSTACK_KERNEL_CACHE_SIZE` | LRU size for per-project kernels (default 32). |
50+
| `OBJECTSTACK_KERNEL_TTL_MS` | Idle eviction TTL in ms (default 900000). |
51+
| `AUTH_SECRET` | Better Auth session secret (≥ 32 chars). |
52+
53+
`OBJECTSTACK_DATABASE_URL` only configures the control plane — per-project
54+
database URLs and credentials come from `sys_project` rows and are chosen
55+
by the user when they provision a project via Studio / the REST API.
8356

8457
## Setup
8558

apps/server/fly.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fly.toml — ObjectStack Server (multi-project shape)
1+
# fly.toml — ObjectStack Server
22
#
33
# Deploy from the repo root so the monorepo Dockerfile can see the full
44
# workspace:
@@ -14,7 +14,8 @@
1414
# Secrets (never commit — use `fly secrets set …`):
1515
# AUTH_SECRET, OBJECTSTACK_COOKIE_DOMAIN,
1616
# TURSO_ORG_NAME, TURSO_API_TOKEN,
17-
# (optional) TURSO_DATABASE_URL + TURSO_AUTH_TOKEN for multi-project-remote
17+
# (optional) OBJECTSTACK_DATABASE_URL + OBJECTSTACK_DATABASE_AUTH_TOKEN
18+
# — override the default local-SQLite control DB with a remote libSQL.
1819

1920
app = "objectstack-server"
2021
primary_region = "iad"
@@ -55,11 +56,10 @@ kill_timeout = "30s"
5556
destination = "/data"
5657

5758
[env]
58-
# Enable multi-project-local mode by default — control plane lives in the
59-
# SQLite file on the attached volume. Override to multi-project-remote by
60-
# setting OBJECTSTACK_CONTROL_PLANE_URL + TURSO_DATABASE_URL via secrets.
61-
OBJECTSTACK_MULTI_PROJECT = "true"
62-
OBJECTSTACK_CONTROL_DB = "/data/control.db"
59+
# Control plane lives in the SQLite file on the attached volume. Override
60+
# with a remote libSQL/Turso by setting `OBJECTSTACK_DATABASE_URL` (and
61+
# optionally `OBJECTSTACK_DATABASE_AUTH_TOKEN`) via `fly secrets set`.
62+
OBJECTSTACK_DATABASE_URL = "file:/data/control.db"
6363
OBJECTSTACK_KERNEL_CACHE_SIZE = "50"
6464
OBJECTSTACK_KERNEL_TTL_MS = "1800000"
6565
OBJECTSTACK_ENV_CACHE_TTL_MS = "300000"

0 commit comments

Comments
 (0)