Skip to content
Concepts

Tenancy and scopes

How AppCore isolates tenants, apps and environments, binds every request to one scope, and authorizes consumers, operators, services and providers.

On this page

Every piece of data in AppCore belongs to exactly one scope: a tenant, an app and an environment. A scope has its own runtime Worker and its own D1 database. A request can only ever reach one scope, and that scope is fixed by where the request is deployed, never by anything the client sends.

The hierarchy

Diagram (Mermaid source)
flowchart TD
  T["Tenant<br/>(your organization / legal operator)"] --> A1["App A<br/>(one product, one bundle ID + package name)"]
  T --> A2["App B"]
  A1 --> D["development"]
  A1 --> S["staging"]
  A1 --> P["production"]
  P --> RS["Resource set (resource_set_id)<br/>runtime Worker + app D1 + provider connections"]
  RS --> U["End users, purchases, entitlements,<br/>devices, consent, analytics"]
LevelWhat it isNotes
TenantThe organization that owns apps: legal entity name, country, display name.Operators are invited to a tenant and given roles. Your AppCore plan is attached here.
AppOne consumer product.Has its own Android package ID and iOS bundle ID. An ID that already belongs to another app is refused with 409 STORE_ID_TAKEN. A second app copies the first app's branding (you can edit it after) and gets new users, routes, provider connections and resources.
Environmentdevelopment, staging or production.Each environment is a separate resource set: one runtime Worker, one D1 database, its own provider connections and its own users. See Environments.
UserAn end user of one app in one environment.A user_id is only meaningful inside its scope. The same person in your staging and production apps is two unrelated users.

No cross-app sharing. Identities, entitlements, purchases and consent are never shared between apps or environments. Bundles across apps are not part of this release.

The scope object

JSON
{ "tenant_id": "ten_…", "app_id": "app_…", "environment_id": "production" }
  • tenant_id and app_id are opaque IDs: 1–128 characters, starting with a letter or digit, then letters, digits and _ . : -.
  • environment_id is one of development, staging, production.
  • The scope appears in events, reservations, entitlement snapshots and consent records. It is informational in responses. You never send it to select data.

How a request is bound to a scope

  1. Your app calls the API host of one app environment. You get it from the operator console, and you configure the SDK with it.
  2. That host routes to that environment's runtime Worker. The Worker reads its scope only from its deployment configuration. If the configuration is missing or malformed, every request fails closed with 503 SCOPE_NOT_CONFIGURED.
  3. Before any route runs, the runtime checks the single, immutable app_scope row in its D1 database. If the database belongs to a different scope, the runtime answers 503 SCOPE_MISMATCH and serves nothing. If the row is missing, it answers 503 SCOPE_NOT_INITIALIZED.
  4. Headers such as X-Tenant-ID are ignored. They never select a database.
  5. An ID from another scope gets the same 404 as an ID that does not exist, so a response never reveals whether something exists in another app.

Who can call what: authentication channels

ChannelWhoHow it works
consumerSessionYour app's end users (and guests where allowed)An opaque, signed session token. Native clients receive it in the set-auth-token response header after sign-in. Sessions last 30 days, are resolved live on every request, and stop working immediately when revoked or when the user is blocked or deleted. A token signed for another app is rejected.
operatorSessionPeople using the operator consoleA separate HttpOnly cookie on the control plane, with recent-auth and origin checks. Operator calls reach a runtime through the control-plane gateway. The gateway sends a short-lived (60 s) signed capability bound to that one resource set, method, path and body hash, carrying only that operator's permissions for that scope.
serviceCapabilityYour own backend, or AppCore internalsA short-lived credential limited to one scope, audience, operation and expiry. It is never shipped in a mobile app. Example: capturing metered credit usage.
providerSignatureApple, Google, Meta, PSPs calling webhooksEach provider is verified with its own mechanism: Apple signed JWS, Google Pub/Sub OIDC token, Meta raw-body HMAC. There is no shared signature header.

Operator permissions are checked on the server for every mutation. Roles can be granted for a whole tenant, one app or one environment. Several actions require a written reason and a recent sign-in, and some require a second person (for example, campaign approval). See the operator handbook and permissions.

What this means for your app

  • Configure the SDK with one API host per app environment. Use a separate build flavor for staging and production. Never switch hosts at runtime with the same stored session.
  • Do not send tenant or app identifiers in headers or bodies to "select" data. They are ignored or rejected.
  • Treat user_id as opaque and scoped. Do not use it to join users across your apps or environments.
  • A 404 for an ID you got from another environment is expected, not a bug.
  • Keep service capabilities and provider secrets on servers. The mobile app only ever holds the consumer session.
  • If you run several products, create several apps. Do not multiplex two products through one app's users or catalog.