# ynotfins/nfa-alerts-enterprise architecture

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

- Interactive diagram: https://gitdiagram.com/ynotfins/nfa-alerts-enterprise
- Repository: https://github.com/ynotfins/nfa-alerts-enterprise

## Overview

#### Purpose and active entry points
NFA Alerts Enterprise is an emergency-response monorepo. Its production implementation is a mobile-first Next.js PWA; Android and iOS are placeholders. Web UI enters through `apps/web/src/app/layout.tsx`, `apps/web/src/app/page.tsx`, and route groups under `apps/web/src/app/(auth)` and `apps/web/src/app/(dashboard)`. Server endpoints are Next route handlers under `apps/web/src/app/api`.

#### Runtime and deployment boundary
The active runtime is TypeScript/Next.js, deployed as a PWA with service workers and manifest assets in `apps/web/public/sw.js`, `apps/web/public/firebase-messaging-sw.js`, and `apps/web/public/manifest.json`. Deployment settings are in `apps/web/vercel.json`; repo automation includes `scripts/next-build.mjs` and `scripts/vps-deploy.sh`. Firebase project `nfa-alerts-v2` is the backend boundary.

#### Authentication, identity, and authorization
Firebase Auth-backed client/server authentication is separated into `apps/web/src/lib/auth-client.ts`, `apps/web/src/lib/server-auth.ts`, and `apps/web/src/contexts/auth-context.tsx`. The signup flow gathers credentials, profile, legal acceptance, and signature through `apps/web/src/app/(auth)/signup/page.tsx`, `apps/web/src/app/(auth)/signup/profile/page.tsx`, and `apps/web/src/app/(auth)/signup/signature/page.tsx`. Dashboard access and role-sensitive experience are organized beneath `apps/web/src/app/(dashboard)/layout.tsx`, with profile boundary logic in `apps/web/src/lib/profile-boundary.ts`.

#### Incident-response domain
Incidents are the primary operational workflow: listing/filtering, detail, homeowner information, documents/photos, and signing. Route composition lives under `apps/web/src/app/(dashboard)/incidents/page.tsx`, `apps/web/src/app/(dashboard)/incidents/[id]/layout.tsx`, and `apps/web/src/app/(dashboard)/incidents/[id]/sign/page.tsx`. Domain persistence and business operations are concentrated in `apps/web/src/services/incidents.ts`, with validation contracts in `apps/web/src/schemas/incident.ts` and document generation in `apps/web/src/lib/pdf-generator.ts`.

#### Realtime coordination and communications
Firestore/Firebase client integrations support profiles, live presence/location, chat, and notifications via `apps/web/src/lib/firebase.ts`, `apps/web/src/lib/firebase-db.ts`, and `apps/web/src/lib/db.ts`. Chat is exposed through `apps/web/src/app/(dashboard)/chat/[threadId]/page.tsx`, client state in `apps/web/src/hooks/use-chat.ts`, and service operations in `apps/web/src/services/chat.ts`. Chaser discovery and routing are separate dashboard capabilities in `apps/web/src/app/(dashboard)/chasers/page.tsx` and `apps/web/src/app/(dashboard)/route/page.tsx`; Google Maps is encapsulated by `apps/web/src/components/google-map.tsx`.

#### Ingestion, notifications, and external APIs
The externally sensitive ingestion boundary is `apps/web/src/app/api/webhook/route.ts`, supported by parsing, geocoding, and error modules in `apps/web/src/lib/webhook/parser.ts`, `apps/web/src/lib/webhook/geocoder.ts`, and `apps/web/src/lib/webhook/errors.ts`. Push delivery crosses Firebase Admin and FCM through `apps/web/src/lib/firebase-admin.ts`, `apps/web/src/app/api/notifications/send/route.ts`, and `apps/web/src/components/push-notification-provider.tsx`. Weather is served through `apps/web/src/app/api/weather/route.ts`.

#### Data governance and administration
Firebase is governed as infrastructure, not embedded solely in app code: Firestore rules/indexes and Storage rules are in `firebase/firestore.rules`, `firebase/firestore.indexes.json`, and `firebase/storage.rules`. Administrative user and location management live in `apps/web/src/app/(dashboard)/admin/users/page.tsx` and `apps/web/src/app/(dashboard)/admin/locations/page.tsx`; operational repair endpoints reside under `apps/web/src/app/api/admin`.

