> ## 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.

# Database Schema

> Full PostgreSQL schema for Grouple — all tables, relationships, and enums

## Entity Relationship Overview

```
countries → cities → neighbourhoods
                 ↓
merchants (subscription_plans) → venues → venue_amenities (amenities)
                                       → venue_cuisines (cuisines)
                                       → venue_knowledge
                                       → venue_leads ← enquiries ← customers
                                                    ↓
                                                proposals → beos
                                                         → commission_settlements
```

## Core Tables

### `customers`

Registered end-customers (event planners).

| Column                  | Type      | Notes                  |
| ----------------------- | --------- | ---------------------- |
| id                      | uuid      | Primary key            |
| supabase\_user\_id      | uuid      | Links to Supabase Auth |
| first\_name, last\_name | text      |                        |
| email                   | text      | NOT NULL               |
| phone                   | text      |                        |
| company\_name           | text      |                        |
| created\_at             | timestamp |                        |

### `merchants`

Venue owners / managers.

| Column                  | Type    | Notes                    |
| ----------------------- | ------- | ------------------------ |
| id                      | uuid    | Primary key              |
| supabase\_user\_id      | uuid    | Links to Supabase Auth   |
| first\_name, last\_name | text    |                          |
| email                   | text    | NOT NULL                 |
| role                    | text    |                          |
| company\_name           | text    |                          |
| logo\_url               | text    |                          |
| onboarding\_completed   | boolean |                          |
| plan\_id                | text    | FK → subscription\_plans |
| currency\_code          | text    |                          |

### `venues`

Individual venues listed by merchants.

| Column                               | Type    | Notes                   |
| ------------------------------------ | ------- | ----------------------- |
| id                                   | uuid    | Primary key             |
| merchant\_id                         | uuid    | FK → merchants          |
| venue\_name                          | text    | NOT NULL                |
| address, city\_id, neighbourhood\_id |         | Location                |
| seated\_capacity, standing\_capacity | integer |                         |
| price\_min, price\_max               | numeric |                         |
| operating\_hours                     | jsonb   |                         |
| venue\_type\_id                      | uuid    | FK → venue\_types       |
| currency\_code                       | text    |                         |
| is\_active                           | boolean |                         |
| public\_token                        | text    | For public-facing links |
| is\_featured                         | boolean |                         |

### `enquiries`

Customer group booking requests (RFQs).

| Column                      | Type    | Notes                                 |
| --------------------------- | ------- | ------------------------------------- |
| id                          | uuid    | Primary key                           |
| rfq\_number                 | integer | Auto-incremented sequence             |
| event\_date                 | date    | NOT NULL                              |
| time\_slot                  | time    | NOT NULL                              |
| group\_size                 | integer | NOT NULL                              |
| budget\_tier                | enum    | Economy / Standard / Premium / Luxury |
| city\_id, neighbourhood\_id | uuid    |                                       |
| event\_category\_id         | uuid    | FK → event\_categories                |
| cuisine\_preference\_id     | uuid    | FK → cuisines                         |
| venue\_type\_id             | uuid    | FK → venue\_types                     |
| customer\_id                | uuid    | FK → customers                        |
| currency\_code              | text    | Auto-synced from city                 |
| status                      | text    | open / confirmed                      |
| confirmed\_proposal\_id     | uuid    | Set on confirmation                   |
| confirmed\_venue\_id        | uuid    | Set on confirmation                   |

### `venue_leads`

Junction between an enquiry and a specific venue — one lead per venue per enquiry.

| Column                                                        | Type      | Notes                                                                  |
| ------------------------------------------------------------- | --------- | ---------------------------------------------------------------------- |
| id                                                            | uuid      | Primary key                                                            |
| enquiry\_id                                                   | uuid      | FK → enquiries                                                         |
| venue\_id                                                     | uuid      | FK → venues                                                            |
| merchant\_id                                                  | uuid      | FK → merchants                                                         |
| status                                                        | enum      | pending / accepted / declined / connected / closed\_won / closed\_lost |
| merchant\_rfq\_number                                         | integer   | Auto-set by trigger                                                    |
| proposed\_event\_date                                         | date      | Merchant can counter-propose                                           |
| proposed\_group\_size                                         | integer   |                                                                        |
| is\_counter\_offer                                            | boolean   |                                                                        |
| accepted\_at, declined\_at, closed\_won\_at, closed\_lost\_at | timestamp |                                                                        |
| is\_read                                                      | boolean   |                                                                        |

