Home › Supabase › Supabase backend rules

Supabase backend rules

Cursor rules for apps on Supabase: Row Level Security first, migrations, typed clients and Edge Functions.

CursorSupabase

How to use

Save this as .cursor/rules/supabase.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/supabase.mdcDownload  
---
description: Supabase conventions
globs: ["supabase/**", "**/*.{ts,tsx,sql}"]
---

# Supabase

## Security (non-negotiable)
- Every table in `public` has Row Level Security enabled with explicit policies. Write policies in the same migration that creates the table.
- The `service_role` key is server-only. Never put it in client code or `NEXT_PUBLIC_*`/`EXPO_PUBLIC_*` variables.
- Use `auth.uid()` in policies; wrap in `(select auth.uid())` for performance.

## Schema
- All schema changes via migrations: `supabase migration new <name>`, test locally with `supabase db reset`. Never change production schema in the dashboard.
- Add indexes for columns used in policies and foreign keys.

## Client
- Generate types: `supabase gen types typescript --local > types/database.ts`; create clients with `createClient<Database>()`.
- Use `@supabase/ssr` for server-side auth in SSR frameworks.
- Always check `{ data, error }` and handle `error`.

## Edge Functions
- Deno, in `supabase/functions/<name>/index.ts`; validate input and verify the JWT unless the function is intentionally public.

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Cloudflare Agents SDK rules

Cursor rules for stateful AI agents on Cloudflare (agents package): Durable Object state, SQL, scheduling, and WebSockets.

CursorCloudflare Workers / Hono

Convex backend rules

Cursor rules for Convex backends: schema, validated queries/mutations/actions, indexes, and auth checks.

CursorConvex

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.