Skip to content

Docs

Backend Starter

Connect OSAGI Console to Backend Starter: PostgreSQL with row-level security, Better Auth sign-in and two-factor, and the same /api contract as the mock.

OSAGI Backend Starter is the real back-end of this console, sold apart: PostgreSQL with row-level security on the console's permission model, Better Auth sign-in with an authenticator app for everyone, an audit journal, letters and webhooks, under the same /api/<module> contract as the mock. One build setting connects them.

Connect the console

  1. Run the backend (its README: docker compose up -d, then owner-create for the first owner). Set its PUBLIC_ORIGIN to the console's address in the browser, such as https://console.example.com.
  2. Build the console with NEXT_PUBLIC_API_BASE set to the address the console's server reaches the backend at, such as http://127.0.0.1:8787 or http://api:8787, then start it:
bash
NEXT_PUBLIC_API_BASE=http://127.0.0.1:8787 pnpm buildpnpm start
  1. Open the set-password link the backend printed, sign in and set up the authenticator app.

To try both on one machine, deploy/compose.full.yml starts PostgreSQL, Mailpit, the backend and the console built against it.

Important

The setting is read when the console is built: set it before pnpm build (or pass it as a build argument of the image), and build again after a change. A malformed value stops the build.

How they talk

WhoTalks toHow
The browserThe console onlyOne origin: the backend's paths are forwarded by the console, so the session cookie is first-party and no CORS is needed
The console's serverThe backend at NEXT_PUBLIC_API_BASEPages, server actions and the sign-in check call it with the visitor's cookie
The backendPostgreSQL, the mail serverWith the visitor's rights, under row-level security
  • Sign-in is the backend's: the sign-in screens, the set-password page and the security settings call its Better Auth endpoints under /api/auth. The demo sign-in is off whatever OSAGI_DEMO_AUTH says.
  • Who is signed in comes from the backend's GET /api/me on every request: rights, sections, the owner flag and the second factor. Its session cookie is osagi.session_token; if the backend's COOKIE_PREFIX is not osagi, set API_COOKIE_PREFIX on the console to the same value.
  • Cross-site writes are refused twice: by the console for its own routes, and by the backend, which takes a write with a session cookie only from PUBLIC_ORIGIN and only as JSON (or a file upload).

What is connected

ModuleWhere it runs
Sign-in, sessions, two-factorBackend
Access: users, groups, permissions, approvers, auditBackend
Requests: journal, card, approvals, statuses, attachments of a draftBackend
Operations: overview, monitoring, infrastructure, alerts, analytics, endpoints, events, errors, auditBackend
Health of the footerBackend
Assistant chat, consultants, memory, request drafts and AI reviewsBackend, when it serves its assistant module and the console is built with NEXT_PUBLIC_API_ASSISTANT=on; else mock
Support: my requests, the thread and files, the department's queue, cards and actionsBackend
Reports: SLA and sales, leads, workload, marketingBackend, on what your producers send to its ingest API
Docs, the overview's activity feedMock

The reports are not built by the backend: a job of yours that reads your CRM and time tracking sends the data the screens show, with a reports service key. Until it does, a report screen says there is no data. Build the console with NEXT_PUBLIC_REPORT_TIME_ZONE set to the backend's REPORT_TIME_ZONE, so both count days in one zone.

A screen that still runs on the mock says so above its content: Sample data: not on your backend yet. It works under the backend's sign-in and rights, but its data lives in the console's memory and is gone after a restart. The overview's activity card carries the same mark.

Without the backend's assistant module, three request features answer 501 not_available: the AI review of a request, the approval chat and its redraft proposal.

When something fails

What you seeWhy
The build stops with "NEXT_PUBLIC_API_BASE is not an absolute address"Use an origin only: scheme, host and port, no path
Sign-in answers "The request did not come from the console"The backend's PUBLIC_ORIGIN is not the address in the browser
Every page sends you back to sign-inThe console looks for another cookie name: set API_COOKIE_PREFIX to the backend's COOKIE_PREFIX
"The backend cannot be reached" (502) or "did not answer in time" (504)The console's server cannot reach NEXT_PUBLIC_API_BASE
The backend does not start: REPORT_TIME_ZONE needs "one UTC offset since 2000"The zone's offset changed on some day since 2000: set both sides to the fixed zone of today's offset (Etc/GMT-5 for UTC+5); the console reads such a zone as UTC

See Connecting your API for the contract both sides share.