PLAN.md: Phases 9–14, editions (local, server, multi-tenant), users, agents and billing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,11 @@ running a Federated Core can install as a CoreDesktop sibling.
|
|||||||
| AI for the app | Uses Hermes' Anthropic key and model when the user agrees (2026-11-20), copied to `hermes-ai.json` by `supermarket hermes` and `update.sh`. It calls the model directly, never through Hermes: post writing reads untrusted web text, which must not reach an agent with tools and CRM access |
|
| AI for the app | Uses Hermes' Anthropic key and model when the user agrees (2026-11-20), copied to `hermes-ai.json` by `supermarket hermes` and `update.sh`. It calls the model directly, never through Hermes: post writing reads untrusted web text, which must not reach an agent with tools and CRM access |
|
||||||
| Suite shape | One repo, one app with modules (Content, Prospects, SEO, Metrics, Sites), plus an MCP endpoint for agents |
|
| Suite shape | One repo, one app with modules (Content, Prospects, SEO, Metrics, Sites), plus an MCP endpoint for agents |
|
||||||
| Backups | SQLite's own `VACUUM INTO`, on request, before every migration and daily, in `<data>/backups`; secrets never in them (Phase 6) |
|
| Backups | SQLite's own `VACUUM INTO`, on request, before every migration and daily, in `<data>/backups`; secrets never in them (Phase 6) |
|
||||||
|
| Editions | **local**, **server** (one team, one company) and **multi** (many teams at one address, each with its own domains), chosen by `SUPERMARKET_MODE` (2026-11-25; Phases 9–14) |
|
||||||
|
| Database by edition | SQLite for local; **Postgres** for server and multi-tenant (2026-11-25) |
|
||||||
|
| Users | Owner (with billing), admins (the whole system, users and connections), members (given modules, each view or edit) and agents (a key, given modules). Sign-in by **email and password**, with optional two-factor for everyone, or **the Core's Authelia (OIDC)** (2026-11-25) |
|
||||||
|
| Posting accounts | Several social accounts per platform (the company's, users' own); admins set who may post to which; a post can go to one or several at once (2026-11-25) |
|
||||||
|
| Billing | Multi-tenant only: a **Stripe subscription** per team, managed by its owner. Each team brings its own keys for AI and services (2026-11-25) |
|
||||||
|
|
||||||
## Where things stand (2026-11-22)
|
## Where things stand (2026-11-22)
|
||||||
|
|
||||||
@@ -1770,6 +1775,549 @@ items worth acting on also join *What to write next*.
|
|||||||
**Not in this phase:** buying links, automatic outreach, and authority
|
**Not in this phase:** buying links, automatic outreach, and authority
|
||||||
scores (they need a paid index).
|
scores (they need a paid index).
|
||||||
|
|
||||||
|
### Editions: local, server and multi-tenant (Phases 9–14)
|
||||||
|
|
||||||
|
**Planned 2026-11-25.** Supermarket will come in three editions, chosen
|
||||||
|
when it starts by `SUPERMARKET_MODE`:
|
||||||
|
|
||||||
|
| | **local** (today) | **server** | **multi** (multi-tenant) |
|
||||||
|
|---|---|---|---|
|
||||||
|
| Who | One person, on their own computer | One team | Many teams, each signing in at one address (e.g. `app.supermarket.example`) |
|
||||||
|
| Domains | One company | One company (its websites) | One company per team, each with its own websites |
|
||||||
|
| Database | SQLite (`app.db`) | Postgres | Postgres, with every team's rows marked with its team |
|
||||||
|
| Sign-in | None: only this computer can reach it | Email and password, or the Core's sign-in (OIDC) | The same, set per team |
|
||||||
|
| Files | The data folder | The data folder (a volume) | Object storage (S3-compatible), plus scratch disk |
|
||||||
|
| Billing | None | None | Stripe subscriptions, managed by each team's owner |
|
||||||
|
| Keys for AI and services | The user's own | The team's own | Each team's own (none from the platform) |
|
||||||
|
| Agents | Agent keys | Agent keys | Agent keys, per team |
|
||||||
|
|
||||||
|
**Words used below.**
|
||||||
|
- A **team** is one company using Supermarket: its profile, websites,
|
||||||
|
connections and data. Local and server installs have exactly one; on
|
||||||
|
multi-tenant, each team sees only its own.
|
||||||
|
- A **user** is a person, or an **agent** (a program, such as an AI agent,
|
||||||
|
using a key instead of a password), who belongs to a team with a role.
|
||||||
|
- **Connections** are the services a team connects to Supermarket:
|
||||||
|
origami.chat, explee.com, Stripe, Plausible, Google Search Console, Bing,
|
||||||
|
Gitea, Listmonk, X, LinkedIn, the Core, and the AI provider. Today they
|
||||||
|
are spread over Settings (Accounts, Sources, Email, Search engines,
|
||||||
|
Tracking, AI, Core); admins set them up.
|
||||||
|
|
||||||
|
**Roles.**
|
||||||
|
- **Owner**: one per team. Everything an admin can do, plus billing (plan,
|
||||||
|
payment card, invoices), handing ownership to another admin, and
|
||||||
|
deleting the team. On local and server, the first user is the owner.
|
||||||
|
- **Admin**: the whole system: every module, Settings and Connections,
|
||||||
|
and users (invite, change access, remove), including other admins.
|
||||||
|
Admins can't change billing or remove the owner.
|
||||||
|
- **Member**: only the modules they're given (any of Content, Prospects,
|
||||||
|
SEO, Sites, Metrics), each as *view* (read-only) or *edit*
|
||||||
|
(decided 2026-11-25). Overview, the sidebar and Search show only those
|
||||||
|
modules; the Market is readable by every member, editable by admins and
|
||||||
|
by members with Content or Prospects (it feeds both).
|
||||||
|
- **Agent**: like a member, given modules, but signs in with a key and
|
||||||
|
never sees the web pages. Only an admin can create one.
|
||||||
|
|
||||||
|
**What stays the same:** the local edition. It still has no sign-in
|
||||||
|
(the port is bound to 127.0.0.1), still uses SQLite, and its data folder
|
||||||
|
keeps working without a migration step by hand. On local, everything is
|
||||||
|
done as the owner.
|
||||||
|
|
||||||
|
#### What has to change, from a look at the code (2026-11-25)
|
||||||
|
|
||||||
|
- **The database.**
|
||||||
|
- The schema is 40 tables, in 29 SQLite migrations, and about 40,000
|
||||||
|
lines of Go run SQL through `database/sql`. SQLite-only SQL found:
|
||||||
|
- `strftime` defaults (12)
|
||||||
|
- `COLLATE NOCASE` (16)
|
||||||
|
- `INSERT OR …` (4)
|
||||||
|
- two-argument `max()`/`min()` (around 50; Postgres says
|
||||||
|
`greatest`/`least`)
|
||||||
|
- `json_extract`/`json_each` (7)
|
||||||
|
- `LastInsertId` (11; Postgres needs `RETURNING id`)
|
||||||
|
- `PRAGMA` (8)
|
||||||
|
- `?` placeholders everywhere (Postgres takes `$1`)
|
||||||
|
- The settings table, with 122 reads and writes, and every table's
|
||||||
|
unique keys assume one company.
|
||||||
|
- **Secrets** are in `secrets.json` in the data folder (41 reads). In the
|
||||||
|
server and multi-tenant editions they go into the database, encrypted.
|
||||||
|
- **Files.** The data folder holds:
|
||||||
|
- the sites' git clones (`sites/`) and page previews (`previews/`)
|
||||||
|
- backups
|
||||||
|
- the CRM bridge's state, Hermes' files, the MCP socket and its token
|
||||||
|
- **The company profile** is loaded in about 44 places as *the* profile.
|
||||||
|
Background jobs (`RunSEO`, `RunTracking`, `RunOutreach`, `RunMetrics`,
|
||||||
|
`RunScheduler`, `RunImports`, `RunDiscovery`, `RunBackups`) each run
|
||||||
|
once, in-process, for the one company.
|
||||||
|
- **In-memory state** that is per company, or per process, includes:
|
||||||
|
- OAuth flows in progress
|
||||||
|
- Reddit's app token
|
||||||
|
- the one-email-at-a-time lock
|
||||||
|
|
||||||
|
On multi-tenant this has to be per team, and safe with several copies
|
||||||
|
of the app running.
|
||||||
|
- **No users.** Requests are trusted because they come from localhost
|
||||||
|
(plus a same-origin check on forms). `/mcp` takes one bearer token
|
||||||
|
(`mcp-token`) that can do everything it offers.
|
||||||
|
- **What agents can do today:** `/mcp` has 6 tools (the profile, the
|
||||||
|
Market, and the CRM bridge's queue). An agent can't yet drive the
|
||||||
|
modules.
|
||||||
|
|
||||||
|
#### Phase 9: Groundwork: editions, Postgres, secrets and files
|
||||||
|
|
||||||
|
Nothing changes for the local user; this makes the rest possible. A
|
||||||
|
commit after each part; the whole test suite runs against both SQLite and
|
||||||
|
Postgres from part 2 on.
|
||||||
|
|
||||||
|
1. **The edition and its settings.** `SUPERMARKET_MODE` (`local`, the
|
||||||
|
default; `server`; `multi`). It is read once at start, along with:
|
||||||
|
- `SUPERMARKET_DATABASE_URL`: `postgres://…`, required for server and
|
||||||
|
multi
|
||||||
|
- `SUPERMARKET_PUBLIC_URL`: already there; `https://` is required for
|
||||||
|
server and multi
|
||||||
|
- `SUPERMARKET_SECRET_KEY`: the key that encrypts secrets in the
|
||||||
|
database
|
||||||
|
- `SUPERMARKET_STORAGE`: a folder, or `s3://bucket/prefix` with its
|
||||||
|
credentials
|
||||||
|
- `SUPERMARKET_MAIL_URL`: the SMTP server for the app's own mail
|
||||||
|
(invitations, password resets), separate from each team's outreach
|
||||||
|
mail
|
||||||
|
|
||||||
|
Start refuses a combination that doesn't make sense, and says why:
|
||||||
|
server without a database URL, or multi on `http://`. Settings → About
|
||||||
|
shows the edition.
|
||||||
|
2. **One database layer, two databases.**
|
||||||
|
- `internal/db` gets a dialect (SQLite or Postgres, using the `pgx`
|
||||||
|
driver) and a small set of helpers:
|
||||||
|
- placeholders rewritten for Postgres
|
||||||
|
- `Insert…Returning` for new IDs
|
||||||
|
- `Greatest`/`Least`
|
||||||
|
- case-insensitive text (a `citext` column, or `lower()` in unique
|
||||||
|
indexes)
|
||||||
|
- JSON reads
|
||||||
|
- upserts
|
||||||
|
- The SQL in the packages is changed to use them, package by package,
|
||||||
|
with the tests run against both databases at each step.
|
||||||
|
- Timestamps stay as RFC 3339 text in both databases. Comparisons keep
|
||||||
|
working and the change stays mechanical; switching to `timestamptz`
|
||||||
|
can come later.
|
||||||
|
3. **The Postgres schema and its migrations.**
|
||||||
|
- Postgres starts from one migration that is today's schema 29 as a
|
||||||
|
whole. After it, each new migration is written once for both
|
||||||
|
databases, or as a pair when they must differ.
|
||||||
|
- `db.Version` carries on counting from 29 for both, so a backup or
|
||||||
|
export says which schema it holds.
|
||||||
|
- Before a migration, the local edition still makes its backup with
|
||||||
|
`VACUUM INTO`. On Postgres, the operator's backups (`pg_dump`, or the
|
||||||
|
host's snapshots) take that place, and the app records a migration
|
||||||
|
marker.
|
||||||
|
4. **Secrets in the database, encrypted.**
|
||||||
|
- A `secrets` table holds each secret's name and its ciphertext,
|
||||||
|
encrypted with AES-256-GCM under `SUPERMARKET_SECRET_KEY`.
|
||||||
|
`secrets.Store` keeps its interface, so the 41 callers don't change.
|
||||||
|
- The local edition keeps `secrets.json`, so its backups still leave
|
||||||
|
secrets out, unchanged.
|
||||||
|
- On server and multi, losing the key means re-entering every
|
||||||
|
connection: the operator is told so at setup, and the key never goes
|
||||||
|
in the database or its backups.
|
||||||
|
5. **Files behind one interface.** A `storage` package with two
|
||||||
|
implementations: a folder (local and server) and S3-compatible object
|
||||||
|
storage (multi). These go through it:
|
||||||
|
- backups and exports
|
||||||
|
- uploaded files
|
||||||
|
- CRM-bridge state and other small state files, which move into the
|
||||||
|
database
|
||||||
|
|
||||||
|
The sites' git clones and page previews stay on local disk as a cache:
|
||||||
|
they can be cloned and built again. They sit under a folder per team,
|
||||||
|
so a team can't reach another's clone.
|
||||||
|
6. **Background jobs that can run on several copies of the app.**
|
||||||
|
- A `jobs` table holds each job's kind, team, when it is next due and
|
||||||
|
who has it, claimed with `FOR UPDATE SKIP LOCKED` on Postgres. The
|
||||||
|
`Run…` loops become job kinds run once per team.
|
||||||
|
- With several copies running, one claims each job; on SQLite the
|
||||||
|
table works as today, in one process.
|
||||||
|
- In-memory state that has to be shared (OAuth flows in progress, the
|
||||||
|
sending lock, Reddit's token) moves into the database or becomes a
|
||||||
|
database lock.
|
||||||
|
7. **Moving a local install to a server.** `supermarket export` writes a
|
||||||
|
team's whole database plus its secrets: a mode-0600 `.tar.gz` that
|
||||||
|
warns it holds credentials, as `backup --with-secrets` does. `supermarket
|
||||||
|
import` loads it into a Postgres database, as a server's team, or as a
|
||||||
|
new team on multi-tenant (Phase 13). It is checked by moving
|
||||||
|
Federated's own install over and comparing row counts.
|
||||||
|
|
||||||
|
**Done when:** every test passes on SQLite and on Postgres, and
|
||||||
|
Federated's local install runs unchanged. The same data, exported and
|
||||||
|
imported into Postgres, shows the same pages.
|
||||||
|
|
||||||
|
#### Phase 10: Users, sign-in and roles (the server edition)
|
||||||
|
|
||||||
|
This makes the server edition usable by a team. A commit after each part.
|
||||||
|
|
||||||
|
1. **Users and sessions.**
|
||||||
|
- Tables:
|
||||||
|
- `users`: email, name, kind (person or agent), status (invited,
|
||||||
|
active or disabled), password hash (Argon2id), the profile
|
||||||
|
fields, and the time zone
|
||||||
|
- `memberships`: team, user, role, and the modules granted
|
||||||
|
- `sessions`: server-side, with only a random ID in a `Secure`,
|
||||||
|
`HttpOnly`, `SameSite=Lax` cookie
|
||||||
|
- On local, every request is the owner, as today, and nothing asks
|
||||||
|
anyone to sign in.
|
||||||
|
- Forms get a CSRF token, as well as today's same-origin check.
|
||||||
|
2. **The first owner.**
|
||||||
|
- On a new server, the start-up log prints a one-time setup link
|
||||||
|
(also `supermarket setup-link`).
|
||||||
|
- Whoever opens it creates the owner: email, name and password. Then
|
||||||
|
they fill in the company profile, as on local.
|
||||||
|
- Until that's done, every other page says the setup isn't finished.
|
||||||
|
3. **Signing in and out.**
|
||||||
|
- Email and password, with a reset link by email
|
||||||
|
(`SUPERMARKET_MAIL_URL`). The link is single-use and lasts an hour.
|
||||||
|
- Sign-in is limited per address and per IP, and an account locks
|
||||||
|
after repeated failures; the user is told, and an admin can unlock
|
||||||
|
it.
|
||||||
|
- Each user sees their active sessions and can sign out of the others
|
||||||
|
(Settings → Your account).
|
||||||
|
- Changing the password ends their other sessions.
|
||||||
|
- **Two-factor sign-in** is an option for every user, owners and admins
|
||||||
|
included (decided 2026-11-25): an authenticator app (TOTP), with
|
||||||
|
ten single-use recovery codes. Each user turns it on under Settings →
|
||||||
|
Your account. An admin can reset it for someone who lost their phone,
|
||||||
|
which is logged. Signing in with the Core (Phase 12) leaves
|
||||||
|
two-factor to Authelia.
|
||||||
|
4. **Creating users (admins).** On Settings → Users, an admin:
|
||||||
|
- enters an email and a name
|
||||||
|
- picks *Admin*, or *Member* with the modules to give, each as
|
||||||
|
*view* or *edit*
|
||||||
|
- sends the invitation
|
||||||
|
|
||||||
|
The new user gets an email with a link that lasts 7 days and can be
|
||||||
|
used once. The link leads to:
|
||||||
|
- choosing a password, or signing in with the Core (Phase 12)
|
||||||
|
- filling in their profile: name, title, time zone, photo, and which
|
||||||
|
emails they want (such as the daily SEO email, Phase 3)
|
||||||
|
|
||||||
|
Admins can resend or withdraw an invitation, change someone's role or
|
||||||
|
modules, disable or remove them, and see when each person last signed
|
||||||
|
in.
|
||||||
|
5. **Access enforced everywhere.**
|
||||||
|
- Each route belongs to a module (or to Settings or Overview). A
|
||||||
|
request outside the user's modules gets a 403 page, and htmx
|
||||||
|
fragments are checked the same way.
|
||||||
|
- Each route is also marked as reading or changing. A *view* member
|
||||||
|
sees the module's pages without the buttons and forms that change
|
||||||
|
things, and the server refuses those requests too, not just hides
|
||||||
|
them.
|
||||||
|
- The sidebar, Overview's cards, Search results and the daily emails
|
||||||
|
show only the user's modules.
|
||||||
|
- Only admins see Settings, apart from Your account.
|
||||||
|
- One table maps routes to modules, and a test fails when a new route
|
||||||
|
isn't in it.
|
||||||
|
6. **Connections, for admins.** Settings gets a **Connections** page that
|
||||||
|
lists every connected service with its state (connected, missing,
|
||||||
|
failing, last checked) and a link to set it up. The existing pages stay
|
||||||
|
where they are, behind admin access. Who connected each one, and when,
|
||||||
|
is recorded.
|
||||||
|
7. **Posting accounts, and who may post to them** (decided 2026-11-25).
|
||||||
|
- The social accounts posts go out from (X, LinkedIn profiles and the
|
||||||
|
LinkedIn page, Reddit) become **posting accounts**. There can be
|
||||||
|
several of each: the company's, and any user's own, each signed in
|
||||||
|
once by its owner or an admin.
|
||||||
|
- Settings → Posting accounts has a grid of users against accounts,
|
||||||
|
saying who may post to which. A user's own account is theirs by
|
||||||
|
default. Admins may post to every account; an admin can grant others.
|
||||||
|
- On a draft, the writer picks one account or several at once, from
|
||||||
|
those they're allowed and that are set up (signed in and working).
|
||||||
|
Each account gets its own copy, within that platform's limits, and
|
||||||
|
the draft shows where it went.
|
||||||
|
- Posting as someone else needs that permission. The post, and the
|
||||||
|
audit log, record both who wrote it and which account it went out as.
|
||||||
|
- A user who signs their own account out, or is removed, takes it out
|
||||||
|
of everyone's list; scheduled posts to it are held and their writers
|
||||||
|
told.
|
||||||
|
- Agents get the same grid: an agent posts only to the accounts it's
|
||||||
|
allowed.
|
||||||
|
8. **Who did what.** An `audit_log` records:
|
||||||
|
- sign-ins (and failed ones)
|
||||||
|
- invitations and role changes
|
||||||
|
- connection changes
|
||||||
|
- anything sent or published (posts, emails, site pushes, mailing-list
|
||||||
|
adds)
|
||||||
|
- deletions
|
||||||
|
|
||||||
|
Each entry has the user and the time. Admins see it under Settings →
|
||||||
|
Activity. Posts, drafts and emails also record who made them, shown
|
||||||
|
as *by Jane*.
|
||||||
|
9. **The server package.**
|
||||||
|
- A `compose.server.yaml` runs the app, Postgres, and Caddy for HTTPS
|
||||||
|
on the team's own domain. Supermarket is published on Caddy's port,
|
||||||
|
not on 127.0.0.1.
|
||||||
|
- Server installs face the internet by default (decided 2026-11-25),
|
||||||
|
so sign-in limits, two-factor and the audit log matter from day one.
|
||||||
|
They can also be deployed on a private network or VPN: then Caddy
|
||||||
|
uses a certificate from the team's own CA, or DNS validation, since
|
||||||
|
Let's Encrypt can't reach it; services that call in (Stripe's
|
||||||
|
webhooks) don't, and polling takes over as on local.
|
||||||
|
- An `install-server.sh` asks for the domain and the mail server, and
|
||||||
|
generates the secret key and database password.
|
||||||
|
- Postgres gets nightly `pg_dump` backups. Settings → Backups shows
|
||||||
|
them on server, with restore done by the operator.
|
||||||
|
- The OAuth redirect addresses become `https://<domain>/auth/…`, so
|
||||||
|
each service's developer app needs that address added.
|
||||||
|
- Hermes and the CRM bridge: on a server, Hermes reaches `/mcp` with an
|
||||||
|
agent key that has the CRM scope (Phase 11), instead of the socket.
|
||||||
|
|
||||||
|
**Done when:** a server install's owner can invite an admin and a member
|
||||||
|
who has only SEO. The member signs in and sees only SEO. Every other
|
||||||
|
module, Settings and their fragments answer 403. The log shows each step.
|
||||||
|
|
||||||
|
#### Phase 11: Agents
|
||||||
|
|
||||||
|
Every edition gets this, including local, where an agent key replaces the
|
||||||
|
single `mcp-token`. A commit after each part.
|
||||||
|
|
||||||
|
1. **Agent users and their keys.**
|
||||||
|
- An admin creates an agent on Settings → Users → *New agent*. It has a
|
||||||
|
name, a description, and the modules it's given, each *read* or
|
||||||
|
*read and act*.
|
||||||
|
- Supermarket shows its key once (`sm_…`). Only a hash of the key is
|
||||||
|
kept.
|
||||||
|
- Keys can have an expiry date. Each key shows when it was last used,
|
||||||
|
and from where. A key can be rotated (the old one keeps working for a
|
||||||
|
day) or revoked.
|
||||||
|
- Agents go in the audit log like people, marked as agents.
|
||||||
|
- On local, today's `mcp-token` becomes the key of a built-in *Hermes*
|
||||||
|
agent with the CRM scope. The socket stays as it is.
|
||||||
|
2. **Module tools over MCP.**
|
||||||
|
- `/mcp` checks the key, and offers only the tools for the agent's
|
||||||
|
modules. A *read* grant gets only the reading tools.
|
||||||
|
- The tools follow what the pages do, module by module:
|
||||||
|
- **Content:** list items, create and edit drafts, schedule or
|
||||||
|
publish
|
||||||
|
- **Prospects:** signals and their replies, people, outreach drafts,
|
||||||
|
mailing lists, suppression
|
||||||
|
- **SEO:** the morning check, What to write next, Links, page edits
|
||||||
|
as proposals
|
||||||
|
- **Sites:** pages, sections, previews, push to Gitea
|
||||||
|
- **Metrics:** reads only
|
||||||
|
- **The Market:** list and edit
|
||||||
|
- Each tool calls the same Go functions the web handlers use, so rules
|
||||||
|
like suppression, opt-in and posting limits hold for agents too.
|
||||||
|
3. **Approvals for what goes out.**
|
||||||
|
- Anything that leaves Supermarket is held by default for a person to
|
||||||
|
approve: a post, an email, a site push, a mailing-list add. The
|
||||||
|
agent gets back *waiting for approval*.
|
||||||
|
- An **Approvals** page (and a count in the sidebar) lists what agents
|
||||||
|
asked to do. Members with that module, and admins, approve or refuse
|
||||||
|
each item, and can edit it first.
|
||||||
|
- An admin can let an agent act without approval, per module. This is
|
||||||
|
recorded, and the agent's page warns about it.
|
||||||
|
- The reason: agents read untrusted web text (signals, replies,
|
||||||
|
search results), the same risk that keeps the app's AI away from
|
||||||
|
Hermes' tools today.
|
||||||
|
4. **Limits and visibility.**
|
||||||
|
- Each agent has a rate limit per minute and a cap per day on things
|
||||||
|
that go out.
|
||||||
|
- The agent's page shows its recent calls (tool, result, time) and
|
||||||
|
what it's waiting on.
|
||||||
|
- A *Pause* switch stops all of an agent's calls at once.
|
||||||
|
5. **A JSON API, for scripts that aren't MCP clients.** It uses the same
|
||||||
|
key and has the same scopes and approvals, as REST under `/api/v1`,
|
||||||
|
covering what the MCP tools do. It's documented at `/api/v1/docs`.
|
||||||
|
This part can wait until someone needs it.
|
||||||
|
|
||||||
|
**Done when:** an agent with Content (read and act) and SEO (read) can run
|
||||||
|
a day's work through MCP: read the morning check, write drafts from What
|
||||||
|
to write next, and schedule them. Each draft waits on Approvals, and the
|
||||||
|
SEO tools that change things aren't offered to it. Revoking the key stops
|
||||||
|
it at once.
|
||||||
|
|
||||||
|
#### Phase 12: Signing in with the Core (OIDC)
|
||||||
|
|
||||||
|
1. **An OIDC sign-in.**
|
||||||
|
- The Core runs **Authelia** (2026-11-25), which is an OpenID Connect
|
||||||
|
provider. Its clients are listed in Authelia's configuration, so the
|
||||||
|
Core's admin adds Supermarket there: Supermarket's Settings → Sign-in
|
||||||
|
shows the block to paste (client ID, the hashed secret, the redirect
|
||||||
|
address `https://<domain>/auth/core/callback`, scopes `openid email
|
||||||
|
profile groups`).
|
||||||
|
- On Settings → Sign-in, an admin enters the issuer address (suggested
|
||||||
|
as `https://authelia.<Core domain>` from the Core's domain), the
|
||||||
|
client ID and the secret, and *Test* checks the provider's discovery
|
||||||
|
document.
|
||||||
|
- The sign-in page then offers *Sign in with <Core>*, with the code
|
||||||
|
flow and PKCE.
|
||||||
|
2. **Who may sign in.**
|
||||||
|
- Only invited users: the Core's account is matched by email at the
|
||||||
|
first sign-in, and then remembered by its subject ID.
|
||||||
|
- Optionally, an admin turns on *anyone with an address at
|
||||||
|
<domain> joins as a member with these modules*.
|
||||||
|
3. **Password, Core, or both.** An admin can require the Core's sign-in
|
||||||
|
for everyone. If they do, passwords are turned off, except the
|
||||||
|
owner's, kept as a way in if the Core is down.
|
||||||
|
4. **Signing out**, which also ends the Authelia session where Authelia
|
||||||
|
supports it.
|
||||||
|
5. **Groups, later:** Authelia's groups could map to roles (a
|
||||||
|
`supermarket-admins` group makes admins). Until then roles are set in
|
||||||
|
Supermarket.
|
||||||
|
|
||||||
|
Open question: is Authelia's address on every Core
|
||||||
|
`authelia.<Core domain>`, and will the Core's developer add Supermarket's
|
||||||
|
client, or should the Core's admin tooling do it?
|
||||||
|
|
||||||
|
#### Phase 13: Multi-tenant
|
||||||
|
|
||||||
|
Many teams sign in at one address, each working on its own domains. This
|
||||||
|
builds on Phases 9–12. A commit after each part.
|
||||||
|
|
||||||
|
1. **Teams everywhere.**
|
||||||
|
- Every table that holds a company's data gets `team_id`, and its
|
||||||
|
unique keys include it. The settings table's key becomes
|
||||||
|
(team, key). This is a migration for both databases; local and
|
||||||
|
server get team 1.
|
||||||
|
- Queries go through a team-scoped handle (`db.Team(id)`) that adds
|
||||||
|
the team to every query. A test walks every query in the code and
|
||||||
|
fails on one without it.
|
||||||
|
2. **A second guard in Postgres.** Every team table gets row-level
|
||||||
|
security (`team_id = current_setting('app.team')`), set for each
|
||||||
|
request's transaction. A query the handle missed returns nothing,
|
||||||
|
instead of another team's rows. Platform jobs that need to see every
|
||||||
|
team use a separate database role.
|
||||||
|
3. **Signing up and creating a team.**
|
||||||
|
- On multi, the home page offers *Sign up*: an email, password, and
|
||||||
|
the company's name and first website. That person becomes the
|
||||||
|
team's owner, and the team starts on a trial (Phase 14).
|
||||||
|
- A user can belong to several teams, with a team switcher in the
|
||||||
|
sidebar; the role is per team.
|
||||||
|
- Invitations work as in Phase 10, within a team.
|
||||||
|
4. **Proving a domain is the team's.** Before Supermarket does anything
|
||||||
|
with a website (crawl it, read its Search Console data, publish to
|
||||||
|
it), the team proves it's theirs, in one of three ways:
|
||||||
|
- a DNS TXT record
|
||||||
|
- a file on the site
|
||||||
|
- a Google Search Console property they own
|
||||||
|
|
||||||
|
A domain can belong to one team at a time. This keeps one team from
|
||||||
|
claiming another company's site.
|
||||||
|
5. **Each team's connections and jobs.**
|
||||||
|
- Connections and secrets are per team: each team brings its own AI
|
||||||
|
key and services (decided 2026-11-25).
|
||||||
|
- The OAuth redirect addresses are the platform's
|
||||||
|
(`https://app…/auth/<service>/callback`), with the team in the
|
||||||
|
state. Teams register that address in their own developer apps.
|
||||||
|
- Background jobs run per team (Phase 9, part 6), with each team's
|
||||||
|
share of the work kept fair, so one team's 10,000 pages don't hold
|
||||||
|
up another's morning check.
|
||||||
|
- Each team has limits on outgoing fetches and storage, set by plan.
|
||||||
|
6. **The Core, per team.**
|
||||||
|
- A team running a Federated Core enters its Core's domain under
|
||||||
|
Connections. That replaces the `core.conf` a local install reads.
|
||||||
|
- Hermes and the CRM bridge connect from the team's own side, using
|
||||||
|
an agent key (Phase 11). The platform never holds a Core's admin
|
||||||
|
credentials.
|
||||||
|
7. **The platform's own admin.** This is for the people running the
|
||||||
|
service, separate from teams. Super-admins sign in at a separate
|
||||||
|
`/platform` area with two-factor sign-in required, and can:
|
||||||
|
- list teams, with their plan, usage and health
|
||||||
|
- suspend a team
|
||||||
|
- see jobs failing across teams
|
||||||
|
- resend a team's invitations
|
||||||
|
|
||||||
|
They can't read a team's data by default. *View as* requires a reason,
|
||||||
|
is time-limited, and is logged in the team's own audit log.
|
||||||
|
8. **A team's data is theirs.**
|
||||||
|
- The owner can export everything (Phase 9's export, without the
|
||||||
|
secrets unless asked for).
|
||||||
|
- Deleting the team removes its rows and files after 30 days. The
|
||||||
|
deletion can be undone within that time, and every user in the team
|
||||||
|
gets an email when it's asked for.
|
||||||
|
9. **Running at scale.** Several copies of the app can sit behind one
|
||||||
|
load balancer. Everything a request needs to remember lives in the
|
||||||
|
database (sessions, OAuth flows in progress, locks), so any copy can
|
||||||
|
answer any request. Files are in object storage. Postgres runs with
|
||||||
|
connection pooling. Per-team metrics feed the platform page.
|
||||||
|
|
||||||
|
**Done when:** two teams with their own domains are signed up. Neither
|
||||||
|
can see or change the other's data, through any page, fragment, MCP tool
|
||||||
|
or job, and a test proves it for every route and tool. Three copies of the
|
||||||
|
app share the work.
|
||||||
|
|
||||||
|
#### Phase 14: Billing (multi-tenant)
|
||||||
|
|
||||||
|
The platform bills each team through **Stripe Billing**. This uses the
|
||||||
|
platform's own Stripe account (`SUPERMARKET_STRIPE_KEY`), which is
|
||||||
|
separate from the team's own Stripe connection that the Metrics module
|
||||||
|
reads.
|
||||||
|
|
||||||
|
1. **Plans.** Plans live in a configuration file, mapped to Stripe
|
||||||
|
prices. Each plan sets:
|
||||||
|
- the modules included
|
||||||
|
- seats (people), and how many agents
|
||||||
|
- websites, and pages crawled
|
||||||
|
- fetch and storage limits
|
||||||
|
|
||||||
|
The trial is 14 days on the top plan.
|
||||||
|
2. **The owner's Billing page.** It shows the plan, seats in use, the
|
||||||
|
trial's end, and the next invoice. *Change plan* goes to Stripe
|
||||||
|
Checkout. *Payment and invoices* goes to Stripe's Customer Portal.
|
||||||
|
Only the owner sees it; admins see the plan, not the payment details.
|
||||||
|
3. **Stripe's events.** The multi-tenant edition can be reached from the
|
||||||
|
internet, so it takes Stripe's webhooks, with their signatures checked
|
||||||
|
(local still polls). Supermarket keeps the subscription's state per
|
||||||
|
team: trialing, active, past due, canceled.
|
||||||
|
4. **What happens when it lapses.**
|
||||||
|
- Past due: a banner, and the owner gets an email.
|
||||||
|
- After 14 days: the team becomes read-only. Nothing is fetched,
|
||||||
|
sent or published, and agents get *the team's subscription has
|
||||||
|
lapsed*.
|
||||||
|
- After 60 days, the team is deleted as in Phase 13, part 8, with
|
||||||
|
emails first.
|
||||||
|
5. **Seats.** Inviting beyond the plan's seats asks the owner to add a
|
||||||
|
seat; admins are told to ask the owner.
|
||||||
|
|
||||||
|
Open questions for this phase:
|
||||||
|
- Pricing: per seat, a flat price per team, or tiers by websites?
|
||||||
|
- Is there an annual plan?
|
||||||
|
- Tax: Stripe Tax?
|
||||||
|
|
||||||
|
#### Order
|
||||||
|
|
||||||
|
```
|
||||||
|
Phase 9 (groundwork) ──► Phase 10 (users; the server edition) ──► Phase 11 (agents)
|
||||||
|
│ │
|
||||||
|
└──► Phase 12 (Core sign-in) │
|
||||||
|
▼
|
||||||
|
Phase 13 (multi-tenant) ◄─────────── 9, 10, 11, 12
|
||||||
|
│
|
||||||
|
└──► Phase 14 (billing)
|
||||||
|
```
|
||||||
|
|
||||||
|
Phase 11's first two parts can start on local right after Phase 9, since
|
||||||
|
they replace the `mcp-token`.
|
||||||
|
|
||||||
|
#### Open questions (2026-11-25)
|
||||||
|
|
||||||
|
1. Can a person belong to several teams on multi-tenant? (Planned: yes.)
|
||||||
|
2. ~~View-only access~~ *Resolved 2026-11-25:* members get each module
|
||||||
|
as *view* or *edit* (Phase 10, part 5).
|
||||||
|
3. ~~Posting as yourself~~ *Resolved 2026-11-25:* posting accounts,
|
||||||
|
several per platform, with admins choosing who may post to which; a
|
||||||
|
post can go out as yourself, as someone else, or to several accounts
|
||||||
|
at once (Phase 10, part 7).
|
||||||
|
4. *Partly resolved 2026-11-25:* the Core runs Authelia. Who adds
|
||||||
|
Supermarket's client to it is still open (Phase 12).
|
||||||
|
5. Where will the multi-tenant edition be hosted, and which object
|
||||||
|
storage will it use?
|
||||||
|
6. Should agents' outgoing actions always need approval at first, with
|
||||||
|
no switch until Phase 11 has run for a while?
|
||||||
|
7. ~~Internet or private~~ *Resolved 2026-11-25:* server installs face
|
||||||
|
the internet, and can also be deployed on a private network (Phase 10,
|
||||||
|
part 9).
|
||||||
|
8. ~~Two-factor~~ *Resolved 2026-11-25:* an option for every user,
|
||||||
|
owners and admins included (Phase 10, part 3).
|
||||||
|
|
||||||
### Future enhancements
|
### Future enhancements
|
||||||
|
|
||||||
Not in any phase yet; picked up when the user asks.
|
Not in any phase yet; picked up when the user asks.
|
||||||
|
|||||||
Reference in New Issue
Block a user