Architecture

How Nebutra is built — monorepo structure, request flow, and the key layers of the platform.

Overview

Nebutra is a Turborepo monorepo with multiple apps and shared packages: design system, type-safe API contract, and runtime tokens. Components are independently deployable.

Browser / Mobile Client


┌─────────────────────────────┐
│  Cloudflare DNS + CDN/WAF   │
└─────────────┬───────────────┘

   ┌──────────┼──────────┬──────────────┐
   ▼          ▼          ▼              ▼
landing    docs      web + auth      API gateway
(Vercel)  (Vercel)   (ECS Next)      (ECS Hono)
nebutra.com docs.     app. + auth.   api.nebutra.com
                     nebutra.com

                          │ REST / cookies (.nebutra.com)

                 ┌──────────────────┐
                 │ backends/gateway │  @nebutra/gateway
                 │ auth, RBAC, S2S  │
                 └────────┬─────────┘

             ┌────────────┼────────────┐
             ▼            ▼            ▼
        PostgreSQL      Redis/KV    AI / workers

Apps

AppURLFrameworkSteady-state host
landingnebutra.comNext.js 16Vercel
sailor-docsnebutra.com/docsNext.js + FumadocsVercel
webapp.nebutra.comNext.js 16ECS (Next standalone)
authauth.nebutra.comNext.js 16ECS login center
backends/gatewayapi.nebutra.comHono + NodeECS (@nebutra/gateway)
idpsso.nebutra.comNext.jsECS OIDC issuer
studiostudio.nebutra.comSanityVercel / optional
design-docsinternalFumadocsoptional
storybookinternalStorybookoptional

Core packages

PackageDescription
@nebutra/uiComponent library — Radix + Nebutra primitives
@nebutra/tokensRuntime CSS design tokens
@nebutra/authProvider adapters + JWT S2S (signServiceToken)
@nebutra/permissionsRBAC — CASL or OpenFGA
@nebutra/dbPrisma client + multi-tenant helpers
@nebutra/queueQStash or BullMQ
@nebutra/meteringUsage metering → ClickHouse
@nebutra/webhooksOutbound webhooks (HMAC signing for delivery, not S2S)
@nebutra/tenantTenant context + RLS helpers

Request flow

Request

  ├─ 1. Cloudflare        (DNS, CDN, WAF)

  ├─ 2. App origin
  │     ├─ Marketing/docs → Vercel
  │     └─ app / auth / api → ECS PM2

  ├─ 3. Gateway middleware (api.*)
  │     ├─ CORS
  │     ├─ Auth           (session / Better Auth JWT, or S2S service JWT)
  │     ├─ Tenant         (org context)
  │     ├─ RBAC
  │     └─ Rate limit

  └─ 4. Route handler → JSON envelope { success, data, error }

Service-to-service calls use short-lived HS256 JWTs in x-service-token (not legacy hex-HMAC).

Database isolation

StrategyIsolationRecommended for
Shared schemaRLS via tenant_idMost SaaS (default)
Separate schemaSchema per tenantMid-market residency
Separate databaseDB per tenantStrict compliance

AI layer

Gateway AI surfaces (authenticated, tenant-scoped), for example:

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

Usage feeds the metering pipeline for quotas and billing.

Provider swap pattern

# Auth (production default)
AUTH_PROVIDER=better-auth
NEXT_PUBLIC_AUTH_PROVIDER=better-auth

# Alternatives: clerk | next-auth | supabase | dev

Align AUTH_PROVIDER and NEXT_PUBLIC_AUTH_PROVIDER across auth center, web, and landing.

How is this guide?

Edit on GitHub

Last updated on

On this page