Skip to content

Commit d097278

Browse files
committed
feat: supabase skill with db and realtime references
Adds the supabase agent skill with comprehensive references for: - Database: schema design, RLS policies, migrations, indexing, query optimization, security - Realtime: channels, broadcast, presence, postgres changes, auth setup, error handling
1 parent 0d88c8a commit d097278

34 files changed

+2777
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dist/
1212
# AI Agent directories
1313
.agent/
1414
.agents/
15-
.claude/
1615
.codex/
1716
.gemini/
1817
.goose/
@@ -21,3 +20,4 @@ dist/
2120

2221
# Generated skills in any dot directory
2322
.*/skills/
23+
.claude/

GETTING_STARTED.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Getting Started
2+
3+
Contributor guide for adding content to the Supabase Agent Skills.
4+
5+
## Quick Start
6+
7+
1. Create a reference file in `skills/supabase/references/`
8+
2. Use `skills/supabase/references/_template.md` as your starting point
9+
3. Update `skills/supabase/SKILL.md` to reference your new file
10+
4. Run `npm run build && npm run check`
11+
12+
## Creating Reference Files
13+
14+
```bash
15+
# Main topic
16+
skills/supabase/references/{feature}.md
17+
18+
# Sub-topics (optional)
19+
skills/supabase/references/{feature}/{subtopic}.md
20+
```
21+
22+
**Examples:**
23+
24+
- `references/auth.md` - Authentication overview
25+
- `references/auth/nextjs.md` - Auth setup for Next.js
26+
- `references/storage.md` - Storage overview
27+
28+
## Writing Guidelines
29+
30+
Follow the [Agent Skills Open Standard](https://agentskills.io/) best practices:
31+
32+
1. **Concise is key** - Only include what Claude doesn't already know
33+
2. **Show, don't tell** - Prefer code examples over explanations
34+
3. **Progressive disclosure** - Keep SKILL.md lean, put details in reference files
35+
4. **Concrete examples** - Include runnable code with real values
36+
5. **Common mistakes first** - Help agents avoid pitfalls
37+
38+
**Good example** (~50 tokens):
39+
40+
```typescript
41+
// Get user session
42+
const { data: { session } } = await supabase.auth.getSession();
43+
```
44+
45+
**Avoid** (~150 tokens):
46+
47+
```markdown
48+
Sessions are a way to track authenticated users. When a user logs in,
49+
a session is created. You can get the current session using the
50+
getSession method which returns a promise...
51+
```
52+
53+
## Update SKILL.md
54+
55+
Add your reference to the resources table:
56+
57+
```markdown
58+
| Area | Resource | When to Use |
59+
| ------------ | ----------------------- | ------------------------------ |
60+
| Your Feature | `references/feature.md` | Brief description of use cases |
61+
```
62+
63+
## Validate
64+
65+
```bash
66+
npm run validate -- supabase # Check files
67+
npm run build -- supabase # Generate AGENTS.md
68+
npm run check # Format and lint
69+
```

skills/supabase/AGENTS.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# supabase
2+
3+
> **Note:** `CLAUDE.md` is a symlink to this file.
4+
5+
## Overview
6+
7+
Guides and best practices for working with Supabase. Covers getting started, Auth, Database, Storage, Edge Functions, Realtime, supabase-js SDK, CLI, and MCP integration. Use for any Supabase-related questions.
8+
9+
## Structure
10+
11+
```
12+
supabase/
13+
SKILL.md # Main skill file - read this first
14+
AGENTS.md # This navigation guide
15+
CLAUDE.md # Symlink to AGENTS.md
16+
references/ # Detailed reference files
17+
```
18+
19+
## Usage
20+
21+
1. Read `SKILL.md` for the main skill instructions
22+
2. Browse `references/` for detailed documentation on specific topics
23+
3. Reference files are loaded on-demand - read only what you need
24+
25+
## Reference Categories
26+
27+
| Priority | Category | Impact | Prefix |
28+
|----------|----------|--------|--------|
29+
| 1 | Database | CRITICAL | `db-` |
30+
| 2 | Realtime | MEDIUM-HIGH | `realtime-` |
31+
32+
Reference files are named `{prefix}-{topic}.md` (e.g., `query-missing-indexes.md`).
33+
34+
## Available References
35+
36+
**Database** (`db-`):
37+
- `references/db-conn-pooling.md`
38+
- `references/db-migrations-diff.md`
39+
- `references/db-migrations-idempotent.md`
40+
- `references/db-migrations-testing.md`
41+
- `references/db-perf-indexes.md`
42+
- `references/db-perf-query-optimization.md`
43+
- `references/db-rls-common-mistakes.md`
44+
- `references/db-rls-mandatory.md`
45+
- `references/db-rls-performance.md`
46+
- `references/db-rls-policy-types.md`
47+
- `references/db-rls-views.md`
48+
- `references/db-schema-auth-fk.md`
49+
- `references/db-schema-extensions.md`
50+
- `references/db-schema-jsonb.md`
51+
- `references/db-schema-realtime.md`
52+
- `references/db-schema-timestamps.md`
53+
- `references/db-security-functions.md`
54+
- `references/db-security-service-role.md`
55+
56+
**Realtime** (`realtime-`):
57+
- `references/realtime-broadcast-basics.md`
58+
- `references/realtime-broadcast-database.md`
59+
- `references/realtime-patterns-cleanup.md`
60+
- `references/realtime-patterns-debugging.md`
61+
- `references/realtime-patterns-errors.md`
62+
- `references/realtime-postgres-changes.md`
63+
- `references/realtime-presence-tracking.md`
64+
- `references/realtime-setup-auth.md`
65+
- `references/realtime-setup-channels.md`
66+
67+
---
68+
69+
*27 reference files across 2 categories*

skills/supabase/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

skills/supabase/SKILL.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: supabase
3+
description: Guides and best practices for working with Supabase. Covers getting started, Auth, Database, Storage, Edge Functions, Realtime, supabase-js SDK, CLI, and MCP integration. Use for any Supabase-related questions.
4+
license: MIT
5+
metadata:
6+
author: supabase
7+
version: '1.0.0'
8+
organization: Supabase
9+
date: January 2026
10+
abstract: Comprehensive Supabase development guide for building applications with Supabase services. Contains guides covering Auth, Database, Storage, Edge Functions, Realtime, client libraries, CLI, and tooling. Each reference includes setup instructions, code examples, common mistakes, and integration patterns.
11+
---
12+
13+
# Supabase
14+
15+
Supabase is an open source Firebase alternative that provides a Postgres database, authentication, instant APIs, edge functions, realtime subscriptions, and storage. It's fully compatible with Postgres and works with any language, framework, or ORM.
16+
17+
## Supabase Documentation
18+
19+
Always reference the Supabase documentation before making Supabase-related claims. The documentation is the source of truth for all Supabase-related information.
20+
21+
You can use the `curl` commands to fetch the documentation page as markdown:
22+
23+
**Documentation:**
24+
25+
```bash
26+
# Fetch any doc page as markdown
27+
curl -H "Accept: text/markdown" https://supabase.com/docs/<path>
28+
```
29+
30+
## Overview of Resources
31+
32+
Reference the appropriate resource file based on the user's needs:
33+
34+
### Database
35+
36+
| Area | Resource | When to Use |
37+
| ------------------ | ------------------------------- | ---------------------------------------------- |
38+
| RLS Security | `references/db-rls-*.md` | Row Level Security policies, common mistakes |
39+
| Connection Pooling | `references/db-conn-pooling.md` | Transaction vs Session mode, port 6543 vs 5432 |
40+
| Schema Design | `references/db-schema-*.md` | auth.users FKs, timestamps, JSONB, extensions |
41+
| Migrations | `references/db-migrations-*.md` | CLI workflows, idempotent patterns, db diff |
42+
| Performance | `references/db-perf-*.md` | Indexes (BRIN, GIN), query optimization |
43+
| Security | `references/db-security-*.md` | Service role key, security_definer functions |
44+
45+
### Realtime
46+
47+
| Area | Resource | When to Use |
48+
| ---------------- | ------------------------------------ | ----------------------------------------------- |
49+
| Channel Setup | `references/realtime-setup-*.md` | Creating channels, naming conventions, auth |
50+
| Broadcast | `references/realtime-broadcast-*.md` | Client messaging, database-triggered broadcasts |
51+
| Presence | `references/realtime-presence-*.md` | User online status, shared state tracking |
52+
| Postgres Changes | `references/realtime-postgres-*.md` | Database change listeners (prefer Broadcast) |
53+
| Patterns | `references/realtime-patterns-*.md` | Cleanup, error handling, React integration |
54+
55+
**CLI Usage:** Always use `npx supabase` instead of `supabase` for version consistency across team members.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Section Definitions
2+
3+
Reference files are grouped by prefix. Claude loads specific files based on user
4+
queries.
5+
6+
---
7+
8+
## 1. Database (db)
9+
10+
**Impact:** CRITICAL
11+
**Description:** Row Level Security policies, connection pooling, schema design patterns, migrations, performance optimization, and security functions for Supabase Postgres.
12+
13+
## 2. Realtime (realtime)
14+
15+
**Impact:** MEDIUM-HIGH
16+
**Description:** Channel setup, Broadcast messaging, Presence tracking, Postgres Changes listeners, cleanup patterns, error handling, and debugging.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Action-Oriented Title
3+
tags: relevant, keywords
4+
---
5+
6+
# Feature Name
7+
8+
One-sentence description of what this does and when to use it.
9+
10+
## Quick Start
11+
12+
```typescript
13+
// Minimal working example with real code
14+
import { createClient } from "@supabase/supabase-js";
15+
const supabase = createClient(url, key);
16+
17+
// Core operation
18+
const { data, error } = await supabase.from("table").select("*");
19+
```
20+
21+
## Common Patterns
22+
23+
### Pattern Name
24+
25+
```typescript
26+
// Concrete example - prefer this over explanations
27+
const { data } = await supabase.from("users").select("id, email").eq("active", true);
28+
```
29+
30+
## Common Mistakes
31+
32+
**Mistake**: Brief description of what goes wrong.
33+
34+
```typescript
35+
// Incorrect
36+
const data = await supabase.from("users").select(); // Missing error handling
37+
38+
// Correct
39+
const { data, error } = await supabase.from("users").select("*");
40+
if (error) throw error;
41+
```
42+
43+
## Related
44+
45+
- [subtopic.md](subtopic.md) - For advanced X patterns
46+
- [Docs](https://supabase.com/docs/guides/feature) - Official guide
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: Use Correct Connection Pooling Mode
3+
impact: CRITICAL
4+
impactDescription: Prevents connection exhaustion and enables 10-100x scalability
5+
tags: connection-pooling, supavisor, transaction-mode, session-mode
6+
---
7+
8+
## Use Correct Connection Pooling Mode
9+
10+
Supabase provides Supavisor for connection pooling. Choose the right mode based
11+
on your application type.
12+
13+
## Transaction Mode (Port 6543)
14+
15+
Best for: Serverless functions, edge computing, stateless APIs.
16+
17+
```bash
18+
## Transaction mode connection string
19+
postgres://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
20+
```
21+
22+
**Limitations:**
23+
24+
- No prepared statements
25+
- No SET commands
26+
- No LISTEN/NOTIFY
27+
- No temp tables
28+
29+
```javascript
30+
// Prisma - disable prepared statements
31+
const prisma = new PrismaClient({
32+
datasources: {
33+
db: {
34+
url: process.env.DATABASE_URL + "?pgbouncer=true",
35+
},
36+
},
37+
});
38+
```
39+
40+
## Session Mode (Port 5432)
41+
42+
Best for: Long-running servers, apps needing prepared statements.
43+
44+
```bash
45+
## Session mode (via pooler for IPv4)
46+
postgres://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:5432/postgres
47+
```
48+
49+
## Direct Connection (Port 5432)
50+
51+
Best for: Migrations, admin tasks, persistent servers.
52+
53+
```bash
54+
## Direct connection (IPv6 only unless IPv4 add-on enabled)
55+
postgres://postgres.[ref]:[password]@db.[ref].supabase.co:5432/postgres
56+
```
57+
58+
## Common Mistakes
59+
60+
**Incorrect:**
61+
62+
```javascript
63+
// Serverless with session mode - exhausts connections
64+
const pool = new Pool({
65+
connectionString: "...pooler.supabase.com:5432/postgres",
66+
max: 20, // Too many connections per instance!
67+
});
68+
```
69+
70+
**Correct:**
71+
72+
```javascript
73+
// Serverless with transaction mode
74+
const pool = new Pool({
75+
connectionString: "...pooler.supabase.com:6543/postgres",
76+
max: 1, // Single connection per serverless instance
77+
});
78+
```
79+
80+
**Incorrect:**
81+
82+
```bash
83+
## Transaction mode with prepared statements
84+
DATABASE_URL="...pooler.supabase.com:6543/postgres"
85+
## Error: prepared statement already exists
86+
```
87+
88+
**Correct:**
89+
90+
```bash
91+
## Add pgbouncer=true to disable prepared statements
92+
DATABASE_URL="...pooler.supabase.com:6543/postgres?pgbouncer=true"
93+
```
94+
95+
## Connection Limits by Compute Size
96+
97+
| Compute | Direct Connections | Pooler Clients |
98+
| ------- | ------------------ | -------------- |
99+
| Nano | 60 | 200 |
100+
| Small | 90 | 400 |
101+
| Medium | 120 | 600 |
102+
| Large | 160 | 800 |
103+
104+
## Related
105+
106+
- [Docs](https://supabase.com/docs/guides/database/connecting-to-postgres)

0 commit comments

Comments
 (0)