Welcome to Nebutra Sailor Docs 🎉
ChangelogIntroductionLicensing
Help Center (External) ↗

Architecture

How a Nebutra-Sailor project is built — monorepo structure, request flow, and the key layers.

Overview

A scaffolded project is a Turborepo monorepo: Next.js 16 apps, a Hono API gateway, and shared @nebutra/* packages (design system, permissions, billing, auth, …). Per ADR 2026-09-24 Sailor convergence, backends/gateway is the only place business endpoints live — apps/web route handlers are limited to what's intrinsically Next (auth callbacks, OG routes, framework hooks).

Browser
   │
   ▼
apps/web (Next.js 16)
   ├─ pages / Server Components
   └─ app/api/[[...route]]  ──▶  backends/gateway (Hono), mounted in-process
                                   (GATEWAY_MODE=embedded, the default)
                                        │
                           ┌────────────┼────────────┐
                           ▼            ▼             ▼
                      PostgreSQL      Redis      AI providers
                     (Prisma, RLS)  (cache/queue)  (gateway)

The template makes no deployment-platform choice — see Deployment Overview for what create-sailor actually generates (Dockerfile.web, docker-compose.yml) and the embedded/external gateway split.

Apps in a default scaffold

AppFrameworkRole
webNext.js 16The authenticated product app; hosts the gateway by default
landingNext.js 16Public marketing site
authNext.js 16Better Auth login center
mail-preview—Local preview server for transactional email templates
backends/gatewayHonoThe sole business API

Nebutra's own instance additionally runs studio (Sanity CMS) and storybook — neither ships in the default scaffold.

Core packages

PackageDescription
@nebutra/uiComponent library — Radix + Nebutra primitives
@nebutra/tokensRuntime CSS design tokens
@nebutra/authBetter Auth server instance + service-to-service JWTs (signServiceToken / verifyServiceToken)
@nebutra/permissionsRBAC/ABAC — CASL, in-process
@nebutra/dbPrisma client (getSystemDb, getTenantDb)
@nebutra/tenantTenant context (getCurrentTenant) + RLS helper (withRls)
@nebutra/billingCheckout, entitlements, usage metering
@nebutra/queueQStash, in-memory fallback in dev
@nebutra/meteringUsage metering → ClickHouse
@nebutra/webhooksOutbound webhook delivery, built in

Request flow (embedded gateway, the default)

Request
  │
  ├─ 1. apps/web receives it. A more specific Next route always wins over
  │     the catch-all; the catch-all only ever gets what nothing else matched.
  │
  ├─ 2. app/api/[[...route]] hands off to the Hono app (backends/gateway),
  │     built in-process (no background queue workers — those run via the
  │     QStash webhook delivery route either way).
  │
  ├─ 3. Gateway middleware
  │     ├─ Auth        (Better Auth session cookie, or x-service-token for S2S)
  │     ├─ Tenant       (org context)
  │     ├─ Permissions  (CASL)
  │     └─ Rate limit
  │
  └─ 4. Route handler — response shape is whatever that route's Zod schema
        declares. Errors use one shared envelope from `@nebutra/errors`:
        { error: { code, message, details? }, requestId? }.

Service-to-service calls use short-lived HS256 JWTs in x-service-token, not a legacy hex-HMAC scheme. See API Authentication.

Database and row-level security

Every table's access rule is declared once, in packages/platform/db/prisma/schema.prisma, as an /// @rls comment — inferred automatically from a tenantId / organizationId column in the common case. A generator turns that into Postgres RLS policies on every prisma generate; pnpm db:deploy applies them. See Database Overview and Row-Level Security — this is the one isolation strategy the template ships, not a menu of shared-schema / schema-per-tenant / database-per-tenant options.

AI layer

Gateway AI routes (authenticated, tenant-scoped), governed at runtime via nebutra ai (no scaffold-time provider choice — see AI Providers):

  • POST /api/v1/ai/chat
  • POST /api/v1/ai/embeddings
  • GET /api/v1/ai/models
  • POST /api/v1/ai/chat/completions

Usage feeds the metering pipeline for quotas and billing.

Auth configuration

# Better Auth is the only auth provider — no Clerk/NextAuth/Supabase adapters
AUTH_PROVIDER=better-auth
NEXT_PUBLIC_AUTH_PROVIDER=better-auth

# Unconfigured (no BETTER_AUTH_SECRET) degrades to a dev fallback — see `nebutra status`

Keep AUTH_PROVIDER and NEXT_PUBLIC_AUTH_PROVIDER aligned across every app that shares a session (auth center, web, landing).

How is this guide?

Edit on GitHub

Last updated on

On this page

Overview
Apps in a default scaffold
Core packages
Request flow (embedded gateway, the default)
Database and row-level security
AI layer
Auth configuration