Skip to content

API ​

Accepted architecture · 1 October 2026, option 2

Agentfy hosts the harness; Store Deputy API exposes the single MCP; the store module exposes one signed JSON endpoint (Module Protocol, operations from operations.json). Store Deputy governs connections, actor/shopper context, permissions, approvals and audit without building another harness. Connect → login/register → secure pairing → automatic agent provisioning in Agentfy with Store Deputy MCP → return to the module. App contains teams, agents, account, billing and per-agent chat.

This replaces the earlier same-day direct-module-MCP design. Existing code and prototypes below do not implement the new integration. Shopper sessions and the real OpenCart cart have separate scoped bindings; cookies stay in the shop. See the accepted central MCP decision for boundaries, delivery stages and remaining contract work.

Built; runs on a developer's machine · 15 October 2026 (STOR-72). Not deployed. It has only ever talked to the two local test shops and to a fake Agentfy. Since STOR-72 it follows the API core contract shared with Bonsite, Securify and Shiffty.

The API is the one service that knows who a person is, which team they belong to, what their role allows and which stores the team has connected. Every other part asks it. Nothing else talks to a shop.

What it does today ​

  • Accounts. Register, confirm the email with a six-digit code sent to it (no session before that), sign in, renew a session, sign out, reset a forgotten password by an emailed link. Signing out takes effect at once: every request is checked against the live session, not only against the token it carries. A renewal token works once; presenting a used one ends the whole session.
  • Teams and roles. A person who registers gets a team when they confirm their email; a person who arrives through an invitation gets none and joins the inviting team (they can create a team of their own later). The automatic team is named after its owner until it connects its first store; then it takes that store's name, unless someone has renamed it. Owners and admins may rename it. A team has exactly one owner; the others are admins or members. Owners and admins invite people by email; the invitation grants nothing until the link in the letter is used. The owner and admins change roles between member and admin and remove members and other admins (inviting an admin stays with the owner); nobody touches the owner, and nobody changes their own role or removes themselves this way (leaving is a separate action). The owner role moves only when the chosen member accepts a handover.
  • Team API keys. An owner or admin makes a key for scripts. It is shown once, reads its own team only, and stops at once when revoked or when the team changes hands.
  • A key as an AI client's access to the MCP server (STOR-90, 2 November 2026; implemented only locally, founder's acceptance pending). When the key is made, the owner or admin also chooses which of the team's stores it opens and what it may do there, by the Admin Agent's permission names (catalog.read, sales.read, addresses.read, catalog.write, sales.write; the last two only let the client propose changes (prices, stock, status, storefronts, variants, categories; order statuses and coupons since 2 November 2026), which an owner or admin approves on the site as before; sales.write includes sales.read). Any AI client (Claude Desktop or Code, Cursor, a script) then connects to POST /mcp with Authorization: Bearer sd_…: the same chain as the Admin Agent, API → MCP → module. A key-only tool store_list returns the key's stores, and every other tool takes a store argument (a store id), checked against the key's stores and that the store is active. This is the one exception to "no tool argument names a store" and it holds for keys only; an Admin Agent's calls take no such argument. What a call may do is the key's permissions, cut down to the platform-wide agent settings and to what the store's module declares; a blocked team, a paused or disconnected store, and a revoked, expired or closed-team key are refused as they are for the agent. A key may make 120 tool calls a minute (a constant; plans do not set it). Every call is written to the journal with the key and the store, and the store's Activity shows it as "API key «Name»"; a proposal made through a key shows in Awaiting approval under the same words. Transport is the existing stateless streamable HTTP; there is no OAuth. Proven only against the two local test shops, with no real MCP client run in the automated tests.
  • Stores, catalog, price changes, agents. Connect a shop through its module, keep a copy of its catalog, let agents propose price changes for a person to approve, and run each store's agent in Agentfy (or in the fake Agentfy locally). These have their own pages.
  • Platform admins. Store Deputy's own staff see clients, plans, stores, agents and the agents' tool calls in the admin console, and keep the Agentfy connection and the mail server in Settings.
  • Service checks. A health check and an interactive description of every route at /docs.
