Architecture
Review Board

Technical Architecture for an AI-Native Trust Center + Dataroom Platform

March 2026

"Built to be maintained by AI agents. Designed for zero-friction B2B trust."

01 / 24

AI-First Architecture Principles

Test Suite as Authority

Tests are the immune system for an AI-maintained codebase. They are the deployment gate — not an aspiration. Every merge requires passing suite.

Structural Safety Over Process

RLS policies, typed schemas, and tenant-scoped DB instances prevent bugs by construction. You cannot write cross-tenant code even if you try.

🔍

Greppable, Explicit Code

Every permission check, every AI task registration is explicit and searchable. No magic strings, no implicit behavior. AI agents can grep to understand the entire surface area.

Modular Monolith

Feature-flag-gated modules within a single application. Shared infrastructure cleanly separated from feature code. One deploy unit, many bounded contexts.

Observable AI

Every AI invocation is metered. Every output is auditable. Every cost is attributable to a tenant and task. No unobserved AI execution is structurally possible.

02 / 24

High-Level Architecture

🌐 Cloudflare CDN & Edge Network
Global edge caching • DDoS protection • Custom domains via Cloudflare for SaaS
🌎 Public Trust Center
ISR • SEO-optimized
/trust/[slug]
🔓 Invited Dataroom
Visitor OAuth + grants
/trust/[slug]/dataroom
🛠 Admin Application
CSR / SPA • Auth-gated
Controls, requirements, dataroom ops
📄 Marketing Site
Static generation
Maximum performance
⚙ Nuxt 4 (Nitro Engine)
tRPC + REST API • Better Auth + visitor OAuth • Drizzle ORM • Vercel AI SDK
🗃 PostgreSQL
Neon (Serverless)
RLS • Drizzle ORM
📦 R2 Storage
Per-tenant buckets
S3-compatible API
🔐 KV + Cache
Sessions • Config
Feature flags
📊 Queues
Bulk AI ops
Background tasks
💳 Stripe
Billing • Usage • Tax
🤖 OpenRouter
AI Gateway
Multi-model
🔒 Neon Auth
Better Auth
Custom SCIM
✍ DocuSeal
NDA signing sidecar
Webhook callback
03 / 24

The Stack

Framework

Nuxt 4 (v4.3.1) + Vue 3
Cloud-agnostic via Nitro — deploy anywhere

UI Layer

Nuxt UI v4 + Tailwind CSS v4
125+ components • Reka UI (WAI-ARIA accessible)

🗃

Database

Neon (Serverless PostgreSQL)
Branching, autoscale, zero cold start

ORM

Drizzle ORM v1.0
SQL-like API • Zero runtime overhead • drizzle-zod

🔒

Authentication

Neon Auth (Better Auth) + Custom SCIM
Managed auth • SSO at no per-user cost

💳

Payments

Stripe
Billing + Usage Records + Tax • Built-in metering

🤖

AI Layer

Vercel AI SDK + OpenRouter Gateway
Multi-model • Streaming • Structured output

Infrastructure

Cloudflare Pages + Workers + R2 + KV + Queues
Terraform IaC • GitHub Actions CI/CD

TypeScript Strict Vitest + Playwright Full-Stack Type Safety Zero Vendor Lock-In
04 / 24

Why These Choices — Eliminated Alternatives

Category Eliminated Chosen Rationale
Framework Next.js Nuxt 4 Next.js creates deep Vercel vendor lock-in. Nuxt/Nitro deploys to any platform via adapters.
ORM Prisma Drizzle ORM Prisma requires Rust engine sidecar and custom DSL. Drizzle is SQL-like, zero runtime, native TS.
Backend Supabase Neon + Custom Supabase bundles auth/storage/DB — conflicts with best-of-breed choices. SOC 2 at $599/mo.
Deployment Vercel Cloudflare Vercel pricing: $9,000+/mo for 1,000+ custom domains. Cloudflare for SaaS: included.
SSO/Auth WorkOS Neon Auth + SCIM WorkOS charges per-connection, reaching $50k+/mo at scale. Neon Auth + custom SCIM: flat cost.
Orchestration Kubernetes Cloudflare Workers K8s: $300-500/mo baseline at zero tenants. Workers: zero idle cost, scales to zero.