### `proposals`

Proposals sent by merchants in response to leads.

| Column                                          | Type    | Notes                                                  |
| ----------------------------------------------- | ------- | ------------------------------------------------------ |
| id                                              | uuid    | Primary key                                            |
| venue\_lead\_id                                 | uuid    | FK → venue\_leads                                      |
| venue\_id                                       | uuid    | FK → venues                                            |
| title                                           | text    |                                                        |
| status                                          | enum    | draft / sent / viewed / confirmed / declined / expired |
| offer\_valid\_until                             | date    |                                                        |
| details                                         | text    | AI-generated or manual                                 |
| package\_inclusions                             | text\[] |                                                        |
| amount, service\_fee, discount, total           | numeric |                                                        |
| price\_type                                     | enum    | Per Person / Per Bottle / Per Item / Per Event         |
| payment\_terms, venue\_policies                 | text    |                                                        |
| ai\_generated                                   | boolean |                                                        |
| public\_token                                   | text    | For public-facing proposal links                       |
| signed\_by\_name, signed\_at, signature\_base64 |         | Digital signature                                      |
| selected\_packages                              | jsonb   |                                                        |
| currency\_code                                  | text    |                                                        |

### `commission_settlements`

Auto-created when a proposal is confirmed.

| Column                     | Type    | Notes                                             |
| -------------------------- | ------- | ------------------------------------------------- |
| proposal\_id               | uuid    | FK → proposals                                    |
| merchant\_id               | uuid    | FK → merchants                                    |
| applied\_commission\_rate  | numeric | From subscription plan                            |
| status                     | enum    | unpaid / pending\_verification / paid / cancelled |
| is\_paid                   | boolean |                                                   |
| receipt\_url, invoice\_url | text    |                                                   |

### `beos`

Banquet Event Orders linked to confirmed proposals.

| Column                        | Type | Notes          |
| ----------------------------- | ---- | -------------- |
| proposal\_id                  | uuid | FK → proposals |
| setup\_time                   | text |                |
| table\_setup                  | text |                |
| staffing\_requirements        | text |                |
| av\_requirements              | text |                |
| sales\_contact, venue\_mobile | text |                |
| miscellaneous\_notes          | text |                |

### `venue_knowledge`

PDF menus and brochures uploaded by merchants for AI extraction.

| Column          | Type  | Notes                               |
| --------------- | ----- | ----------------------------------- |
| venue\_id       | uuid  | FK → venues                         |
| merchant\_id    | uuid  | FK → merchants                      |
| file\_path      | text  | NOT NULL — path in Supabase Storage |
| extracted\_data | jsonb | AI-extracted content                |
| status          | text  |                                     |

### Support Tables

| Table                        | Purpose                                             |
| ---------------------------- | --------------------------------------------------- |
| `cities`                     | City list with default currency                     |
| `countries`                  | Country reference data                              |
| `neighbourhoods`             | Neighbourhood lookup (FK → cities)                  |
| `amenities`                  | Amenity types (e.g. "Private Room", "AV Equipment") |
| `cuisines`                   | Cuisine types                                       |
| `event_categories`           | Event types                                         |
| `venue_types`                | Venue type categories                               |
| `subscription_plans`         | Merchant plan definitions                           |
| `exchange_rates`             | Currency exchange rates (updated by Edge Function)  |
| `lead_response_times`        | Tracks how quickly merchants respond to leads       |
| `lead_values`                | Estimated booking value per lead                    |
| `merchant_lead_counter`      | Tracks last RFQ number per merchant                 |
| `merchant_analytics_v3`      | Materialised view for analytics dashboard           |
| `merchant_commission_ledger` | View for commission tracking                        |

## Enums

| Enum                 | Values                                                                     |
| -------------------- | -------------------------------------------------------------------------- |
| `budget_tier`        | Economy, Standard, Premium, Luxury                                         |
| `lead_status`        | pending, accepted, declined, connected, closed\_won, closed\_lost          |
| `proposal_status`    | draft, sent, viewed, confirmed, declined, expired                          |
| `commission_status`  | unpaid, pending\_verification, paid, cancelled                             |
| `price_type`         | Per Person, Per Bottle, Per Item, Per Event                                |
| `currency_code_type` | USD, AED, GBP, INR, EUR                                                    |
| `occasion_type`      | Corporate, Birthday Party, Conferences/Seminars, Gala Dinners, and 13 more |
