229 tests passing · All security reviewed

Stop rebuilding
auth.
Every. Project.

10 production-hardened, security-reviewed canonical components — drop them into any Neon + Cloudflare project and ship features instead of infrastructure.

api/generate/route.ts
import { getUserTier, requireCapability } from '@/canonical/tiers' import { consumeRateLimit } from '@/canonical/rate-limit' import { callAIStream } from '@/canonical/ai' export async function POST(req: Request) { const { userId, prompt } = await req.json() // tier → capability → rate-limit — three lines const tier = await getUserTier(userId) await requireCapability(tier, 'ai_calls') await consumeRateLimit({ key: userId, limit: 100, windowMs: 60_000 }) // audit row bound to stream lifecycle const handle = callAIStream({ prompt, feature: 'generate', userId, mode: 'standard' }) return new Response(handle.textStream as ReadableStream) }
Security Reviewed
10
canonical components
229
tests across the library
10/10
security reviews passed
v1.7
current release
Components

Every foundation block. Already hardened.

Each component is Zod-validated at every trust boundary, server-only enforced, fully tested — and reviewed against the standard before it shipped.

Passed
canonical/auth
Email/password auth for Next.js App Router. Enumeration-resistant sign-in, shape-leak-resistant forgot password, httpOnly cookie sessions.
await signIn({ email, password }) // → AuthResult<AuthUser>
20 tests
Passed
canonical/billing
Stripe subscriptions with idempotent webhook processing, price pre-flight validation, fail-safe status reads. server-only throughout.
await getSubscriptionStatus(userId) // → BillingUser | 'none' on error
20 tests
Passed
canonical/ai · callAI
Single entry point for all AI calls. Routes standard / priority / flagship modes. Writes audit row on every invocation — success and failure both.
const r = await callAI({ prompt, feature: 'tag', userId })
28 tests
Passed
canonical/ai · callAIStream
Streaming counterpart. Audit row bound to the API stream lifecycle — not consumer iteration. Client disconnects cannot lose the log.
const h = callAIStream({ prompt, feature, mode: 'flagship' })
14 tests
Passed
canonical/events
Server-side product analytics. Contractually non-throwing — drops on failure, never breaks the request path. JSONB properties, Neon-native.
void logEvent({ event_name: 'user_signed_up', userId })
10 tests
Passed
canonical/access
Access-code gating. Codes stored as SHA-256 hashes — a DB leak exposes nothing redeemable. Race-safe redemption on the Neon HTTP driver.
await redeemAccessCode({ code, userId }) // → ok | error reason
16 tests
Passed
canonical/tiers
Tier / plan gating with fail-safe defaults. On any ambiguity → free tier. Never grants access on doubt. Composes with billing and access codes.
await requireCapability(tier, 'ai_calls') // throws CapabilityError if not entitled
15 tests
Passed
canonical/email
Transactional email via Resend. Workers-compatible. Anonymization Principle — recipient and template stored as SHA-256 hashes. No PII in the send log.
await sendTransactionalEmail({ to, template: 'welcome', subject, html })
12 tests
Passed
canonical/rate-limit
Fixed-window rate limiter. Fail-open by default — never blocks on infra failure. failClosed opt-in for auth/billing paths. Single race-safe UPSERT.
await consumeRateLimit({ key: userId, limit: 100, windowMs: 60_000 })
11 tests
Passed
canonical/billing · one-time
One-time purchase billing. WinterCG-portable webhook handler. Insert-first idempotency. SubtleCrypto signature verification. Ownership from session metadata only.
await createOneTimeCheckoutSession({ userId, priceId, successUrl })
12 tests
The Standard

What "hardened" actually means.

Most component libraries declare themselves production-ready. Product Foundation defines exactly what that means — and runs every component through this checklist before it ships.

A component that doesn't pass is not canonical. It's a candidate. Only canonical components propagate to products. Every entry in SYSTEM-RESOURCES.md names the sprint it passed in.

This is the bar. Zero exceptions.

  • Security
  • No secrets in component code — env validated lazily with friendly errors
  • Zod input validation at every trust boundary — before any external call
  • No SQL injection — parameterized queries only, zero string concatenation
  • server-only enforced at module level — build fails on client import
  • Enumeration-resistant auth — identical errors for wrong-password and no-such-user
  • Production-Ready
  • TypeScript strict mode clean — zero errors, zero any
  • All error paths handled — no silent failures, no console.log in prod paths
  • Audit row written on every invocation — success and failure paths both
  • Idempotency by design — billing and email never double-process the same event
  • Tested
  • Happy path, all error paths, security failure modes — all covered
  • 229 tests across 10 components — all passing before canonicalization
How it works

From zero to production-hardened.

Check the catalog before you build anything. If it's there, use it. If it's not, build it to the standard and add it.

Before you build
Check the catalog
Browse the interactive catalog or search SYSTEM-RESOURCES.md. Every component is documented: exports, dependencies, test count, and what it does and doesn't do.
$ open foundation.nextintelligence.ca/catalog
Scaffold
pf-add
The zero-dependency CLI copies a component into your project, merges its .env.example additively, and prints the exact deps block to install. No overwriting, no surprises.
$ node pf-add.mjs auth
Ship
Build the product, not the plumbing
The component is already hardened, tested, and reviewed. Wire it to your routes and domain tables — then focus on the features that actually differentiate you.
Propagation only after canonicalization
Built for

The modern SaaS stack.

Every new component targets Neon + Cloudflare. The Supabase dialect is frozen for legacy products. Components are WinterCG-portable — they run on Cloudflare Workers without modification.

Neon Postgres
Cloudflare Pages
Stripe
Resend

Your next product starts here.

Create an account to browse all 10 components, see their exact APIs and test counts, and copy what you need.