⚠ Decision principle: Every choice evaluated against three criteria — AI-maintainability, cost at 1,000 tenants, and vendor exit cost.

05 / 24

Multi-Tenant Data Architecture

Hybrid Isolation Model

Free & Pro

Shared DB + Row-Level Security

All tenants in one Neon project. RLS policies enforce tenant_id filtering at the database layer. Even buggy application code cannot cross boundaries.

Enterprise

Dedicated Neon Project

Physically isolated database per enterprise tenant. Full compute isolation. Same Drizzle schema, separate infrastructure.

✓ Why AI-safe: Isolation is declarative and structurally enforced. An AI agent cannot accidentally write cross-tenant queries.

Implementation

tenant_id on every table

Non-nullable UUID column. Composite indexes include tenant_id. No table exists without tenant scoping.

useTenantDb(ctx)

Returns a tenant-scoped Drizzle instance. All queries automatically filtered. Shared or dedicated connection resolved transparently.

RLS Policies at DB Layer

PostgreSQL Row-Level Security policies ensure defense-in-depth. Even if application bypasses useTenantDb, the DB blocks cross-tenant reads.

Migration Strategy

Drizzle Kit generates migrations. Applied to shared DB + all dedicated projects via CI pipeline. Single schema source of truth.

06 / 24

Validation — Single Source of Truth

One schema definition propagates across the entire application. A single change is reflected everywhere — API, forms, AI content, and database constraints.

🗃
Drizzle Schema
DB table definitions
drizzle-zod
Auto-generates schemas
Zod Schema
Runtime validation
🔌

API Validation

tRPC inputs validated by Zod at the boundary

📄

Form Validation

Same schema drives client-side form rules

🤖

AI Content Validation

AI-generated output validated before persistence

🛠

TypeScript Types

Inferred TS types catch breaks at build time

⚠ AI-Safety: When an AI agent modifies a DB column, TypeScript strict mode surfaces every downstream break at compile time. No silent schema drift.

07 / 24

Three-Layer Caching

Zero additional infrastructure. No Redis. No Memcached. All built into the Cloudflare stack.

L1
EDGE

Cloudflare CDN

ISR for public trust center pages. Stale-while-revalidate. Instant purge on tenant publish action. Sub-50ms TTFB globally.

ISR PURGE ON PUBLISH CDN EDGE
L2
GLOBAL

Cloudflare KV

Session data, tenant configuration, feature flags, SCF control-framework mappings. Eventually consistent, globally replicated.

SESSIONS CONFIG FEATURE FLAGS
L3
REQUEST

Workers Cache API

Request-scoped computed results. Expensive DB aggregations cached per-worker. Fine-grained TTL control.

COMPUTED AGGREGATIONS PER-WORKER
$0
additional caching cost
0
extra services to manage
<50ms
global TTFB

What Gets Cached vs What Stays Live

Public trust pages and structured trust APIs cache aggressively. Dataroom grants, NDA status, and visitor activity stay request-authenticated and bypass edge caching where access decisions must be real time.

08 / 24

Authentication & Authorization

Auth Provider

Neon Auth + Visitor Identity

  • Managed admin authentication — email, social, SSO
  • Visitor OAuth via Google, Microsoft, or GitHub after invite-hash acceptance
  • Custom SCIM endpoint for enterprise directory sync
  • No per-user or per-connection pricing
  • Session-based with Cloudflare KV storage

Visitor Access Contract

  • Single-use invite hash links public evaluator identity to a persistent visitor record
  • Visitor groups inherit grant matrix rules for folders, packages, and document actions
  • OAuth session expires after 60 minutes, but visitor identity persists for future invites and audit

Permission-Based RBAC

Owner Admin Viewer

Permissions scoped to modules:

documents:write controls:publish requirements:verify dataroom:grant team:manage settings:admin

Route-Prefix Security

