- Learn
- Stack Essentials
- Supabase
- Introduction to Supabase
Understand why Supabase is the backend of choice for AI-built applications and what it provides.
Introduction to Supabase
Supabase is the backend platform that AI tools integrate by default. It provides database, authentication, and storage—everything needed for full-stack applications.
What is Supabase?
Supabase is an open-source Firebase alternative built on PostgreSQL:
Supabase Platform
├── Database (PostgreSQL)
├── Authentication
├── Storage (Files)
├── Edge Functions
├── Realtime
└── Vector/AI (pgvector)
Why AI Tools Choose Supabase
1. Official Integrations
AI builders have native Supabase support:
Lovable:
Settings → Supabase → Connect
Auto-generates database schemas and queries
Bolt.new:
Built-in Supabase integration
One-click project creation
v0:
Generates Supabase client code
Server Actions with Supabase queries
2. Simple API
AI can generate correct code easily:
// Clean, readable queries
const { data, error } = await supabase
.from('users')
.select('*')
.eq('status', 'active')
// Insert data
const { data, error } = await supabase
.from('posts')
.insert({ title: 'Hello', content: 'World' })
.select()
3. Built-in Auth
No separate auth service needed:
// Sign up
await supabase.auth.signUp({
email: 'user@example.com',
password: 'password'
})
// Sign in
await supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'password'
})
// Get current user
const { data: { user } } = await supabase.auth.getUser()
4. Row Level Security
Secure by default with RLS:
-- Users can only see their own data
CREATE POLICY "Users see own data"
ON posts
FOR SELECT
USING (auth.uid() = user_id);
5. Built-in AI Features
Supabase includes AI-powered development tools:
AI SQL Editor:
Dashboard → SQL Editor → "Write a query to..."
AI generates SQL from natural language
AI Assistant:
Dashboard → AI Assistant (sidebar)
Ask questions about your schema, debug queries
Vector Search (pgvector):
-- Store embeddings for AI applications
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
content TEXT,
embedding VECTOR(1536)
);
-- Similarity search
SELECT * FROM documents
ORDER BY embedding <-> '[...]'::vector
LIMIT 5;
Core Features
Database (PostgreSQL)
Full Postgres with extensions:
-- Standard SQL
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email TEXT UNIQUE NOT NULL,
name TEXT,
created_at TIMESTAMPTZ DEFAULT now()
);
-- With extensions
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgvector";
Authentication
Multiple auth methods:
| Method | Use Case |
|---|---|
| Email/Password | Standard signup |
| Magic Link | Passwordless |
| OAuth | Google, GitHub, etc. |
| Phone/SMS | Mobile verification |
Storage
File storage with permissions:
// Upload file
await supabase.storage
.from('avatars')
.upload('user-123/profile.jpg', file)
// Get public URL
const { data } = supabase.storage
.from('avatars')
.getPublicUrl('user-123/profile.jpg')
Realtime
Live data subscriptions:
// Subscribe to changes
supabase
.channel('messages')
.on('postgres_changes', {
event: 'INSERT',
schema: 'public',
table: 'messages'
}, (payload) => {
console.log('New message:', payload.new)
})
.subscribe()
Edge Functions
Serverless functions:
// supabase/functions/hello/index.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
serve(async (req) => {
const { name } = await req.json()
return new Response(
JSON.stringify({ message: `Hello ${name}!` }),
{ headers: { 'Content-Type': 'application/json' } }
)
})
Supabase vs Alternatives
vs Firebase
| Feature | Supabase | Firebase |
|---|---|---|
| Database | PostgreSQL (relational) | Firestore (NoSQL) |
| Queries | SQL | Proprietary |
| Self-host | Yes | No |
| Open source | Yes | No |
| AI tool support | Excellent | Limited |
vs PlanetScale
| Feature | Supabase | PlanetScale |
|---|---|---|
| Database | PostgreSQL | MySQL |
| Auth built-in | Yes | No |
| Storage | Yes | No |
| Realtime | Yes | No |
| AI integrations | More | Fewer |
vs Direct Postgres
| Feature | Supabase | Raw Postgres |
|---|---|---|
| Setup time | Minutes | Hours |
| Auth | Built-in | DIY |
| Storage | Built-in | DIY |
| Dashboard | Yes | No |
| Scaling | Managed | Manual |
How AI Tools Use Supabase
Lovable Pattern
// AI generates complete CRUD
import { createClient } from '@/lib/supabase/client'
export async function getTasks() {
const supabase = createClient()
const { data, error } = await supabase
.from('tasks')
.select('*')
.order('created_at', { ascending: false })
if (error) throw error
return data
}
Bolt.new Pattern
// Server component with Supabase
import { createServerClient } from '@/lib/supabase/server'
export default async function Page() {
const supabase = createServerClient()
const { data: posts } = await supabase
.from('posts')
.select('*, author:users(name)')
return <PostList posts={posts} />
}
Claude Code Pattern
// Full-stack generation
// 1. Creates schema
// 2. Generates types
// 3. Builds queries
// 4. Adds RLS policies
Project Structure
AI tools generate this structure:
project/
├── lib/
│ └── supabase/
│ ├── client.ts # Browser client
│ ├── server.ts # Server client
│ └── middleware.ts # Auth middleware
├── types/
│ └── supabase.ts # Generated types
├── supabase/
│ ├── migrations/ # SQL migrations
│ └── seed.sql # Seed data
└── .env.local # Credentials
Getting Started
1. Create Project
Visit supabase.com and create a new project.
2. Get Credentials
From project settings:
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...
3. Install Client
npm install @supabase/supabase-js
4. Create Client
// lib/supabase/client.ts
import { createBrowserClient } from '@supabase/ssr'
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
)
}
Summary
- Supabase provides database, auth, and storage in one platform
- AI tools have native Supabase integrations
- PostgreSQL gives you full SQL power
- Row Level Security protects data at the database level
- Managed service handles scaling and maintenance
Next Steps
Set up Supabase in your Next.js project with proper client configuration.