Royal Glow internal docs · now fully interactive — Steps, API tables, file trees & live status
Royal Glow Docs
System Design

High-Level Design

Architecture overview, technology decisions matrix, data model, auth design, and API patterns for Royal Glow.

High-Level Design

Executive Summary

Royal Glow Salon & Spa is a premium beauty and wellness establishment in Bengaluru, India. This document describes the high-level design of the full-stack digital operations platform.

A monolithic modular monorepo on Next.js 16 + Neon + Cloudflare's edge, designed for 20k–50k users at ₹0/month, India-first (DPDP, IST, paise, GST 18%), with Lighthouse ≥95 performance and 100 accessibility/SEO.

Scale Targets

Prop

Type

Key Constraints

Prop

Type

Architecture Overview

Layered Monorepo

Presentation  →  API (thin)  →  Business Logic  →  Data Access  →  Database
apps/{web,admin}  apps/{web,admin}/api  packages/business  packages/db  Neon PostgreSQL

Prop

Type

Hosting Topology

Browser/PWA
    │ HTTPS

Cloudflare (DNS + DDoS + WAF)

    ├── Cloudflare Workers (web + admin via OpenNext adapter, edge SSR + API)
    └── Cloudflare KV (service catalog cache, 5-min TTL)

         ├── Render Singapore (Payload CMS)
         ├── Cloud Run (@rgss/invoicing PDF render service)
         ├── Neon PostgreSQL (4 branches: dev/test/pprd/prod)
         ├── Upstash Redis + QStash (cache + queue)
         ├── Cloudflare R2 (images, PDFs, backups)
         └── Ably (realtime WebSocket, 6 channels)

Technology Decisions Matrix

CategoryChoiceKey Reason
FrameworkNext.js 16 (App Router)SSR + SSG + API routes + edge-ready
RuntimeBun3x faster installs, native TypeScript
DatabaseNeon PostgreSQL 16Branching, serverless, all jobs via QStash
ORMDrizzle ORMPure TypeScript, runs on CF Workers V8
AuthBetter AuthSelf-hosted, Google OAuth, RBAC plugin
Edge HostingCloudflare Workers (OpenNext)Generous free tier, global edge
Origin HostingRender (Singapore)Free tier, closest to India
RealtimeAbly6M messages/mo free vs Pusher's 200k/day
CMSPayload CMS v3Self-hosted Next.js plugin, zero vendor lock-in
Email (transactional)ResendModern DX, React Email templates
Email (marketing)BrevoUnsubscribe management, DPDP-compliant
CacheUpstash RedisServerless, works on CF Workers
File StorageCloudflare R2S3-compatible, zero egress fees
AnalyticsPostHog1M events/mo, feature flags, DPDP-compliant
Error MonitoringSentryIndustry standard, CF Workers support
ValidationZodTypeScript-native inference, industry standard
StylingTailwind CSS v4Utility-first, design tokens
Componentsshadcn/ui + RadixCopy-paste ownership, Radix accessibility

Data Architecture

Database Strategy

Neon PostgreSQL 16 with Git-like branching.

Prop

Type

Data Model Overview (38 tables)

DomainTablesKey Entities
Auth4user, session, account, verification
Profiles2customer_profile, staff_profile
Services3service_category, service, service_staff
Scheduling4staff_schedule, staff_time_off, holiday, waitlist
Bookings4booking, booking_service, booking_note, booking_history
Billing2invoice, invoice_item
SPA Memberships2spa_membership, spa_membership_tier
Offers3offer, offer_service, offer_redemption
CRM/Leads5lead, lead_note, customer_tag, customer_tag_assignment, customer_note
Loyalty2loyalty_account, loyalty_transaction
Notifications2notification, push_subscription
Branches1branch
System5daily_sales_summary, monthly_gst_summary, audit_log, system_setting, feature_flag_override

Key Data Conventions

Prop

Type

Three-Layer Cache Hierarchy

Prop

Type

Authentication & Authorization

Auth Architecture

  • Provider: Google OAuth 2.0 only (no email/password)
  • Sessions: PostgreSQL session table (HttpOnly, Secure, SameSite=Lax cookies)
  • CSRF: Built-in via Better Auth
  • Token type: Session-based (not JWT) — revocable, server-validated

Six roles in ascending privilege:

Customer → Staff → Receptionist → Manager → Owner → Developer
RoleAccess
CustomerPublic pages, own bookings/profile/gems
StaffOwn schedule, assigned booking notes, leave requests
ReceptionistLowest admin role — bookings, billing, memberships, leave approvals
ManagerFull operational access — staff, services, reports, settings
OwnerFull business access including admin.theroyalglow.in/users
DeveloperEverything + admin.theroyalglow.in/integrations, admin.theroyalglow.in/logs

Initiate

User clicks "Sign in with Google".

Redirect to the Google consent screen (shows "Royal Glow Salon & Spa").

Callback

User grants consent and Google calls back with an auth code.

Exchange

Better Auth exchanges the code for tokens and creates/finds the user in the DB.

Session

A session is created and an HttpOnly cookie is set.

Route

Has a customer_profile? YES → homepage. NO → /onboarding.

API Design

Thin API Layer Pattern

Request → Parse → Zod Validate → Business Logic → Response

API routes are thin orchestrators. No database queries in route handlers.

Standard Response Shape

// Success
{ success: true, data: T, meta?: { page, totalPages, totalCount } }

// Error
{ success: false, error: { code, message, statusCode, requestId, retryable?, details? } }

API Groups

Prop

Type

Non-Functional Requirements

Prop

Type

OpenReport an issue

Was this page helpful?

On this page