# ekirmen/zeatingmaps architecture

> Architecture diagram of the GitHub repository ekirmen/zeatingmaps, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ekirmen/zeatingmaps
- Repository: https://github.com/ekirmen/zeatingmaps

## Overview

1. **Overall shape**
   ZeatingMaps is a multi-tenant ticketing platform split into three main runtime surfaces: a public storefront, an organizer backoffice, and SaaS/admin consoles. The frontend is a single React/Vite codebase under `src/`, while backend capabilities are mostly Vercel serverless functions under `api/`, backed by Supabase PostgreSQL.

2. **Primary user-facing applications**
   The UI is partitioned by business role, not just by route:
   - `src/store/` is the buyer-facing storefront for discovering events, choosing seats, paying, and downloading tickets.
   - `src/backoffice/` is the organizer/tenant operations app for event setup, seating maps, sales, CRM, email campaigns, and reporting.
   - `src/saas/` and `src/admin-saas/` are super-admin / tenant-management surfaces for platform-level billing, access control, monitoring, and tenant lifecycle.

3. **Core data boundary: Supabase multi-tenancy**
   Supabase is the system of record and the primary isolation boundary. The repo strongly centers on `tenant_id`-scoped data with Row Level Security enforcement. Client code uses Supabase through shared config and service wrappers in `src/config/`, `src/supabaseClient.jsx`, and `src/services/`, while serverless functions use elevated service credentials when needed.

4. **Transaction and payment pipeline**
   Payment flows are orchestrated from the storefront and backoffice through service modules such as `src/store/services/paymentGatewaysService.js`, `src/services/paymentTransactionsService.jsx`, and related payment processors. On the server side, the `/api/payments/...` functions and `api-lib/payments/` handle intent creation, transaction creation, locator-based lookup, email follow-up, and ticket output generation.

5. **Seat inventory and locking**
   Seat availability is managed as a shared real-time concern. The frontend has dedicated seat stores and sync hooks (`src/services/seatLocksService.jsx`, `src/hooks/useMapaSeatsSync.jsx`, `src/store/components/SeatSelectionTimer.jsx`, etc.), while the backend exposes atomic lock endpoints under `/api/seat-locks/`. This is a key consistency boundary to prevent double-selling in both the online store and the box office.

6. **Event and venue domain model**
   The backoffice’s operational model is built around `Recinto` (venue), `Sala` (hall), `Zona` (zone), `Evento` (event), and `Función` (performance). These concepts are reflected in the API (`/api/recintos`, `/api/zonas`, `/api/mapas/[salaId]`) and in dedicated backoffice pages for CRUD, pricing, discounts, promotions, and seat configuration.

7. **Seating-map editor and runtime viewer**
   A major subsystem is the custom seating-map engine. The editor lives mostly in `src/backoffice/components/CrearMapa/` and related `compMapa` components, with many hooks for selection, snapping, history, transforms, validation, and drag/drop. The storefront and backoffice consumers reuse seating-view components under `src/components/` and `src/store/components/`, with worker-based computation for layout and seat calculations.

8. **Checkout, carts, and state management**
   Cart and session state are managed client-side with Zustand stores and custom hooks. The storefront uses `src/store/cartStore.js`, `src/store/hooks/`, and local persistence patterns to support seat reservations, timers, restored carts, and payment retries. This layer is the boundary between UI selection and payment execution.

9. **Tickets, downloads, and post-payment fulfillment**
   Fulfillment is handled after transaction completion by generating downloadable artifacts. The repository includes PDF ticket generation and Apple Wallet support through `api/download-ticket.js` and `api-lib/payments/pkpass-generator.js`, plus download helpers in `src/utils/downloadTicket.jsx` and `src/utils/downloadPkpass.jsx`. Email delivery of tickets is also part of this fulfillment path.

10. **Email and campaign subsystem**
   Email is a first-class subsystem, not just a notification utility. `api/send-email/`, `api/webhooks/resend.js`, and backoffice email tooling support transactional mail, campaign composition, template editing, open tracking, and tenant-specific configuration. Supporting services exist in `src/backoffice/services/` and `src/services/emailTemplateService.jsx`.

11. **PWA, offline, and performance helpers**
   The public experience is optimized for mobile and intermittent connectivity. `public/service-worker.js`, `public/offline.html`, `public/seatCalculations.worker.js`, and the `src/workers/` folder indicate offline/PWA support and background computation. There are also preloading, lazy-loading, and image optimization utilities used to keep the storefront and seating maps responsive.

12. **Printing and on-site sales**
   The backoffice includes a presencial sales/box-office workflow (`src/backoffice/pages/Boleteria.jsx`) with printer integrations. The repo explicitly supports BOCA and Godex thermal printing via services/components under `src/backoffice/services/bocaPrinterService.jsx` and printer config UI, which affects the architecture as a separate fulfillment/output channel.

