688 lines
38 KiB
Markdown
688 lines
38 KiB
Markdown
# Superbrain
|
|
|
|
A multi-user bookmark workspace: URLs with Markdown notes, tags, calendar
|
|
dates, editable kanban boards, project collections with typed properties and
|
|
saved views, pages, previews, sharing, contacts and email signals.
|
|
|
|
**Documentation:** [API reference](API.md) — every Go endpoint, request and
|
|
response contract · [Running superbrain](RUNNING.md) — setup, everyday
|
|
commands and troubleshooting · [Authelia connection guide](web/docs/AUTHELIA.md)
|
|
— single sign-on setup.
|
|
|
|
## Run the whole app
|
|
|
|
**Client setup guide:** [Running superbrain](RUNNING.md) covers cloning, setup,
|
|
first login, everyday commands, updates, and troubleshooting on Windows,
|
|
macOS, and Linux.
|
|
|
|
Superbrain installs three ways — pick the one that matches your target:
|
|
|
|
1. **Self-hosted with Docker Compose** (this section): one command on any
|
|
Docker host. Default shape: email/password signup and login, optional
|
|
Authelia, optional SMTP-backed password reset.
|
|
2. **Standalone remote server** — `scripts/deploy.sh` provisions a target
|
|
machine end to end (nginx + Let's Encrypt + database backups). See
|
|
[Deploying to a server](#deploying-to-a-server) below.
|
|
3. **Federated "core" suite host** — a one-shot suite installer for
|
|
operators running their own federated core (traefik, Authelia, shared
|
|
postgres, pdns, superpanel). See
|
|
[Installing into a federated core suite](#installing-into-a-federated-core-suite)
|
|
below.
|
|
|
|
The `TIER` environment variable selects the product shape and derives the
|
|
auth defaults (explicit `AUTH_MODE`/`SIGNUP_ENABLED` override): unset =
|
|
both password login and Authelia; `TIER=multi` = hosted self-service
|
|
(signup, password login, self-reset); `TIER=core` = Authelia SSO only.
|
|
Details: [web/docs/AUTHELIA.md](web/docs/AUTHELIA.md) §7.
|
|
|
|
Requires Docker with Compose v2 or newer. On a new installation:
|
|
|
|
```bash
|
|
git clone https://github.com/andrewthecodertx/superbrain.git
|
|
cd superbrain
|
|
cp .env.example .env
|
|
docker run --rm node:22-alpine node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
|
|
```
|
|
|
|
Put the generated value in `AUTH_SECRET` in `.env`, save the file, then run:
|
|
|
|
```bash
|
|
docker compose up -d --build # builds and starts PostgreSQL, Go and Next.js
|
|
```
|
|
|
|
On Windows PowerShell, use `Copy-Item .env.example .env` instead of `cp`.
|
|
|
|
- Web interface: **http://localhost:3000**. Sign up, then sign in.
|
|
- Go API: **http://localhost:8080** (local access; endpoints in [API.md](API.md)).
|
|
- PostgreSQL: `db:5432` inside Docker; not published on the host.
|
|
- With `ADMIN_EMAILS` empty, the first non-`@example.com` account becomes
|
|
administrator and completes a one-shot bootstrap: afterwards signup never
|
|
auto-promotes again, even if the last administrator is demoted or removed
|
|
— recovery is operator-driven (`ADMIN_EMAILS` + seed, or promotion by an
|
|
existing admin). Addresses in `ADMIN_EMAILS` are reserved for
|
|
operator-provisioned accounts; automatic
|
|
promotion requires a verified email. Existing accounts are preserved on restart.
|
|
- `docker compose down` stops the stack. It does not delete the database volume.
|
|
|
|
`make run` and `make stop` are optional shortcuts for the Compose commands.
|
|
`docker-compose.full.yml` is a compatibility alias for the same complete stack.
|
|
|
|
### Existing Docker database
|
|
|
|
Set `POSTGRES_VOLUME` to its existing Docker volume name and
|
|
`POSTGRES_VOLUME_EXTERNAL=true`. The volume must contain the `superbrain`
|
|
database and `superbrain` role. Stop the previous PostgreSQL container before
|
|
mounting that volume in this stack.
|
|
|
|
`db/schema.sql` initializes a **new, empty** database once. `db/migrations/`
|
|
holds the ordered, checksummed additive migrations that `db/migrate.sh` runs
|
|
(ledger table `_migration`) before Go starts. Each migration is applied and
|
|
recorded in a single transaction under an advisory lock, so a crash never
|
|
leaves an applied file unrecorded (or vice versa) and a second concurrent
|
|
runner aborts instead of double-applying. Neither path drops a database.
|
|
Do not run the initial schema against an already initialized database, and do
|
|
not edit a migration that has been applied — add a new numbered file.
|
|
Migrations are additive (new columns/tables/indexes with defaults), so the
|
|
previous application release keeps working against a migrated database;
|
|
rolling the data itself back means restoring the pre-deploy dump (see
|
|
RUNNING.md), not reverting SQL. Because schema.sql and the chain are two
|
|
paths to the same schema, every schema change needs both a schema.sql edit
|
|
and a new migration; `make db-converge` (included in `make check`) fails
|
|
when they drift apart. The page-search migration enables the `pg_trgm`
|
|
extension (bundled with PostgreSQL and trusted, so the database owner can
|
|
install it); the index-backed page search depends on it.
|
|
|
|
## Architecture
|
|
|
|
- `internal/`: Go API, persistence, authorization and integrations. SQL values
|
|
are parameterized; camelCase JSON matches the Next.js client contract.
|
|
- `web/`: Next.js UI and NextAuth browser sessions. Credentials are verified
|
|
by Go. A server-side API proxy signs 60-second identity assertions; Go
|
|
reloads roles and resolves admin impersonation on every data request.
|
|
Signing out in the browser also revokes backend sessions ("sign out
|
|
everywhere"): it bumps the user's token version, so prior assertions and
|
|
Go cookie sessions stop working.
|
|
- The frontend has no runtime Prisma client or direct database connection.
|
|
- Go also supports its own HttpOnly `superbrain_session` cookie for direct API
|
|
consumers. Administration uses the real user; data uses the effective user.
|
|
- Containers share the Compose backend network. The app runs as non-root
|
|
with a read-only filesystem; the web container has temporary `/tmp` storage.
|
|
|
|
## Features and integrations
|
|
|
|
- Bookmarks: create/edit/delete, tags, contacts, previews, calendar dates,
|
|
alerts, Markdown downloads and public read-only links. All Bookmarks can
|
|
group by Calendar (due month), Tags, Kanban, Collections or Contacts, and
|
|
the Calendar offers Day/Week/Month/Year and a date-sorted List view.
|
|
- Bookmark collections use cursor pagination; the UI follows every page so
|
|
collections larger than 200 remain visible on all organization screens.
|
|
- Notion-style workspace shell: a Quick Find command palette (Ctrl/Cmd+K)
|
|
jumps to any page, bookmark, tag or view and runs commands (new page, add
|
|
bookmark, theme toggle); the slim top bar shows a breadcrumb path
|
|
(workspace / section / page). The sidebar is grouped: Quick find, a Pages
|
|
group (All Pages tree, Pinned Pages, Untagged Pages), a Bookmarks group
|
|
(All Bookmarks, Calendar, and expandable Tags / Kanban / Collections /
|
|
Contacts lists that deep-link to a specific tag, column, collection or
|
|
contact), and Trash. Sections collapse, page rows expose hover actions
|
|
(pin, inline rename, delete), and drag reordering persists.
|
|
- Pages: WYSIWYG editing (Notion-style; Markdown remains the storage
|
|
format) with autosave, a slash-command block menu (type `/` for headings,
|
|
to-dos, lists, quotes, dividers and code) and the `[]` + space to-do
|
|
shortcut. Every URL added to a page — Link button, links popover or a
|
|
bare-URL paste — is also saved as a bookmark linked to the page, reusing
|
|
an existing same-URL bookmark instead of duplicating it. Pages can be
|
|
tagged (drag a page onto a tag), nested under a parent, pinned, reordered
|
|
and exported; pages link each other and can embed live collections. Every
|
|
save keeps a restorable revision, and deletions are recoverable from
|
|
Trash (deleting a parent promotes its children).
|
|
Saves are queued per page; unsaved drafts are kept in the current browser tab
|
|
for recovery after a failed save, together with the server version they were
|
|
based on. Page switching waits for pending saves. When another tab or device
|
|
saved first, autosave pauses in an explicit conflict state — the editor
|
|
offers overwrite, save-as-copy and discard, and typing alone never
|
|
overwrites the newer version.
|
|
- Kanban: custom columns, card moves, reorder; deleting a column moves
|
|
cards. Only explicitly placed bookmarks appear on the board — unassigned
|
|
bookmarks stay off it until added.
|
|
- Collections: per-project workflow state over your existing bookmarks. The
|
|
same link joins many collections without duplication, each with its own
|
|
typed properties (text, number, select, multi-select, date, checkbox, URL),
|
|
saved table/board views, server-side filters with typed operator
|
|
allowlists, and manual ordering. Membership adds context — it never owns
|
|
or publishes the bookmark: removing an item or a whole collection keeps
|
|
the bookmark, and a bookmark whose share was revoked disappears from
|
|
collections everywhere. Every mutating PATCH carries an expected version,
|
|
so concurrent editors get a conflict instead of a silent overwrite;
|
|
reordering and property deletion advance the affected items' and views'
|
|
revisions too, and deletions are idempotent removals.
|
|
- Connected services: a WebDAV share, CalDAV calendar or CardDAV address
|
|
book materializes as its own collection whose files, events or contacts
|
|
are bookmarks (URL = the DAV location). Sync mirrors the server: vanished
|
|
items detach but keep their bookmarks, your own removals stay removed,
|
|
and listings are bounded so a truncated walk never reconciles deletions.
|
|
Configure in Settings → WebDAV / CalDAV / CardDAV; on Core deployments
|
|
with Nextcloud the forms offer a one-click prefill for your account.
|
|
- Sharing: bookmarks, tags and calendar dates; recipients read shared content.
|
|
Owners can revoke shares. Shared tags and dates expose the associated URLs.
|
|
Tag sharing is group-wide: every recipient of a tag sees all bookmarks
|
|
carrying it, including ones other recipients add. Shared readers get a
|
|
narrowed response: the link and its reader-facing content only — never the
|
|
owner's contact record, the other recipients, alerts, or mailbox watches.
|
|
- Public bookmark links deliberately publish the title, description, notes,
|
|
due date, tags and preview; contacts, alerts, mailbox watches and the
|
|
owner identity stay private. The share panel states this before you toggle.
|
|
- Remote preview images and favicons are loaded by your browser directly
|
|
from the third-party host, with `referrerPolicy="no-referrer"` so the app
|
|
URL is not disclosed; opening a page can still let those hosts observe the
|
|
request. Server-side fetches (previews, CardDAV, IMAP) never touch private
|
|
network ranges, including 6to4/Teredo/NAT64-wrapped addresses. Previews are
|
|
pinned to HTTP/HTTPS ports 80/443 and mailbox connections to IMAP ports
|
|
143/993; CardDAV uses the explicitly configured HTTPS port.
|
|
- Text fields have per-field caps in addition to the request-body limit, so
|
|
an oversized bookmark title, tag name, note or page body is rejected
|
|
instead of bloating every list and search.
|
|
- Alerts: browser notifications and in-app dismissal, polled every five minutes.
|
|
- Nextcloud: CardDAV REPORT sync using each user's app password. Credentials
|
|
are used for that request only, not stored, and never travel plaintext:
|
|
the Nextcloud URL must use https (redirects are not followed).
|
|
- IMAP: encrypted per-user settings, real login tests, sender/subject searches,
|
|
email watchers, and Message-ID deduplication. Verified TLS is required —
|
|
plaintext mailbox logins are rejected. Watcher ingestion is incremental: a
|
|
durable per-source UID checkpoint processes bounded batches until caught up
|
|
instead of re-scanning the last 50 matches. Configure integrations in
|
|
Settings, then check watchers from a bookmark.
|
|
Enabled email watchers also run every five minutes in the Go process,
|
|
including watches enabled with the original mailbox-watch switch. The
|
|
scheduler runs users with bounded concurrency, per-user failure backoff,
|
|
and a database-backed lease so extra instances never double-poll a mailbox.
|
|
- Notifications: delivery channels — email via the server's SMTP relay,
|
|
Slack webhooks, Matrix rooms, Telegram bots and Signal (a signal-cli REST
|
|
bridge) — and rules that fire when a new mailbox signal arrives, a
|
|
bookmark comes due, or a share is received. Rules can target other people
|
|
in your organization; each recipient gets the delivery through their own
|
|
enabled channel, and history lists every delivery including suppressed
|
|
ones. Channel secrets are encrypted at rest and never echoed back;
|
|
availability follows your plan. Configure in Settings → Notifications.
|
|
- Branded email: password resets, notification deliveries and automation
|
|
emails use the Superbrain HTML design with a plain-text alternative
|
|
(reset links get a proper button and an expiry note). Every email carries
|
|
a footer: **Email preferences** (deep-links to Settings → Notifications),
|
|
**Help center**, and — only for mail to your own account address —
|
|
**Unsubscribe**. Unsubscribe works without signing in (the link carries a
|
|
secure token, and mail clients get native one-click unsubscribe): it turns
|
|
off your email channels and the automations that email you, never affects
|
|
password resets or other account emails, and is reversible in Settings.
|
|
Third-party recipients never receive a link that changes someone else's
|
|
preferences.
|
|
- **AI automations ("hey superbrain")**: describe an automation in plain
|
|
language — *"when the round trip on https://… drops below $400, email
|
|
david@example.com"* — and Superbrain compiles it into a task you review
|
|
and confirm before anything is saved. Two doors: the floating **Ask
|
|
Superbrain** assistant drawer (ephemeral chat on every screen; automation
|
|
requests come back as confirm-before-create proposal cards; *Save to
|
|
page* keeps a conversation) and Settings → Automations (form + task list
|
|
+ delivery history). Tasks watch a public web page on a schedule (one
|
|
extracted fact per check, e.g. a price threshold) or react to new mailbox
|
|
signals, then notify a channel, email a recipient, or save a bookmark.
|
|
The AI only ever *proposes* validated specs; actions are a fixed, bounded
|
|
set (no logins, no bookings, no deletes, no multi-step chains yet),
|
|
every fetch goes through the same private-range network guard as
|
|
previews, and email actions are hard-capped. AI is **bring-your-own-key**
|
|
per user (Settings → AI: provider, model picker, key with show/hide —
|
|
encrypted at rest — plus optional **custom instructions** that refine the
|
|
in-app assistant's tone and focus; the automation and page-reading prompts
|
|
stay server-owned) with an optional server-wide key for plans that include
|
|
it; without any key, AI features report "not configured" and everything
|
|
else keeps working. Details: RUNNING.md → "AI automations".
|
|
- Profile: Settings → Profile holds your display name, bio, location,
|
|
occupation, organization and website; your email stays the read-only
|
|
sign-in identity. Your name appears where you share with others — public
|
|
bookmark links never reveal it. Saving refreshes the name shown in the
|
|
top bar without a re-login. Settings are grouped (Account, Connections,
|
|
AI & Automation, Developer) and support `?tab=` deep links.
|
|
- Help center: a public guide at `/help` covers every surface of the app
|
|
(bookmarks, collections, pages, board, signals, notifications, assistant,
|
|
connections, developer access) plus an FAQ; linked from the sign-in page
|
|
and email footers.
|
|
- Developer access: personal API keys (`sb_…`, Settings → API Keys)
|
|
authenticate machine clients against the Go API directly, and the
|
|
`superbrain-mcp` server exposes bookmarks, tags and pages to MCP clients.
|
|
Settings → MCP also registers external MCP servers for Superbrain to dial
|
|
as a client. Both follow your plan.
|
|
|
|
### Connecting Authelia (OIDC)
|
|
|
|
Authelia is the primary sign-in path when configured. The trusted Next.js
|
|
server handles the OIDC authorization-code flow, validates the ID token, and
|
|
then exchanges the verified identity for a local Go user. Email/password
|
|
sign-in remains available as a fallback. The full
|
|
[Authelia connection guide](web/docs/AUTHELIA.md) includes the client
|
|
registration example and the identity-mapping details.
|
|
|
|
#### 1. Register the app in Authelia
|
|
|
|
Use an Authelia installation with OIDC enabled and a valid HTTPS issuer URL.
|
|
Register `superbrain` as a confidential client with:
|
|
|
|
- Scopes: `openid`, `profile`, `email`.
|
|
- Grant type: `authorization_code`; response type: `code`.
|
|
- Token endpoint authentication: `client_secret_basic`.
|
|
- Redirect URI: `<PUBLIC_APP_URL>/api/auth/callback/authelia`, for example
|
|
`https://superbrain.company.tld/api/auth/callback/authelia`.
|
|
|
|
Generate a client secret as described in the connection guide. Put its
|
|
**hashed digest** in Authelia and its **plain value** in the app's
|
|
`OIDC_CLIENT_SECRET`. The redirect URI must exactly match the public web URL
|
|
and callback path. It points to the Next.js server, not the Go API on port 8080.
|
|
|
|
#### 2. Configure superbrain
|
|
|
|
Edit the root `.env`, replacing the sample values with your deployment values:
|
|
|
|
```dotenv
|
|
NEXTAUTH_URL=https://superbrain.company.tld
|
|
COOKIE_SECURE=1
|
|
OIDC_ISSUER=https://auth.company.tld
|
|
OIDC_CLIENT_ID=superbrain
|
|
OIDC_CLIENT_SECRET=<plain-client-secret>
|
|
```
|
|
|
|
Serve the web app through an HTTPS reverse proxy; the default Docker ports
|
|
bind to localhost. Keep your existing `AUTH_SECRET` unchanged. Apply the
|
|
environment changes with `docker compose up -d --build`, then check
|
|
**Settings → Sign-in**. When all three variables hold real values, the Authelia
|
|
button is enabled.
|
|
|
|
#### 3. How identity mapping works
|
|
|
|
The Next server owns OIDC verification and the callback. After Authelia returns
|
|
a verified identity, NextAuth's `jwt` callback calls the Go API's
|
|
`POST /api/auth/oidc/identity` endpoint with a short-lived service token
|
|
(`typ=oidc-provision`). Go resolves the OIDC subject to a local `User` through
|
|
the `Account` table:
|
|
|
|
- An existing provider link is authoritative.
|
|
- A matching local account with no password may be linked when Authelia asserts
|
|
a verified email.
|
|
- A matching local **password** account returns `409 Account link required`.
|
|
Email alone is not proof of identity; an administrator links it explicitly
|
|
with `POST /api/admin/oidc-link` (`{userId,subject}`).
|
|
- Otherwise Go creates a password-less local user. The first external user on a
|
|
fresh installation follows the same bootstrap-admin rules as signup.
|
|
|
|
The NextAuth session and every API assertion use the **local** `User.id`, never
|
|
Authelia's `sub` claim. A Go `tokenVersion` bump on sign-out revokes both the
|
|
NextAuth-backed assertions and Go cookie sessions.
|
|
|
|
The Go OIDC login/callback handlers in `internal/oidc/provider.go` remain 501
|
|
stubs. They are not the NextAuth callback implementation; the Next server drives
|
|
the flow. Config status (including an `enabled` flag) indicates that values are
|
|
present, not that Go itself runs an OIDC client.
|
|
|
|
## Developer commands
|
|
|
|
```bash
|
|
make run # build and start the full Compose stack
|
|
make stop # stop the stack, keep the PostgreSQL volume
|
|
make build # Go compile
|
|
make vet # Go vet
|
|
make test # Go unit tests with race detection
|
|
make integration # Docker PostgreSQL + CardDAV/IMAP fixture tests
|
|
make db-shell # psql inside the database container
|
|
make logs # Go and Next.js logs
|
|
make migrate # ordered additive database migrations
|
|
make db-converge # schema.sql vs migration-chain drift check
|
|
make check # release validation (fails without DB coverage)
|
|
make audit # dependency advisory scans (needs govulncheck)
|
|
```
|
|
|
|
The same release gate runs automatically on every push and pull request
|
|
(`.github/workflows/check.yml`), including the browser smoke tests against
|
|
the composed stack. Pass `YARN="corepack yarn"` to `make check` when yarn
|
|
comes through corepack.
|
|
|
|
Integration tests create/drop random test schemas; they never clear app data.
|
|
They exercise CRUD, sharing, ownership boundaries, impersonation, encryption,
|
|
CardDAV sync, IMAP login/search and signal deduplication.
|
|
|
|
Frontend checks (from `web/`): `yarn lint`, `yarn build`, and
|
|
`yarn eslint -c eslint.ssr.config.mjs .`. Builds enforce TypeScript checks.
|
|
|
|
Browser smoke tests (with the stack running):
|
|
|
|
```bash
|
|
npm --prefix scripts ci
|
|
CHROMIUM_PATH=/usr/bin/chromium make e2e
|
|
```
|
|
|
|
These verify login, UI bookmark creation, Go-backed persistence, public links,
|
|
Quick Find deep links, kanban, the collections workflow (membership without
|
|
duplication, typed properties, table+board over one membership), page
|
|
autosave/slash commands/exports and every application screen. Test accounts
|
|
have unique names and only those accounts are deleted afterward.
|
|
|
|
Targeted browser regressions (after `yarn build` in `web/`):
|
|
|
|
```bash
|
|
npm --prefix scripts run test:regressions
|
|
```
|
|
|
|
These run an isolated Next server with API fixtures and test login CSRF,
|
|
browser sign-out revocation, autosave switching/ordering/recovery (including
|
|
drafts whose base version is unknown, which pause for review), pagination,
|
|
bookmark editing, the WebDAV/CalDAV/CardDAV settings walkthroughs and the
|
|
profile save round-trip (including the session name refresh), without
|
|
creating or deleting application users.
|
|
|
|
Optional operator-provisioned account: set its address in `ADMIN_EMAILS` in
|
|
the root `.env`, run `docker compose up -d`, then:
|
|
|
|
```bash
|
|
docker compose exec -e SEED_EMAIL=admin@company.tld -e SEED_PASSWORD='<chosen-password>' app /superbrain --seed
|
|
```
|
|
|
|
This trusted command creates an admin for an allowlisted address. It never
|
|
changes an existing account's password or role, or deletes data. Additional
|
|
existing users can be promoted from the Admin screen.
|
|
|
|
## Deploying to a server
|
|
|
|
Deployment is target-agnostic — there are no built-in host or domain
|
|
defaults. Point DNS for your domain at the server, have an ssh alias (or
|
|
host) ready, then run from the repository root:
|
|
|
|
```bash
|
|
HOST=app-server DOMAIN=superbrain.example.tld CERTBOT_EMAIL=ops@example.tld ./scripts/deploy.sh
|
|
```
|
|
|
|
(`make deploy` runs the same script with the same variables.) It records the
|
|
exact git revision, refuses dirty trees unless `ALLOW_DIRTY=1`, rsyncs the
|
|
source, and on the server: provisions Docker/nginx/certbot, writes `.env` on
|
|
first deploy, takes a pre-deploy database dump plus `.env` snapshot into
|
|
`/var/backups/superbrain` (15 retained), builds revision-tagged images, and
|
|
installs the nginx + Let's Encrypt reverse proxy from
|
|
`deploy/nginx/superbrain.conf.template`. Rollback means re-deploying an older
|
|
revision or restoring a pre-deploy dump; migrations are additive. See
|
|
RUNNING.md → "Running on a remote server" for the operator checklist.
|
|
|
|
## Installing into a federated core suite
|
|
|
|
For operators running their own copy of the federated suite (traefik +
|
|
Authelia + shared postgres + pdns + superpanel), Superbrain is a
|
|
first-class suite app. On the **core host**, as root:
|
|
|
|
```bash
|
|
sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/install.sh)"
|
|
```
|
|
|
|
No clone and nothing to copy: the installer and the suite integration files
|
|
ship inside the migrate image at `/deploy`. Pin a release with
|
|
`SUPERBRAIN_VERSION=0.2.17` (default `latest`), or use a local checkout's
|
|
files instead with `SUPERBRAIN_SRC=/path/to/repo`.
|
|
|
|
The installer:
|
|
|
|
1. **Preflights the suite** — Authelia is *required* (the core tier is
|
|
SSO-only: password login, signup and reset are disabled at the API),
|
|
plus the house mail relay credential for notification emails, the
|
|
`core` docker network, and fixed-IP availability (override with
|
|
`SUPERBRAIN_{WEB,APP,MIGRATE}_IP` on collision).
|
|
2. **Installs the house integration** — `/federated/lib/superbrain.sh`,
|
|
`/federated/services/superbrain/service` and the `upgrade/pre` hook,
|
|
then runs the standard `/federated/bin/installapp superbrain`: compose +
|
|
`.env` generation (`TIER=core`), **image pulls from Docker Hub**
|
|
(`federatedcomputer/superbrain-{app,web,migrate}`, one shared version
|
|
tag, amd64 + arm64 — no source, no builds on the host), database + user
|
|
on the shared postgres (the migrate image bootstraps the schema and
|
|
runs the ledger itself), pdns record, monitors, superpanel catalog
|
|
entry.
|
|
3. **Registers the Authelia OIDC client** — including the `claims_policy`
|
|
that puts `email` in the ID token (without it every SSO login fails
|
|
with AccessDenied), validated before Authelia is restarted.
|
|
4. **Seeds and verifies** — a password-less `admin@$DOMAIN` account
|
|
(ADMIN via `ADMIN_EMAILS`; it links to your Authelia identity by
|
|
verified email on first SSO login), then container/DNS/SSO/HTTPS
|
|
checks and the operator's first-login instructions.
|
|
|
|
Prerequisites: Authelia with the OIDC provider configured, shared
|
|
`postgresql`, traefik, pdns, and the house `mail` relay (shared `fcore`
|
|
sender account). Full design record, IP plan, upgrade flow and incident
|
|
history: [deploy/federated/STRATEGY.md](deploy/federated/STRATEGY.md).
|
|
|
|
**MCP (AI tool access):** Superbrain links into the suite's `mcpserver`
|
|
MCP gateway like every other app —
|
|
`/federated/bin/installapp-mcpserver superbrain` mints a dedicated API key
|
|
for the admin account and points the gateway at the Go API
|
|
(`http://superbrain-app:8080`). The gateway spawns `superbrain-mcp` (the
|
|
pip-installable stdio MCP server in [`mcp/`](mcp/), configured entirely by
|
|
`SUPERBRAIN_API_URL`/`SUPERBRAIN_API_KEY`), exposing bookmarks, tags and
|
|
pages to `mcphub`, Hermes and any other MCP client. API keys are a core-plan
|
|
feature (`mcp-core` connector); users can also mint their own in
|
|
Settings → API Keys and attach clients directly.
|
|
|
|
**Updating** an installed core is the standard house flow — bump `VERSION`
|
|
in `/federated/services/superbrain/service` to the new release tag and run
|
|
`/federated/bin/upgrade superbrain` (the pre-hook backs up the database
|
|
and pulls all three images). Or one command, which also syncs the suite
|
|
files from the release's migrate image (version defaults to `latest`):
|
|
|
|
```bash
|
|
sudo bash -c "$(docker run --rm --pull always federatedcomputer/superbrain-migrate cat /deploy/update.sh)" update.sh [version]
|
|
```
|
|
|
|
Releases are semver tags without a `v` prefix (`0.2.17`); the three images
|
|
are published under the same tag (plus `:latest`) for linux/amd64 and
|
|
linux/arm64. The migrate image is self-contained: it detects an empty
|
|
database, applies `schema.sql` as the superbrain user,
|
|
then runs the checksummed migration ledger, and it carries
|
|
`deploy/federated/` at `/deploy` — the host never needs the source tree.
|
|
|
|
## Publishing release images (Docker Hub)
|
|
|
|
Releases are three multi-arch images sharing **one semver tag without a `v`
|
|
prefix** (the suite's `VERSION_RX` is `^[0-9][0-9\.]*$`), plus `:latest`:
|
|
|
|
```
|
|
federatedcomputer/superbrain-app:<version> Go API (context ., Dockerfile)
|
|
federatedcomputer/superbrain-web:<version> Next.js UI (context web, web/Dockerfile)
|
|
federatedcomputer/superbrain-migrate:<version> DB bootstrap (context db, db/Dockerfile)
|
|
```
|
|
|
|
Platforms: `linux/amd64,linux/arm64`. Source of truth: this Gitea repo
|
|
(`https://gitea.federated.computer/Federated_Computer/brain.git`) at the
|
|
matching tag. The repositories auto-create on first push under the
|
|
`federatedcomputer` namespace; keep them **public** so cores can pull
|
|
without registry credentials. Never move an existing tag — cut a new
|
|
version instead.
|
|
|
|
**How publishing works in this deployment:** a separate process triggered
|
|
on push to `main` builds and publishes the image set — that is the path
|
|
that has always delivered releases. The repo's own tag-triggered CI
|
|
(Option A) runs the smoke gate on every tag, but its publish job needs the
|
|
one-time `DOCKERHUB_*` secrets setup below; until those are set by a
|
|
repo-owner account, the publish job fails at login and publishing falls
|
|
back to the separate process or Option B. The smoke job is still a valid
|
|
gate either way.
|
|
|
|
### Option A — CI: push a tag (publish needs the secrets setup)
|
|
|
|
`.github/workflows/release.yml` runs on Gitea Actions for tags matching
|
|
`[0-9]+.[0-9]+.[0-9]+`. A smoke job first builds the migrate image and
|
|
bootstraps a throwaway PostgreSQL with it (fresh schema, complete ledger,
|
|
idempotent re-run) and runs Go build/vet/unit tests; only then does the
|
|
publish job build and push all three images. Prerequisites (one-time,
|
|
instance admin):
|
|
|
|
1. An **act_runner** registered against `https://gitea.federated.computer`
|
|
with access to a docker socket.
|
|
2. Repo/org **Actions secrets** `DOCKERHUB_USERNAME` and `DOCKERHUB_TOKEN`
|
|
(an access token with write permission on the `federatedcomputer`
|
|
namespace).
|
|
|
|
Then releasing is:
|
|
|
|
```bash
|
|
git checkout main && git pull
|
|
git tag -a 0.2.17 -m "release 0.2.17"
|
|
git push origin 0.2.17
|
|
```
|
|
|
|
Watch the run under the repo's Actions tab; verify with
|
|
`docker manifest inspect federatedcomputer/superbrain-app:0.2.17`.
|
|
|
|
### Option B — manual build & push (no runner required)
|
|
|
|
From any Linux machine with Docker, buildx and login rights:
|
|
|
|
```bash
|
|
git clone https://gitea.federated.computer/Federated_Computer/brain.git
|
|
cd brain && git checkout 0.2.17 # always build from the tag
|
|
|
|
# One-time per machine: buildx builder + cross-arch emulation
|
|
docker buildx create --use --name multiarch
|
|
docker run --privileged --rm tonistiigi/binfmt --install arm64
|
|
|
|
docker login -u <dockerhub-user> # token prompt
|
|
|
|
# Smoke the migrate image BEFORE publishing (mirrors the CI gate):
|
|
docker buildx build --load --build-context deploy=deploy/federated -t sb-migrate:smoke db/
|
|
docker run -d --name sb-smoke-pg -e POSTGRES_USER=superbrain \
|
|
-e POSTGRES_PASSWORD=x -e POSTGRES_DB=superbrain postgres:16.15-alpine
|
|
docker run --rm --link sb-smoke-pg -e DB_HOST=sb-smoke-pg -e PGPASSWORD=x sb-migrate:smoke
|
|
docker run --rm --link sb-smoke-pg -e DB_HOST=sb-smoke-pg -e PGPASSWORD=x sb-migrate:smoke # re-run: "up to date"
|
|
docker rm -f sb-smoke-pg
|
|
|
|
# Build + push all three (each command pushes <version> and latest):
|
|
V=0.2.17
|
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
|
-t federatedcomputer/superbrain-app:$V -t federatedcomputer/superbrain-app:latest .
|
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
|
--build-arg SUPERBRAIN_VERSION=$V \
|
|
-t federatedcomputer/superbrain-web:$V -t federatedcomputer/superbrain-web:latest web
|
|
docker buildx build --platform linux/amd64,linux/arm64 --push \
|
|
--build-context deploy=deploy/federated \
|
|
-t federatedcomputer/superbrain-migrate:$V -t federatedcomputer/superbrain-migrate:latest db
|
|
```
|
|
|
|
Notes: the arm64 web build runs under qemu and is the slow step (tens of
|
|
minutes on modest hardware); the app image is a static Go binary and the
|
|
migrate image is `postgres:16.15-alpine` + `db/` + `deploy/federated/`
|
|
(supplied as the named `deploy` build context), both quick. Go builds
|
|
must stay legacy-builder compatible (no `$BUILDPLATFORM` tricks) so local
|
|
`docker compose build` keeps working on hosts without BuildKit defaults.
|
|
|
|
### After publishing
|
|
|
|
Bump `VERSION=` in `deploy/federated/service` to the new tag (commit it —
|
|
and release it — hosts sync the service file via `update.sh` from the
|
|
migrate image), then on each
|
|
core: `/federated/bin/upgrade superbrain` (or update.sh, which syncs the
|
|
service file first). The pre-upgrade hook takes a pg_dump and pulls all
|
|
three images; `upgrade_app` snapshots, redeploys and rewrites
|
|
`IMAGE_VERSION` in the app `.env`.
|
|
|
|
## Environment variable reference
|
|
|
|
Everything the stack reads, so a generated `.env` (or hosting environment)
|
|
stays correct as features are added. `.env.example` carries the same list
|
|
with annotations. "Required" means the app refuses to start or the feature
|
|
is off without it.
|
|
|
|
### Core (every deployment)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `AUTH_SECRET` | **yes** | — | Signs NextAuth JWTs, Go session cookies, proxy assertions and service tokens. Keep stable: rotating it signs everyone out and (without `ENCRYPTION_KEY`) invalidates stored IMAP passwords. `openssl rand -base64 32` |
|
|
| `NEXTAUTH_SECRET` | no | `AUTH_SECRET` | Alternative name; takes precedence when both are set (both sides use the same precedence) |
|
|
| `NEXTAUTH_URL` | **yes** in production | — | Exact browser-facing origin. Drives OIDC callbacks, the proxy's origin allowlist, cookie-secure derivation, password-reset links and the email footer links (preferences / help / unsubscribe) |
|
|
| `ENCRYPTION_KEY` | no | derived from `AUTH_SECRET` | Dedicated key for stored credentials (IMAP passwords, notification channel secrets, BYO AI keys). Set it and rotating `AUTH_SECRET` no longer touches them. Back it up with the database |
|
|
| `COOKIE_SECURE` | no | derived from `NEXTAUTH_URL` scheme | Set `0` explicitly only for local HTTP |
|
|
| `DATABASE_URL` | **yes** (Go) | — | `postgres://user:pass@host:5432/db?sslmode=disable`; `DB_URL` is the Makefile fallback |
|
|
|
|
### Compose stack (repo `docker-compose.yml`)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `POSTGRES_PASSWORD` | **yes** | — | Fail-fast `:?` interpolation — compose refuses to start without it |
|
|
| `POSTGRES_VOLUME` | no | `superbrain_pgdata` | Data volume name |
|
|
| `POSTGRES_VOLUME_EXTERNAL` | no | `false` | `true` to mount a pre-existing volume |
|
|
| `APP_HOST_PORT` / `WEB_HOST_PORT` | no | `8080` / `3000` | 127.0.0.1 host bindings; when shifting `WEB_HOST_PORT`, `NEXTAUTH_URL` must match the browser-facing origin |
|
|
| `PORT` | no | `8080` | Go listen port inside the container |
|
|
|
|
### Access policy (tier & auth shape)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `TIER` | no | unset | `core` (Authelia-only) or `multi` (self-service signup); derives the three below. Invalid values fail startup |
|
|
| `AUTH_MODE` | no | tier-derived, else `both` | `both` / `password` / `oidc` — overrides the tier. Invalid values fail startup |
|
|
| `SIGNUP_ENABLED` | no | tier-derived, else on | `0` closes self-service registration |
|
|
| `ALLOW_BOOTSTRAP_SIGNUP` | no | tier-derived, else on | `0` stops the first signup from claiming admin (set `0` on any exposed host) |
|
|
| `ADMIN_EMAILS` | no | empty | Comma-separated operator addresses: reserved at signup, ADMIN at first SSO login, ADMIN via `--seed` |
|
|
| `TRUSTED_PROXY` | no | unset | `1` only when the proxy overwrites `X-Real-IP` (bundled nginx template does; traefik does not) — enables per-client rate-limit identity |
|
|
|
|
### Authelia OIDC (all three required for SSO; placeholders = off)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `OIDC_ISSUER` | for SSO | — | Exact issuer from Authelia's discovery document |
|
|
| `OIDC_CLIENT_ID` | for SSO | — | Must match the Authelia client |
|
|
| `OIDC_CLIENT_SECRET` | for SSO | — | The **plain** secret, not the digest |
|
|
|
|
### Transactional mail (password reset, notification + automation email)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `SMTP_HOST` | for mail | — | Relay host; unset disables reset (503) and email delivery |
|
|
| `SMTP_PORT` | no | `587` | `465` = implicit TLS; otherwise STARTTLS when advertised |
|
|
| `SMTP_USERNAME` / `SMTP_PASSWORD` | no | — | AUTH PLAIN when the relay requires it |
|
|
| `SMTP_FROM` | **with SMTP_HOST** | — | Envelope+header sender |
|
|
| `NETGUARD_TRUSTED_HOSTS` | no | empty | Comma-separated operator-pinned hostnames allowed to resolve to private addresses (split-horizon relays). Never user-supplied names |
|
|
| `NEXTCLOUD_URL` | no | empty | Nextcloud origin; when set (Core writes `https://nextcloud.<domain>`), Settings → WebDAV/CalDAV/CardDAV offer one-click Nextcloud prefills. A convenience hint (deployment DATA, never a TIER code fork) — it gates nothing and allows nothing; a malformed value is ignored |
|
|
|
|
### AI (assistant, automations)
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `AI_API_KEY` | for the server-wide key | — | Operator fallback key; per-user BYO configs (Settings → AI) take precedence, and free/standard plans are BYO-only |
|
|
| `AI_MODEL` | no | `nvidia/nemotron-3-ultra-550b-a55b:free` | Any model the provider serves |
|
|
| `AI_BASE_URL` | no | `https://openrouter.ai/api/v1` | Any OpenAI-compatible endpoint |
|
|
| `AI_PROVIDER` | no | `openai-compatible` | or `anthropic` / `gemini` |
|
|
|
|
### Federated suite installs only
|
|
|
|
| Variable | Required | Default | Purpose |
|
|
|---|---|---|---|
|
|
| `IMAGE_VERSION` | **yes** | `1.0.0` | Shared tag for the three registry images; `upgrade` rewrites it. Must be the ONLY `VERSION=`-containing line in the file (upgrade_app's sed matches every occurrence) |
|
|
| `DB_HOST` / `DB_USER` / `DB_NAME` / `PGPASSWORD` | **yes** | — | Shared suite postgres coordinates, read by the migrate image's bootstrap |
|
|
| `API_BASE_URL` | **yes** (web) | — | Server-only DNS to the Go container (`http://superbrain-app:8080`) |
|
|
| `AUTH_TRUST_HOST` | **yes** (web) | — | `true` behind the reverse proxy |
|
|
|
|
### Tests/fixtures only — never in production
|
|
|
|
| Variable | Default | Purpose |
|
|
|---|---|---|
|
|
| `TEST_DATABASE_URL` | unset (DB tests skip) | Integration test database |
|
|
| `INTEGRATIONS_ALLOW_PRIVATE` | unset | Allows private-range dials (loopback fakes, deliberate LAN deployments) |
|
|
| `INTEGRATIONS_ALLOW_INSECURE_IMAP` | unset | Permits plaintext IMAP for fixtures |
|
|
| `BASE_URL` / `CHROMIUM_PATH` / `E2E_KEEP_DATA` | see `.env.example` | Browser suites |
|
|
|
|
## Client test build
|
|
|
|
Use [RUNNING.md](RUNNING.md) for the client handoff. Test login, bookmark editing,
|
|
tag/contact organization, calendar dates and views, kanban, a collections
|
|
workflow (create a collection, add the same bookmark to two collections, give
|
|
each a status, move a card on a board view), Markdown pages/exports,
|
|
Quick Find (Ctrl/Cmd+K), slash commands in the page editor, profile
|
|
particulars (Settings → Profile), the public help center (`/help`), and
|
|
sharing with separate accounts.
|
|
|
|
Current integration boundaries:
|
|
|
|
- Authelia is the primary sign-in path when configured; email/password remains
|
|
a fallback. Existing password accounts require explicit linking to an
|
|
Authelia identity.
|
|
- IMAP and Nextcloud require the client's own service credentials.
|
|
- Alerts are browser-only and checked every five minutes while the app is open.
|
|
- Page autosave needs an API connection. Check the save indicator; use **Save
|
|
now** after a failed save. Tab-local drafts are recovery aids, not backups.
|