# hectoray99/speeddigital architecture

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

- Interactive diagram: https://gitdiagram.com/hectoray99/speeddigital
- Repository: https://github.com/hectoray99/speeddigital

## Overview

1. This is a Vite + React + TypeScript single-page application. The entrypoint in `src/main.tsx` bootstraps `App.tsx`, and the UI is organized into route-driven screens rather than a server-rendered app.

2. The app is clearly multi-role and multi-tenant. There are three top-level experience areas: public-facing pages, tenant/admin pages, and super-admin pages. The presence of `SuperAdminGuard`, `AuthGuard`, `SuperAdminLayout`, and `MainLayout` shows that route access and shell chrome are separated from feature screens.

3. Public routes live under `src/pages/public` and cover landing, login, auth callback, a digital menu, and a public portal for students/gym attendance. These routes are likely accessible without the main admin shell and serve as the authentication and guest entry points.

4. The admin area under `src/pages/admin` is the core operational surface. It is subdivided by business domain: dashboard, clients, finance, kitchen, products, salon, services, settings, staff, and onboarding. This suggests one frontend supporting several vertical workflows within the same tenant.

5. A lot of the admin UX is modal-based. Components like `CreateClientModal`, `CreateProductModal`, `CreateReceivableModal`, `RegisterPaymentModal`, `NewAppointmentModal`, `TablePOSModal`, and `EnrollModal` indicate that many create/update flows happen in overlays rather than dedicated pages. That usually means the main pages are list/detail views with action-driven CRUD dialogs.

6. The services area is especially workflow-heavy. Files such as `Agenda`, `MasterCalendar`, `DisciplineManager`, `Resources`, `CheckoutModal`, and `NewAppointmentModal` point to scheduling, calendar coordination, appointment checkout, and resource management. This is the likely center of time-based operations and booking logic.

7. Finance is split into both a general finance page and a cash register page. Combined with receivables, debtor lists, payment registration, and the Supabase edge function named `mp-checkout`, the architecture includes payment orchestration and likely external payment-provider integration, not just local bookkeeping.

8. Backend state is centered on Supabase. `src/lib/supabase.ts` is the client entry point, `supabase_schema_completo.sql` defines the database schema, and `supabase/functions` contains serverless edge functions. This means authentication, persistence, and at least some business workflows are delegated to Supabase rather than a custom API server.

9. The two Supabase functions are important integration boundaries: `send-receipt` for outbound receipt/notification delivery and `mp-checkout` for checkout/payment creation. These are the main server-side business endpoints visible in the repo and likely connect the frontend to external services.

10. Client-side state is kept in a small set of stores: `authStore` and `portalStore`. That suggests global state is intentionally limited, with most domain state fetched on demand from Supabase and page-local UI state handled in components/modals.

11. `bookingService.ts` and `cloudinary.ts` are the notable non-Supabase service modules. Booking logic is separated from UI screens, and Cloudinary implies external media/file handling for uploads, assets, or user-generated content.

12. The super-admin area is a separate control plane for managing organizations, subscriptions, promotions, announcements, and the super-admin dashboard. This is a clear platform-operator boundary, distinct from day-to-day tenant administration.

13. The repository also includes onboarding flows for new tenants, including `OnboardingWizard`, `GymOnboardingModal`, and `Onboarding.tsx`. That indicates the app supports provisioning and initial setup of a new organization inside the same product.

14. From an architecture-diagram perspective, the main flow is: public entry/auth callback -> client-side auth state -> guarded admin or super-admin layouts -> domain pages/modals -> Supabase database/functions and external services like payment/receipt delivery and Cloudinary. The system is primarily a front-end SPA with Supabase-backed backend services and a role-based UI split.

