Architecture
The parts of Gatehouse, why each exists, and how a request travels from sign-in to the log.
Gatehouse is one codebase deployed as Cloudflare Workers: the gateway, which people and their apps reach; the console and admin API, for administrators; and the log Worker, which keeps the log and has no address. The gateway's settings decide which services it offers and which sign-in it uses.
| Worker | Address | Paths | Sign-in |
|---|---|---|---|
| Gateway | gatehouse.theleeorganization.com | Connectors at /mcp/<connector>, one for each service the settings list; the Script API at /api/<app>/<path>; the member pages; the Gatehouse app's sign-in return at /signed-in | Microsoft Entra ID, for a member of the Gatehouse users or administrators group, then Gatehouse's OAuth |
| Console and admin API | gatehouse-admin.theleeorganization.com | The console at /console; the admin API at /admin/v1/, for the console, the Gatehouse app and the CLI; the log API at /logs/v1/ | Cloudflare Access for a member of the Gatehouse administrators group on a managed device, then a Microsoft Entra ID token for Gatehouse's admin scope, checked by the Worker. Not Gatehouse's OAuth, so the console and the app still work when the gateway is turned off |
Parts
Each part is a separate module of the one codebase.
App --> Router --> Sign-in
|
+--> MCP server --+
+--> Script API --+--> Permissions --> Service calls --> Service
Console, Gatehouse app --> Cloudflare Access --> Admin API
Gateway, admin API --> Log Worker --> Log database, sealed archive
| Part | What it does | Why it exists |
|---|---|---|
| Router | The entry point of the gateway's Worker. Sends sign-in paths, /mcp/* and /api/* to their part, and runs the timers. | One place decides where a request goes. |
| Sign-in | An OAuth 2.1 authorization server built on Cloudflare's workers-oauth-provider library. Holds the list of 3 allowed apps, shows the consent page, and signs the person in with Microsoft Entra ID. Tokens and app access are stored encrypted in Workers KV. | Sign-in is the one part every app meets first, and the only part that issues tokens. |
| Permissions | Decides whether a tool is Allowed, Ask first or Never for a group, from the settings, within limits set in code. | What an app may do changes only by a recorded change to the settings, and the emergency controls can only take access away. |
| MCP server | MCP servers over Streamable HTTP, built for each request from the tool catalogues and the permissions. | An app sees only the tools it may use, as they are at that moment. |
| Script API | /api/<app>/<path> for the CLI. Passes reads and a few named commands for Sonarr, Radarr and SABnzbd on an exact list, and refuses anything else with 403. Drops any credential the script sends and adds Gatehouse's own. | Scripts reach these apps without holding their keys. |
| Admin API | What the console, the Gatehouse app and the CLI call, under /admin/v1/ on its own Worker at gatehouse-admin.theleeorganization.com: remove app access, approve or deny, set the emergency controls, read health, read and change the settings. The log API beside it reads the log. It holds no secret; what only the gateway's Worker can do, it asks that Worker over a service binding. See API reference. | Administrators have their own API, for administration only, and no AI app can reach it. It does not sign in through the system it controls, so it can turn the gateway off and back on. |
| Console | The administrators' pages on the same Worker, at /console. Each change it makes is an admin API request, with the same checks and records, and a change that grants access needs a fresh sign-in. | One place to run Gatehouse from a browser. |
| Store | One D1 database. It holds the emergency controls, approvals, app registrations, each app access's last use and hourly count, health and the settings with their history. | The state Gatehouse runs on is in one place. |
| Service calls | The calls to every service and the health check every 5 minutes. | Every outbound call goes through one part that holds the credentials. |
| Log | Every event Gatehouse records, held by its own Worker: a D1 database, and an R2 archive that refuses a delete or overwrite until each stream's retention ends. Every 5 minutes each stream is sealed with a signed, chained digest; every hour it is verified. | The record of what happened is kept apart from what it records, and cannot be changed by the Workers that write it. |
3 apps reach the admin API from outside the Workers:
- The console, in a browser. Its session is kept on the server; the browser holds only a cookie.
- The Gatehouse app, for iPhone and iPad with iOS or iPadOS 17.4 or later. It talks only to the admin API. It locks each time it opens or returns from the background and asks for Face ID, and Approve and Deny each ask for Face ID again. Its sign-in is kept in the Keychain on that device only, and is not synced.
- The Gatehouse CLI, for Node 20 or later, with no dependencies. It signs in through the browser on every run, using OAuth with PKCE as a public app with no secret: to Gatehouse for the Script API, and to Microsoft Entra ID and Cloudflare Access for the admin and log APIs. Its token lives only in the memory of that process, lasts 15 minutes, and is never renewed.
How a request travels
An AI app using a tool through MCP:
- The app signs in once. The person signs in through Gatehouse's OAuth, with Microsoft Entra ID. The consent page, such as "Allow Claude Code to use GitHub?", lists the service's tools. When the person selects Allow access, Gatehouse gives the app access.
- Each request is checked. Gatehouse checks the token, then reads the emergency controls and the app access's count for this hour in one round trip. The permissions decide.
- Allowed: Gatehouse calls the service with its own credential and the header
User-Agent: Gatehouse/1 (<app name>), returns the result, and records the request in the log. - Ask first: Gatehouse creates an approval, which shows on Approvals. No notification is sent. The app receives the approval's code and waits. When an administrator approves within the approval window (10 minutes unless an administrator sets 5 to 30 in Settings, Gateway) and the app sends the same request again, it runs once.
- Never: the tool is not offered, so the app cannot ask for it.
- Off: when a kill switch is Off, Gatehouse refuses the request with 503.
Every request, whatever its outcome, is recorded in the log.
What is recorded
| Record | What it holds |
|---|---|
| Request | When, gateway, account, app, service, tool, state, HTTP status, time taken, IP address, agent string, a keyed fingerprint of the arguments, and the names of the arguments and their size |
| Sign-in | Who, app, outcome, reason, authentication methods, IP address and agent string |
| Approval | The request it belongs to, a summary of its arguments, who decided, and when |
| Permissions or settings change | Who, what, the value before and after, and the settings' version |
| Admin request | Who, how they were admitted, the request, its status, IP address and agent string |
No record holds a credential or a request's result. A request record holds a fingerprint of the arguments, never the arguments. A person is recorded by their Microsoft Entra ID object ID, with their name and email address in the security stream only. An approval's summary is the tool and up to the first 120 characters of the arguments in canonical form.
| Stream | Holds | Kept |
|---|---|---|
| Security | Sign-ins, tokens, requests, approvals, settings and key changes, admin requests | 548 days, the last 90 also in the log database |
| Log audit | Changes to the log itself | 548 days, the last 90 also in the log database |
| Access | Each request's arrival at the gateway | 90 days, the last 30 also in the log database |
| System | Health, timers, deploys and errors | 90 days, the last 30 also in the log database |
The archive refuses to delete or overwrite a sealed segment before its stream's time ends, and a lifecycle rule deletes it a day after. An approval's code is never in the log.
Recovery
Recovery is D1 Time Travel: the database can be put back to any minute in the last 30 days (Workers Paid). Nothing else is copied for recovery. An administrator of the Cloudflare account restores it through the Cloudflare dashboard or API. When Gatehouse cannot read its settings, the admin API refuses every request until they are restored.
If the Cloudflare account itself is lost, Gatehouse is rebuilt from its code and Terraform, with no records. The log is not restored by Time Travel: it is never rewritten, only appended to.
The sign-in stores (tokens, codes and app access) are not recovered. After a loss, each app signs in again.
Admin API versions
The admin API is version 1, at /admin/v1/. Its resources use the words the console uses: alerts, app access, emergency controls, accounts, apps, sign out everything and system.
The addresses without a version, under /admin/, are deprecated. They reach the same actions under their old names, and every answer from them has a Deprecation header and a Link to the same action under /admin/v1/. They are removed once nothing has used them for 7 days after the Gatehouse app and the CLI moved to version 1. An app or script still on them changes its paths to /admin/v1/, and reads whether a change gives more access from grants_access.
/.well-known/gatehouse-clients is deprecated in the same way: the CLI's ID is in Gatehouse's sign-in metadata, as gatehouse_cli_client_id.