Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/supabase-reference-architecture

@0d57af8
Run it yourself

Implement enterprise Supabase reference architectures — monorepo layout, multi-tenant RLS, microservices with cross-project access, framework integration, edge functions, caching, queue patterns, and audit logging. Use when designing a new Supabase project from scratch, reviewing project structure for production readiness, planning multi-tenant isolation, or establishing team architecture standards. Trigger with phrases like "supabase architecture", "supabase project structure", "supabase monorepo", "supabase multi-tenant", "supabase reference design", "how to organize supabase at scale".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/supabase-reference-architecture

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesexamples.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Examples — Multi-Tenant Setup and Job Queue Consumer

Complete Multi-Tenant Setup (TypeScript)

// Use the current request's authenticated, non-admin client.
import { getSupabaseServer } from './supabase-server'

export async function readTenantProjects(tenantId: string) {
  const supabase = await getSupabaseServer()
  const { data: { user }, error: authError } = await supabase.auth.getUser()
  if (authError || !user) throw new Error('Authentication required')

  const { data, error } = await supabase.from('projects')
    .select('id, name, created_at')
    .eq('org_id', tenantId) // Query scope only; membership RLS authorizes access.
    .order('created_at', { ascending: false })
  if (error) throw new Error('Project query failed')
  return data
}

Job Queue Consumer (TypeScript)

import { getSupabaseAdmin } from './admin'

async function processJobs() {
  const supabase = getSupabaseAdmin()

  while (true) {
    // Atomically claim the next job
    const { data: job, error } = await supabase
      .rpc('claim_next_job', { p_job_type: 'send-email' })

    if (error || !job) {
      // No jobs available — wait before polling again
      await new Promise(r => setTimeout(r, 5000))
      continue
    }

    try {
      // Process the job
      console.log(`Processing job ${job.id}:`, job.payload)
      await sendEmail(job.payload)

      // Mark complete
      await supabase
        .from('job_queue')
        .update({ status: 'completed', completed_at: new Date().toISOString() })
        .eq('id', job.id)
    } catch (err) {
      // Mark failed — pg_cron will retry if attempts < max_attempts
      await supabase
        .from('job_queue')
        .update({
          status: 'failed',
          error_message: err instanceof Error ? err.message : String(err)
        })
        .eq('id', job.id)
    }
  }
}

async function sendEmail(payload: Record<string, unknown>) {
  console.log('Sending email to:', payload.to)
}

processJobs().catch(console.error)

SvelteKit Integration

Use a request-scoped cookie adapter, not a raw Cookie header. Keep privileged clients in a separate server-only module, never in ordinary request locals.

// src/hooks.server.ts — application supplies its Database and App.Locals types.
import { createServerClient } from '@supabase/ssr'
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_PUBLISHABLE_KEY } from '$env/static/public'
import type { Handle } from '@sveltejs/kit'
import type { Database } from '@my-platform/supabase'

export const handle: Handle = async ({ event, resolve }) => {
  event.locals.supabase = createServerClient<Database>(
    PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_PUBLISHABLE_KEY, {
      cookies: {
        getAll: () => event.cookies.getAll(),
        setAll: (updates) => {
          for (const { name, value, options } of updates) {
            event.cookies.set(name, value, { ...options, path: '/' })
          }
        }
      }
    }
  )
  const response = await resolve(event)
  // Manual cache protection also covers resolved error/redirect responses.
  const headers = new Headers(response.headers)
  headers.set('Cache-Control', 'private, no-store')
  return new Response(response.body, {
    status: response.status, statusText: response.statusText, headers
  })
}

Each protected server load/action must call event.locals.supabase.auth.getUser() and reject errors or an absent user before using user data. This hook alone does not authorize a route. Use the configured legacy anon key if the project has not adopted publishable keys; never use a service-role key for this client. Follow the current SvelteKit adapter for framework typing and response handling.

The hook applies manual private, no-store protection rather than relying on setAll cache-header arguments. Disable shared/CDN caching for authenticated routes and verify the deployed cache policy; a CDN configuration can override origin headers.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides comprehensive architectural patterns and documentation for enterprise Supabase deployments, focusing on security, scalability, and best practices.

  • Socket2mo

    2 alerts: gptSecurity, gptAnomaly

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
What it can do
Reads files Edits files Runs commands
version
1.55.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 8 allowed tools
ReadWriteEditBash(npm:*)Bash(npx:*)Bash(supabase:*)GrepGlob
Other metadata
tags
[
  "saas",
  "supabase",
  "architecture",
  "patterns",
  "multi-tenant",
  "monorepo"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/supabase-reference-architecture