13. **Auxiliary local infrastructure**
   Two local helper servers exist outside the main Vercel deployment path: `local-sync-server/` and `servidor-local/`. These suggest local synchronization/test harnesses for map or data workflows during development, distinct from production serverless APIs.

14. **Cross-cutting boundaries**
   Authentication, tenant access, roles, and audit logging are pervasive concerns. They are implemented via shared contexts, protected-route wrappers, role-based access components, audit services, and tenant guards across all three app surfaces. For an architecture diagram, these should be drawn as shared platform layers cutting across storefront, backoffice, and SaaS admin, with Supabase RLS and serverless service-role functions as the main enforcement boundaries.

Main entry points: [`src/store/StoreApp.jsx`](https://github.com/ekirmen/zeatingmaps/blob/main/src/store/StoreApp.jsx) (Storefront), [`src/backoffice/BackofficeAppWithRoles.jsx`](https://github.com/ekirmen/zeatingmaps/blob/main/src/backoffice/BackofficeAppWithRoles.jsx) (Backoffice), [`src/config/supabase.jsx`](https://github.com/ekirmen/zeatingmaps/blob/main/src/config/supabase.jsx) (Supabase client), [`src/contexts/AuthContext.jsx`](https://github.com/ekirmen/zeatingmaps/blob/main/src/contexts/AuthContext.jsx) (Auth & tenant)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend surfaces"]
  node_store_app["Storefront<br/>buyer UI<br/>[StoreApp.jsx]"]
  node_backoffice_app["Backoffice<br/>organizer UI"]
  node_saas_app["SaaS admin<br/>platform UI"]
  node_admin_saas_app["Admin SaaS<br/>admin UI<br/>[AdminSaasApp.jsx]"]
  node_backoffice_ops["Ops tools<br/>organizer features"]
  node_store_checkout["Checkout flow<br/>buyer flow<br/>[Pay.jsx]"]
end

subgraph group_backend["Backend APIs"]
  node_seat_api["Seat locks API<br/>serverless api<br/>[[[...action]].js]"]
  node_payments_api["Payments API<br/>serverless api<br/>[[[...action]].js]"]
  node_domain_api["Domain API<br/>serverless api<br/>[delete.js]"]
  node_email_api["Email API<br/>serverless api<br/>[[[...provider]].js]"]
end

subgraph group_platform["Shared platform"]
  node_supabase_client[("Supabase client<br/>data access<br/>[supabase.jsx]")]
  node_tenant_auth(("Auth & tenant<br/>guards/contexts<br/>[AuthContext.jsx]"))
  node_shared_services["Shared services<br/>domain services"]
  node_seat_sync["Seat sync<br/>realtime state"]
  node_map_engine{{"Map engine<br/>editor/runtime<br/>[SeatingMap.jsx]"}}
  node_payment_flow["Payments<br/>checkout pipeline"]
  node_fulfillment["Fulfillment<br/>tickets/output<br/>[download-ticket.js]"]
  node_email_system["Email system<br/>mail pipeline<br/>[emailService.jsx]"]
end

subgraph group_local["Local tooling"]
  node_local_tools["Local helpers<br/>dev servers<br/>[server.js]"]
end

node_store_app -->|"reads/writes"| node_supabase_client
node_backoffice_app -->|"reads/writes"| node_supabase_client
node_saas_app -->|"reads/writes"| node_supabase_client
node_admin_saas_app -->|"reads/writes"| node_supabase_client
node_store_app -->|"protects"| node_tenant_auth
node_backoffice_app -->|"protects"| node_tenant_auth
node_saas_app -->|"protects"| node_tenant_auth
node_admin_saas_app -->|"protects"| node_tenant_auth
node_store_app -->|"orchestrates"| node_store_checkout
node_backoffice_app -->|"orchestrates"| node_backoffice_ops
node_backoffice_app -->|"uses"| node_map_engine
node_store_app -->|"uses"| node_map_engine
node_store_app -->|"locks seats"| node_seat_sync
node_backoffice_app -->|"locks seats"| node_seat_sync
node_store_checkout -->|"executes"| node_payment_flow
node_backoffice_ops -->|"executes"| node_payment_flow
node_payment_flow -->|"calls"| node_payments_api
node_seat_sync -->|"calls"| node_seat_api
node_shared_services -->|"calls"| node_domain_api
node_fulfillment -->|"extends"| node_payments_api
node_fulfillment -->|"sends"| node_email_api
node_email_system -->|"calls"| node_email_api
node_email_system -->|"reads/writes"| node_supabase_client
node_local_tools -.->|"syncs"| node_supabase_client

click node_store_app "https://github.com/ekirmen/zeatingmaps/blob/main/src/store/StoreApp.jsx"
click node_backoffice_app "https://github.com/ekirmen/zeatingmaps/blob/main/src/backoffice/BackofficeAppWithRoles.jsx"
click node_saas_app "https://github.com/ekirmen/zeatingmaps/tree/main/src/saas"
click node_admin_saas_app "https://github.com/ekirmen/zeatingmaps/blob/main/src/admin-saas/AdminSaasApp.jsx"
click node_supabase_client "https://github.com/ekirmen/zeatingmaps/blob/main/src/config/supabase.jsx"
click node_tenant_auth "https://github.com/ekirmen/zeatingmaps/blob/main/src/contexts/AuthContext.jsx"
click node_shared_services "https://github.com/ekirmen/zeatingmaps/tree/main/src/services"
click node_seat_sync "https://github.com/ekirmen/zeatingmaps/blob/main/src/services/seatLocksService.jsx"
click node_map_engine "https://github.com/ekirmen/zeatingmaps/blob/main/src/components/SeatingMap.jsx"
click node_payment_flow "https://github.com/ekirmen/zeatingmaps/blob/main/src/store/services/paymentGatewaysService.js"
click node_fulfillment "https://github.com/ekirmen/zeatingmaps/blob/main/api/download-ticket.js"
click node_email_system "https://github.com/ekirmen/zeatingmaps/blob/main/src/backoffice/services/emailService.jsx"
click node_backoffice_ops "https://github.com/ekirmen/zeatingmaps/tree/main/src/backoffice/pages"
click node_store_checkout "https://github.com/ekirmen/zeatingmaps/blob/main/src/store/pages/Pay.jsx"
click node_seat_api "https://github.com/ekirmen/zeatingmaps/blob/main/api/seat-locks/[[...action]].js"
click node_payments_api "https://github.com/ekirmen/zeatingmaps/blob/main/api/payments/[locator]/[[...action]].js"
click node_domain_api "https://github.com/ekirmen/zeatingmaps/blob/main/api/recintos/[id]/delete.js"
click node_email_api "https://github.com/ekirmen/zeatingmaps/blob/main/api/send-email/[[...provider]].js"
click node_local_tools "https://github.com/ekirmen/zeatingmaps/blob/main/local-sync-server/server.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_store_app,node_backoffice_app,node_saas_app,node_admin_saas_app,node_backoffice_ops,node_store_checkout toneBlue
class node_seat_api,node_payments_api,node_domain_api,node_email_api toneAmber
class node_supabase_client,node_tenant_auth,node_shared_services,node_seat_sync,node_map_engine,node_payment_flow,node_fulfillment,node_email_system toneMint
class node_local_tools toneRose
```

## Components

### Frontend surfaces

React/Vite app partitioned by business role.

- [Storefront](https://github.com/ekirmen/zeatingmaps/blob/main/src/store/StoreApp.jsx): buyer UI · Public event discovery, seat selection, checkout, and ticket access. · `src/store/StoreApp.jsx`
- [Backoffice](https://github.com/ekirmen/zeatingmaps/blob/main/src/backoffice/BackofficeAppWithRoles.jsx): organizer UI · Organizer operations for events, seating maps, CRM, campaigns, reporting, and box office. · `src/backoffice/BackofficeAppWithRoles.jsx`
- [SaaS admin](https://github.com/ekirmen/zeatingmaps/tree/main/src/saas): platform UI · Super-admin and tenant-management console for platform operations. · `src/saas`
- [Admin SaaS](https://github.com/ekirmen/zeatingmaps/blob/main/src/admin-saas/AdminSaasApp.jsx): admin UI · Admin-facing tenant and payment-gateway management surface. · `src/admin-saas/AdminSaasApp.jsx`
- [Ops tools](https://github.com/ekirmen/zeatingmaps/tree/main/src/backoffice/pages): organizer features · Event, venue, pricing, CRM, reports, printing, and support workflows. · `src/backoffice/pages`
- [Checkout flow](https://github.com/ekirmen/zeatingmaps/blob/main/src/store/pages/Pay.jsx): buyer flow · Cart, timers, seat reservation, payment screens, and success pages. · `src/store/pages/Pay.jsx`

### Backend APIs

Serverless endpoints and payment helpers.

- [Seat locks API](https://github.com/ekirmen/zeatingmaps/blob/main/api/seat-locks/[[...action]].js): serverless api · Atomic seat-lock endpoints to prevent double-selling. · `api/seat-locks/[[...action]].js`
- [Payments API](https://github.com/ekirmen/zeatingmaps/blob/main/api/payments/[locator]/[[...action]].js): serverless api · Payment intent, transaction, locator lookup, and follow-up actions. · `api/payments/[locator]/[[...action]].js`
- [Domain API](https://github.com/ekirmen/zeatingmaps/blob/main/api/recintos/[id]/delete.js): serverless api · Venue, zone, map, audit, and event-domain endpoints. · `api/recintos/[id]/delete.js`
- [Email API](https://github.com/ekirmen/zeatingmaps/blob/main/api/send-email/[[...provider]].js): serverless api · Send-email and provider webhook endpoints for transactional mail. · `api/send-email/[[...provider]].js`

### Shared platform

Cross-cutting client-side data, auth, tenancy, and shared subsystems.

- [Supabase client](https://github.com/ekirmen/zeatingmaps/blob/main/src/config/supabase.jsx): data access · Shared client configuration and service wrappers for multi-tenant data access. · `src/config/supabase.jsx`
- [Auth & tenant](https://github.com/ekirmen/zeatingmaps/blob/main/src/contexts/AuthContext.jsx): guards/contexts · Shared authentication, tenant switching, access control, and role enforcement. · `src/contexts/AuthContext.jsx`
- [Shared services](https://github.com/ekirmen/zeatingmaps/tree/main/src/services): domain services · Client-side domain services for events, venues, users, audit, and payments. · `src/services`
- [Seat sync](https://github.com/ekirmen/zeatingmaps/blob/main/src/services/seatLocksService.jsx): realtime state · Seat locks, cleanup, and live synchronization used by storefront and box office. · `src/services/seatLocksService.jsx`
- [Map engine](https://github.com/ekirmen/zeatingmaps/blob/main/src/components/SeatingMap.jsx): editor/runtime · Custom seating-map editor, viewer, and worker-based layout computation. · `src/components/SeatingMap.jsx`
- [Payments](https://github.com/ekirmen/zeatingmaps/blob/main/src/store/services/paymentGatewaysService.js): checkout pipeline · Cart, processors, transactions, retries, and gateway orchestration. · `src/store/services/paymentGatewaysService.js`
- [Fulfillment](https://github.com/ekirmen/zeatingmaps/blob/main/api/download-ticket.js): tickets/output · Ticket PDF, Apple Wallet, email delivery, and downloads after payment. · `api/download-ticket.js`
- [Email system](https://github.com/ekirmen/zeatingmaps/blob/main/src/backoffice/services/emailService.jsx): mail pipeline · Transactional and campaign email, templates, config, and webhook handling. · `src/backoffice/services/emailService.jsx`

### Local tooling

Developer-side helper servers outside the main production path.

- [Local helpers](https://github.com/ekirmen/zeatingmaps/blob/main/local-sync-server/server.js): dev servers · Local sync and test harnesses for development workflows. · `local-sync-server/server.js`

## Connections

- Storefront → Supabase client: reads/writes · Buyer UI uses shared Supabase access for public data and session state.
- Backoffice → Supabase client: reads/writes · Organizer UI uses shared Supabase access for tenant-scoped operations.
- SaaS admin → Supabase client: reads/writes · Platform admin UI uses shared data access for platform records.
- Admin SaaS → Supabase client: reads/writes · Admin console uses shared data access for management workflows.
- Storefront → Auth & tenant: protects · Public app is gated by auth, tenant context, and role-aware routes.
- Backoffice → Auth & tenant: protects · Backoffice uses guards and role-based access.
- SaaS admin → Auth & tenant: protects · SaaS surface uses admin authentication and guards.
- Admin SaaS → Auth & tenant: protects · Admin SaaS uses admin auth hooks and route guards.
- Storefront → Checkout flow: orchestrates · Storefront drives cart, seat selection, and payment screens.
- Backoffice → Ops tools: orchestrates · Backoffice coordinates CRUD, CRM, reports, printing, and support tools.
- Backoffice → Map engine: uses · Backoffice embeds the seating-map editor and viewer.
- Storefront → Map engine: uses · Buyer seat selection reuses the seating-map runtime.
- Storefront → Seat sync: locks seats · Seat selection relies on shared locking and live sync.
- Backoffice → Seat sync: locks seats · Box office and organizer tools share the same reservation boundary.
- Checkout flow → Payments: executes · Checkout hands off to payment processors and transaction tracking.
- Ops tools → Payments: executes · Backoffice can create, search, refund, or reconcile transactions.
- Payments → Payments API: calls · Client payment modules use the serverless payment endpoints.
- Seat sync → Seat locks API: calls · Seat locking is enforced through atomic API endpoints.
- Shared services → Domain API: calls · Shared domain services back event, venue, map, and audit operations.
- Fulfillment → Payments API: extends · Post-payment fulfillment is triggered from payment actions.
- Fulfillment → Email API: sends · Ticket delivery and follow-up mail use the email endpoints.
- Email system → Email API: calls · Backoffice email tooling uses the send-email and webhook APIs.
- Email system → Supabase client: reads/writes · Email config, templates, and campaign data are persisted in Supabase.
- Local helpers → Supabase client: syncs · Local helper servers support development-time data and map workflows.
