0
0
Supabasecloud~5 mins

Supabase architecture (Postgres, Auth, Storage, Realtime, Edge Functions)

Choose your learning style9 modes available
Introduction

Supabase helps you build apps quickly by giving you ready tools for data, users, files, live updates, and custom code.

You want a database that works well with your app and is easy to manage.
You need to let users sign up, log in, and keep their info safe.
You want to store and serve files like images or documents.
You want your app to update live when data changes without refreshing.
You want to run small custom code close to your users for faster responses.
Syntax
Supabase
Supabase consists of these main parts:

1. Postgres: A database to store your app data.
2. Auth: Manages user sign-up, login, and security.
3. Storage: Stores files like pictures or videos.
4. Realtime: Sends live updates when data changes.
5. Edge Functions: Run custom code near users for fast responses.

Each part works together to make building apps easier.

You can use them all or just the ones you need.

Examples
This is like a digital filing cabinet for your app's information.
Supabase
Postgres: Store user profiles and app data in tables.
Think of it as the app's front door with a lock and key.
Supabase
Auth: Let users create accounts and log in securely.
Like a cloud folder where your app keeps files.
Supabase
Storage: Upload and serve images or documents.
Similar to a live chat that updates without refreshing.
Supabase
Realtime: Notify users instantly when new messages arrive.
Like having a helper nearby to do small jobs fast.
Supabase
Edge Functions: Run code close to users for quick tasks like sending emails.
Sample Program

This example shows how you set up each part of Supabase for a simple task app.

Supabase
# Supabase basic setup example

# 1. Create a Postgres table for tasks
CREATE TABLE tasks (
  id SERIAL PRIMARY KEY,
  title TEXT NOT NULL,
  completed BOOLEAN DEFAULT FALSE
);

# 2. Enable Auth for user sign-up and login
# (Configured in Supabase dashboard, no SQL needed)

# 3. Use Storage to save task images
# (Configured in dashboard, upload files via API)

# 4. Use Realtime to listen for task updates
# (Client subscribes to changes on tasks table)

# 5. Write an Edge Function to send notification on new task
// Edge Function code example (JavaScript):
export async function handler(req) {
  const { task } = await req.json();
  // send notification logic here
  return new Response('Notification sent for task: ' + task.title);
}
OutputSuccess
Important Notes

Supabase uses Postgres, a popular and powerful database.

Auth keeps user data safe with secure login methods.

Realtime uses websockets to send live updates instantly.

Summary

Supabase combines database, user management, file storage, live updates, and custom code.

It helps you build apps faster without managing servers.

You can pick and choose which parts to use based on your app needs.