> ## Documentation Index
> Fetch the complete documentation index at: https://docs.grouple.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# Supabase Overview

> Supabase powers the database, auth, email, and serverless logic for Grouple

## What Supabase Handles

Supabase is the core backend for Grouple. It's not just a database — it handles a significant portion of the business logic:

| Responsibility            | How                                                                                    |
| ------------------------- | -------------------------------------------------------------------------------------- |
| Primary database          | PostgreSQL (20+ tables)                                                                |
| Authentication            | GoTrue (JWT-based)                                                                     |
| Email sending             | Edge Functions (send-lead-email, send-proposal-email, reservation-confirmation-emails) |
| Business logic automation | 14 Database Triggers                                                                   |
| Complex queries           | 40+ RPC Functions                                                                      |
| File storage              | 3 Storage buckets                                                                      |
| Currency rates            | Edge Function (update-exchange-rates)                                                  |
| AI proposal generation    | Edge Function (generate-proposal)                                                      |
| OCR processing            | Edge Function (mistral-ocr)                                                            |

## Project Details

| Field        | Value                                               |
| ------------ | --------------------------------------------------- |
| Project      | Proposal maker                                      |
| Organisation | grouple.in Org                                      |
| Environment  | Production (main branch)                            |
| Region       | Supabase hosted                                     |
| Connection   | Via connection pooler (pooled connections from ECS) |

## Authentication Flow

```
User signs up / logs in via Supabase Auth
        ↓
GoTrue issues JWT
        ↓
JWT used for:
  - Frontend direct Supabase CRUD (RLS enforced per user)
  - API requests to ECS backend (validated server-side)
        ↓
On new customer INSERT:
  DB Trigger: on_customer_created_link_enquiries
  → Links any pre-existing enquiries (submitted before signup) to this customer
```

## Row Level Security (RLS)

All tables have RLS enabled. Key patterns:

* **Merchants** can only see/edit their own venues, leads, proposals
* **Customers** can only see their own enquiries and proposals
* **Public** can read venues and submit enquiries (anonymous)
* **Service role** has full access (used by Edge Functions and workers)
