Falsafa
FrontendHigh-Level Design

Observability and Debug Mode

Debug mode architecture, environment variables, mock auth/storage, and how the frontend logs client-side errors and exposes health check endpoints.

The frontend has two observability mechanisms: a debug mode for local development and simple console-based error reporting for production. There is no structured logging service, OpenTelemetry setup, or Sentry integration.

Debug Mode

NEXT_PUBLIC_DEBUG_MODE=true is a build-time environment variable that transforms the application into a fully offline, mock-backed development environment.

What debug mode does

ComponentNormal behaviorDebug mode behavior
Middleware middleware.tsRedirects unauthenticated requests to loginAllows every request immediately
Auth helper auth()Creates SSR Supabase client, calls getUser()Returns a mock admin user immediately
Client context useAuth()Calls supabase.auth.getUser(), fetches /api/auth/meReturns the mock user as authenticated, isAdmin: true
Client factory lib/supabase.tsInitializes Supabase client with URL + anon keyReturns a mock proxy that throws on any DB query
Stripe Elements checkout pageRenders real card inputRenders a mock form
create-intent APICalls Stripe APIReturns mock clientSecret
Payment completionWaits for Stripe webhookDirectly simulates library assignment
Admin check useAuth()Queries user_rolesReturns admin role for mock user

The mock user returned by debug mode is:

{
  id: 'mock-user-id',
  email: 'debug@debug.com',
  displayName: 'Debug User',
  role: 'admin',
  status: 'active',
}

When debug mode is useful

  • Developing auth pages without a Supabase project
  • Testing the admin panel without seeding data
  • Working on payment UI without a Stripe account
  • Running the frontend in environments where Supabase is unavailable

Environment Variables

The frontend reads the following environment variables at build time or runtime (Next.js convention: NEXT_PUBLIC_* is inlined at build time, non-public vars are server-only):

VariablePurposeRequired
NEXT_PUBLIC_SUPABASE_URLSupabase project URLYes
NEXT_PUBLIC_SUPABASE_ANON_KEYSupabase anon/public keyYes
SUPABASE_SERVICE_ROLE_KEYService-role key for admin clientNo (falls back to anon key in dev)
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYStripe publishable keyYes (for payments)
STRIPE_SECRET_KEYStripe secret keyYes (for payments)
STRIPE_WEBHOOK_SECRETStripe webhook signing secretYes (for webhooks)
NEXT_PUBLIC_DEBUG_MODEEnables debug modeNo
NEXT_PUBLIC_APP_URLPublic app URL for Stripe redirects and link generationNo
NEXT_PUBLIC_MAX_FILE_SIZEMax book upload file size in bytesNo
NEXT_PUBLIC_MAX_COVER_SIZEMax cover image file size in bytesNo

Runtime Error Logging

The frontend uses console.error() for runtime error logging. There is no centralized error handler:

  • API routes catch errors and return 500 { error: message } responses.
  • Client components catch promise rejections and show toast notifications via sonner.
  • Server components throw errors that Next.js surfaces in the terminal or Vercel logs.

Health Check

GET /api/media/health is the only health check endpoint. It tests that the Supabase Storage client can list buckets. Used by the admin panel's system monitor.

There is no health check for the Python backend connection - the chat API route simply fails with a network error if the backend is unreachable.

What is Missing

  • No structured logging service (no Winston, Pino, or console.log wrappers).
  • No OpenTelemetry instrumentation.
  • No client-side error tracking (no Sentry, no LogRocket).
  • No performance monitoring.
  • No uptime monitoring endpoint beyond the storage health check.
  • No audit trail for admin actions.

These are intentional omissions for the initial build - the application relies on Vercel's platform logging for production observability.

On this page