Sample output
What a Governed Scaffold Looks Like
A real Stackbilder scaffold for a multi-tenant SaaS API with Stripe billing, Cloudflare Workers, D1, and KV. This is what every scaffold includes — free tier.
Project structure
The governed scaffold file tree
Every scaffold ships with the project structure and the .ai/ governance directory in the same ZIP.
The application files give you the correct layout; the governance files give your AI agents the rules.
my-saas-api/ ├── src/ │ ├── worker.ts // edge entry point, request router │ ├── middleware/ │ │ ├── auth.ts // session validation, cookie parsing │ │ └── ratelimit.ts // KV-backed sliding window rate limiter │ ├── routes/ │ │ ├── api/ │ │ │ ├── users.ts // CRUD — tenant-scoped, RLS enforced │ │ │ ├── billing.ts // Stripe checkout + portal redirects │ │ │ └── webhooks.ts // Stripe webhook receiver (sig-verified) │ │ └── health.ts // liveness probe, returns build hash │ ├── lib/ │ │ ├── db.ts // D1 query helpers, prepared statements │ │ ├── auth.ts // session create/destroy, tenant binding │ │ └── stripe.ts // Stripe client init, webhook verify │ └── types.ts // Env, Session, Tenant, User interfaces ├── migrations/ │ └── 0001_create_schema.sql // D1 schema: tenants, users, sessions ├── .ai/ ← governance directory │ ├── threat-model.md // STRIDE analysis, 8 identified threats │ ├── adr-001-auth-strategy.md // cookie sessions vs JWTs — decided │ ├── adr-002-data-isolation.md // RLS via tenant_id column — decided │ ├── test-plan.md // 23 test specs, 85% coverage target │ └── constraints.yaml // machine-readable guardrails for agents ├── wrangler.toml // D1, KV, secrets, triggers, routes ├── package.json └── tsconfig.json
.ai/threat-model.md
STRIDE threat model — excerpt
Four of the eight identified threats for this architecture. Each threat has an ID, STRIDE category, severity rating, attack vector, and a concrete mitigation mapped to a specific file or configuration. This is not generic security advice — it is analysis specific to the multi-tenant SaaS + Stripe + D1 + KV combination.
.ai/adr-001-auth-strategy.md
ADR-001: Authentication strategy
Architectural decision records document the non-obvious choices in your system — with the alternatives considered, the constraints that ruled them out, and the consequences your team accepts. When an AI agent or new developer tries to change this decision, the ADR explains exactly why it was made.
- + Immediate session revocation on logout or compromise
- + No token refresh loop — session stays valid until explicit expiry
- + Cannot be tampered with — opaque token carries no claims
- + HttpOnly cookie is inaccessible to XSS payloads
- + Session store provides audit trail of active sessions per tenant
- - One KV read per authenticated request (~1ms latency overhead)
- - Session store is a dependency — KV outage degrades auth
- - CSRF protection required (SameSite=Strict mitigates for same-origin)
- - Not suitable for native mobile apps needing Authorization header
.ai/test-plan.md
Integration test plan — excerpt
Not boilerplate test categories — specific test cases derived from the threat model and architectural decisions. The test plan is structured so you can hand it directly to Vitest or a QA engineer without translation.
wrangler.toml
Bindings, wired correctly
D1 database, KV namespace, Stripe webhook secret, and Durable Objects configured for the correct environment splits. No hand-editing required.
name = "my-saas-api" main = "src/worker.ts" compatibility_date = "2025-01-01" compatibility_flags = ["nodejs_compat"] # D1 — tenant data + sessions (separate DBs) [[d1_databases]] binding = "DB" database_name = "my-saas-api-prod" database_id = "<replace-after-create>" # KV — session store + rate-limit counters [[kv_namespaces]] binding = "SESSION" id = "<replace-after-create>" # Secrets — never in source # wrangler secret put STRIPE_SECRET_KEY # wrangler secret put STRIPE_WEBHOOK_SECRET # wrangler secret put SESSION_SECRET [env.staging] name = "my-saas-api-staging" [[env.staging.d1_databases]] binding = "DB" database_name = "my-saas-api-staging" database_id = "<replace-after-create>" [triggers] crons = ["0 * * * *"] # hourly: session cleanup
.ai/constraints.yaml
Agent guardrails
Machine-readable constraints your AI coding agents read before modifying the codebase. Prevents architectural drift — the next Cursor session cannot accidentally disable auth or add a direct DB client without triggering a violation.
version: 1 scaffold_id: "my-saas-api" stack: "cloudflare-workers" invariants: # Rules that must never be violated - id: auth-middleware-required description: "All routes under /api/* must pass through src/middleware/auth.ts before reaching route handlers." severity: critical - id: tenant-predicate-required description: "Every D1 query touching tenant data must use withTenant() helper. Direct DB.prepare() on tenant tables is forbidden." severity: critical - id: webhook-signature-required description: "Stripe webhook handler must call verifyWebhookSignature() before any body parsing or DB mutation." severity: critical - id: no-secrets-in-source description: "API keys, webhook secrets, and session secrets must be accessed via env.BINDING_NAME only. Hardcoded credential strings are forbidden." severity: critical decisions: - adr-001 # cookie sessions — do not add JWT - adr-002 # RLS via withTenant() — no row policies threat_model_ref: ".ai/threat-model.md"
Questions about scaffold output
Is this real scaffold output or a mock?
This is a realistic representation of what Stackbilder generates for a multi-tenant SaaS API with Stripe billing on Cloudflare Workers. The threat model threats, ADR structure, test specs, and constraint YAML are generated by the same deterministic engine that runs on every scaffold — same input, same output.
How do I download my scaffold files?
After generating a scaffold, the flow detail page gives you a ZIP download containing the full project structure and .ai/ governance directory. Individual files can also be copied to clipboard. The ZIP is production-ready: drop it in a new directory and wrangler deploy works.
Does it work for stacks other than Cloudflare Workers?
Cloudflare Workers — with D1, KV, R2, and service bindings — is fully supported today. The governance artifacts (threat model, ADRs, test plan, constraints) are substantially stack-agnostic and useful regardless of what you're building on. Additional stacks are on the roadmap.
What's different in Pro?
Free tier includes the full governance suite — threat model, ADRs, test plan, project scaffold — for up to 3 scaffolds per month. Pro ($29/mo) removes the monthly limit and adds LLM polish mode: idiomatic implementation code for worker.ts, route handlers, middleware, and migration SQL, guided by the deterministic governance constraints.
Generate your own governed scaffold
Your architecture. Your threat model. Your ADRs.
Describe your app. Get the full governance suite in under 20ms. Free tier includes 3 scaffolds per month — no credit card.
Related pages