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.

referencesproject-structure.md

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

Project Structure — Monorepo Layout

Recommended Directory Layout

my-platform/
├── packages/
│   └── supabase/                    # Shared Supabase package
│       ├── supabase/
│       │   ├── config.toml          # Supabase CLI config
│       │   ├── migrations/          # Version-controlled SQL migrations
│       │   │   ├── 20260101000000_create_tenants.sql
│       │   │   ├── 20260102000000_create_profiles.sql
│       │   │   └── 20260103000000_create_audit_log.sql
│       │   ├── seed.sql             # Development seed data
│       │   └── functions/           # Edge Functions (Deno runtime)
│       │       ├── process-order/index.ts
│       │       └── send-notification/index.ts
│       ├── src/
│       │   ├── client.ts            # Client singleton (anon key)
│       │   ├── admin.ts             # Admin client (service_role, server only)
│       │   ├── database.types.ts    # Auto-generated from `supabase gen types`
│       │   └── errors.ts            # Custom error classes
│       ├── package.json
│       └── tsconfig.json
├── apps/
│   ├── web/                         # Next.js / SvelteKit frontend
│   ├── admin/                       # Internal admin dashboard
│   └── worker/                      # Background job runner
├── pnpm-workspace.yaml
└── turbo.json

Migration Management

Keep migrations in version control. Every schema change is a new migration file.

# Generate a new migration after making changes in the dashboard
supabase db diff --use-migra -f add_orders_table

# Apply migrations locally
supabase db reset

# Push migrations to production
supabase db push

# Regenerate TypeScript types after any schema change
supabase gen types typescript --local > packages/supabase/src/database.types.ts

Add a turbo.json pipeline so type generation runs after migrations:

{
  "pipeline": {
    "@my-platform/supabase#gen-types": {
      "outputs": ["src/database.types.ts"],
      "cache": false
    },
    "build": {
      "dependsOn": ["@my-platform/supabase#gen-types"]
    }
  }
}

Microservices with Separate Supabase Projects

For large organizations, each service owns its own Supabase project. Cross-service reads use the service_role key (bypasses RLS).

// services/billing/src/supabase.ts
import { createClient } from '@supabase/supabase-js'
import type { BillingDB } from './database.types'

export const billingDb = createClient<BillingDB>(
  process.env.BILLING_SUPABASE_URL!,
  process.env.BILLING_SUPABASE_SERVICE_ROLE_KEY!,
  { auth: { autoRefreshToken: false, persistSession: false } }
)

// Cross-project access: read user profiles from the main project
import type { MainDB } from '@my-platform/supabase'

const mainDb = createClient<MainDB>(
  process.env.MAIN_SUPABASE_URL!,
  process.env.MAIN_SUPABASE_SERVICE_ROLE_KEY!,
  { auth: { autoRefreshToken: false, persistSession: false } }
)

export async function getUserProfile(userId: string) {
  const { data, error } = await mainDb
    .from('profiles')
    .select('id, email, display_name, avatar_url')
    .eq('id', userId)
    .single()

  if (error) throw new Error(`Cross-project profile lookup failed: ${error.message}`)
  return data
}

Cross-project access rules:

  • Always use service_role key (it bypasses RLS)
  • Never expose service_role keys to client-side code
  • Limit cross-project calls to read-only where possible
  • Consider caching cross-project lookups to reduce latency

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