Main entry points: [`src/components/layout/MainLayout.tsx`](https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/MainLayout.tsx) (Main Layout), [`src/App.tsx`](https://github.com/hectoray99/speeddigital/blob/main/src/App.tsx) (App), [`src/lib/supabase.ts`](https://github.com/hectoray99/speeddigital/blob/main/src/lib/supabase.ts) (Supabase), [`src/components/layout/SuperAdminLayout.tsx`](https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/SuperAdminLayout.tsx) (Super Layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_app["Client App"]
  node_main_entry(("Main<br/>entrypoint<br/>[main.tsx]"))
  node_app_shell["App<br/>router<br/>[App.tsx]"]
  node_auth_guard{{"Auth Guard<br/>route-guard<br/>[AuthGuard.tsx]"}}
  node_super_guard{{"Super Guard<br/>route-guard"}}
  node_main_layout["Main Layout<br/>shell<br/>[MainLayout.tsx]"]
  node_super_layout["Super Layout<br/>shell"]
  node_auth_store[("Auth Store<br/>state<br/>[authStore.ts]")]
  node_portal_store[("Portal Store<br/>state<br/>[portalStore.ts]")]
end

subgraph group_public["Public Experience"]
  node_landing_login["Landing & Login<br/>public-pages<br/>[Landing.tsx]"]
  node_public_portal["Public Portal<br/>public-pages<br/>[PublicRouter.tsx]"]
  node_digital_menu["Digital Menu<br/>public-page<br/>[DigitalMenu.tsx]"]
end

subgraph group_tenant_admin["Tenant Admin"]
  node_dashboard["Dashboard<br/>tenant-screen<br/>[Dashboard.tsx]"]
  node_clients["Clients<br/>tenant-screen<br/>[Clients.tsx]"]
  node_finance["Finance<br/>tenant-screen<br/>[Finance.tsx]"]
  node_services["Services<br/>workflow<br/>[Agenda.tsx]"]
  node_staff["Staff<br/>tenant-screen<br/>[Staff.tsx]"]
  node_products["Products<br/>tenant-screen<br/>[Products.tsx]"]
  node_kitchen_salon["Kitchen & Salon<br/>tenant-screen<br/>[Kitchen.tsx]"]
  node_onboarding["Onboarding<br/>tenant-screen<br/>[Onboarding.tsx]"]
end

subgraph group_super_admin["Super Admin"]
  node_super_dashboard["Super Dashboard<br/>superadmin-screen"]
  node_super_orgs["Organizations<br/>superadmin-screen"]
  node_super_billing["Subscriptions<br/>superadmin-screen"]
end

subgraph group_backend["Backend Services"]
  node_supabase_client[("Supabase<br/>backend-client<br/>[supabase.ts]")]
  node_supabase_db[("Schema")]
  node_edge_checkout["MP Checkout<br/>edge-function<br/>[index.ts]"]
  node_edge_receipt["Send Receipt<br/>edge-function<br/>[index.ts]"]
  node_booking_service["Booking Service<br/>[bookingService.ts]"]
  node_cloudinary["Cloudinary<br/>[cloudinary.ts]"]
end

node_main_entry -->|"mounts"| node_app_shell
node_app_shell -->|"protects"| node_auth_guard
node_app_shell -->|"protects"| node_super_guard
node_auth_guard -->|"renders"| node_main_layout
node_super_guard -->|"renders"| node_super_layout
node_main_layout -->|"routes"| node_dashboard
node_main_layout -->|"routes"| node_clients
node_main_layout -->|"routes"| node_finance
node_main_layout -->|"routes"| node_services
node_main_layout -->|"routes"| node_staff
node_main_layout -->|"routes"| node_products
node_main_layout -->|"routes"| node_kitchen_salon
node_main_layout -->|"routes"| node_onboarding
node_super_layout -->|"routes"| node_super_dashboard
node_super_layout -->|"routes"| node_super_orgs
node_super_layout -->|"routes"| node_super_billing
node_app_shell -->|"exposes"| node_landing_login
node_app_shell -->|"exposes"| node_public_portal
node_app_shell -->|"exposes"| node_digital_menu
node_landing_login -->|"updates"| node_auth_store
node_public_portal -->|"updates"| node_portal_store
node_auth_store -->|"auth/data"| node_supabase_client
node_portal_store -->|"data"| node_supabase_client
node_dashboard -->|"reads"| node_supabase_client
node_clients -->|"reads/writes"| node_supabase_client
node_finance -->|"calls"| node_edge_checkout
node_finance -->|"calls"| node_edge_receipt
node_services -->|"uses"| node_booking_service
node_services -->|"reads/writes"| node_supabase_client
node_products -->|"uploads"| node_cloudinary
node_supabase_client -->|"persists to"| node_supabase_db
node_edge_checkout -->|"writes"| node_supabase_db
node_edge_receipt -->|"reads"| node_supabase_db

click node_main_entry "https://github.com/hectoray99/speeddigital/blob/main/src/main.tsx"
click node_app_shell "https://github.com/hectoray99/speeddigital/blob/main/src/App.tsx"
click node_auth_guard "https://github.com/hectoray99/speeddigital/blob/main/src/components/AuthGuard.tsx"
click node_super_guard "https://github.com/hectoray99/speeddigital/blob/main/src/components/SuperAdminGuard.tsx"
click node_main_layout "https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/MainLayout.tsx"
click node_super_layout "https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/SuperAdminLayout.tsx"
click node_auth_store "https://github.com/hectoray99/speeddigital/blob/main/src/store/authStore.ts"
click node_portal_store "https://github.com/hectoray99/speeddigital/blob/main/src/store/portalStore.ts"
click node_landing_login "https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/landing/Landing.tsx"
click node_public_portal "https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/portal/PublicRouter.tsx"
click node_digital_menu "https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/menu/DigitalMenu.tsx"
click node_dashboard "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/dashboard/Dashboard.tsx"
click node_clients "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/clients/Clients.tsx"
click node_finance "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/finance/Finance.tsx"
click node_services "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/services/Agenda.tsx"
click node_staff "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/staff/Staff.tsx"
click node_products "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/products/Products.tsx"
click node_kitchen_salon "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/kitchen/Kitchen.tsx"
click node_onboarding "https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/Onboarding.tsx"
click node_super_dashboard "https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminDashboard.tsx"
click node_super_orgs "https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminOrganizations.tsx"
click node_super_billing "https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminSubscriptions.tsx"
click node_supabase_client "https://github.com/hectoray99/speeddigital/blob/main/src/lib/supabase.ts"
click node_supabase_db "https://github.com/hectoray99/speeddigital/blob/main/supabase_schema_completo.sql"
click node_edge_checkout "https://github.com/hectoray99/speeddigital/blob/main/supabase/functions/mp-checkout/index.ts"
click node_edge_receipt "https://github.com/hectoray99/speeddigital/blob/main/supabase/functions/send-receipt/index.ts"
click node_booking_service "https://github.com/hectoray99/speeddigital/blob/main/src/services/bookingService.ts"
click node_cloudinary "https://github.com/hectoray99/speeddigital/blob/main/src/services/cloudinary.ts"

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_main_entry,node_app_shell,node_auth_guard,node_super_guard,node_main_layout,node_super_layout,node_auth_store,node_portal_store toneBlue
class node_landing_login,node_public_portal,node_digital_menu toneAmber
class node_dashboard,node_clients,node_finance,node_services,node_staff,node_products,node_kitchen_salon,node_onboarding toneMint
class node_super_dashboard,node_super_orgs,node_super_billing toneRose
class node_supabase_client,node_supabase_db,node_edge_checkout,node_edge_receipt,node_booking_service,node_cloudinary toneIndigo
```

## Components

### Client App

Vite + React SPA shell, routing, guards, and feature screens.

- [Main](https://github.com/hectoray99/speeddigital/blob/main/src/main.tsx): entrypoint · Bootstraps the React application. · `src/main.tsx`
- [App](https://github.com/hectoray99/speeddigital/blob/main/src/App.tsx): router · Top-level route composition and app wiring. · `src/App.tsx`
- [Auth Guard](https://github.com/hectoray99/speeddigital/blob/main/src/components/AuthGuard.tsx): route-guard · Protects tenant/admin routes. · `src/components/AuthGuard.tsx`
- [Super Guard](https://github.com/hectoray99/speeddigital/blob/main/src/components/SuperAdminGuard.tsx): route-guard · Protects super-admin routes. · `src/components/SuperAdminGuard.tsx`
- [Main Layout](https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/MainLayout.tsx): shell · Tenant/admin chrome and navigation. · `src/components/layout/MainLayout.tsx`
- [Super Layout](https://github.com/hectoray99/speeddigital/blob/main/src/components/layout/SuperAdminLayout.tsx): shell · Super-admin chrome and navigation. · `src/components/layout/SuperAdminLayout.tsx`
- [Auth Store](https://github.com/hectoray99/speeddigital/blob/main/src/store/authStore.ts): state · Global auth/session state. · `src/store/authStore.ts`
- [Portal Store](https://github.com/hectoray99/speeddigital/blob/main/src/store/portalStore.ts): state · Public portal/session state. · `src/store/portalStore.ts`

### Public Experience

Unauthenticated entry points and public portal flows.

- [Landing & Login](https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/landing/Landing.tsx): public-pages · Landing page, login, staff login, and auth callback. · `src/pages/public/landing/Landing.tsx`
- [Public Portal](https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/portal/PublicRouter.tsx): public-pages · Student portal, attendance, and public router. · `src/pages/public/portal/PublicRouter.tsx`
- [Digital Menu](https://github.com/hectoray99/speeddigital/blob/main/src/pages/public/menu/DigitalMenu.tsx): public-page · Guest-facing digital menu experience. · `src/pages/public/menu/DigitalMenu.tsx`

### Tenant Admin

Role-scoped operational screens for tenant users.

- [Dashboard](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/dashboard/Dashboard.tsx): tenant-screen · Tenant overview and operational home. · `src/pages/admin/dashboard/Dashboard.tsx`
- [Clients](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/clients/Clients.tsx): tenant-screen · Client management and detail views. · `src/pages/admin/clients/Clients.tsx`
- [Finance](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/finance/Finance.tsx): tenant-screen · Financial operations and cash register. · `src/pages/admin/finance/Finance.tsx`
- [Services](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/services/Agenda.tsx): workflow · Scheduling, calendar, booking, and checkout workflows. · `src/pages/admin/services/Agenda.tsx`
- [Staff](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/staff/Staff.tsx): tenant-screen · Attendance, payroll, scheduling, and timeclock. · `src/pages/admin/staff/Staff.tsx`
- [Products](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/products/Products.tsx): tenant-screen · Product catalog and inventory-facing operations. · `src/pages/admin/products/Products.tsx`
- [Kitchen & Salon](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/kitchen/Kitchen.tsx): tenant-screen · Vertical-specific operational screens. · `src/pages/admin/kitchen/Kitchen.tsx`
- [Onboarding](https://github.com/hectoray99/speeddigital/blob/main/src/pages/admin/Onboarding.tsx): tenant-screen · Tenant setup and initial provisioning flow. · `src/pages/admin/Onboarding.tsx`

### Super Admin

Platform operator control plane.

- [Super Dashboard](https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminDashboard.tsx): superadmin-screen · Platform overview for operators. · `src/pages/superadmin/SuperAdminDashboard.tsx`
- [Organizations](https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminOrganizations.tsx): superadmin-screen · Tenant and organization management. · `src/pages/superadmin/SuperAdminOrganizations.tsx`
- [Subscriptions](https://github.com/hectoray99/speeddigital/blob/main/src/pages/superadmin/SuperAdminSubscriptions.tsx): superadmin-screen · Subscription and platform billing controls. · `src/pages/superadmin/SuperAdminSubscriptions.tsx`

### Backend Services

Supabase-backed persistence, edge functions, and external service integrations.

- [Supabase](https://github.com/hectoray99/speeddigital/blob/main/src/lib/supabase.ts): backend-client · Frontend client for auth, data, and storage. · `src/lib/supabase.ts`
- [Schema](https://github.com/hectoray99/speeddigital/blob/main/supabase_schema_completo.sql): database-schema · Canonical database schema definition. · `supabase_schema_completo.sql`
- [MP Checkout](https://github.com/hectoray99/speeddigital/blob/main/supabase/functions/mp-checkout/index.ts): edge-function · Payment checkout creation and provider integration. · `supabase/functions/mp-checkout/index.ts`
- [Send Receipt](https://github.com/hectoray99/speeddigital/blob/main/supabase/functions/send-receipt/index.ts): edge-function · Receipt and notification delivery. · `supabase/functions/send-receipt/index.ts`
- [Booking Service](https://github.com/hectoray99/speeddigital/blob/main/src/services/bookingService.ts): service · Shared booking and appointment logic. · `src/services/bookingService.ts`
- [Cloudinary](https://github.com/hectoray99/speeddigital/blob/main/src/services/cloudinary.ts): service · External media and upload handling. · `src/services/cloudinary.ts`

## Connections

- Main → App: mounts · Application entry bootstraps the router shell.
- App → Auth Guard: protects · Tenant routes are wrapped by auth protection.
- App → Super Guard: protects · Super-admin routes are wrapped by role protection.
- Auth Guard → Main Layout: renders · Authenticated tenant users enter the main shell.
- Super Guard → Super Layout: renders · Authorized operators enter the super-admin shell.
- Main Layout → Dashboard: routes · Main shell hosts tenant screens.
- Main Layout → Clients: routes · Main shell hosts client management.
- Main Layout → Finance: routes · Main shell hosts finance screens.
- Main Layout → Services: routes · Main shell hosts booking and service workflows.
- Main Layout → Staff: routes · Main shell hosts staff operations.
- Main Layout → Products: routes · Main shell hosts product operations.
- Main Layout → Kitchen & Salon: routes · Main shell hosts vertical-specific workflows.
- Main Layout → Onboarding: routes · Main shell hosts tenant setup flow.
- Super Layout → Super Dashboard: routes · Super-admin shell hosts platform dashboards.
- Super Layout → Organizations: routes · Super-admin shell hosts organization management.
- Super Layout → Subscriptions: routes · Super-admin shell hosts subscription management.
- App → Landing & Login: exposes · Public routes provide entry and authentication.
- App → Public Portal: exposes · Public portal routes are reachable without the admin shell.
- App → Digital Menu: exposes · Guest menu route is public-facing.
- Landing & Login → Auth Store: updates · Login and callback flows populate auth state.
- Public Portal → Portal Store: updates · Portal flows keep public-session state.
- Auth Store → Supabase: auth/data · Auth state is sourced from Supabase.
- Portal Store → Supabase: data · Public portal reads/writes via Supabase.
- Dashboard → Supabase: reads · Tenant screens query backend data.
- Clients → Supabase: reads/writes · Client management persists through Supabase.
- Finance → MP Checkout: calls · Payment flows delegate checkout creation.
- Finance → Send Receipt: calls · Payment and receipt flows trigger notifications.
- Services → Booking Service: uses · Scheduling screens share booking logic.
- Services → Supabase: reads/writes · Service workflows persist operational data.
- Products → Cloudinary: uploads · Product/media workflows use Cloudinary.
- Supabase → Schema: persists to · Frontend client targets the Supabase schema.
- MP Checkout → Schema: writes · Checkout function records payment-related state.
- Send Receipt → Schema: reads · Receipt function reads transaction context.
