How devgupta0910/disasterguard works
1. This repository is a React + TypeScript + Vite single-page application for emergency/disaster assistance. The app is designed to work in a mobile-style, field-use flow: capture evidence, run analysis, show guidance, and persist results for later review.
2. The UI is organized around a shared app shell in src/components/layout (Header, BottomNav, AppShell) and route-like pages in src/pages (HomePage, OnboardingPage, HistoryPage, SettingsPage). This suggests a tabbed/mobile navigation model rather than a multi-page server-rendered app.
3. The core product logic is split into feature domains:
- firstaid for first-aid scanning and results,
- hazard for safe-passage / hazard assessment,
- structure for structure scan and result review,
- water for water safety checks,
- family for matching and mesh-based family coordination.
Each domain has its own scan/check component plus a result component, which makes the architecture highly workflow-oriented.
4. Shared UI primitives in src/components/shared handle common interactions and presentation: camera capture, voice input, loading states, checklist items, guidance cards, and severity badges. These components are reused across the analysis workflows to keep the feature modules thin and consistent.
5. The input layer is browser/device driven. Hooks in src/hooks wrap camera access, geolocation, offline detection, and voice support (useCamera, useGeolocation, useOffline, useVoice). These hooks feed the feature workflows with sensor data and ambient context, especially for scan-based assessment and location-aware guidance.
6. Analysis appears to be AI-assisted and prompt-driven. src/lib/prompts/* contains task-specific prompts for each domain, while src/lib/model-router.ts and src/lib/gemma.ts suggest a routing layer that selects or invokes a model backend. Supporting utilities like imageUtils.ts and geo.ts likely preprocess visual and location inputs before analysis.
7. The app is built to function offline or in poor connectivity conditions. src/lib/db.ts provides local persistence, and src/lib/offline-queue.ts indicates queued work when network/model access is unavailable. The HistoryPage likely reads from this local store to show past assessments and outcomes.
8. There is a separate mesh/family coordination subsystem. src/context/MeshContext.tsx, src/lib/mesh.ts, src/lib/mesh-relay.ts, src/lib/family-matching.ts, and src/components/family/* indicate peer/device coordination for locating or matching family members, with server/relay.ts acting as the only explicit backend service in the tree.
9. Global app state is split between AppContext for general application state and MeshContext for mesh/network state. This keeps standard UI/navigation state separate from cross-device coordination and makes the architecture easier to diagram as two state domains.
10. The project is intentionally frontend-heavy and lightweight on infrastructure: Vite, React, TypeScript, ESLint, and a small TS relay server. Static assets live under public/, while server/relay.ts is the main non-browser component, likely supporting real-time or relay-based messaging for the mesh feature.
Main entry points: AppShell.tsx App shell · model-router.ts Model router · HomePage.tsx Home · FamilyMesh.tsx Family mesh
Components 33
UI shell
Navigation and page framing
- App · Bootstraps the React app and routes into the shell
src/App.tsx - App shell · Shared frame with header and bottom navigation
src/components/layout/AppShell.tsx - Header · Top-level app chrome
src/components/layout/Header.tsx - Bottom nav · Mobile-style primary navigation
src/components/layout/BottomNav.tsx - Home · Main dashboard entry for field workflows
src/pages/HomePage.tsx - Onboarding · Initial setup and guidance flow
src/pages/OnboardingPage.tsx - History · Past assessments and saved results
src/pages/HistoryPage.tsx - Settings · App preferences and configuration
src/pages/SettingsPage.tsx
Assessment flows
Domain workflows for scans, checks, and results
- First aid · Scan-based first aid assessment and guidance
src/components/firstaid/FirstAidScan.tsx - Aid result · Rendered outcome for first aid analysis
src/components/firstaid/FirstAidResult.tsx - Hazard check · Safe-passage and hazard assessment flow
src/components/hazard/SafePassage.tsx - Hazard result · Rendered outcome for hazard analysis
src/components/hazard/HazardResult.tsx - Structure scan · Structural assessment workflow
src/components/structure/StructureScan.tsx - Structure result · Rendered outcome for structure analysis
src/components/structure/StructureResult.tsx - Water check · Water safety evaluation flow
src/components/water/WaterCheck.tsx - Water result · Rendered outcome for water analysis
src/components/water/WaterResult.tsx
Shared UI
Reusable primitives used across workflows
- Shared UI · Common capture, guidance, and status components
src/components/shared/CameraCapture.tsx
State and hooks
Global state and device/browser integrations
- App context · General application state and coordination
src/context/AppContext.tsx - Mesh context · Mesh/network state for cross-device coordination
src/context/MeshContext.tsx - Device hooks · Camera, geolocation, offline, and voice integrations
src/hooks/useCamera.ts
Core logic
Persistence, routing, prompts, and preprocessing
- Local DB · Local storage for saved assessments and history
src/lib/db.ts - Offline queue · Queued work when connectivity or backend access is unavailable
src/lib/offline-queue.ts - Model router · Selects or dispatches requests to the model backend
src/lib/model-router.ts - Gemma · Model integration used by the analysis pipeline
src/lib/gemma.ts - Prompts · Task-specific prompts for each assessment domain
src/lib/prompts/firstaid-prompt.ts - Preprocess · Image and location preprocessing helpers
src/lib/imageUtils.ts
Mesh coordination
Peer matching and relay-based family coordination
- Family mesh · Peer coordination and family location flow
src/components/family/FamilyMesh.tsx - Match alert · Alerts when a family match is found
src/components/family/MatchAlert.tsx - Person card · Profile card for a family member or match
src/components/family/PersonCard.tsx - Mesh lib · Peer relay and family matching logic
src/lib/mesh.ts - Relay client · Client-side relay plumbing for mesh messaging
src/lib/mesh-relay.ts - Family match · Matching and coordination rules for family search
src/lib/family-matching.ts - Relay server · Lightweight backend relay supporting mesh coordination
server/relay.ts
Connections 47
- App → App shell: renders · App mounts the shared shell
- App shell → Header: includes · Shell composes the header
- App shell → Bottom nav: includes · Shell composes bottom navigation
- App shell → Home: hosts · Shell frames the main dashboard
- App shell → Onboarding: hosts · Shell frames onboarding
- App shell → History: hosts · Shell frames history
- App shell → Settings: hosts · Shell frames settings
- Home → First aid: launches · Home surfaces first-aid workflow
- Home → Hazard check: launches · Home surfaces hazard workflow
- Home → Structure scan: launches · Home surfaces structure workflow
- Home → Water check: launches · Home surfaces water workflow
- Home → Family mesh: launches · Home surfaces family coordination
- First aid → Aid result: outputs · Scan flow produces a result view
- Hazard check → Hazard result: outputs · Hazard flow produces a result view
- Structure scan → Structure result: outputs · Structure flow produces a result view
- Water check → Water result: outputs · Water flow produces a result view
- First aid → Shared UI: uses · Assessment UI reuses common primitives
- Hazard check → Shared UI: uses · Assessment UI reuses common primitives
- Structure scan → Shared UI: uses · Assessment UI reuses common primitives
- Water check → Shared UI: uses · Assessment UI reuses common primitives
- Family mesh → Match alert: uses · Mesh UI shows match notifications
- Family mesh → Person card: uses · Mesh UI renders people and matches
- App context → App shell: supports · General app state feeds the shell and pages
- Mesh context → Family mesh: supports · Mesh state drives coordination UI
- Device hooks → First aid: feeds · Camera and voice input support scans
- Device hooks → Hazard check: feeds · Location and offline state support checks
- Device hooks → Structure scan: feeds · Device context supports structure scans
- Device hooks → Water check: feeds · Device context supports water checks
- Device hooks → Family mesh: feeds · Geolocation and device capabilities support mesh use
- First aid → Model router: analyzes via · Assessment requests are routed to AI backends
- Hazard check → Model router: analyzes via · Assessment requests are routed to AI backends
- Structure scan → Model router: analyzes via · Assessment requests are routed to AI backends
- Water check → Model router: analyzes via · Assessment requests are routed to AI backends
- Model router → Gemma: dispatches · Router can invoke the Gemma integration
- Model router → Prompts: uses · Router applies domain prompts
- Model router → Preprocess: uses · Inputs are preprocessed before analysis
- Model router → Offline queue: falls back to · Work can be queued when offline or unavailable
- Aid result → Local DB: persists · Results are stored for later review
- Hazard result → Local DB: persists · Results are stored for later review
- Structure result → Local DB: persists · Results are stored for later review
- Water result → Local DB: persists · Results are stored for later review
- History → Local DB: reads · History page reads saved assessments
- Offline queue → Local DB: stores · Queued work can be retained locally
- Family mesh → Mesh lib: coordinates via · Coordination UI uses mesh logic
- Mesh lib → Relay client: transports via · Mesh logic uses relay transport
- Mesh lib → Family match: matches via · Family search uses matching rules
- Relay client → Relay server: connects to · Client relay talks to the server relay