# garc-ia/sandy-yasmin-agendamento-flow architecture

> Architecture diagram of the GitHub repository garc-ia/sandy-yasmin-agendamento-flow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/garc-ia/sandy-yasmin-agendamento-flow
- Repository: https://github.com/garc-ia/sandy-yasmin-agendamento-flow

## Overview

##### Project Type and Purpose
- This is a serverless full-stack web application: a React/TypeScript Single-Page Application (SPA) for salon appointment booking and administration, backed by Supabase (Postgres + Auth + Edge Functions).
- The README confirms use of Vite, React, TypeScript, shadcn-ui, Tailwind CSS, and Supabase.

##### High-Level Architectural Components
a. Client Browsers
- Public users: book appointments, view services.
- Authenticated clients: manage their profile & view appointment history.
- Admin users: dashboard for managing salons, services, appointments, clients, WhatsApp templates, etc.
b. Static Hosting / CDN
- Vite builds static assets (HTML, JS, CSS) deployed to a CDN (e.g., Vercel, Netlify) via Lovable.
c. React SPA
- src/pages & src/components: UI layers, routing via React Router or Vite’s file-based router.
- Global state & context: auth-context.tsx, theme-context.tsx, AppointmentDialogContext, etc.
- Custom hooks for business logic, data fetching, and mutation (src/hooks, src/components/appointment/context/hooks).
d. API & Data Layer
- Supabase client (src/integrations/supabase/client.ts) for Auth, Realtime, and Database (CRUD).
- Supabase Edge Functions (./supabase/functions) for server-side logic (auto-complete, reset appointments).
e. Database
- Supabase Postgres: tables for appointments, clients, professionals, services, reviews, WhatsApp templates, etc.
f. External Services
- WhatsApp integration via utility functions (src/lib/whatsappUtils.ts).
- Optional custom domains via Lovable.

##### Relationships and Data Flows
- Browser ↔ Static CDN: initial asset load (index.html, bundled JS/CSS).
- React SPA ↔ Supabase Auth API: sign-in, sign-up, session management.
- React SPA ↔ Supabase Postgres: queries (appointments, clients, services) and mutations through the JS client.
- React SPA ↔ Supabase Edge Functions: special RPC (auto-complete, reset) invoked over HTTP.
- Real-time subscriptions: React SPA listens to database changes (e.g., appointment status updates).
- Business logic encapsulated in custom hooks and context providers.

##### Architectural Patterns & Design Principles
- Component-based UI with a clear directory split: admin, appointment, auth, client-area, shared, ui primitives.
- Separation of concerns: UI components (src/components), pages (src/pages), business logic (src/hooks), data integrations (src/integrations), and utilities (src/lib, src/utils).
- Context providers for cross-cutting concerns (auth, theme, dialogs).
- Atomic/design system approach via shadcn-ui primitives in src/components/ui.
- Serverless functions for backend logic without managing servers.

##### Essential Details
- Supabase Auth and Database as separate services.
- Both static hosting and serverless function deployment.
- Real-time data path for live appointment updates.
- Atomic component system in the UI layer.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and CDN
    Browser["Browser (Public, Client, Admin)"]:::ui
    CDN["CDN / Static Hosting\n(Vite Build)"]:::ui
    Browser -->|"Fetch assets"| CDN
    CDN -->|"Serve SPA"| SPA

    %% SPA Entry
    SPA["React SPA\n(React + Vite + Tailwind)"]:::ui

    %% UI Layer
    subgraph "UI Layer"
        Pages["Pages\n(src/pages)"]:::ui
        Components["Components\n(src/components)"]:::ui
        Primitives["UI Primitives\n(src/components/ui)"]:::ui
        AdminComponents["Admin Dashboard\n(src/components/admin & src/pages/admin)"]:::ui
    end
    SPA --> Pages
    SPA --> Components
    SPA --> Primitives
    SPA --> AdminComponents

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Context["Context Providers\n(Auth, Theme, AppointmentDialog)"]:::ui
        Hooks["Custom Hooks\n(src/hooks & appointment hooks)"]:::ui
    end
    SPA --> Context
    Context --> Hooks

    %% Integrations and Data Services
    subgraph "Data & API Layer"
        SupabaseClient["Supabase JS Client\n(src/integrations/supabase/client.ts)"]:::data
        SupabaseTypes["Supabase Types\n(src/integrations/supabase/types.ts)"]:::data
        SupabaseAuth["Supabase Auth"]:::data
        SupabaseDB["Supabase Postgres"]:::data
    end
    Hooks -->|"Supabase SDK calls"| SupabaseClient
    SupabaseClient --> SupabaseAuth
    SupabaseClient --> SupabaseDB
    SupabaseClient --> SupabaseTypes

    %% Serverless Functions
    subgraph "Edge Functions (TypeScript)" 
        AutoComplete["Auto-Complete Appointments"]:::func
        ResetAppointments["Reset Appointments"]:::func
    end
    SPA -->|"RPC call (HTTP)"| AutoComplete
    SPA -->|"RPC call (HTTP)"| ResetAppointments
    AutoComplete --> SupabaseDB
    ResetAppointments --> SupabaseDB

    %% Real-time Subscription
    SupabaseDB -->|"Realtime subscription"| SPA

    %% External Services
    WhatsApp["WhatsApp Service"]:::ext
    SPA -->|"HTTP API"| WhatsApp
    AutoComplete -->|"Utility call"| WhatsApp

    %% Utilities
    Utils["Utilities\n(src/lib)"]:::ext
    WhatsAppUtils["WhatsApp Utils\n(src/lib/whatsappUtils.ts)"]:::ext
    SPA --> Utils
    SPA --> WhatsAppUtils

    %% Click Events
    click CDN "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/index.html"
    click CDN "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/vite.config.ts"
    click SPA "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/main.tsx"
    click SPA "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/App.tsx"
    click Pages "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/pages"
    click Components "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/components"
    click Primitives "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/components/ui"
    click AdminComponents "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/components/admin"
    click AdminComponents "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/pages/admin"
    click Context "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/components/appointment/context/AppointmentDialogContext.tsx"
    click Hooks "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/components/appointment/context/hooks"
    click Context "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/context/auth-context.tsx"
    click Context "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/context/theme-context.tsx"
    click Hooks "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/hooks"
    click SupabaseClient "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/integrations/supabase/client.ts"
    click SupabaseTypes "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/integrations/supabase/types.ts"
    click AutoComplete "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/supabase/functions/auto-complete-appointments/index.ts"
    click AutoComplete "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/supabase/functions/auto-complete-appointments/utils.ts"
    click ResetAppointments "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/supabase/functions/reset-appointments/index.ts"
    click WhatsAppUtils "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/blob/main/src/lib/whatsappUtils.ts"
    click Utils "https://github.com/garc-ia/sandy-yasmin-agendamento-flow/tree/main/src/lib"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef data fill:#DFFFD0,stroke:#228B22,color:#228B22;
    classDef func fill:#FFE0B2,stroke:#FF8C00,color:#FF8C00;
    classDef ext fill:#F0F0F0,stroke:#808080,color:#808080;
```
