ØSTEN AI

Local Setup

Prerequisites

ToolVersionWhy
Node.js24 (see .nvmrc)Matches CI and backend/Dockerfile. Other majors mostly work, but build differences will be yours alone.
npm10+Ships with Node 24
Docker Desktopany recentRuns the local Postgres

nvm use / fnm use picks up .nvmrc automatically.

One-command bootstrap

npm run setup

This is idempotent — safe to re-run any time. It:

  1. Copies backend/.env.example → backend/.env, frontend/.env.example → frontend/.env.local, and the same for landing/ — without overwriting files that already exist.
  2. Installs dependencies in backend/, frontend/, landing/ and docs-site/ (each keeps its own lockfile; there is no npm workspace hoisting).
  3. Starts Postgres via docker compose up -d db and waits for it.
  4. 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
AppPortURL
Backend (Fastify)8080http://localhost:8080/api/health
Dashboard (frontend/)3001http://localhost:3001
Landing (landing/)3002http://localhost:3002
Docs (docs-site/)3000http://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-secrets lists 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:

DatabaseUsed by
osten_ailocal development
osten_ai_testtests, 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 organizations

Migrations 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:

ShapeWhy 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 code

Two 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 --revoke

Sign 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-migrate

Neon 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-local
DATABASE_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:

AppUnit testsEnd-to-endRun it
backend152, backend/test/—npm run test:backend
frontend45, colocated __tests__/4 Playwright specs, frontend/e2e/npm run test:frontend, npm run test:e2e:frontend
landing9, 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 chromium

The 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 _test or _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:watch

Running 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 --build

Auth & org headers

  • The frontend apiClient attaches the Firebase Authorization header and x-organization-id from the selected organization automatically. Prefer it over raw fetch, which will 401 or 400.
  • Every org-scoped query must filter on organization_id; see docs/MULTI_TENANT_SECURITY.md (internal).

Troubleshooting

SymptomCause / 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 databasePostgres is not running: npm run db:up
relation "..." does not existPending migrations: npm run db:migrate
Port 3001 or 8080 already in useAn earlier npm run dev is still alive. On Windows: netstat -ano | findstr :3001 then taskkill /PID <pid> /F
Docker errors on npm run setupDocker Desktop is not running
Tests time out on the first test of a fileCold transform cache. vitest.config.ts allows 30s; a second run is much faster.
Lint or build behaves differently from CINode version drift — npm run doctor checks it against .nvmrc

More: troubleshooting.md.

On this page