Local Setup
Prerequisites
| Tool | Version | Why |
|---|---|---|
| Node.js | 24 (see .nvmrc) | Matches CI and backend/Dockerfile. Other majors mostly work, but build differences will be yours alone. |
| npm | 10+ | Ships with Node 24 |
| Docker Desktop | any recent | Runs the local Postgres |
nvm use / fnm use picks up .nvmrc automatically.
One-command bootstrap
npm run setupThis is idempotent — safe to re-run any time. It:
- Copies
backend/.env.example→backend/.env,frontend/.env.example→frontend/.env.local, and the same forlanding/— without overwriting files that already exist. - Installs dependencies in
backend/,frontend/,landing/anddocs-site/(each keeps its own lockfile; there is no npm workspace hoisting). - Starts Postgres via
docker compose up -d dband waits for it. - Runs the migrations.
If something is off later, npm run doctor reports what without changing
anything.
Running
npm run dev # backend :8080 + dashboard :3001
npm run dev:all # also the landing page on :3002| App | Port | URL |
|---|---|---|
| Backend (Fastify) | 8080 | http://localhost:8080/api/health |
Dashboard (frontend/) | 3001 | http://localhost:3001 |
Landing (landing/) | 3002 | http://localhost:3002 |
Docs (docs-site/) | 3000 | http://localhost:3000 — npm run dev:docs |
npm run dev:all starts the first three; the docs site is separate because it
is rarely needed alongside them. Each app can also be run on its own with
npm --prefix <app> run dev.
Credentials
Everything in backend/.env except DATABASE_URL is optional.
backend/src/config/env.ts validates the environment at boot, and every
integration fails closed when its variables are unset — an unconfigured Stripe
returns 503 BILLING_NOT_CONFIGURED rather than crashing the server. So you only
need to fill in credentials for the feature you are actually working on.
- Which values, and where they come from:
docs/SETUP.md(internal) - Adding a new variable means three edits, or it will work locally and fail
in production:
backend/src/config/env.ts,backend/.env.example, and the--set-env-vars/--set-secretslists in.github/workflows/deploy-backend.yml.
Frontend .env.local can point NEXT_PUBLIC_API_URL at either the local
backend or https://api.ostenai.com to develop the UI against real data.
Database
docker-compose.yml runs Postgres 15 and creates two databases on first start:
| Database | Used by |
|---|---|
osten_ai | local development |
osten_ai_test | tests, via TEST_DATABASE_URL |
npm run db:up # start Postgres
npm run db:migrate # apply pending migrations
npm run db:psql # psql shell into the dev database
npm run db:reset # destroy the volume and rebuild from migrations
npm run db:logs # follow Postgres logs
npm run db:seed:demo # fill (or refill) the demo organizationsMigrations are plain SQL in backend/migrations/, applied by node-pg-migrate
in filename order. Write them additively (add a column, backfill, then stop
reading the old one in a later release). During a deploy the migration job runs
before the new revision takes traffic, so the previous revision briefly serves
against the new schema — a destructive migration takes the site down for that
window.
Demo data
An empty database makes most of the dashboard look broken — every chart is a
zero. npm run db:seed:demo writes three complete demo organizations instead:
| Shape | Why it is there | |
|---|---|---|
| Nordic Gear (Demo) | SEK, pro, approve-only. 10 campaigns across Google, Meta and TikTok; 90 days of daily metrics down to keyword level; GA4 traffic; a connected Shopify store with ~2 500 orders carrying UTM attribution, a product catalogue and product segments; AI recommendations with feedback, and an agent activity log. | The full product, with every panel populated. This is the org to demo from. |
| Fjord Coffee Roasters (Demo) | NOK, starter, auto-pilot. Four campaigns on Google and Meta, a smaller team, GA4 — and no Shopify. | Two things at once: a second row in the organization switcher and the admin list, and the account a customer who only runs ads actually sees. |
| AMÁKA (Demo) | SEK, starter, approve-only. A small roastery modeled on the live customer AMÁKA: their four real products, prices and product photos (served from their Shopify CDN), four campaigns with synthetic numbers, and four Christmas planner drafts with full Swedish copy. | The creative demo. Because the products have real photos, the assistant and Creative Studio render ads and videos of the actual bags, and the drafts open in the wizard ready to walk through. |
The set is deliberately mixed, so both halves of the product get exercised:
the merchant view (orders, catalogue, segments, product-level recommendations)
on Nordic Gear and AMÁKA, and the ads-only view on Fjord Coffee, where those
screens have to degrade gracefully rather than show a broken chart. A test in
backend/test/demoSeed.test.ts pins that split, so adding a store to Fjord
Coffee fails the build rather than quietly removing the ads-only case.
The generator is seeded, so the same day always produces the same account, and the numbers reconcile: ad clicks feed GA4 sessions, ad conversions become attributed Shopify orders, and the stated AOV and break-even ROAS match the orders that were actually written. Without a store there are no orders to write, so GA4's conversions and revenue come from the ad conversions plus the profile's organic share, at its stated average order value — the blended numbers still add up. Re-running replaces the demo organizations and touches nothing else.
npm run db:seed:demo # 90 days, every demo organization
npm run db:seed:demo -- --days 30 # a shorter window
npm run db:seed:demo -- --only nordic-gear # or fjord-coffee, amaka
npm run db:seed:demo -- --firebase # also create the demo logins
npm run db:seed:demo -- --no-access-code # skip the demo invitation codeTwo guards: the seeder refuses any database that is not on localhost unless you
pass --force, and it only creates Firebase logins when you ask for
--firebase (that writes to the shared Firebase project, so it is not something
a setup command should do behind your back).
--no-access-code matters only when the target is not this machine. The seeder
writes DEMO-ACCESS-2026 into access_codes and a few pending access requests
so the super-admin queues have something in them; locally that is the point, and
on production it is a working invitation code. Seeding production is covered by
"Keeping the demo current" in docs/super-admin.md (internal).
Without --firebase there is no password to sign in with — reach the demo org
by signing in as a super admin and using Open as customer on
/admin/organizations. The seeder prints a direct link for each organization.
Super admin
SUPER_ADMIN_EMAILS in backend/.env only promotes an account at signup,
so it cannot help an account that already exists. To promote one:
npm run db:super-admin -- --list
npm run db:super-admin -- you@example.com
npm run db:super-admin -- you@example.com --revokeSign out and back in afterwards — the dashboard caches the profile.
The role unlocks /admin in the dashboard, every /api/admin/* route, and
access to any organization (which is what Open as customer on
/admin/organizations uses). While viewing a customer's account a banner says
so and carries the way out. docs/super-admin.md covers it in full — it is
internal, so it is not part of this site.
Using Neon instead of the Docker Postgres
Production runs on Neon, and npm run setup / npm run doctor follow
DATABASE_URL rather than assuming a container. There are two ways to develop
against Neon.
A Neon branch. Create a development branch in the Neon console and put its
pooled connection string in backend/.env:
DATABASE_URL="postgresql://USER:PASSWORD@ep-xxx-pooler.eu-central-1.aws.neon.tech/neondb?sslmode=require"npm run setup then skips Docker entirely, verifies the connection, and stops
short of migrating: a remote database is never migrated implicitly, because
setup is what people run when something looks broken and the URL might be
pointing at production. Apply the schema yourself once you are sure of the
target:
npm run db:migrate # or: npm run setup -- --remote-migrateNeon Local. An ephemeral branch on localhost:5433, created when the
container starts and deleted when it stops:
# NEON_API_KEY and NEON_PROJECT_ID in a root .env (gitignored) or your shell
docker compose --profile neon up -d neon-localDATABASE_URL="postgresql://neon:npg@localhost:5433/neondb?sslmode=disable"npm run doctor labels both modes so the target is never in doubt. In either
mode db:up, db:reset and db:psql still mean the Docker Postgres — they are
the local container's commands, and db:reset refuses to run when
DATABASE_URL points somewhere it cannot reset. Tests always need a local
database (see below).
Testing
npm run verify # typecheck + lint + test everywhere. Run this before pushing.What each app has, and how to run just that app:
| App | Unit tests | End-to-end | Run it |
|---|---|---|---|
backend | 152, backend/test/ | — | npm run test:backend |
frontend | 45, colocated __tests__/ | 4 Playwright specs, frontend/e2e/ | npm run test:frontend, npm run test:e2e:frontend |
landing | 9, landing/lib/__tests__/ | 12 Playwright specs, landing/e2e/ | npm run test:landing, npm run test:e2e:landing |
docs-site | — | — | npm run build:docs (a broken docs build or a failed allow-list check is the failure mode) |
npm run test # all unit tests: backend + frontend + landing
npm run test:e2e # all Playwright suites (each starts its own dev server)
npm run test:coverage # backend coverage report -> backend/coverage/Playwright needs its browser once per machine:
npx --prefix frontend playwright install chromiumThe landing suite covers what breaks quietly on a marketing site: every static
route still 200s (the legal pages are referenced by the Google/Meta/TikTok/
Shopify OAuth app registrations, so a 404 there can fail a platform review),
every blog post in lib/blog-data.ts renders, an unknown slug 404s instead of
rendering an empty post, and no call-to-action link contains undefined —
which is what the signup buttons degrade to when NEXT_PUBLIC_APP_URL is
missing at build time.
Backend tests mock src/db/pool, so they need no running database. The one
thing that does is npm run db:migrate — and CI verifies that separately by
applying every migration to an empty database on each run.
The tests cannot touch a real database
backend/test/setup.ts runs before every test file and aborts the whole suite
unless DATABASE_URL:
- has
NODE_ENV=test, - resolves to a loopback host (so no Neon, Cloud SQL, staging box, or tunnel), and
- names a database ending in
_testor_ci(so the local dev database is refused too — a fixture that truncates tables would otherwise eat your data).
Mocking src/db/pool is a convention, not a guarantee; one test that forgets,
plus a TEST_DATABASE_URL left over in a shell, is all it takes. This check
turns that into a refusal before the first test runs:
Refusing to run the test suite.
DATABASE_URL points at host "ep-cool-1.eu-central-1.aws.neon.tech", which is not local.To point tests at a different local database, set TEST_DATABASE_URL.
Watch mode while working on one area:
npm --prefix backend run test:watchRunning the production images locally
Day-to-day development runs on the host — bind-mounting node_modules into a
container makes Next.js fast refresh painfully slow. To smoke-test the actual
Dockerfile that ships to Cloud Run:
docker compose --profile full up --buildAuth & org headers
- The frontend
apiClientattaches the FirebaseAuthorizationheader andx-organization-idfrom the selected organization automatically. Prefer it over rawfetch, which will 401 or 400. - Every org-scoped query must filter on
organization_id; seedocs/MULTI_TENANT_SECURITY.md(internal).
Troubleshooting
| Symptom | Cause / fix |
|---|---|
npm run dev exits immediately with "Invalid environment configuration" | A required variable is missing from backend/.env. The message names it. |
| Backend starts but every request 500s on the database | Postgres is not running: npm run db:up |
relation "..." does not exist | Pending migrations: npm run db:migrate |
| Port 3001 or 8080 already in use | An earlier npm run dev is still alive. On Windows: netstat -ano | findstr :3001 then taskkill /PID <pid> /F |
Docker errors on npm run setup | Docker Desktop is not running |
| Tests time out on the first test of a file | Cold transform cache. vitest.config.ts allows 30s; a second run is much faster. |
| Lint or build behaves differently from CI | Node version drift — npm run doctor checks it against .nvmrc |
More: troubleshooting.md.