Skip to main content
Architecture

System Architecture

Technology stack

LayerTechnology
FrameworkTanStack Start v1 (React 19, Vite 7)
RoutingFile-based routes under src/routes/ (auto-generated tree)
Server logiccreateServerFn from @tanstack/react-start
Edge runtimeCloudflare Workers (workerd, nodejs_compat)
BackendLovable Cloud (Supabase: Postgres, Auth, Storage, Edge Functions)
UI primitivesshadcn/ui on Tailwind CSS v4 (tokens in src/styles.css)
Client stateTanStack Query in router context
DocumentationMarkdown chapters + react-pdf (/docs)

Application layers

 ┌──────────────────────────────────────────────────────────┐
 │ Presentation                                             │
 │  • src/routes/*  • src/components/*  • shadcn/ui         │
 ├──────────────────────────────────────────────────────────┤
 │ Application                                              │
 │  • createServerFn (queries, mutations, business rules)   │
 │  • TanStack Query (caching, suspense, revalidation)      │
 │  • Hooks: useTenant, useAccessAuditLog, useInactivityTimer│
 ├──────────────────────────────────────────────────────────┤
 │ Domain / Security                                        │
 │  • src/lib/rbac/roles.ts        (role model)             │
 │  • src/lib/security/*           (LLM guard, encryption)  │
 │  • src/lib/resilience/*         (circuit breaker)        │
 ├──────────────────────────────────────────────────────────┤
 │ Platform                                                 │
 │  • Supabase Postgres (RLS-enforced)                      │
 │  • Supabase Auth (TOTP MFA, AAL2)                        │
 │  • Edge Functions (login-rate-limit, …)                  │
 │  • Cloudflare Workers (SSR, server fn dispatch)          │
 └──────────────────────────────────────────────────────────┘

Runtime topology

                       ┌──────────────────────────┐
                       │      Browser (SPA)       │
                       │  React 19 · TanStack QC  │
                       └──────────┬───────┬───────┘
                                  │       │
            supabase-js (auth/    │       │  fetch /_serverFn/*
            session/realtime)     │       │
                                  │       ▼
                       ┌──────────┴──────────────┐
                       │ Cloudflare Worker (SSR) │
                       │  • TanStack Start route │
                       │  • createServerFn       │
                       │  • attachSupabaseAuth   │
                       └──────────┬──────────────┘
                                  │  PostgREST + RLS as user
                                  ▼
                       ┌─────────────────────────┐
                       │ Supabase Postgres       │
                       │  • RLS on every table   │
                       │  • SECURITY DEFINER fns │
                       └─────────────────────────┘
                                  ▲
                                  │ service-role only
                                  │
                       ┌──────────┴──────────────┐
                       │ Supabase Edge Functions │
                       │  • login-rate-limit     │
                       └─────────────────────────┘

Component map

ConcernLocation
Routessrc/routes/ (file-based; _authenticated/ for gated subtrees)
App shell, sidebar, role switchersrc/components/app/
Access governance UIsrc/components/access-governance-v2/
Security guardssrc/components/security/ (InactivityGuard)
Documentation UIsrc/components/docs/
Server fn definitionssrc/lib/**/*.functions.ts
Server-only helperssrc/lib/**/*.server.ts (blocked from client by import guard)
Edge functionssupabase/functions/*
SQL migrationssupabase/migrations/*

Authenticated request data flow

1. User submits form in /app/* page
2. Component calls a serverFn via useServerFn()
3. attachSupabaseAuth (global functionMiddleware) reads
   supabase.auth.getSession() and adds Authorization: Bearer <jwt>
4. Worker receives RPC, requireSupabaseAuth verifies JWT,
   creates a per-request Supabase client scoped to that user
5. Server fn runs query — Postgres RLS evaluates auth.uid()
6. Append-only audit entry written to access_audit_log
7. Response returned; TanStack Query caches and re-renders

Infrastructure overview

ElementProvider / runtime
Web tierCloudflare Workers, regionally distributed
App databaseSupabase Postgres (managed)
Object storageSupabase Storage (when used)
Edge functionsSupabase Edge Runtime (Deno)
DNS / TLSManaged by Lovable / Cloudflare
SecretsLovable Cloud secret store (SUPABASE_SERVICE_ROLE_KEY, webhook secrets)

Notes on the documentation runtime

The /docs route is part of the same TanStack Start app — it is not a separate site. Chapters are bundled at build time via import.meta.glob, so the manual ships with the application and is always in sync with the deployed version. PDF export runs in the browser via @react-pdf/renderer.