How arunesh2407/ggnh works
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: appwrite.ts Appwrite client · App.tsx App routes · accessControlService.ts Access control service · inventoryService.ts Inventory service
Components 23
React Client
- Browser entry
src/main.tsx - App routes · Composes public, authentication, and staff routes.
src/App.tsx - Public layout
src/components/layout/PublicLayout.tsx - Staff layout
src/components/layout/StaffLayout.tsx - Public contact & booking · Sends email and may invoke SMS/WhatsApp webhooks.
Staff Operations
- Attendance context
src/context/AttendanceContext.tsx - Attendance service · Manages staff and attendance documents.
src/services/attendanceService.ts - Attendance views · Operational attendance and reporting views.
src/pages/AdminAttendance.tsx - Appointment service · Manages booked-to-completed appointment transitions.
src/services/appointmentService.ts - Staff appointments
src/pages/StaffAppointments.tsx
Identity & Access
- Staff route guard
src/components/ProtectedRoute.tsx - Auth session context · Enforces inactivity logout, session expiry, roles, and active status.
src/context/AuthContext.tsx - Access control service · Persists roles and account activation status.
src/services/accessControlService.ts - User access admin · Owners manage staff accounts.
src/pages/AdminUserAccess.tsx
Operational Data
- Inventory service · Inventory persistence and business operations.
src/services/inventoryService.ts - Item master & categories · Maintains item master data and categories.
src/pages/inventory/ItemMaster.tsx - Suppliers & receiving · Manages suppliers and stock receipts.
src/pages/inventory/Suppliers.tsx - Inventory operations & reports · Operational inventory dashboard and reports.
src/pages/inventory/InventoryHome.tsx - Appwrite client · Centralized Appwrite connectivity.
src/lib/appwrite.ts
External & Backend
- Firebase Auth · Email/password identities and authentication.
- Appwrite Database · Stores operational and access-control documents.
- Account deletion function · Deletes identity and associated access data with server credentials.
functions/src/deleteUserAccessAccount.ts - FormSubmit & webhooks
Connections 23
- 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