AreaRoutes (all under /v1)
Sign-in/auth/register, /auth/verify-email, /auth/resend-code, /auth/login, /auth/refresh, /auth/logout, /auth/me, /auth/password/forgot, /auth/password/reset
Teams/teams, /teams/:teamId, /teams/:teamId/leave
Members/teams/:teamId/members, /teams/:teamId/members/:userId
Invitations/teams/:teamId/invitations, /teams/:teamId/invitations/:id, /invitations/accept
API keys/teams/:teamId/api-keys, /teams/:teamId/api-keys/:keyId
Handing a team over/teams/:teamId/ownership-transfer, /teams/:teamId/ownership-transfer/accept
Stores/teams/:teamId/stores, /teams/:teamId/stores/authorize, /teams/:teamId/stores/:storeId
Platform admins/admin/**, /settings/**

Some addresses carry no version, because something other than our sites calls them at an address fixed outside this repository: GET /health (the health checks), POST /mcp (Agentfy), /connections/exchange and /connections/confirm (OpenCart modules already installed in shops) and /module/opencart3/download (the module download link). They never move to a version.

Until 31 December 2026 the former /api/… addresses still answer: /api/<path> is served as /v1/<path> (and /api/health as /health, /api/docs as /docs), with the headers Deprecation: true and Link: </v1/<path>>; rel="successor-version".

Every answer has one shape. Success is { success: true, data }, with meta added to a page of a list. A refusal is { success: false, code, message, details?, requestId }: the code says what went wrong, and the request id finds the request's log lines.

How the code is arranged ​

All code lives in slices, grouped from the lowest to the highest. A group may use the groups before it and none after it.

api/src/slices/
  setup/       shared plumbing, no business rules: config, core (errors,
               the answer shape, rate limits, health), logger, request,
               prisma, secret, job, mail, network, setting, agentfy,
               monitoring (error tracking)
  user/        who is acting: user, password, session, auth
  team/        team, member, access, invitation, apiKey, ownershipTransfer
  billing/     plans and usage limits
  store/       connected shops and the driver that talks to their module
  catalog/     the copy of each shop's catalog
  operations/  proposed changes, approvals and their execution
  mcp/         the agents' tools and their policy
  agent/       each store's agent in Agentfy, and chat
  admin/       the platform admins' console and Settings

A slice has the same shape every time. Team invitations, as an example:

team/invitation/
  invitation.module.ts      wires each contract to its implementation
  invitation.controller.ts  routes, input, output
  teamInvitation.prisma     this slice's database table
  dtos/                     request and response shapes (zod)
  domain/                   rules and contracts
    invitation.service.ts     who may invite, what accepting does
    invitation.gateway.ts     contract: saving and loading invitations
    mails/invitation.mail.ts  the letter
    errors/                   one class per failure
  data/
    invitation.gateway.ts     PostgreSQL through Prisma 8

The database is reached through Prisma inside a gateway. An outside service is different: the shop module, Agentfy and the mail providers are each wrapped in a repository, so their wire formats stay out of the rules.

One request, layer by layer ​

An owner invites a colleague. This is what happens to that request.

  1. Request id and limits. The request gets an id (the caller's X-Request-Id, if it is a plain identifier) that every log line and the answer carry. The rate limit counts it.
  2. Sign-in check. A check registered for every route establishes who is calling — a person with a live session or a team API key.
  3. Team role. The route needs an admin or the owner of this team. Someone outside the team is told the team does not exist.
  4. Validation. The body is checked against its zod schema. A wrong field answers VALIDATION_ERROR with the list of fields.
  5. Service — the rules. The address is not a member already; only the owner may invite an admin. A pending invitation to the same address is replaced.
  6. Gateway and mail. The invitation is saved with only a hash of its token; the letter carries the one copy. If the letter cannot be sent, the invitation is withdrawn again.
  7. Answer. The controller returns the invitation; the API wraps it as { success: true, data }.

The service never imports the database client or the mail library. It knows contracts and nothing about how they are met.

Rules every slice follows ​

  • Slice folders are singular; routes are plural.
  • A contract is an abstract class in domain/. Its implementation sits in data/, and the slice's module ties the two together.
  • A slice uses another slice through its domain: a store asks team access whether the caller's role is allowed; it never reads another slice's data layer.
  • Every route carries an operation name and documents its answer, so the sites' generated client knows both.
  • Every route requires sign-in unless it is explicitly marked as open.
  • Each slice owns the schema of its own tables; Prisma 8 reads all of them as one contract.
  • Every failure is a domain error with a code; nothing else reaches a client.
  • Imports between slices use short aliases — #setup/…, #user/…, #team/… — not long relative paths.
  • bun run check runs the boundary check, the type check and the linter.

The points where this API knowingly differs from CleanSlice are listed in the overview.

Error tracking (GlitchTip) ​

Built; checked on a developer's machine · 8 November 2026 (STOR-114). Not switched on anywhere: no deployed environment has the variables yet. The local checks and their results are in the STOR-114 pull request.

When the API fails on its own side, the error goes to Store Deputy's GlitchTip (errors.dreamvention.com, project storedeputy-api; it speaks the Sentry protocol), grouped, with the environment and the release that produced it.

Sent:

  • an answer with a 5xx status: a bug (500 INTERNAL_ERROR), a domain error with a 5xx status (for example 503), a 5xx from the framework;
  • an error nothing caught, and a promise rejection nobody handled;
  • a background job that has failed for the last time, tagged job with its kind (plus its id and attempts), and a failing poll of the job queue (tag job=poll, at most once every 5 minutes). A failed attempt that will be retried is only logged: a shop that was down for a minute is not an incident.

Never sent: a refusal the caller caused (4xx: not found, VALIDATION_ERROR, sign-in and permission refusals, the rate limit). Every event carries the request id (X-Request-Id) as a tag, so the event and the request's log lines find each other.

Scrubbed: the request keeps its method, its path without query string or fragment, and its User-Agent; nothing else. Bodies, cookies, Authorization, Cookie and every other header, tokens (sd_… keys, JWTs, Bearer …), email addresses, a job's payload, log lines (there are no breadcrumbs at all), source lines around the stack frames, local variables and the host name never leave the API. The user is an id, never an email, a name or an address. An error message is scrubbed by the same rules, but free text the code put into a message cannot always be recognised; the filters send only the API's own failures, not the content of a shop or a chat.

VariableValue
SENTRY_DSNThe DSN of the storedeputy-api project, read when the API starts. Empty: tracking is off.
SENTRY_ENVIRONMENTprod, dev or local, nothing else. GlitchTip keeps every environment name it has seen, so with a DSN and any other value, or none, tracking stays off and the start log says why; the API itself starts as usual. The SDK's own default (production) is never sent.
SENTRY_RELEASEThe git sha of the build.

Turning it off. Leave SENTRY_DSN empty, or remove it. The SDK is then not started at all and makes no network call. This is the default of the local stand, the tests and CI.

Checking it locally. Put SENTRY_DSN (the API project's DSN) and SENTRY_ENVIRONMENT=local into api/.env.dev and restart the API. The start log shows Error tracking on: environment local, release …, and a 500 then appears in GlitchTip under environment local. Remove both lines afterwards. A test event carries the tag task=<Jira key>.

The SDK (@sentry/nestjs, pinned to an exact version) is started by the first import of the API's entry file, before anything else is loaded. Performance tracing (sample rate 0), sessions, breadcrumbs and trace headers on the API's own outgoing calls are off.

How it is checked ​

bun run test makes a throwaway PostgreSQL database for the run, applies the migrations, and drops it afterwards; every suite starts from an empty database. The scenarios run against a real PostgreSQL in Docker, not against mocks; the ones that need the two local test shops or the local mail catcher run separately. Their results for STOR-72 are in the pull request, not on this page.

Not built yet ​

  • Deployment. No hosting has been chosen.
  • A production mail provider: until one is configured, registration on a deployed API answers 503.
  • Rate limits shared between several API instances: counts are kept in each instance's memory, which suits one instance.
  • Settings secrets still use their own key (SETTINGS_KEY); moving them to the common one is a follow-up.

Module ↔ API protocol: Module Protocol 1