# ashwinth2004/w2w-fitness-rehab architecture

> Architecture diagram of the GitHub repository ashwinth2004/w2w-fitness-rehab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashwinth2004/w2w-fitness-rehab
- Repository: https://github.com/ashwinth2004/w2w-fitness-rehab

## Overview

#### Purpose and runtime
W2W Fitness & Rehab is a Vite/React single-page clinic website combining public marketing, appointment booking, enquiries, and a single-admin CRM/dashboard. The browser app is hosted on Vercel; Firebase provides Auth and Firestore; Vercel serverless functions use Resend for email. Primary bootstraps are `src/main.jsx`, `src/App.jsx`, and `index.html`.

#### Public-site routing and presentation
`src/App.jsx` owns application routing between public pages, booking, and admin routes. Public content is organized as page-level views such as `src/pages/Home.jsx`, `src/pages/Appointment.jsx`, and `src/pages/Contact.jsx`, with shared navigation, SEO, and site chrome in `src/components/Navbar.jsx`, `src/components/Footer.jsx`, and `src/components/Seo.jsx`. Static crawl/PWA assets live under `public/`, including `public/sitemap.xml` and `public/sw.js`.

#### Booking and availability flow
Booking UI is split between reusable form/modal/slot components: `src/components/BookingForm.jsx`, `src/components/BookingModal.jsx`, and `src/components/SlotPicker.jsx`. Booking state is coordinated through `src/context/BookingContext.jsx`. The frontend Firestore layer in `src/lib/firestore.js` reads slot availability and persists bookings; availability records are intentionally public-write while appointment personal data is admin-protected by `firestore.rules`. Booking confirmation/email delivery crosses a backend boundary through `src/lib/email.js` to `api/send-enquiry.js`.

#### Enquiries and notification backend
Public enquiries originate in `src/components/EnquiryForm.jsx`, persist to Firestore, then invoke `api/send-enquiry.js`. This Vercel function is the Resend integration boundary and requires server-side email credentials. Scheduled reminder processing is separate in `api/send-reminders.js`; `vercel.json` configures its daily cron execution. Reminders use Firebase Admin credentials rather than browser Firebase access.

#### Authentication and admin boundary
Firebase client initialization is centralized in `src/firebase.js`. `src/context/AuthContext.jsx` establishes signed-in admin state, while `src/components/ProtectedRoute.jsx` gates dashboard access. Admin shell/navigation is defined by `src/pages/admin/AdminLayout.jsx`; entry and authentication are handled by `src/pages/admin/Login.jsx`. Firestore rules in `firestore.rules` enforce authenticated access to clinic data, with indexes declared in `firestore.indexes.json`.

#### Clinic operations and CRM
The dashboard composes operational modules: `src/pages/admin/Dashboard.jsx` for overview, `src/pages/admin/Appointments.jsx` for appointment lifecycle, and `src/pages/admin/Clients.jsx` / `src/pages/admin/ClientDetail.jsx` for patient records, notes, and progress. Additional care workflows are distinct modules in `src/pages/admin/Treatment.jsx`, `src/pages/admin/Rehab.jsx`, and `src/pages/admin/Fitness.jsx`. These pages consume the shared Firestore data layer rather than directly coupling UI to Firebase queries.

#### Reporting, content, and recovery
Client and monthly branded reports are generated client-side through `src/lib/pdf.js` and exposed via `src/pages/admin/Reports.jsx`; progress visualizations are rendered in dashboard/client views using Recharts. Admin-managed blog/review content is handled by `src/pages/admin/Content.jsx` and displayed through `src/pages/Blog.jsx` / `src/pages/BlogPost.jsx`. Operational Firestore backup/restore is an independent Node script subsystem: `scripts/backup.mjs`, `scripts/restore.mjs`, and `scripts/lib/admin.mjs`.

