# Convivo — Architecture High-level system overview, tech stack, environment setup, and system-wide data flows. For component-level detail, see [backend/README.md](./backend/README.md) and [frontend/README.md](./frontend/README.md). ## 1. The product in one paragraph Convivo is a mobile-first web app (PWA) for conference attendees. People log in with the **QR code on their lanyard + the email they used to buy their ticket** (no email is ever sent). They pick one session per slot, scan peers' lanyards to make connections, get checked in by staff, and rate sessions. Every action earns **points**, and a **live leaderboard** turns networking into a game. ## 2. System diagram ```mermaid flowchart LR subgraph Browser["Browser"] A["Convivo PWA
React 18 + Vite 5 + TS
mobile-first, installable"] AD["APPE Admin
React 18 + Vite 5 + TS
desktop-first console"] end subgraph Docker["Docker (local)"] subgraph AppC["convivo-app container (:3000)"] N["nginx
serves SPA + proxies Supabase paths"] end subgraph AdminC["convivo-admin container (:3001)"] NA["nginx
serves SPA + proxies Supabase paths"] end subgraph Core["Supabase core (Supabase CLI)"] K["Kong API gateway
:54321"] K --> G["GoTrue (Auth)"] K --> R["PostgREST"] K --> RT["Realtime"] K --> S["Storage"] K --> EF["Edge Functions
sync-trigger"] R --> P[("Postgres 17
schema · RLS · points RPCs")] RT --> P G --> P EF -->|"service-role RPCs"| R end MA["mock-api (:54330)
Pretix + Sessionize fixtures"] end A -->|"same-origin /auth /rest /realtime /storage /functions"| N AD -->|"same-origin /auth /rest /realtime /storage /functions"| NA N -->|"proxy (supabase_kong_Convivo:8000)"| K NA -->|"proxy (supabase_kong_Convivo:8000)"| K EF -->|"GET /pretix/attendees · /sessionize/sessions"| MA ``` **Key idea:** there is **no custom backend**. Supabase provides auth, data, business logic (as Postgres RPCs), and realtime. The app is a thin client that talks to Supabase through **same-origin paths**, so there is no CORS to manage. ## 3. Tech stack | Layer | Choice | Why | |---|---|---| | Core | **Supabase (local, Docker)** via the Supabase CLI | Postgres + Auth + REST + Realtime + Storage in one managed stack; RLS + RPCs keep all logic in the DB | | App | **React 18 + Vite 5 + TypeScript** (PWA) | Fast, mobile-first, installable; same-origin proxy avoids CORS | | QR | `html5-qrcode` (scan) + `qrcode.react` (render) | Camera scan with manual-entry fallback | | Client | `@supabase/supabase-js` | Auth + REST + Realtime in one client | | Interfaces | **`sync-trigger` Edge Function** (Deno) + **mock API** (Node) | Pulls real Pretix/Sessionize data and imports it via service-role RPCs; the mock API serves fixtures locally | | Packaging | **Docker** (multi-stage build → nginx) | The app is a sidecar that joins the Supabase network | ## 4. The two halves ### Backend — the Supabase core Everything server-side lives in Postgres. See [backend/README.md](./backend/README.md): - **Schema** — 13 tables (people, the event, participation, schedule, and the event's activity). → [backend/schema.md](./backend/schema.md) - **Business logic** — transactional `security definer` RPCs that award points and keep the leaderboard consistent. → [backend/rpcs.md](./backend/rpcs.md) - **Security** — Row Level Security on every table; the app only ever uses the **anon key + the user's session JWT**. → [backend/rls.md](./backend/rls.md) - **Interfaces** — service-role-only sync RPCs (`sync_pretix_attendees`, `sync_sessionize_sessions`) called by the `sync-trigger` Edge Function, which pulls from Pretix/Sessionize (or the local mock API). → [backend/interfaces.md](./backend/interfaces.md) - **Data** — seed with 1 event, 6 slots, 18 sessions, 14 contacts, 13 registrations, 3 sponsors. → [backend/seed.md](./backend/seed.md) ### Frontend — the attendee PWA A single-page React app with a tab shell and a few full-screen takeovers. See [frontend/README.md](./frontend/README.md): - **Structure** — contexts (auth, toast), the event hook, the tab shell. → [frontend/app-structure.md](./frontend/app-structure.md) - **Screens** — Login, Home, Agenda, Scan/Check-in, Connections, Feedback, Leaderboard, Profile. → [frontend/screens.md](./frontend/screens.md) - **API client** — a thin typed wrapper over `supabase.rpc` / `supabase.from`. → [frontend/api-client.md](./frontend/api-client.md) ### Frontend — the admin console (APPE Admin) A separate desktop-first React app for organizers, guarded to the **`is_admin`** flag. See [frontend/admin-app.md](./frontend/admin-app.md): - **Views** — Dashboard (active event + aggregates), Contacts, Registrations, Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity, Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV). - **Auth guard** — same QR + email login, but non-admin sessions are rejected. - **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`, `create_registration`, `set_registration_type`, `evaluate_session_feedback` (AI stub), and `set_session_material` (see [backend/rpcs.md](./backend/rpcs.md)). ## 5. How a request flows (example: staff check-in) ```mermaid sequenceDiagram participant U as Staff (PWA) participant N as nginx (app container) participant K as Kong participant R as PostgREST participant DB as Postgres (RPC) U->>N: POST /rest/v1/rpc/checkin_attendee {session, attendeeQr} N->>K: proxy (same-origin) K->>R: route /rest R->>DB: execute checkin_attendee() as `authenticated` Note over DB: security definer → bypasses RLS
1. insert checkin (ON CONFLICT do nothing)
2. _award_points(+10) → registrations.points + points_log
3. _sync_leaderboard() DB-->>R: {checkin_id, attendee_name, points, already} R-->>K: JSON K-->>N: JSON N-->>U: result sheet ("+10 pts · now 62") Note over DB: leaderboard row changed → Realtime broadcasts to all open apps ``` The same pattern applies to every mutation: the app calls an RPC, Postgres does the work atomically, and the `leaderboard` table change fans out over Realtime. ## 6. Authentication model - The **QR token is the Supabase Auth password**; the **email is the identifier**. Login is a standard `signInWithPassword({ email, password: qrToken })`. - `enable_confirmations = false`, so **no email is sent** — the email is only a "confirm it's you" check against the ticket purchase. - After login, the app holds a **session JWT** (in `localStorage`) that lasts **24 hours** (`jwt_expiry = 86400`). Every request sends the **anon key** (public) + the **session JWT** (identity). - The **service-role key is never in the app** — it bypasses RLS and stays server-side. See [backend/rls.md](./backend/rls.md) for what each role can do. ## 7. Environment & ports | Service | Port | Notes | |---|---|---| | **Convivo app** | **3000** | Vite dev server (dev) or nginx (Docker) | | **Convivo admin** | **3001** | Vite dev server (dev) or nginx (Docker) | | Supabase API (Kong) | 54321 | The single gateway the apps proxy to | | Supabase Studio | 54323 | UI — login `postgres` / `postgres` | | Postgres | 54322 | Direct DB access (`postgres` / `postgres`) | | SMTP (Mailpit) | 54324 | Captures emails (none are sent in this flow) | **Run it** (full instructions in the root [`README.md`](../README.md)): ```bash npm run db:start # start the Supabase core (Docker) npm run db:reset # (re)apply migrations + seed npm run app:dev # attendee dev server on :3000 npm run admin:dev # admin dev server on :3001 # — or — docker compose up --build # both apps as Docker sidecars (:3000 + :3001) ``` ## 8. The demo clock The app uses a **simulated "now"** of `2026-10-23 10:20` (see [frontend/app-structure.md](./frontend/app-structure.md#the-event-clock)) so that Slot 1 is *done* and Slot 2 is *live* — matching the mockup. This is a frontend concern only; the database stores real slot times. ## 9. Repository layout ``` Convivo/ ├─ apps/convivo/ # Attendee web PWA (React + Vite + TS) │ ├─ Dockerfile # Multi-stage: build → nginx │ ├─ nginx.conf.template # SPA + same-origin proxy to the Supabase core │ └─ src/ # screens, components, lib, context ├─ apps/admin/ # Admin console (React + Vite + TS, desktop-first) │ ├─ Dockerfile # Multi-stage: build → nginx │ ├─ nginx.conf.template # SPA + same-origin proxy to the Supabase core │ └─ src/ # views, components, lib, context ├─ supabase/ │ ├─ config.toml # Local stack config (ports, auth, RLS defaults) │ ├─ migrations/ │ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign) │ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded) │ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials │ │ ├─ 20260825000000_interfaces.sql # external_id + sync_runs + sync RPCs │ │ └─ 20260826000000_registration_qr_token.sql # ← current: QR token on registration │ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state ├─ docker-compose.yml # Runs both app sidecars on the Supabase network ├─ docs/ # ← this documentation └─ mockup/index.html # Original interactive mockup (design reference) ```