Starter Docs

Product System Design

Product architecture, data model, services, and security model.

Status: Working architecture blueprint for the universal Starter Kit monorepo—a production-grade baseline for multi-tenant web, mobile, and API applications.

1. System Vision & Architecture Principles

Starter is built as a secure modular monolith first, with event-driven seams and clear module boundaries, designed to scale into independent services when load or compliance requires it.

The core operational loop is:

Action requested -> policy verification -> state transition in Postgres
-> outbox event -> background worker (notifications, audit, AI assist)
-> real-time sync to Web & Mobile clients

Engineering principles:

  • Relational Source of Truth: PostgreSQL with Drizzle ORM holds all primary records.
  • Tenant Isolation: Every multi-tenant operation is scoped by organizationId and workspaceId.
  • Stateless Application Servers: API containers scale horizontally without local file or session state.
  • Defense in Depth: Multi-factor authentication, passkeys (WebAuthn), CSRF protection, and strict Zod validation.

2. Product Boundaries & Personas

Primary personas:

PersonaPrimary SurfaceCore Capabilities
Organization OwnerWeb DashboardWorkspace lifecycle, billing, plan management, audit trails
Workspace AdminWeb Dashboard, MobileMember invitations, role assignment, policy rules, integrations
Team MemberWeb Console, MobileDay-to-day operations, task management, profile and security settings
Viewer / AuditorWeb Console (Read-only)Compliance review, audit inspection, activity telemetry

3. High-Level Architecture

                    +----------------------+
                    |   apps/docs          |
                    |   Fumadocs site      |
                    +----------------------+

+----------------+     +------------------+      +------------------+
| apps/web       |     | apps/nest-api    |      | apps/mobile      |
| Next.js App    |<--->| NestJS API Spine |<---->| Expo App         |
+----------------+     +--------+---------+      +------------------+
                                |
               +----------------+----------------+
               |                                 |
       +-------v--------+                  +-----v------------+
       | Postgres       |                  | apps/rust        |
       | Source of truth|                  | Axum Performance |
       +-------+--------+                  +------------------+
               |
       +-------v--------+
       | Redis          |
       | Cache / Queue  |
       +----------------+

4. Service Layout

Core Production Services

ServicePathRoleTechnology
Web Consoleapps/webPublic landing, admin dashboard, user settings, billingNext.js, React, Tailwind CSS
Mobile Appapps/mobileCross-platform mobile clientExpo Router, Uniwind
API Spineapps/nest-apiAuth, tenancy, users, billing, MFA, passkeysNestJS, Drizzle ORM, Zod
Performance Serviceapps/rustHigh-throughput data processing & micro-benchmarksRust, Axum, Tokio
Documentationapps/docsTechnical documentation and architecture guidesFumadocs, MDX

Shared Monorepo Packages

PackageWorkspace NameResponsibility
UI Primitives@starter/uiShadcn-style primitives, tokens, and motion components
Logger@starter/loggerInjectable logger for TypeScript and Rust
TypeScript Config@starter/typescript-configShared tsconfig.json bases across apps and packages

5. Data Model & Tenancy

Tenancy and Access Control

TablePurposeKey Attributes
organizationsTop-level tenant accountid, name, slug unique, status, createdAt
workspacesProject / environment boundaryid, organization_id, name, slug, environment
usersGlobal user identityid, email unique, status, password_hash
user_profilesPersonal details and avatarid, user_id, display_name, avatar_url, locale
membershipsUser access to workspaceid, workspace_id, user_id, status
rolesRole definitionsid, workspace_id nullable, code, name
permissionsGranular permission catalogid, code unique, module, description
role_permissionsPermissions assigned to rolesrole_id, permission_id
sessionsActive user sessionsid, user_id, token_hash, expires_at, ip, userAgent
subscriptionsBilling and plan stateid, user_id, provider, plan_id, status

6. Security & Authentication Architecture

  1. Password Authentication:
    • Hashed using Argon2id with per-user salt.
  2. Session & Token Model:
    • Short-lived JWT access tokens (15 minutes).
    • Long-lived secure, HTTP-only refresh cookies with rotation and revocation.
  3. Multi-Factor Authentication (MFA):
    • RFC 6238 TOTP factors with encrypted secret storage.
    • Encrypted backup codes generated on factor activation.
  4. Passkeys (WebAuthn):
    • FIDO2 / WebAuthn standard support.
    • Credential challenge verification stored with TTL.
  5. CSRF & Rate Limiting:
    • Double-submit CSRF cookie guard on state-changing API endpoints.
    • In-memory / Redis token-bucket rate limiting on authentication routes.

7. Event Streams & Outbox Pattern

All critical events follow the outbox pattern inside database transactions to ensure consistency:

TopicPartition KeyPurpose
starter.workspace.events.v1workspaceIdWorkspace creation, update, and quota telemetry
starter.auth.events.v1userIdLogin, password reset, MFA factor activation
starter.billing.events.v1organizationIdCheckout, subscription renewal, invoice payment
starter.notification.events.v1recipientIdTransactional emails, in-app alerts
starter.audit.events.v1workspaceIdImmutable audit trail for compliance
starter.ai.actions.v1workspaceIdPrompt telemetry, assist proposals, approval queue

8. Deployment & Infrastructure

The starter supports multiple deployment targets out of the box:

  • Local Development: docker-compose.yml orchestrates PostgreSQL, Nest API, Web, AI API, and optional Rust.
  • Production Web: Next.js deployed on Vercel with standalone output.
  • Production API: NestJS container deployed on Render, Fly.io, or AWS ECS with pooled PostgreSQL (e.g. Neon).
  • Object Storage: S3-compatible private buckets (Cloudflare R2, AWS S3) with pre-signed upload URLs.

On this page