Main entry points: [`src/lib/firestore.js`](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/lib/firestore.js) (Firestore data layer), [`src/pages/admin/AdminLayout.jsx`](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/AdminLayout.jsx) (Admin shell & login), [`src/App.jsx`](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/App.jsx) (App routing), [`src/pages/Home.jsx`](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/Home.jsx) (Public pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public site"]
  node_public_pages["Public pages<br/>page views<br/>[Home.jsx]"]
  node_site_chrome["Site chrome &amp; SEO<br/>shared components<br/>[Navbar.jsx]"]
  node_static_assets["Crawl &amp; PWA assets<br/>public assets"]
end

subgraph group_booking["Booking &amp; enquiries"]
  node_booking_ui["Booking UI<br/>form components<br/>[BookingForm.jsx]"]
  node_booking_state["Booking state<br/>React context<br/>[BookingContext.jsx]"]
  node_enquiry_form["Enquiry form<br/>public form<br/>[EnquiryForm.jsx]"]
end

subgraph group_admin["Admin CRM"]
  node_auth_boundary["Admin auth gate<br/>[AuthContext.jsx]"]
  node_admin_shell["Admin shell &amp; login<br/>admin entry<br/>[AdminLayout.jsx]"]
  node_crm_modules["CRM care modules<br/>admin pages<br/>[Appointments.jsx]"]
  node_reporting["Reports &amp; progress<br/>admin reporting<br/>[Reports.jsx]"]
  node_content["Content management<br/>admin and public content<br/>[Content.jsx]"]
end

subgraph group_backend["Backend operations"]
  node_email_function{{"Enquiry email function<br/>Vercel serverless function<br/>[send-enquiry.js]"}}
  node_reminder_function{{"Daily reminder worker<br/>scheduled serverless function<br/>[send-reminders.js]"}}
  node_backup_restore["Firestore backup &amp; restore<br/>Node operations scripts<br/>[backup.mjs]"]
end

node_bootstrap(("Vite React bootstrap<br/>browser entry<br/>[main.jsx]"))
node_router["App routing<br/>SPA router<br/>[App.jsx]"]
node_firestore_layer["Firestore data layer<br/>frontend data access<br/>[firestore.js]"]
node_firebase_client{{"Firebase client<br/>Firebase initialization<br/>[firebase.js]"}}
node_firestore[("Cloud Firestore<br/>database")]
node_firestore_rules["Firestore access rules<br/>security policy<br/>[firestore.rules]"]

node_bootstrap -->|"mounts"| node_router
node_router -->|"routes to"| node_public_pages
node_router -->|"routes to"| node_booking_ui
node_router -->|"guards admin routes"| node_auth_boundary
node_public_pages -->|"uses"| node_site_chrome
node_public_pages -.->|"served with"| node_static_assets
node_booking_ui -->|"coordinates through"| node_booking_state
node_booking_state -->|"reads slots and saves bookings"| node_firestore_layer
node_enquiry_form -->|"persists enquiry"| node_firestore_layer
node_booking_ui -->|"sends confirmation"| node_email_function
node_enquiry_form -->|"sends notification"| node_email_function
node_firestore_layer -->|"uses"| node_firebase_client
node_firebase_client -->|"connects to"| node_firestore
node_firestore_rules -.->|"authorizes access"| node_firestore
node_auth_boundary -->|"authenticates with"| node_firebase_client
node_auth_boundary -->|"admits"| node_admin_shell
node_admin_shell -->|"hosts"| node_crm_modules
node_admin_shell -->|"hosts"| node_reporting
node_admin_shell -->|"hosts"| node_content
node_crm_modules -->|"uses shared data layer"| node_firestore_layer
node_reporting -->|"reads clinic data"| node_firestore_layer
node_content -->|"manages content in"| node_firestore_layer
node_reminder_function -->|"reads appointments"| node_firestore
node_backup_restore -->|"exports and restores"| node_firestore

click node_bootstrap "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/main.jsx"
click node_router "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/App.jsx"
click node_public_pages "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/Home.jsx"
click node_site_chrome "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/Navbar.jsx"
click node_booking_ui "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/BookingForm.jsx"
click node_booking_state "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/context/BookingContext.jsx"
click node_enquiry_form "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/EnquiryForm.jsx"
click node_firestore_layer "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/lib/firestore.js"
click node_firebase_client "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/firebase.js"
click node_firestore_rules "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/firestore.rules"
click node_auth_boundary "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/context/AuthContext.jsx"
click node_admin_shell "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/AdminLayout.jsx"
click node_crm_modules "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Appointments.jsx"
click node_reporting "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Reports.jsx"
click node_content "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Content.jsx"
click node_email_function "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/api/send-enquiry.js"
click node_reminder_function "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/api/send-reminders.js"
click node_backup_restore "https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/scripts/backup.mjs"

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_public_pages,node_site_chrome,node_static_assets toneBlue
class node_booking_ui,node_booking_state,node_enquiry_form toneAmber
class node_auth_boundary,node_admin_shell,node_crm_modules,node_reporting,node_content toneMint
class node_email_function,node_reminder_function,node_backup_restore toneRose
class node_bootstrap,node_router,node_firestore_layer,node_firebase_client,node_firestore,node_firestore_rules toneNeutral
```

## Components

### Public site

- [Public pages](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/Home.jsx): page views · Marketing, contact, and appointment views. · `src/pages/Home.jsx`
- [Site chrome & SEO](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/Navbar.jsx): shared components · `src/components/Navbar.jsx`
- **Crawl & PWA assets**: public assets · Includes sitemap and service worker.

### Booking & enquiries

- [Booking UI](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/BookingForm.jsx): form components · Form, modal, and slot picker. · `src/components/BookingForm.jsx`
- [Booking state](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/context/BookingContext.jsx): React context · `src/context/BookingContext.jsx`
- [Enquiry form](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/components/EnquiryForm.jsx): public form · `src/components/EnquiryForm.jsx`

### Admin CRM

- [Admin auth gate](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/context/AuthContext.jsx): auth context and route guard · Establishes admin state and protects dashboard routes. · `src/context/AuthContext.jsx`
- [Admin shell & login](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/AdminLayout.jsx): admin entry · Dashboard navigation and sign-in entry. · `src/pages/admin/AdminLayout.jsx`
- [CRM care modules](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Appointments.jsx): admin pages · Appointments, clients, treatment, rehab, and fitness workflows. · `src/pages/admin/Appointments.jsx`
- [Reports & progress](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Reports.jsx): admin reporting · Client/monthly PDFs and Recharts visualizations. · `src/pages/admin/Reports.jsx`
- [Content management](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/pages/admin/Content.jsx): admin and public content · Admin blog/reviews displayed on public blog pages. · `src/pages/admin/Content.jsx`

### Backend operations

- [Enquiry email function](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/api/send-enquiry.js): Vercel serverless function · Resend integration for enquiries and booking confirmations. · `api/send-enquiry.js`
- [Daily reminder worker](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/api/send-reminders.js): scheduled serverless function · Uses Firebase Admin credentials for reminders. · `api/send-reminders.js`
- [Firestore backup & restore](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/scripts/backup.mjs): Node operations scripts · Independent administrative recovery tooling. · `scripts/backup.mjs`

### Other components

- [Vite React bootstrap](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/main.jsx): browser entry · `src/main.jsx`
- [App routing](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/App.jsx): SPA router · Routes public, booking, and admin experiences. · `src/App.jsx`
- [Firestore data layer](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/lib/firestore.js): frontend data access · Shared booking and CRM persistence boundary. · `src/lib/firestore.js`
- [Firebase client](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/src/firebase.js): Firebase initialization · `src/firebase.js`
- **Cloud Firestore**: database · Stores availability, bookings, enquiries, and clinic records.
- [Firestore access rules](https://github.com/ashwinth2004/w2w-fitness-rehab/blob/main/firestore.rules): security policy · Public slot writes; clinic data requires authentication. · `firestore.rules`

## Connections

- Vite React bootstrap → App routing: mounts
- App routing → Public pages: routes to
- App routing → Booking UI: routes to
- App routing → Admin auth gate: guards admin routes
- Public pages → Site chrome & SEO: uses
- Public pages → Crawl & PWA assets: served with
- Booking UI → Booking state: coordinates through
- Booking state → Firestore data layer: reads slots and saves bookings
- Enquiry form → Firestore data layer: persists enquiry
- Booking UI → Enquiry email function: sends confirmation
- Enquiry form → Enquiry email function: sends notification
- Firestore data layer → Firebase client: uses
- Firebase client → Cloud Firestore: connects to
- Firestore access rules → Cloud Firestore: authorizes access
- Admin auth gate → Firebase client: authenticates with
- Admin auth gate → Admin shell & login: admits
- Admin shell & login → CRM care modules: hosts
- Admin shell & login → Reports & progress: hosts
- Admin shell & login → Content management: hosts
- CRM care modules → Firestore data layer: uses shared data layer
- Reports & progress → Firestore data layer: reads clinic data
- Content management → Firestore data layer: manages content in
- Daily reminder worker → Cloud Firestore: reads appointments
- Firestore backup & restore → Cloud Firestore: exports and restores
