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
- Run the backend (its README:
docker compose up -d, thenowner-createfor the first owner). Set itsPUBLIC_ORIGINto the console's address in the browser, such ashttps://console.example.com. - Build the console with
NEXT_PUBLIC_API_BASEset to the address the console's server reaches the backend at, such ashttp://127.0.0.1:8787orhttp://api:8787, then start it:
NEXT_PUBLIC_API_BASE=http://127.0.0.1:8787 pnpm buildpnpm start- 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
| Who | Talks to | How |
|---|---|---|
| The browser | The console only | One 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 server | The backend at NEXT_PUBLIC_API_BASE | Pages, server actions and the sign-in check call it with the visitor's cookie |
| The backend | PostgreSQL, the mail server | With 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 whateverOSAGI_DEMO_AUTHsays. - Who is signed in comes from the backend's
GET /api/meon every request: rights, sections, the owner flag and the second factor. Its session cookie isosagi.session_token; if the backend'sCOOKIE_PREFIXis notosagi, setAPI_COOKIE_PREFIXon 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_ORIGINand only as JSON (or a file upload).
What is connected
| Module | Where it runs |
|---|---|
| Sign-in, sessions, two-factor | Backend |
| Access: users, groups, permissions, approvers, audit | Backend |
| Requests: journal, card, approvals, statuses, attachments of a draft | Backend |
| Operations: overview, monitoring, infrastructure, alerts, analytics, endpoints, events, errors, audit | Backend |
| Health of the footer | Backend |
| Assistant chat, consultants, memory, request drafts and AI reviews | Backend, 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 actions | Backend |
| Reports: SLA and sales, leads, workload, marketing | Backend, on what your producers send to its ingest API |
| Docs, the overview's activity feed | Mock |
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 see | Why |
|---|---|
| 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-in | The 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.