Architecture

How VitNode combines TanStack Start for UI and isomorphic routing with Hono for API authorization and database access.

VitNode separates concerns between two core layers:

  1. TanStack Start: Frontend UI, SSR, isomorphic routing, and client caching.
  2. Hono API: Backend routing, session management, staff permissions, and database operations.

System Boundaries

ResponsibilityTanStack Start (Web App)Hono (API)
RoutingPage URLs, dynamic parameters, nested layoutsREST/RPC endpoints under /api/*
Data FetchingRoute loaders and the universal fetcherQuery execution via Drizzle ORM
State & CacheTanStack Query client cacheRedis domain cache & database storage
Security BoundaryUI guards (redirecting unauthenticated users)Enforces authentication, permissions, CSRF, and rate limits

Security Boundary

Route guards (beforeLoad) enhance UX by redirecting visitors early, but the Hono API is the true security boundary. All private endpoints strictly verify cookies and permissions on every request.


End-to-End Request Flow

When a user visits a page (e.g. /blog):

PhaseRuntimeAction
1. RequestBrowserVisitor navigates to /blog
2. RoutingServer (SSR) / BrowserTanStack Router matches route and executes loader
3. Query WarmingServer / Browsercontext.queryClient.query executes isomorphic fetcher
4. RPC CallServer / BrowserThe universal fetcher calls the Hono endpoint by plugin id
5. API MiddlewareServer (Hono)Verifies session cookie, applies rate limits, injects c.get(db)
6. Handler & DatabaseServer (Hono)Handler validates input and queries PostgreSQL via Drizzle
7. ResponseServer / BrowserJSON data hydrates TanStack Query cache and paints component

The Request Pipeline

Before route matching, every request passes through the middleware createVitNodeStart installs - in this order, and an app cannot get in front of any of it:

OrderMiddlewareApplies to
1CSRFServer function calls (handlerType === 'serverFn')
2LocalePage requests: canonical 308 redirects and the locale cookie
3Document cacheHTML responses: forced Cache-Control: private, no-store
4Your ownWhatever requestMiddleware lists

/api/* reaches the same middleware and passes through untouched - no redirect, no rewrite, no cache directive - so the Hono bridge sees the request exactly as the client sent it and keeps its own caching policy. See Configuration.


Plugin System Architecture

VitNode is built around modular plugins located in plugins/*:

  • Independent Packages: Plugins compile to their own dist/ with isolated dependencies.
  • Unified Manifest: Routes, AdminCP navigation, and database models are registered declaratively.
  • Zero Overhead: Inactive plugins contribute no code or overhead to production bundles.

Learn More