# arunesh2407/ggnh architecture

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

- Interactive diagram: https://gitdiagram.com/arunesh2407/ggnh
- Repository: https://github.com/arunesh2407/ggnh

## Overview

#### Purpose and Entry Points
G G Nursing Home Hub is a Vite/React TypeScript application for a nursing-home public site plus authenticated staff administration: attendance, appointments, user access, and inventory. Browser startup is `src/main.tsx`, with application routing/composition in `src/App.tsx`. Public and staff areas are separated by `src/components/layout/PublicLayout.tsx` and `src/components/layout/StaffLayout.tsx`.

#### Client Application Shell and Routing
`src/App.tsx` maps public marketing pages, appointment/contact flow, admin authentication, and staff operational pages. Shared navigation changes at the layout boundary: public pages use `src/components/Navbar.tsx`, while staff pages use `src/components/StaffNavbar.tsx`. `src/components/ProtectedRoute.tsx` is the principal client-side authorization gate for staff/admin routes.

#### Authentication and Access Governance
Firebase Authentication provides email/password login and registration. `src/context/AuthContext.tsx` owns session state, inactivity logout (30 minutes), hard session expiry (24 hours), and authorization context. Access roles and activation status are persisted in Appwrite through `src/services/accessControlService.ts`; roles are owner, editor, and viewer. Owners manage accounts in `src/pages/AdminUserAccess.tsx`; inactive users are blocked even after Firebase authentication.

#### Appwrite Operational Data Layer
Appwrite connectivity is centralized in `src/lib/appwrite.ts`; page components consume domain services rather than direct database calls. `src/services/attendanceService.ts` manages staff/attendance documents, `src/services/appointmentService.ts` manages appointment status transitions, and `src/services/accessControlService.ts` manages user-access records. This boundary permits future modules to add collections/services without coupling persistence to page UI.

#### Staff Operations
Attendance state is exposed through `src/context/AttendanceContext.tsx` and presented through `src/pages/AdminAttendance.tsx` and `src/pages/AdminAttendanceReport.tsx`. Editing is role-driven, with optional email-based editor restriction from environment configuration. Appointment staff workflow resides in `src/pages/StaffAppointments.tsx`, backed by the Appwrite appointment collection and its booked/completed status lifecycle.

#### Inventory Domain
Inventory is a separate staff subdomain with domain types in `src/types/inventory.ts` and persistence/business operations in `src/services/inventoryService.ts`. Its main functional stages are master data and categories (`src/pages/inventory/ItemMaster.tsx`, `src/pages/inventory/ItemCategories.tsx`), suppliers and stock receipt (`src/pages/inventory/Suppliers.tsx`, `src/pages/inventory/StockReceiving.tsx`), and operational/report views (`src/pages/inventory/InventoryHome.tsx`, `src/pages/inventory/InventoryReports.tsx`).

#### External Services and Deletion Boundary
Firebase Auth handles identities; Appwrite Database holds staff, attendance, appointments, and user-access documents. The public contact/appointment form sends email via FormSubmit and may invoke configured SMS/WhatsApp webhooks. Destructive account removal crosses trust boundaries through a Firebase callable function: frontend access-control code invokes the backend function defined in `functions/src/deleteUserAccessAccount.ts`, exported from `functions/src/index.ts`; it removes the Firebase account and associated Firestore/Appwrite access data using server-side credentials. Deployment/configuration surfaces include `appwrite.config.json`, `functions/package.json`, and `vercel.json`.