/api/trust/[slug]/* ● Public browse or email-verified request
/api/trust/[slug]/dataroom/* ● Visitor OAuth session + grant checks
/api/tenant/* ● Admin auth + tenant scope
/api/webhooks/* ● Signature verification only

Middleware Chain

CORS
Rate Limit
Auth
Tenant
Permission
Handler

✓ Greppable: Route prefix decides the identity mode, then every permission check is an explicit requirePermission('scope:action') call. Full audit via grep.

09 / 24

Hybrid tRPC + REST Strategy

tRPC Admin Operations
  • End-to-end type safety — client ↔ server types inferred
  • Zero API schema maintenance — no OpenAPI spec to keep in sync
  • Autocomplete in IDE for all procedures
  • Input validation via Zod at the boundary
  • Batched requests for dashboard loading, requirements review, and dataroom admin flows
REST External-Facing
  • Public trust and visitor dataroom endpoints — standard HTTP for interoperability
  • Webhook receivers (Stripe, DocuSeal, OpenRouter, etc.)
  • SCIM provisioning endpoint for enterprise SSO
  • Future public API for integrations
  • Standard HTTP verbs for interoperability

Shared Middleware Stack

Both tRPC and REST routes reuse the same middleware primitives: CORS → Rate Limit → route-specific identity check → slug or tenant resolution → permission or grant evaluation. No security bypass.

✓ Why AI-Safe

tRPC eliminates API contract mismatch bugs entirely. An AI agent cannot introduce a frontend/backend type mismatch — TypeScript catches it at build.

10 / 24

Three-Tier Rendering Strategy

Strategy determined by route prefix and auth mode, not per-component. Simple, predictable, AI-maintainable.

🌎

Public Trust Routes

ISR + CDN Edge
  • /trust/[slug] and public trust pages
  • ● SEO critical for organic growth
  • ● Served from Cloudflare edge
  • ● Purged on tenant publish action
🛠

Admin Application

CSR / SPA
  • ● Client-side rendered
  • ● Auth-gated, no SEO needed
  • ● Rich dashboard for controls, requirements, and dataroom admin
  • ● tRPC data fetching
📄

Marketing Pages

Static Generation
  • ● Pre-rendered at build time
  • ● Maximum performance
  • ● SEO optimized
  • ● No server compute cost
💡

One Nuxt app, three rendering modes. Route rules in nuxt.config.ts determine rendering strategy, while request-aware visitor flows layer on top for /trust/[slug]/dataroom, /trust/[slug]/dataroom/accept, and /api/webhooks/docuseal.

11 / 24

Three-Tier AI Task System

T1

Local / Code-Based

Deterministic • Zero cost
  • Health score calculations
  • Template instantiation + requirement seeding
  • Schema validation + badge rule checks
  • Coverage rollups and rule-based classification
Cost
$0
Latency
<5ms
T2

Lightweight AI

Cheap • Fast models
  • Text summarization
  • Document classification + access-tier suggestion
  • Badge suggestion + source licensing classification
  • Simple extraction
Cost
Low
Latency
~1s
T3

Cloud LLM

Capable • Full reasoning
  • Content generation + AskMe answer drafting
  • Deep policy analysis
  • Requirement generation and cross-reference mapping
  • Complex reasoning tasks
Cost
High
Latency
3-15s

↑ Tier Promotion Pipeline

Tasks start at T3 (cloud LLM). As patterns solidify and evaluation data accumulates, tasks are promoted to T2 then T1 — reducing cost and latency while maintaining quality.

✓ Primary Test Seam

Each task has a tier toggle. In tests, force T1 for deterministic assertions. No mocking AI APIs.

12 / 24

AI Task Registry

A first-class domain entity for billing-grade attribution. Every AI invocation is registered, metered, and auditable.

Registry Schema

// ai_task_registry
task_id UUID PRIMARY KEY
task_type ENUM — classify, generate, analyze...
tier INTEGER — 1, 2, or 3
tenant_id UUID NOT NULL
model VARCHAR — gpt-4o, claude-3.5...
tokens_in INTEGER
tokens_out INTEGER
cost_cents INTEGER
duration_ms INTEGER
status ENUM — pending, success, failed
created_at TIMESTAMP

Guarantees

☑ Registered Before Execution

Every AI invocation creates a registry row before the API call. Failed calls are still recorded with error status.

💳 Billing-Grade Metering

Stripe Usage Records metered directly from registry data. Aggregation cron produces usage events per tenant per billing period.

📊 Full Observability

Cost per tenant, per task type, per model. Token usage trends. Latency percentiles. All queryable from the registry table.

🚫 No Unmetered Usage

Structurally impossible. The AI SDK wrapper function requires a registry entry. There is no code path to invoke AI without registration.

13 / 24

Propose-Review-Publish State Machine

Draft
Proposed
Reviewed
✓ Accepted
✗ Rejected
Published

Core Principle

🚫 AI Never Publishes Directly

Human review is always required before any AI-generated content goes live. This is the core trust mechanism of the platform.

Enriched Proposals

Every AI proposal includes:

Content — the generated output
Confidence score — model self-assessment
Source references — what the AI based it on
Diff — what changed from previous version
Explanation — why the AI made these choices

Batch Operations

✓ Accept All High-Confidence

Bulk-accept proposals above a confidence threshold. Reduces review fatigue for routine AI-generated content while maintaining oversight.

⚠ Individual Review for Low-Confidence

Low-confidence proposals are flagged for individual human review. The AI communicates its uncertainty transparently.

💡 Trust Flywheel

The platform earns trust by never making unsupervised changes. Over time, users gain confidence and increase batch thresholds — but the human-in-the-loop is never removed.

14 / 24

Tenant Knowledge Sovereignty

🔓 Platform-Owned Content — Shared

SCF control descriptions, framework mappings, badge library assets, and seeded requirement templates. Curated by the platform. Available to all tenants. Versioned and auditable.

🔒 Tenant-Derived Intelligence — Never Shared

Any intelligence derived from a tenant’s data stays within that tenant boundary. Policies, control implementations, AI-generated requirements, dataroom grants, visitor activity, and health scores — never cross-pollinated.

⚠ Anonymized Cross-Tenant Patterns

Only explicit, auditable decisions. Example: “72% of tenants validate this badge from these frameworks” or “most tenants map this requirement to these SCF controls” — aggregated, anonymized, opt-in.

Three Concrete Subsystems

📚

Platform Reference Data Service

Curated SCF framework, control descriptions, badge library, and requirement templates. Versioned. Updated by platform team (human + AI).

AI Task Tier Promotion Pipeline

Evaluation data from T3 tasks informs promotion to T2/T1. Patterns extracted are task-level, not tenant-level.

📊

Tenant-Agnostic Batch Analytics

Aggregated, anonymized statistics. “Average time to complete SOC 2” or dataroom conversion trends. No tenant data leakage.

15 / 24

Health Score — Glass Box

Not a black box. Explainability is a hard constraint. Every score change is traceable to specific input changes.

Deterministic Weighted Formula

Health score is computed from typed, categorized inputs with explicit weights:

Control Coverage 30%
Document Completeness 25%
Evidence Freshness 20%
Vendor Response Rate 15%
Compliance Posture 10%

Input Types

✎ Human-Entered

Control implementations, policy documents, evidence uploads. Directly entered by tenant team members.

📈 Statistical / Measured

Document count, last-updated timestamps, response rates, coverage percentages. Computed from data.

🤖 AI-Derived

Quality assessments, gap analysis, completeness estimates. Always tagged as AI-derived with confidence score.

🔍 Full Audit Trail

Every score change links to the specific input that changed. “Score dropped 4pts because Document X expired 30 days ago.”

16 / 24

Deployment & Infrastructure

Full-Stack Cloudflare

Pages + Workers

Edge compute globally • Zero cold starts • Auto-scaling

📦

R2 Object Storage

Per-tenant bucket isolation • Zero egress fees • S3-compatible API

🔐

KV Store

Config, sessions • Globally replicated • Sub-ms reads

📊

Queues

Bulk AI operations • Background tasks • Guaranteed delivery

🌐

Cloudflare for SaaS

Custom domains at scale • Included in plan • Auto SSL

DocuSeal Sidecar

Production NDA signing runs through a separate DocuSeal deployment behind the app's SigningProvider abstraction. Completion events return through /api/webhooks/docuseal.

Infrastructure as Code

Terraform
  • All Cloudflare resources managed via Terraform
  • Neon database projects provisioned via API
  • State stored remotely, version-controlled
  • Plan/apply integrated into CI pipeline

CI/CD Pipeline

GitHub Actions
Lint
Type Check
Unit Tests
E2E Tests
Build
Deploy

Every stage must pass. No skipping. This is the deployment gate.

17 / 24

Testing Strategy — The Immune System

In an AI-maintained codebase, the test suite is the ultimate authority. It catches regressions from AI-generated code changes before they reach production.

Vitest

Unit + integration tests

  • Component-level isolation tests
  • API endpoint validation
  • Drizzle schema migration tests
  • AI task tier toggle tests
  • RLS policy verification
🎬

Playwright

End-to-end tests (headless)

  • Full user journey flows
  • Multi-tenant isolation verification
  • Trust center rendering validation
  • Admin workflow coverage

💡 AI Task Tier Toggles as Test Seams

The three-tier AI system provides a natural testing boundary:

TEST Force Tier 1 — deterministic assertions, zero API mocking
STAGING Allow Tier 2 — integration test with lightweight models
PROD Full Tier 3 — production AI capabilities

🚫 Non-Negotiable Rules

1. Test suite is the deployment gate — not an aspiration

2. AI agents coding features must include tests that pass

3. No PR merges with failing tests — ever

4. Coverage regression blocks deployment

18 / 24

Code Quality & Security Scanning

Five complementary tools provide defense-in-depth across security vulnerabilities, code quality, and review automation.

SAST — Static Analysis

Semgrep Push & PRs
  • OWASP Top 10 — SQLi, XSS, SSRF
  • JS/TS/Node.js-specific rules
  • Taint analysis for injection tracking
  • SARIF → GitHub Security tab
CodeQL Push & PRs
  • Deep semantic data-flow analysis
  • Control-flow vulnerability detection
  • Security-extended query packs
  • SARIF → GitHub Security tab
SonarCloud Pending — paid subscription
  • Cyclomatic & cognitive complexity
  • Code duplication detection
  • Bug & code smell analysis
  • LCOV coverage ingestion & tracking

Review, DAST & SCA

CodeRabbit AI PR Review
  • Contextual AI code review on every PR
  • Path-specific rules: Nuxt, tRPC, Drizzle
  • Sequence diagrams & change walkthrough
  • AI-generated code smell detection
OWASP ZAP Nuclei DAST
  • ZAP: nightly full scan + PR baseline
  • Nuclei: CVE, misconfig, exposure checks
  • Runtime injection & auth testing
ESLint Dependabot Lint & SCA
  • Complexity ceiling: 15 / depth: 4 / params: 4
  • Dependabot: weekly dep vulnerability PRs
  • npm audit: high-severity CI gate

🛡 Coverage Matrix

SQL Injection
Semgrep + CodeQL + ZAP
XSS
Semgrep + CodeQL + ZAP
OWASP Top 10
Semgrep + CodeQL + ZAP
Complexity
ESLint + SonarCloud*
Duplication
CodeRabbit + SonarCloud*
Test Coverage
Vitest (80%) + SonarCloud*
Dep Vulnerabilities
Dependabot + npm audit
Logic Errors
CodeRabbit + CodeQL
AI Code Smells
CodeRabbit + ESLint

Semgrep, CodeQL & Nuclei upload SARIF to GitHub Security tab — unified vulnerability dashboard. *SonarCloud pending — paid subscription required.

19 / 24

Metering & Billing Architecture

Stripe-Powered Billing

💳

Stripe Billing

Subscription management for Free, Pro, and Enterprise tiers. Handles upgrades, downgrades, prorations, and cancellations.

📈

Usage Records

AI credit metering via Stripe Usage Records. Registry aggregation cron produces usage events per tenant per billing period.

🌐

Stripe Tax

Automated tax calculation and compliance. Handles global tax requirements without custom implementation.

Metering Pipeline

🤖 AI Task Registry
Every invocation recorded with tokens & cost
📊 Aggregation Cron
Hourly rollup per tenant per billing period
💳 Stripe Usage Events
Reported as usage records on subscription items
💰 Invoice & Collection
Stripe handles invoicing, payment, and dunning

📊 Value Reports (FR51)

Time-saved metrics derived from evaluation data + registry data. Weekly Value Reports show customers the ROI of AI assistance.

Free Tier
Included AI Credits
Pro / Enterprise
Usage-Based Overage

Monetizable Product Signals

Pricing expansion follows product depth: requirements verification, DocuSeal-backed NDA execution, dataroom audit exports, and higher-volume AI generation all become metered or packaged upgrade signals.

20 / 24

AI Agentic Development Framework

How AI agents safely maintain this codebase — every architectural choice reinforces agentic maintainability.

TypeScript Strict Mode

Catches type errors at build. AI agents cannot introduce type mismatches that reach production.

🔌

tRPC End-to-End Types

Eliminates API contract mismatches entirely. Frontend/backend type mismatch is impossible.

Zod Single Source of Truth

One schema change propagates everywhere. No schema drift between API, forms, and database.

🔒

RLS + Tenant-Scoped Drizzle + Per-Tenant R2 Buckets

Structural safety against cross-tenant bugs. DB uses RLS + tenant-scoped Drizzle. Documents use dedicated R2 buckets per tenant — physical isolation, not just key prefixes.

🔍

Greppable Permission Checks

Every requirePermission() is explicit. Full security audit via simple text search.

📊

AI Task Registry Enforcement

New AI features must be registered. The SDK wrapper enforces this structurally — no bypass path exists.

Test Suite Gates Deployment

AI agents must write passing tests. No merge without green CI. Tests are the immune system.

Modular Monolith Boundaries

Clear module boundaries. Shared infrastructure separated. AI agents work within bounded contexts.

Toolchain:

GitHub Copilot Workspace Claude Cursor CI/CD Automated Deploy
21 / 24

Y.js as a Targeted Collaboration Layer

Not a platform-wide dependency. Introduced only where multiple humans, or human + AI, need to edit the same live draft concurrently.

Where It Fits

High-Value Use Cases

  • Shared trust-center copy editing
  • Collaborative control-description drafting
  • Reviewer comments and annotations on drafts
  • Future questionnaire workspaces
  • AI + human co-editing of the same artifact

Where It Does Not Belong

  • Basic chat transcripts
  • Standard CRUD forms
  • Billing, notifications, workflow state changes
  • Document metadata management
  • Publish / approve as the system of record

Architectural Boundaries

Draft State, Not Business Record

Y.js holds live collaborative draft state. Canonical business state still lives in PostgreSQL / R2 and flows through propose-review-publish, permissions, and audit logging.

Locking Strategy

Prefer soft presence and section-level claiming over hard pessimistic locks. Real gates remain server-side: accept, review, publish, archive.

Snapshots

Use Y.js snapshots for collaborative restore points. Keep published revisions and compliance evidence snapshots in the normal domain model.

Cloudflare-Compatible Real-Time Path

Nuxt / Vue Editor
Y.js Document
WebSocket Room
Durable Object
R2 Snapshots
Postgres Publish Record

SSE remains the default for operational updates. WebSocket-backed collaboration is added only for shared-editing surfaces.

22 / 24

Compliance Evidence Pipeline

Automated evidence collection from day one. No $500-2,000/mo SaaS tools. Infrastructure we already own.

How It Works

~200 lines Scheduled GitHub Actions + API calls

Cron-scheduled GitHub Actions workflows that call APIs we already use (Cloudflare, Neon, Stripe, GitHub) and collect evidence artifacts automatically.

🐀 Dogfooding

Evidence feeds into our own trust center powered by INeedTrust. We eat our own cooking — the platform proves its value by running on itself.

Evidence Types

Uptime Monitoring

Cloudflare health checks • Response time tracking • Incident detection

🔌

Deployment Frequency

GitHub Actions run history • Deploy success rate • Rollback tracking

Test Coverage

Vitest coverage reports • Playwright results • Coverage trends over time

🔒

Access Logs

Auth event logging • Admin action audit trail • Permission change records

🔐

Encryption Status

TLS certificate validation • Data-at-rest encryption • Key rotation records

23 / 24

Key Takeaways

🤖

AI-Maintained Codebase

Architecture optimized for AI agents with minimal FTEs. Every decision has a “Why AI-safe” justification.

Structural Safety

Bugs prevented by construction — RLS, typed schemas, tenant-scoped instances. Safety over process.

Full-Stack Cloudflare

Zero additional infrastructure. No Redis, no K8s, no managed caches. Edge compute scales to zero.

📊

Observable AI

Every AI invocation metered, auditable, and cost-attributable. No unobserved execution possible.

Tests as Authority

Test suite is the deployment gate. AI agents must write passing tests. The immune system for AI-generated code.

🔒

Trust by Design

Propose-review-publish. Human-in-the-loop. Glass box scoring. Tenant knowledge sovereignty.

“Built to be trustworthy.
Maintained by AI.
Overseen by humans.

24 / 24