Main entry points: [`apps/web/src/lib/firebase.ts`](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/firebase.ts) (Firebase services), [`apps/web/src/app/(dashboard)/layout.tsx`](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/layout.tsx) (Dashboard boundary), [`apps/web/src/services/incidents.ts`](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/services/incidents.ts) (Incident operations), [`apps/web/src/app/layout.tsx`](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/layout.tsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js PWA"]
  node_app_shell["App shell<br/>Next.js entry<br/>[layout.tsx]"]
  node_auth_routes["Auth and signup<br/>route group<br/>[page.tsx]"]
  node_dashboard["Dashboard boundary<br/>route group<br/>[layout.tsx]"]
  node_pwa_assets["PWA runtime<br/>service worker<br/>[sw.js]"]
  node_auth_state["Auth state<br/>Firebase Auth client<br/>[auth-context.tsx]"]
  node_server_auth["Server auth<br/>auth verifier<br/>[server-auth.ts]"]
  node_webhook{{"Incident webhook<br/>API route<br/>[route.ts]"}}
  node_notifications["Push notifications<br/>API and provider<br/>[route.ts]"]
  node_admin["Administration<br/>dashboard and API<br/>[page.tsx]"]
end

subgraph group_domain["Operational workflows"]
  node_incidents_ui["Incidents UI<br/>dashboard routes<br/>[page.tsx]"]
  node_incident_service["Incident operations<br/>domain service<br/>[incidents.ts]"]
  node_incident_contracts["Incident contracts<br/>validation schema<br/>[incident.ts]"]
  node_pdf_generation["PDF generation<br/>document generator<br/>[pdf-generator.ts]"]
  node_chat["Realtime chat<br/>chat workflow<br/>[use-chat.ts]"]
  node_chaser_routing["Chaser routing<br/>dashboard capability<br/>[page.tsx]"]
end

subgraph group_backend["Firebase backend"]
  node_firebase[("Firebase services<br/>backend platform<br/>[firebase.ts]")]
  node_firebase_admin["Firebase Admin<br/>server SDK<br/>[firebase-admin.ts]"]
  node_firestore_governance["Firestore governance<br/>security rules<br/>[firestore.rules]"]
end

subgraph group_external["External integrations"]
  node_google_maps["Google Maps<br/>maps integration<br/>[google-map.tsx]"]
end

node_app_shell -->|"serves"| node_auth_routes
node_app_shell -->|"serves"| node_dashboard
node_app_shell -->|"installs"| node_pwa_assets
node_auth_routes -->|"signs in"| node_auth_state
node_auth_state -->|"uses Auth"| node_firebase
node_dashboard -->|"verifies access"| node_server_auth
node_server_auth -->|"verifies tokens"| node_firebase_admin
node_incidents_ui -->|"operates incidents"| node_incident_service
node_incident_service -->|"validates"| node_incident_contracts
node_incident_service -->|"generates documents"| node_pdf_generation
node_incident_service -->|"persists"| node_firebase
node_chat -->|"realtime data"| node_firebase
node_chaser_routing -->|"presence and locations"| node_firebase
node_chaser_routing -->|"renders routes"| node_google_maps
node_webhook -->|"creates or updates"| node_incident_service
node_notifications -->|"sends via FCM"| node_firebase_admin
node_firebase_admin -->|"admin access"| node_firebase
node_firebase -.->|"enforced by"| node_firestore_governance
node_admin -->|"manages data"| node_firebase
node_dashboard -->|"hosts"| node_incidents_ui
node_dashboard -->|"hosts"| node_chat
node_dashboard -->|"hosts"| node_chaser_routing

click node_app_shell "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/layout.tsx"
click node_auth_routes "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(auth)/signup/page.tsx"
click node_dashboard "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/layout.tsx"
click node_pwa_assets "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/public/sw.js"
click node_auth_state "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/contexts/auth-context.tsx"
click node_server_auth "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/server-auth.ts"
click node_incidents_ui "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/incidents/page.tsx"
click node_incident_service "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/services/incidents.ts"
click node_incident_contracts "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/schemas/incident.ts"
click node_pdf_generation "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/pdf-generator.ts"
click node_chat "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/hooks/use-chat.ts"
click node_chaser_routing "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/route/page.tsx"
click node_webhook "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/api/webhook/route.ts"
click node_notifications "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/api/notifications/send/route.ts"
click node_admin "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/admin/users/page.tsx"
click node_firebase "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/firebase.ts"
click node_firebase_admin "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/firebase-admin.ts"
click node_firestore_governance "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/firebase/firestore.rules"
click node_google_maps "https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/components/google-map.tsx"

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_app_shell,node_auth_routes,node_dashboard,node_pwa_assets,node_auth_state,node_server_auth,node_webhook,node_notifications,node_admin toneBlue
class node_incidents_ui,node_incident_service,node_incident_contracts,node_pdf_generation,node_chat,node_chaser_routing toneAmber
class node_firebase,node_firebase_admin,node_firestore_governance toneMint
class node_google_maps toneRose
```

## Components

### Next.js PWA

Primary production runtime.

- [App shell](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/layout.tsx): Next.js entry · `apps/web/src/app/layout.tsx`
- [Auth and signup](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(auth)/signup/page.tsx): route group · Collects credentials, profile, legal acceptance, and signature. · `apps/web/src/app/(auth)/signup/page.tsx`
- [Dashboard boundary](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/layout.tsx): route group · Enforces dashboard and role-sensitive experience. · `apps/web/src/app/(dashboard)/layout.tsx`
- [PWA runtime](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/public/sw.js): service worker · `apps/web/public/sw.js`
- [Auth state](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/contexts/auth-context.tsx): Firebase Auth client · `apps/web/src/contexts/auth-context.tsx`
- [Server auth](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/server-auth.ts): auth verifier · `apps/web/src/lib/server-auth.ts`
- [Incident webhook](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/api/webhook/route.ts): API route · External ingestion boundary with parsing and geocoding. · `apps/web/src/app/api/webhook/route.ts`
- [Push notifications](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/api/notifications/send/route.ts): API and provider · Sends FCM notifications to PWA clients. · `apps/web/src/app/api/notifications/send/route.ts`
- [Administration](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/admin/users/page.tsx): dashboard and API · Manages users, locations, and operational repairs. · `apps/web/src/app/(dashboard)/admin/users/page.tsx`

### Operational workflows

- [Incidents UI](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/incidents/page.tsx): dashboard routes · Lists, details, documents, and incident signing. · `apps/web/src/app/(dashboard)/incidents/page.tsx`
- [Incident operations](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/services/incidents.ts): domain service · `apps/web/src/services/incidents.ts`
- [Incident contracts](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/schemas/incident.ts): validation schema · `apps/web/src/schemas/incident.ts`
- [PDF generation](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/pdf-generator.ts): document generator · `apps/web/src/lib/pdf-generator.ts`
- [Realtime chat](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/hooks/use-chat.ts): chat workflow · UI state and service operations for incident communication. · `apps/web/src/hooks/use-chat.ts`
- [Chaser routing](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/app/(dashboard)/route/page.tsx): dashboard capability · Discovery and route planning for responders. · `apps/web/src/app/(dashboard)/route/page.tsx`

### Firebase backend

Project nfa-alerts-v2.

- [Firebase services](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/firebase.ts): backend platform · Auth, Firestore, Storage, presence, and FCM. · `apps/web/src/lib/firebase.ts`
- [Firebase Admin](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/lib/firebase-admin.ts): server SDK · `apps/web/src/lib/firebase-admin.ts`
- [Firestore governance](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/firebase/firestore.rules): security rules · Rules and indexes govern backend data access. · `firebase/firestore.rules`

### External integrations

- [Google Maps](https://github.com/ynotfins/nfa-alerts-enterprise/blob/main/apps/web/src/components/google-map.tsx): maps integration · `apps/web/src/components/google-map.tsx`

## Connections

- App shell → Auth and signup: serves
- App shell → Dashboard boundary: serves
- App shell → PWA runtime: installs
- Auth and signup → Auth state: signs in
- Auth state → Firebase services: uses Auth
- Dashboard boundary → Server auth: verifies access
- Server auth → Firebase Admin: verifies tokens
- Incidents UI → Incident operations: operates incidents
- Incident operations → Incident contracts: validates
- Incident operations → PDF generation: generates documents
- Incident operations → Firebase services: persists
- Realtime chat → Firebase services: realtime data
- Chaser routing → Firebase services: presence and locations
- Chaser routing → Google Maps: renders routes
- Incident webhook → Incident operations: creates or updates
- Push notifications → Firebase Admin: sends via FCM
- Firebase Admin → Firebase services: admin access
- Firebase services → Firestore governance: enforced by
- Administration → Firebase services: manages data
- Dashboard boundary → Incidents UI: hosts
- Dashboard boundary → Realtime chat: hosts
- Dashboard boundary → Chaser routing: hosts
