docs: add /docs living documentation per AGENT.MD
- docs/README.md: navigation hub - docs/architecture.md: system overview, tech stack, data flows, ports - docs/backend/: supabase-core, schema, rpcs, rls, seed, docker - docs/frontend/: app-structure, screens, api-client - docs/next-steps.md: Phase 2/3/4 plan + open decisions - Fix README demo-account emails to match the actual seed
This commit is contained in:
1 parent
37684ba116
commit
4abdc7691b
16 files changed
+1494
-7
No files matched your search
@@ -0,0 +1,38 @@
|
||||
# Backend — Supabase Core
|
||||
|
||||
Convivo has **no custom backend**. The entire server side is a **local Supabase
|
||||
stack** (run with the Supabase CLI) plus the schema, RPCs, and RLS that live in
|
||||
Postgres. This folder documents that core.
|
||||
|
||||
| File | What it covers |
|
||||
|---|---|
|
||||
| [supabase-core.md](./supabase-core.md) | The local stack: containers, ports, how to start/reset, config |
|
||||
| [schema.md](./schema.md) | All 9 tables, columns, constraints, indexes |
|
||||
| [rpcs.md](./rpcs.md) | The transactional points RPCs (the business logic) |
|
||||
| [rls.md](./rls.md) | Row Level Security policies + which key the app uses |
|
||||
| [seed.md](./seed.md) | Seed data + the 13 demo accounts |
|
||||
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
|
||||
|
||||
## The big picture
|
||||
|
||||
```
|
||||
Postgres 17 ── schema (9 tables)
|
||||
── RLS (who can read/write what)
|
||||
── RPCs (security definer, transactional points logic)
|
||||
── seed (demo data)
|
||||
```
|
||||
|
||||
- **Data + logic live in the database.** The app never computes points or writes
|
||||
to `profiles.points` directly — it calls RPCs, and Postgres enforces the rules.
|
||||
- **RLS is the security boundary.** The app uses the **anon key + the user's
|
||||
session JWT**; RLS decides what that user may see and do. The service-role key
|
||||
is never shipped to the app. See [rls.md](./rls.md).
|
||||
- **Points are transactional.** Each RPC updates points, inserts the related row,
|
||||
and re-syncs the `leaderboard` mirror in **one transaction**, so the leaderboard
|
||||
is always consistent and duplicate actions never double-award. See [rpcs.md](./rpcs.md).
|
||||
|
||||
## Source of truth
|
||||
|
||||
- Schema + RPCs + RLS: [`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
|
||||
- Seed: [`supabase/seed.sql`](../../supabase/seed.sql)
|
||||
- Stack config: [`supabase/config.toml`](../../supabase/config.toml)
|
||||
@@ -0,0 +1,109 @@
|
||||
# Docker
|
||||
|
||||
Docker is the backbone. Two pieces:
|
||||
|
||||
1. **The Supabase core** — a set of containers managed by the **Supabase CLI**
|
||||
(not by a compose file in this repo). See [supabase-core.md](./supabase-core.md).
|
||||
2. **The app sidecar** — a single container built from
|
||||
[`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile) and orchestrated by
|
||||
the root [`docker-compose.yml`](../../docker-compose.yml).
|
||||
|
||||
The app container **joins the network the CLI created** for the core and proxies
|
||||
the Supabase same-origin paths to the Kong container.
|
||||
|
||||
## How the pieces fit
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph Host
|
||||
CLI["supabase start<br/>(Supabase CLI)"]
|
||||
end
|
||||
subgraph Net["supabase_network_Convivo (external)"]
|
||||
K["supabase_kong_Convivo<br/>:8000 (internal)"]
|
||||
APP["convivo-app<br/>nginx :3000"]
|
||||
end
|
||||
CLI -.creates.-> Net
|
||||
APP -->|"proxy /auth /rest /realtime /storage"| K
|
||||
APP -->|"host port 3000"| U["Browser"]
|
||||
```
|
||||
|
||||
## The app image (`apps/convivo/Dockerfile`)
|
||||
|
||||
Multi-stage build:
|
||||
|
||||
- **Stage 1 — `build`** (`node:20-alpine`): `npm ci` (reproducible via
|
||||
`package-lock.json`), then `npm run build` (tsc + vite). The anon key is baked
|
||||
in at build time via `ARG VITE_SUPABASE_ANON_KEY` (it's not a secret — it's the
|
||||
standard local anon key).
|
||||
- **Stage 2 — `serve`** (`nginx:1.27-alpine`): copies the built `dist/` and an
|
||||
nginx config **template**. The entrypoint
|
||||
([`docker-entrypoint.sh`](../../apps/convivo/docker-entrypoint.sh)) injects the
|
||||
proxy target at container start, then runs nginx.
|
||||
|
||||
### nginx config
|
||||
|
||||
[`nginx.conf.template`](../../apps/convivo/nginx.conf.template) serves the SPA
|
||||
(`try_files ... /index.html` for client-side routing) and proxies the Supabase
|
||||
same-origin paths to the core:
|
||||
|
||||
| Location | Proxied to | Notes |
|
||||
|---|---|---|
|
||||
| `/auth/` | `__SUPABASE_PROXY_TARGET__` | GoTrue |
|
||||
| `/rest/` | `__SUPABASE_PROXY_TARGET__` | PostgREST (tables + RPCs) |
|
||||
| `/realtime/` | `__SUPABASE_PROXY_TARGET__` | WebSocket — `Upgrade`/`Connection` headers + long timeouts |
|
||||
| `/storage/` | `__SUPABASE_PROXY_TARGET__` | Storage (unused in v1) |
|
||||
|
||||
`__SUPABASE_PROXY_TARGET__` is replaced at start with the value of the
|
||||
`SUPABASE_PROXY_TARGET` env var (default `supabase_kong_Convivo:8000`).
|
||||
|
||||
> **Why `:8000` and not `:54321`?** Kong listens on **8000 inside** the container;
|
||||
> the `54321→8000` mapping is host-only. From inside the shared network you must
|
||||
> target the internal port. See [supabase-core.md#ports](./supabase-core.md#ports).
|
||||
|
||||
## Root `docker-compose.yml`
|
||||
|
||||
Runs **only the app** (the core is CLI-managed). Key settings:
|
||||
|
||||
| Setting | Value | Why |
|
||||
|---|---|---|
|
||||
| `build.context` | `./apps/convivo` | Builds the app image |
|
||||
| `ports` | `3000:3000` | The app on the host |
|
||||
| `environment.SUPABASE_PROXY_TARGET` | `supabase_kong_Convivo:8000` (default) | Where nginx proxies |
|
||||
| `networks.supabase` | **external**, name `supabase_network_Convivo` | Joins the CLI-created network |
|
||||
| `healthcheck` | `wget http://127.0.0.1:3000/` | Container reports healthy |
|
||||
|
||||
> If you change `project_id` in `supabase/config.toml`, update the external
|
||||
> network name (`supabase_network_<project_id>`) and the default proxy target
|
||||
> (`supabase_kong_<project_id>:8000`) to match.
|
||||
|
||||
## Running
|
||||
|
||||
```bash
|
||||
# 1. Start the Supabase core (creates containers + supabase_network_Convivo)
|
||||
npm run db:start
|
||||
|
||||
# 2. (Optional) reset to clean seed data
|
||||
npm run db:reset
|
||||
|
||||
# 3. Build + run the app sidecar on :3000
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
Open **http://localhost:3000**.
|
||||
|
||||
### Alternative: dev server (no app container)
|
||||
|
||||
For faster iteration you can skip the app container and use the Vite dev server,
|
||||
which proxies the same paths to `127.0.0.1:54321` (host port):
|
||||
|
||||
```bash
|
||||
npm run db:start
|
||||
npm run app:dev # Vite on :3000
|
||||
```
|
||||
|
||||
## Verified behavior
|
||||
|
||||
- `docker compose build` → `npm ci` + `tsc` + `vite build` all pass in-container.
|
||||
- `GET /` → HTTP 200 (SPA served by nginx).
|
||||
- `GET /auth/v1/health` through the proxy → GoTrue health JSON (proxy works).
|
||||
- Full login (QR + email) works through the Docker-served app.
|
||||
@@ -0,0 +1,126 @@
|
||||
# Row Level Security (RLS)
|
||||
|
||||
RLS is the security boundary. It is **enabled on all 9 tables**, and every policy
|
||||
is scoped to the `authenticated` role. The `anon` role has `GRANT select` at the
|
||||
Postgres level, but RLS blocks it from reading anything — so an unauthenticated
|
||||
request sees no rows.
|
||||
|
||||
Source of truth:
|
||||
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql)
|
||||
(RLS section).
|
||||
|
||||
## Which key does the app use?
|
||||
|
||||
**The anon key — never the service-role (admin) key.**
|
||||
|
||||
- The app ships only `VITE_SUPABASE_ANON_KEY` (baked in at build time). It's the
|
||||
standard local anon JWT, **public by design** — safe to be in the bundle.
|
||||
- Every request carries the **anon key + the user's session JWT** (from the
|
||||
QR+email login). PostgREST then runs as the `authenticated` role, and **RLS
|
||||
decides what that user can see/do**.
|
||||
- The **service-role key is never in the app**. It bypasses RLS entirely, so it
|
||||
must stay server-side (used only for admin ops / verification).
|
||||
|
||||
> Model: *the anon key gets you to the door, the session JWT says who you are,
|
||||
> RLS says what you may touch.*
|
||||
|
||||
## Role helpers
|
||||
|
||||
Two `security definer` functions drive role checks (see [rpcs.md](./rpcs.md#role-helper-functions)):
|
||||
- `is_admin()` — current user's profile has `role = 'admin'`
|
||||
- `is_staff_or_admin()` — current user's profile has `role in ('staff','admin')`
|
||||
|
||||
## Policies by table
|
||||
|
||||
| Table | SELECT | INSERT | UPDATE | DELETE |
|
||||
|---|---|---|---|---|
|
||||
| `profiles` | own **or** admin | — | admin only | admin only |
|
||||
| `slots` | all authenticated | admin only | admin only | admin only |
|
||||
| `sessions` | all authenticated | admin only | admin only | admin only |
|
||||
| `preferences` | own (`profile_id = auth.uid()`) | — | — | — |
|
||||
| `connections` | rows you're in (`from_id` or `to_id` = you) | — | — | — |
|
||||
| `checkins` | own **or** staff/admin | — | — | — |
|
||||
| `feedback` | own | — | — | — |
|
||||
| `leaderboard` | all authenticated | — | — | — |
|
||||
| `points_log` | own **or** admin | — | — | — |
|
||||
|
||||
**"—" (no policy)** means normal users have **no direct write access** — those
|
||||
tables are written only by the `security definer` RPCs, which bypass RLS. This is
|
||||
deliberate: a client cannot `UPDATE profiles SET points = 9999` or insert its own
|
||||
check-in. See [rpcs.md](./rpcs.md).
|
||||
|
||||
### The exact policies
|
||||
|
||||
```sql
|
||||
-- profiles: read own or admin; write admin only
|
||||
create policy "profiles_select_own_or_admin" on public.profiles for select to authenticated
|
||||
using (id = auth.uid() or public.is_admin());
|
||||
create policy "profiles_update_admin" on public.profiles for update to authenticated
|
||||
using (public.is_admin()) with check (public.is_admin());
|
||||
create policy "profiles_delete_admin" on public.profiles for delete to authenticated
|
||||
using (public.is_admin());
|
||||
|
||||
-- slots / sessions: readable by any authenticated user (public agenda); admin writes
|
||||
create policy "slots_select_all" on public.slots for select to authenticated using (true);
|
||||
create policy "slots_admin_insert" on public.slots for insert to authenticated with check (public.is_admin());
|
||||
create policy "slots_admin_update" on public.slots for update to authenticated using (public.is_admin()) with check (public.is_admin());
|
||||
create policy "slots_admin_delete" on public.slots for delete to authenticated using (public.is_admin());
|
||||
-- (sessions: identical four policies)
|
||||
|
||||
-- preferences: read own
|
||||
create policy "prefs_select_own" on public.preferences for select to authenticated
|
||||
using (profile_id = auth.uid());
|
||||
|
||||
-- connections: read rows you're involved in
|
||||
create policy "conn_select_involved" on public.connections for select to authenticated
|
||||
using (from_id = auth.uid() or to_id = auth.uid());
|
||||
|
||||
-- checkins: read own or staff/admin
|
||||
create policy "checkins_select_own_or_staff" on public.checkins for select to authenticated
|
||||
using (profile_id = auth.uid() or public.is_staff_or_admin());
|
||||
|
||||
-- feedback: read own
|
||||
create policy "feedback_select_own" on public.feedback for select to authenticated
|
||||
using (profile_id = auth.uid());
|
||||
|
||||
-- leaderboard: readable by any authenticated user
|
||||
create policy "leaderboard_select_all" on public.leaderboard for select to authenticated using (true);
|
||||
|
||||
-- points_log: read own or admin
|
||||
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
|
||||
using (profile_id = auth.uid() or public.is_admin());
|
||||
```
|
||||
|
||||
## GRANTs
|
||||
|
||||
The new Supabase CLI does **not** auto-expose new tables to the Data API roles, so
|
||||
the migration grants explicitly (RLS still governs what each role can actually see):
|
||||
|
||||
```sql
|
||||
grant usage on schema public to anon, authenticated, service_role;
|
||||
grant select on <all 9 tables> to anon, authenticated, service_role;
|
||||
grant insert, update, delete on <all 9 tables> to authenticated, service_role;
|
||||
grant execute on function <all public RPCs + helpers> to authenticated;
|
||||
```
|
||||
|
||||
Note `anon` gets `select` but **no** `insert/update/delete`; `authenticated` gets
|
||||
full DML at the Postgres level, but **RLS narrows it** to the policies above.
|
||||
|
||||
## Net effect by role
|
||||
|
||||
- **Attendee** — sees their own profile/prefs/connections/feedback, the full
|
||||
agenda, and the leaderboard; can only act through the RPCs (which re-check role
|
||||
internally, e.g. only staff can call `checkin_attendee`).
|
||||
- **Staff** — everything an attendee can do, plus can read all `checkins` and call
|
||||
the check-in RPC.
|
||||
- **Admin** — full read on everything, and the only role with **direct** write
|
||||
access to `profiles` / `slots` / `sessions` (this is what the future Admin app
|
||||
in Phase 3 will use).
|
||||
|
||||
## Things to revisit later
|
||||
|
||||
- `slots` / `sessions` are readable by *any* authenticated user (fine — it's a
|
||||
public agenda). If you ever want the agenda hidden until the event, that's a
|
||||
one-line policy change.
|
||||
- `leaderboard` exposes every attendee's name + points to any authenticated user.
|
||||
That's the intended product behavior (a public leaderboard).
|
||||
@@ -0,0 +1,125 @@
|
||||
# Points RPCs (Business Logic)
|
||||
|
||||
All mutations go through **Postgres RPCs** (`security definer`, transactional).
|
||||
The app never writes to `profiles.points`, `connections`, `checkins`, `feedback`,
|
||||
or `leaderboard` directly — it calls these functions. This is what makes the
|
||||
points system race-free and prevents a client from, e.g., setting its own points.
|
||||
|
||||
Source of truth:
|
||||
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql).
|
||||
|
||||
## Why RPCs?
|
||||
|
||||
- **`security definer`** → the function runs as the table owner and **bypasses
|
||||
RLS**, so it can update points and sync the leaderboard even though the calling
|
||||
user can't write those tables directly.
|
||||
- **Transactional** → each RPC does *update points + insert the related row +
|
||||
re-sync the leaderboard* in **one transaction**. Either all happen or none do.
|
||||
- **Idempotent where it matters** → re-check-in and re-feedback are detected and
|
||||
never double-award.
|
||||
|
||||
## Points rules
|
||||
|
||||
| Action | Points | Awarded to |
|
||||
|---|---|---|
|
||||
| Checked into a session (by staff) | **+10** | the attendee |
|
||||
| Connection accepted | **+5 each** | both people |
|
||||
| Feedback — rating only | **+5** | the attendee |
|
||||
| Feedback — rating + comment | **+10** | the attendee |
|
||||
| Admin adjustment | any | the target (audited as `admin`) |
|
||||
|
||||
## Internal helpers
|
||||
|
||||
### `_award_points(p_profile_id, p_delta, p_category)`
|
||||
The single place points change. In one transaction it:
|
||||
1. `update profiles set points = greatest(0, points + p_delta)` (floored at 0),
|
||||
2. `insert into points_log (profile_id, delta, category)`,
|
||||
3. calls `_sync_leaderboard(p_profile_id)`.
|
||||
|
||||
### `_sync_leaderboard(p_profile_id)`
|
||||
Upserts the `leaderboard` row for that profile from `profiles`
|
||||
(`on conflict (profile_id) do update ...`). This is what makes the leaderboard a
|
||||
consistent, Realtime-friendly mirror.
|
||||
|
||||
## Public read functions
|
||||
|
||||
| Function | Returns | Used for |
|
||||
|---|---|---|
|
||||
| `get_public_profiles()` | `id, full_name, company, role, points` (ordered by points) | Leaderboard initial load, id→name lookups |
|
||||
| `lanyard_lookup(p_qr_token)` | `id, full_name, company, role` | Resolve a scanned QR (pre-login + connect) |
|
||||
| `get_agenda()` | slots with their sessions (flat rows) | Agenda + Home |
|
||||
|
||||
All three are `security definer` and expose **only public columns** (no email, no
|
||||
`qr_token`).
|
||||
|
||||
## Mutation RPCs
|
||||
|
||||
### `set_preference(p_session_id)` → `preferences`
|
||||
Sets (or changes) the preferred session for the slot that `p_session_id` belongs
|
||||
to. Deletes the caller's existing pick for that slot, then inserts the new one.
|
||||
Enforces "one pick per slot".
|
||||
|
||||
### `clear_preference(p_slot_id)` → `void`
|
||||
Removes the caller's pick for a slot.
|
||||
|
||||
### `create_connection_request(p_target_qr)` → `connections`
|
||||
Creates a **pending** connection to the attendee whose QR was scanned.
|
||||
- Resolves the target by `qr_token`; errors if not found or if it's yourself.
|
||||
- **Idempotent:** if the pair already has a connection (either direction), returns
|
||||
the existing one instead of creating a duplicate.
|
||||
|
||||
### `accept_connection(p_connection_id)` → `connections`
|
||||
Accepts an **incoming** request.
|
||||
- Locks the row (`for update`), verifies the caller is the recipient
|
||||
(`to_id = auth.uid()`) and the status is still `pending`.
|
||||
- Sets `status = 'accepted'`, `resolved_at = now()`.
|
||||
- **Awards +5 to both** `from_id` and `to_id` (category `connection`).
|
||||
|
||||
### `reject_connection(p_connection_id)` → `connections`
|
||||
Same guards as accept, but sets `status = 'rejected'`. No points.
|
||||
|
||||
### `checkin_attendee(p_session_id, p_attendee_qr)` → `(checkin_id, attendee_id, attendee_name, points, already)`
|
||||
Staff checks an attendee into a session.
|
||||
- **Role check:** `is_staff_or_admin()` or it raises `staff or admin only`.
|
||||
- Resolves the attendee by `qr_token`.
|
||||
- `insert into checkins ... on conflict (profile_id, session_id) do nothing
|
||||
returning id` — if no row was inserted, the attendee was **already checked in**:
|
||||
sets `already = true` and awards **no points**.
|
||||
- Otherwise awards **+10** to the attendee (category `checkin`).
|
||||
- Returns the attendee's current total points.
|
||||
|
||||
> **Implementation note:** the "already checked in" case is detected via the
|
||||
> `ON CONFLICT ... DO NOTHING returning id` (a `NULL` id means no-op), and the
|
||||
> function uses a **single final `return query`** with flag variables — a
|
||||
> `return query` inside an `if` block would *not* terminate the function and would
|
||||
> double-award.
|
||||
|
||||
### `submit_feedback(p_session_id, p_rating, p_comment)` → `(feedback_id, points, earned)`
|
||||
Post-session feedback.
|
||||
- **Requires the caller to be checked in** to that session (else raises).
|
||||
- Validates `rating` is 1–5.
|
||||
- `earned` = 10 if a non-empty comment, else 5.
|
||||
- **Idempotent:** if feedback already exists for (caller, session), it **updates**
|
||||
the rating/comment and awards **0** (already rewarded on first submission).
|
||||
- Otherwise inserts and awards `earned` (category `feedback`).
|
||||
|
||||
### `adjust_points(p_profile_id, p_delta, p_reason)` → `void`
|
||||
**Admin-only** manual points adjustment (category `admin`). Used by the future
|
||||
Admin app (Phase 3).
|
||||
|
||||
## Role helper functions
|
||||
|
||||
| Function | Returns | Meaning |
|
||||
|---|---|---|
|
||||
| `is_admin()` | `boolean` | current user's profile has `role = 'admin'` |
|
||||
| `is_staff_or_admin()` | `boolean` | current user's profile has `role in ('staff','admin')` |
|
||||
|
||||
Both are `security definer` so they can read `profiles` inside RLS checks and RPC
|
||||
guards.
|
||||
|
||||
## Error handling
|
||||
|
||||
RPCs raise Postgres exceptions with human-readable messages (e.g. `you cannot
|
||||
connect with yourself`, `staff or admin only`, `you must be checked in to this
|
||||
session to give feedback`). The frontend surfaces these via toasts — see
|
||||
[../frontend/api-client.md](../frontend/api-client.md).
|
||||
@@ -0,0 +1,152 @@
|
||||
# Database Schema
|
||||
|
||||
All tables live in the `public` schema. Source of truth:
|
||||
[`supabase/migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql).
|
||||
|
||||
There are **9 tables**: people, schedule, and the event's activity.
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
profiles ||--o{ preferences : "picks"
|
||||
profiles ||--o{ connections : "from/to"
|
||||
profiles ||--o{ checkins : "checked in"
|
||||
profiles ||--o{ feedback : "rates"
|
||||
profiles ||--o{ leaderboard : "mirrored"
|
||||
profiles ||--o{ points_log : "audited"
|
||||
slots ||--o{ sessions : "contains"
|
||||
sessions ||--o{ preferences : "picked"
|
||||
sessions ||--o{ checkins : "checked into"
|
||||
sessions ||--o{ feedback : "rated"
|
||||
```
|
||||
|
||||
## `profiles` — people (source of truth)
|
||||
|
||||
One row per attendee. `id` **is** the Supabase Auth user id.
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | = `auth.users(id)`; `on delete cascade` |
|
||||
| `email` | `text` **unique** | The ticket-purchase email (login identifier) |
|
||||
| `full_name` | `text` | |
|
||||
| `company` | `text` | nullable |
|
||||
| `role` | `text` | `attendee` \| `staff` \| `admin` (default `attendee`) |
|
||||
| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
|
||||
| `points` | `integer` | `>= 0`, default 0 |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
## `slots` — schedule blocks
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `integer` PK | 1–6 |
|
||||
| `name` | `text` | e.g. "Slot 1" |
|
||||
| `slot_date` | `date` | `2026-10-23` |
|
||||
| `start_time` | `time` | |
|
||||
| `end_time` | `time` | |
|
||||
|
||||
## `sessions` — one per (slot, room)
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | `gen_random_uuid()` |
|
||||
| `title` | `text` | |
|
||||
| `description` | `text` | nullable |
|
||||
| `slot_id` | `integer` FK → `slots` | `on delete cascade` |
|
||||
| `room` | `text` | "Main Stage" / "Room A" / "Room B" |
|
||||
| `capacity` | `integer` | nullable (not enforced in v1) |
|
||||
| `speakers` | `text` | |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
Index: `sessions_slot_id_idx (slot_id)`.
|
||||
|
||||
## `preferences` — one pick per slot
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | |
|
||||
| `profile_id` | `uuid` FK → `profiles` | |
|
||||
| `session_id` | `uuid` FK → `sessions` | |
|
||||
| `slot_id` | `integer` | denormalized for easy "one per slot" |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
**Constraint:** `unique (profile_id, slot_id)` — an attendee can pick at most one
|
||||
session per slot. Enforced in the DB *and* by the `set_preference` RPC (which
|
||||
deletes the old pick for the slot before inserting).
|
||||
|
||||
## `connections` — the networking relationship
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | |
|
||||
| `from_id` | `uuid` FK → `profiles` | the requester |
|
||||
| `to_id` | `uuid` FK → `profiles` | the recipient |
|
||||
| `status` | `text` | `pending` \| `accepted` \| `rejected` (default `pending`) |
|
||||
| `created_at` | `timestamptz` | |
|
||||
| `resolved_at` | `timestamptz` | set when accepted/rejected |
|
||||
|
||||
**Constraint:** unique per **unordered pair** via
|
||||
`unique index connections_pair_uniq on (least(from_id, to_id), greatest(from_id, to_id))`.
|
||||
So Ana→Bruno and Bruno→Ana are the *same* connection — a pair can only ever have
|
||||
one.
|
||||
|
||||
## `checkins` — staff check-in of an attendee
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | |
|
||||
| `profile_id` | `uuid` FK → `profiles` | the attendee being checked in |
|
||||
| `session_id` | `uuid` FK → `sessions` | |
|
||||
| `staff_id` | `uuid` FK → `profiles` | the staff member who scanned |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
**Constraint:** `unique (profile_id, session_id)` — one check-in per attendee per
|
||||
session (prevents double points).
|
||||
|
||||
## `feedback` — post-session rating
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | |
|
||||
| `profile_id` | `uuid` FK → `profiles` | |
|
||||
| `session_id` | `uuid` FK → `sessions` | |
|
||||
| `rating` | `integer` | `1–5` |
|
||||
| `comment` | `text` | nullable (bonus points if present) |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
**Constraint:** `unique (profile_id, session_id)` — one feedback per attendee per
|
||||
session.
|
||||
|
||||
## `leaderboard` — Realtime mirror
|
||||
|
||||
A public, Realtime-friendly mirror of points. **Not** the source of truth — it is
|
||||
kept in sync transactionally by the RPCs (see [rpcs.md](./rpcs.md#_sync_leaderboard)).
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `profile_id` | `uuid` PK FK → `profiles` | |
|
||||
| `full_name` | `text` | denormalized for display |
|
||||
| `company` | `text` | denormalized |
|
||||
| `points` | `integer` | |
|
||||
| `updated_at` | `timestamptz` | |
|
||||
|
||||
The app subscribes to `postgres_changes` on this table to update the leaderboard
|
||||
live. See [../frontend/screens.md#leaderboard](../frontend/screens.md#leaderboard).
|
||||
|
||||
## `points_log` — audit trail
|
||||
|
||||
Powers the per-category points breakdown on the Profile screen.
|
||||
|
||||
| Column | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | `uuid` PK | |
|
||||
| `profile_id` | `uuid` FK → `profiles` | |
|
||||
| `delta` | `integer` | points added (can be negative for admin adjustments) |
|
||||
| `category` | `text` | `checkin` \| `connection` \| `feedback` \| `admin` |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
Index: `points_log_profile_id_idx (profile_id)`.
|
||||
|
||||
## Other indexes
|
||||
|
||||
- `profiles_qr_token_idx (qr_token)` — fast lanyard lookups.
|
||||
- `checkins_session_id_idx (session_id)`.
|
||||
@@ -0,0 +1,84 @@
|
||||
# Seed Data & Demo Accounts
|
||||
|
||||
Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs on
|
||||
`npm run db:reset` and is **idempotent** (`on conflict ... do nothing`).
|
||||
|
||||
## What it creates
|
||||
|
||||
| Data | Count | Notes |
|
||||
|---|---|---|
|
||||
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
|
||||
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
|
||||
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** |
|
||||
| `profiles` | 13 | one per user, with role + starting points |
|
||||
| `leaderboard` | 13 | mirrored from `profiles` |
|
||||
| `points_log` | 21 | Ana's coherent breakdown + one `admin` entry per other user |
|
||||
| Ana's demo state | — | 6 preferences, 2 check-ins, 4 connections, 1 feedback |
|
||||
|
||||
> **GoTrue gotcha:** manually-inserted `auth.users` must have
|
||||
> `confirmation_token`, `recovery_token`, `email_change_token_new`, and
|
||||
> `email_change` set to `''` (empty string), **not NULL** — GoTrue's password
|
||||
> grant can't scan a NULL `confirmation_token`. `phone` is left NULL (unique
|
||||
> constraint).
|
||||
|
||||
## Slots
|
||||
|
||||
| id | Time |
|
||||
|---|---|
|
||||
| 1 | 09:00–09:45 |
|
||||
| 2 | 10:00–10:45 |
|
||||
| 3 | 11:30–12:15 |
|
||||
| 4 | 13:15–14:00 |
|
||||
| 5 | 14:00–14:45 |
|
||||
| 6 | 15:00–15:45 |
|
||||
|
||||
## Demo accounts
|
||||
|
||||
Login = **QR code** (typed or scanned) + **email**. The QR token is the password.
|
||||
|
||||
| Person | Role | QR code | Email | Company | Start pts |
|
||||
|---|---|---|---|---|---|
|
||||
| **Ana Silva** | attendee | `CVV-ANA-4821` | ana.silva@nubank.com | Nubank | 40 |
|
||||
| **Bruno Costa** | staff | `CVV-BRU-1177` | bruno.costa@acme.com | Acme Corp | 140 |
|
||||
| **Rita Lopes** | staff | `CVV-RIT-9034` | rita.lopes@globant.com | Globant | 95 |
|
||||
| **Convivo Admin** | admin | `CVV-ADM-0001` | admin@appe.at | Convivo | 0 |
|
||||
| Tomás Ribeiro | attendee | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | Dataprev | 88 |
|
||||
| Sofia Almeida | attendee | `CVV-SOF-2299` | sofia.almeida@loop.com | Loop | 76 |
|
||||
| Marco Chen | attendee | `CVV-MRC-7712` | marco.chen@deepmind.com | DeepMind | 70 |
|
||||
| Julia Santos | attendee | `CVV-JUL-3345` | julia.santos@ifood.com | iFood | 64 |
|
||||
| Pedro Nunes | attendee | `CVV-PED-8801` | pedro.nunes@microsoft.com | Microsoft | 58 |
|
||||
| Carla Mendes | attendee | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | QuintoEssencial | 52 |
|
||||
| Diego Ferreira | attendee | `CVV-DIE-4458` | diego.ferreira@stone.com | Stone | 35 |
|
||||
| Marina Costa | attendee | `CVV-MNA-2210` | marina.costa@olx.com | OLX | 28 |
|
||||
| Lucas Oliveira | attendee | `CVV-LUC-9987` | lucas.oliveira@usp.br | USP | 15 |
|
||||
|
||||
## Ana's demo state (so the app looks alive on first login)
|
||||
|
||||
Ana (id `11111111-…`) is seeded with a coherent 40-point history:
|
||||
|
||||
- **Points breakdown** (`points_log`): 2× check-in (+10 each), 2× connection
|
||||
(+5 each), 1× feedback (+10) = **40**.
|
||||
- **Preferences** — one pick per slot (matches the mockup):
|
||||
- Slot 1 → *Designing for Trust in AI Products*
|
||||
- Slot 2 → *AI in Practice: Lessons from Production*
|
||||
- Slot 3 → *Data Storytelling*
|
||||
- Slot 4 → *Prototyping with AI*
|
||||
- Slot 5 → *Community-Led Growth*
|
||||
- Slot 6 → *Closing Panel: What's Next*
|
||||
- **Check-ins** — checked into Slot 1 and Slot 2 (by staff Bruno).
|
||||
- **Connections**:
|
||||
- accepted with **Bruno** and **Rita**
|
||||
- incoming (pending) from **Sofia**
|
||||
- outgoing (pending) to **Julia**
|
||||
- **Feedback** — rated Slot 1's *Designing for Trust in AI Products* 5★ with a comment.
|
||||
|
||||
> Everyone else gets a single `admin` `points_log` entry for their starting points
|
||||
> (so the Profile breakdown shows "Other"), and no other activity.
|
||||
|
||||
## Suggested demo flow
|
||||
|
||||
1. Log in as **Ana** (attendee) → Home, Agenda, Leaderboard all populated.
|
||||
2. Scan **Marco** (`CVV-MRC-7712`) → send a connection request.
|
||||
3. Log in as **Bruno** (staff) → the Scan tab becomes **Check-in** → pick a
|
||||
session → scan **Carla** (`CVV-CAR-6623`) → she gets +10.
|
||||
4. Watch the **Leaderboard** update live (Realtime).
|
||||
@@ -0,0 +1,88 @@
|
||||
# Supabase Core — Local Stack
|
||||
|
||||
The Supabase core is a set of Docker containers managed by the **Supabase CLI**
|
||||
(installed as a root devDependency — `npx supabase` works out of the box). It is
|
||||
the "main docker" of the project.
|
||||
|
||||
## Containers
|
||||
|
||||
`supabase start` brings up the full local stack (project id `Convivo`):
|
||||
|
||||
| Container | Image | Role |
|
||||
|---|---|---|
|
||||
| `supabase_db_Convivo` | `supabase/postgres:17` | Postgres 17 — schema, RLS, RPCs, data |
|
||||
| `supabase_auth_Convivo` | `supabase/gotrue` | Auth (QR + email login) |
|
||||
| `supabase_rest_Convivo` | `supabase/postgrest` | REST API over Postgres (tables + RPCs) |
|
||||
| `supabase_realtime_Convivo` | `supabase/realtime` | WebSocket realtime (leaderboard) |
|
||||
| `supabase_storage_Convivo` | `supabase/storage-api` | Storage (unused in v1) |
|
||||
| `supabase_kong_Convivo` | `supabase/kong` | **API gateway** — fronts everything on one port |
|
||||
| `supabase_studio_Convivo` | `supabase/studio` | Web UI (Studio) |
|
||||
| `supabase_inbucket_Convivo` | `supabase/mailpit` | Captures emails (none sent in this flow) |
|
||||
| `supabase_pg_meta_Convivo` | `supabase/postgres-meta` | Metadata API (used by Studio) |
|
||||
| `supabase_edge_runtime_Convivo` | `supabase/edge-runtime` | Edge functions (unused in v1) |
|
||||
| `supabase_vector_Convivo` | `supabase/vector` | Log shipping |
|
||||
| `supabase_analytics_Convivo` | `supabase/logflare` | Analytics |
|
||||
|
||||
All containers share the external Docker network **`supabase_network_Convivo`**
|
||||
(named `supabase_network_<project_id>`). The app sidecar joins this network — see
|
||||
[docker.md](./docker.md).
|
||||
|
||||
## Ports
|
||||
|
||||
| Service | Host port | Container port | Notes |
|
||||
|---|---|---|---|
|
||||
| **API (Kong)** | **54321** | 8000 | The single gateway the app proxies to. **Inside the network, Kong is on 8000** — the `54321→8000` mapping is host-only. |
|
||||
| Studio | 54323 | 3000 | UI — login `postgres` / `postgres` |
|
||||
| Postgres | 54322 | 5432 | Direct DB — `postgres` / `postgres` |
|
||||
| SMTP (Mailpit) | 54324 | 8025 | Captures emails |
|
||||
| Analytics | 54327 | 4000 | Logflare |
|
||||
|
||||
> **Gotcha:** from *inside* the shared network (e.g. the app container), reach
|
||||
> Kong at `supabase_kong_Convivo:8000`, **not** `:54321`. The `54321` port only
|
||||
> exists on the host. This is why the app's nginx proxies to
|
||||
> `supabase_kong_Convivo:8000` by default.
|
||||
|
||||
## How to run
|
||||
|
||||
```bash
|
||||
# Start the core (creates containers + the supabase_network_Convivo network)
|
||||
npm run db:start # = supabase start
|
||||
|
||||
# (Re)apply migrations + seed, then restart the stack
|
||||
npm run db:reset # = supabase db reset (NOT `supabase reset`)
|
||||
|
||||
# Stop the core
|
||||
npm run db:stop # = supabase stop
|
||||
|
||||
# Show status / URLs / keys
|
||||
npx supabase status
|
||||
```
|
||||
|
||||
- `db:reset` drops and recreates the database, applies
|
||||
[`migrations/20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql),
|
||||
then runs [`seed.sql`](../../supabase/seed.sql). Use it any time you want a
|
||||
clean demo state.
|
||||
- Migrations and seed are **idempotent** (`on conflict ... do nothing`), so a
|
||||
reset is safe to repeat.
|
||||
|
||||
## Config highlights (`supabase/config.toml`)
|
||||
|
||||
| Setting | Value | Why |
|
||||
|---|---|---|
|
||||
| `project_id` | `Convivo` | Names the Docker network + containers |
|
||||
| `[api] port` | `54321` | Kong gateway port |
|
||||
| `[db] port` | `54322` | Postgres port |
|
||||
| `[studio] port` | `54323` | Studio port |
|
||||
| `[auth.email] enable_confirmations` | `false` | **No email is sent** — the QR+email login never emails the user |
|
||||
| `[auth] site_url` | `http://127.0.0.1:3000` | The app origin |
|
||||
| `[db.seed] sql_paths` | `["./seed.sql"]` | Seed runs on reset |
|
||||
|
||||
## Keys
|
||||
|
||||
| Key | Value | Where it's used |
|
||||
|---|---|---|
|
||||
| **Anon key** | standard local anon JWT (see `apps/convivo/.env.example`) | **Ships in the app** (public by design) |
|
||||
| **Service-role key** | standard local service-role JWT | **Never in the app** — server-side only (used for admin ops / verification) |
|
||||
|
||||
The app's security model (anon key + session JWT + RLS) is documented in
|
||||
[rls.md](./rls.md).
|
||||
Reference in new issue
Block a user