Concepts
Architecture
Mental model

Concepts

How Brokr thinks about infrastructure. Intent in, working stack out. These are the mental models behind every command.

Intent Compilation

Brokr is an intent compiler for infrastructure. You say what you want — "I need a web app with a database" — and Brokr compiles that intent into a concrete infrastructure plan: which providers, which capabilities, which credentials, which DNS records.

The compilation pipeline: intent → CommandPlan → provider resolution → capability provisioning → env injection → deployment. Whether you type canonical CLI syntax, use an alias, or write natural language, all three routes produce the same structured CommandPlan.

Stack Architecture

A stack is a named collection of capabilities wired to real providers. A typical web-app stack includes:

LayerWhat it is
RepoGitHub repository (Brokr-managed or user-managed)
DeploymentVercel project with Git integration
DatabaseNeon Postgres with connection string
StorageCloudflare R2 bucket with presigned URLs
EmailResend with verified domain
DNS{name}.brokr.sh subdomain + optional custom domain
AIGateway access to Claude, GPT, Deepseek

Each layer is optional — you can create a stack with just a repo and deployment, then add capabilities later with brokr add.

Capability Model

Capabilities are the atomic units of infrastructure. Each has a type, a provider, and a status.

TypeDefault Provider
databaseNeon
deploymentVercel
emailResend
repoGitHub
ai_providerBrokr AI Gateway
kv_storeUpstash Redis
storageCloudflare R2
authBrokr Auth

Status lifecycle: requested → provisioning → active → error. Use brokr status --watch to track progress.

Repo Modes

Git is a source-of-code layer in Brokr, not the center of gravity. Two operating modes:

ModeBehaviorDefault mutation
Brokr-managedBrokr creates and owns the repo lifecycle. Best for new stacks.direct
User-managedBrokr attaches infra around your existing repo without taking it over.pr-only

Brokr auto-detects: if you run brokr create from a directory with a GitHub remote, it defaults to user-managed. Otherwise, it creates a new Brokr-managed repo.

Use brokr fork git to fork a Brokr-managed repo into your account (non-destructive), or brokr transfer git to transfer full ownership (irreversible).

Mutation Policies

Mutation policy controls how aggressively Brokr is allowed to write to source control:

PolicyBehavior
directBrokr commits and pushes directly to the default branch.
branchBrokr creates a branch for changes, merges when safe.
pr-onlyBrokr opens a PR for review. Never pushes directly.
bash
brokr create web-app --repo current --mutation pr-only

.env.brokr

.env.brokr is the sole source of truth for all stack environment variables. Not the database. Not .env. Not Vercel.

The flow: provisioning writes vars into .env.brokr. User vars from .env merge in. brokr deploy reads from .env.brokr and pushes to Vercel. The DB stores a copy for the dashboard UI, but is never the deployment source.

.env.brokr is gitignored. If it's missing a value, the fix is in provisioning — never fall back to the DB.

Gateway Architecture

The Brokr gateway (api.brokr.sh) is a Cloudflare Worker that sits between your app and all backend providers. It handles:

FunctionWhat it does
AuthenticationValidates BROKR_TOKEN, resolves per-stack config
AI routingOpenAI-compatible endpoint, routes to Claude/GPT/Deepseek
StorageSigns presigned URLs for R2 uploads and downloads
EmailResolves Resend API key and from domain server-side
Rate limitingPer-stack, per-capability rate limits

Your app never touches provider credentials. The gateway resolves them from the stack config and injects them into upstream requests. One token, all services.