Main entry points: [`src/lib/appwrite.ts`](https://github.com/arunesh2407/ggnh/blob/main/src/lib/appwrite.ts) (Appwrite client), [`src/App.tsx`](https://github.com/arunesh2407/ggnh/blob/main/src/App.tsx) (App routes), [`src/services/accessControlService.ts`](https://github.com/arunesh2407/ggnh/blob/main/src/services/accessControlService.ts) (Access control service), [`src/services/inventoryService.ts`](https://github.com/arunesh2407/ggnh/blob/main/src/services/inventoryService.ts) (Inventory service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_main(("Browser entry<br/>Vite entry<br/>[main.tsx]"))
  node_app["App routes<br/>React router<br/>[App.tsx]"]
  node_public_layout["Public layout<br/>[PublicLayout.tsx]"]
  node_staff_layout["Staff layout<br/>[StaffLayout.tsx]"]
  node_public_contact["Public contact &amp; booking<br/>public flow"]
end

subgraph group_staff["Staff Operations"]
  node_attendance_context["Attendance context<br/>React context"]
  node_attendance_service["Attendance service<br/>domain service"]
  node_attendance_views["Attendance views<br/>staff pages"]
  node_appointment_service["Appointment service<br/>domain service"]
  node_staff_appointments["Staff appointments<br/>staff page"]
end

subgraph group_identity["Identity &amp; Access"]
  node_protected_route{{"Staff route guard<br/>authorization gate<br/>[ProtectedRoute.tsx]"}}
  node_auth_context["Auth session context<br/>React context<br/>[AuthContext.tsx]"]
  node_access_service["Access control service<br/>domain service"]
  node_user_access["User access admin<br/>staff page"]
end

subgraph group_data["Operational Data"]
  node_inventory_service["Inventory service<br/>domain service"]
  node_inventory_master["Item master &amp; categories<br/>inventory pages<br/>[ItemMaster.tsx]"]
  node_inventory_receiving["Suppliers &amp; receiving<br/>inventory pages<br/>[Suppliers.tsx]"]
  node_inventory_reporting["Inventory operations &amp; reports<br/>inventory pages<br/>[InventoryHome.tsx]"]
  node_appwrite_client[("Appwrite client<br/>data gateway<br/>[appwrite.ts]")]
end

subgraph group_backend["External &amp; Backend"]
  node_firebase_auth[("Firebase Auth<br/>identity provider")]
  node_appwrite_db[("Appwrite Database<br/>document database")]
  node_delete_function{{"Account deletion function<br/>Firebase callable function"}}
  node_formsubmit["FormSubmit &amp; webhooks<br/>messaging services"]
end

node_main -->|"mounts"| node_app
node_app -->|"public routes"| node_public_layout
node_app -->|"staff routes"| node_staff_layout
node_app -->|"guards staff routes"| node_protected_route
node_protected_route -->|"checks session and access"| node_auth_context
node_auth_context -->|"authenticates"| node_firebase_auth
node_auth_context -->|"loads role and activation"| node_access_service
node_access_service -->|"uses"| node_appwrite_client
node_user_access -->|"manages accounts"| node_access_service
node_access_service -->|"invokes destructive removal"| node_delete_function
node_delete_function -->|"deletes identity"| node_firebase_auth
node_delete_function -->|"removes access data"| node_appwrite_db
node_appwrite_client -->|"database API"| node_appwrite_db
node_attendance_views -->|"reads attendance state"| node_attendance_context
node_attendance_context -->|"loads and updates"| node_attendance_service
node_attendance_service -->|"uses"| node_appwrite_client
node_staff_appointments -->|"updates lifecycle"| node_appointment_service
node_appointment_service -->|"uses"| node_appwrite_client
node_inventory_master -->|"maintains master data"| node_inventory_service
node_inventory_receiving -->|"records stock receipts"| node_inventory_service
node_inventory_reporting -->|"queries operations"| node_inventory_service
node_inventory_service -->|"uses"| node_appwrite_client
node_public_contact -->|"submits notifications"| node_formsubmit

click node_main "https://github.com/arunesh2407/ggnh/blob/main/src/main.tsx"
click node_app "https://github.com/arunesh2407/ggnh/blob/main/src/App.tsx"
click node_public_layout "https://github.com/arunesh2407/ggnh/blob/main/src/components/layout/PublicLayout.tsx"
click node_staff_layout "https://github.com/arunesh2407/ggnh/blob/main/src/components/layout/StaffLayout.tsx"
click node_protected_route "https://github.com/arunesh2407/ggnh/blob/main/src/components/ProtectedRoute.tsx"
click node_auth_context "https://github.com/arunesh2407/ggnh/blob/main/src/context/AuthContext.tsx"
click node_access_service "https://github.com/arunesh2407/ggnh/blob/main/src/services/accessControlService.ts"
click node_user_access "https://github.com/arunesh2407/ggnh/blob/main/src/pages/AdminUserAccess.tsx"
click node_attendance_context "https://github.com/arunesh2407/ggnh/blob/main/src/context/AttendanceContext.tsx"
click node_attendance_service "https://github.com/arunesh2407/ggnh/blob/main/src/services/attendanceService.ts"
click node_attendance_views "https://github.com/arunesh2407/ggnh/blob/main/src/pages/AdminAttendance.tsx"
click node_appointment_service "https://github.com/arunesh2407/ggnh/blob/main/src/services/appointmentService.ts"
click node_staff_appointments "https://github.com/arunesh2407/ggnh/blob/main/src/pages/StaffAppointments.tsx"
click node_inventory_service "https://github.com/arunesh2407/ggnh/blob/main/src/services/inventoryService.ts"
click node_inventory_master "https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/ItemMaster.tsx"
click node_inventory_receiving "https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/Suppliers.tsx"
click node_inventory_reporting "https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/InventoryHome.tsx"
click node_appwrite_client "https://github.com/arunesh2407/ggnh/blob/main/src/lib/appwrite.ts"
click node_delete_function "https://github.com/arunesh2407/ggnh/blob/main/functions/src/deleteUserAccessAccount.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,node_app,node_public_layout,node_staff_layout,node_public_contact toneBlue
class node_attendance_context,node_attendance_service,node_attendance_views,node_appointment_service,node_staff_appointments toneAmber
class node_protected_route,node_auth_context,node_access_service,node_user_access toneMint
class node_inventory_service,node_inventory_master,node_inventory_receiving,node_inventory_reporting,node_appwrite_client toneRose
class node_firebase_auth,node_appwrite_db,node_delete_function,node_formsubmit toneIndigo
```

## Components

### React Client

- [Browser entry](https://github.com/arunesh2407/ggnh/blob/main/src/main.tsx): Vite entry · `src/main.tsx`
- [App routes](https://github.com/arunesh2407/ggnh/blob/main/src/App.tsx): React router · Composes public, authentication, and staff routes. · `src/App.tsx`
- [Public layout](https://github.com/arunesh2407/ggnh/blob/main/src/components/layout/PublicLayout.tsx): layout · `src/components/layout/PublicLayout.tsx`
- [Staff layout](https://github.com/arunesh2407/ggnh/blob/main/src/components/layout/StaffLayout.tsx): layout · `src/components/layout/StaffLayout.tsx`
- **Public contact & booking**: public flow · Sends email and may invoke SMS/WhatsApp webhooks.

### Staff Operations

- [Attendance context](https://github.com/arunesh2407/ggnh/blob/main/src/context/AttendanceContext.tsx): React context · `src/context/AttendanceContext.tsx`
- [Attendance service](https://github.com/arunesh2407/ggnh/blob/main/src/services/attendanceService.ts): domain service · Manages staff and attendance documents. · `src/services/attendanceService.ts`
- [Attendance views](https://github.com/arunesh2407/ggnh/blob/main/src/pages/AdminAttendance.tsx): staff pages · Operational attendance and reporting views. · `src/pages/AdminAttendance.tsx`
- [Appointment service](https://github.com/arunesh2407/ggnh/blob/main/src/services/appointmentService.ts): domain service · Manages booked-to-completed appointment transitions. · `src/services/appointmentService.ts`
- [Staff appointments](https://github.com/arunesh2407/ggnh/blob/main/src/pages/StaffAppointments.tsx): staff page · `src/pages/StaffAppointments.tsx`

### Identity & Access

- [Staff route guard](https://github.com/arunesh2407/ggnh/blob/main/src/components/ProtectedRoute.tsx): authorization gate · `src/components/ProtectedRoute.tsx`
- [Auth session context](https://github.com/arunesh2407/ggnh/blob/main/src/context/AuthContext.tsx): React context · Enforces inactivity logout, session expiry, roles, and active status. · `src/context/AuthContext.tsx`
- [Access control service](https://github.com/arunesh2407/ggnh/blob/main/src/services/accessControlService.ts): domain service · Persists roles and account activation status. · `src/services/accessControlService.ts`
- [User access admin](https://github.com/arunesh2407/ggnh/blob/main/src/pages/AdminUserAccess.tsx): staff page · Owners manage staff accounts. · `src/pages/AdminUserAccess.tsx`

### Operational Data

- [Inventory service](https://github.com/arunesh2407/ggnh/blob/main/src/services/inventoryService.ts): domain service · Inventory persistence and business operations. · `src/services/inventoryService.ts`
- [Item master & categories](https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/ItemMaster.tsx): inventory pages · Maintains item master data and categories. · `src/pages/inventory/ItemMaster.tsx`
- [Suppliers & receiving](https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/Suppliers.tsx): inventory pages · Manages suppliers and stock receipts. · `src/pages/inventory/Suppliers.tsx`
- [Inventory operations & reports](https://github.com/arunesh2407/ggnh/blob/main/src/pages/inventory/InventoryHome.tsx): inventory pages · Operational inventory dashboard and reports. · `src/pages/inventory/InventoryHome.tsx`
- [Appwrite client](https://github.com/arunesh2407/ggnh/blob/main/src/lib/appwrite.ts): data gateway · Centralized Appwrite connectivity. · `src/lib/appwrite.ts`

### External & Backend

- **Firebase Auth**: identity provider · Email/password identities and authentication.
- **Appwrite Database**: document database · Stores operational and access-control documents.
- [Account deletion function](https://github.com/arunesh2407/ggnh/blob/main/functions/src/deleteUserAccessAccount.ts): Firebase callable function · Deletes identity and associated access data with server credentials. · `functions/src/deleteUserAccessAccount.ts`
- **FormSubmit & webhooks**: messaging services

## Connections

- Browser entry → App routes: mounts
- App routes → Public layout: public routes
- App routes → Staff layout: staff routes
- App routes → Staff route guard: guards staff routes
- Staff route guard → Auth session context: checks session and access
- Auth session context → Firebase Auth: authenticates
- Auth session context → Access control service: loads role and activation
- Access control service → Appwrite client: uses
- User access admin → Access control service: manages accounts
- Access control service → Account deletion function: invokes destructive removal
- Account deletion function → Firebase Auth: deletes identity
- Account deletion function → Appwrite Database: removes access data
- Appwrite client → Appwrite Database: database API
- Attendance views → Attendance context: reads attendance state
- Attendance context → Attendance service: loads and updates
- Attendance service → Appwrite client: uses
- Staff appointments → Appointment service: updates lifecycle
- Appointment service → Appwrite client: uses
- Item master & categories → Inventory service: maintains master data
- Suppliers & receiving → Inventory service: records stock receipts
- Inventory operations & reports → Inventory service: queries operations
- Inventory service → Appwrite client: uses
- Public contact & booking → FormSubmit & webhooks: submits notifications
