Skip to content

About

Alertify.ai combines real-time disaster alerts, AI-driven risk analysis, and emergency response tools to enable faster, smarter, and safer decision-making.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🚨 Alertify

Real-time disaster awareness & emergency SOS β€” in your pocket.

A mobile-first web app that keeps people informed during disasters with live alerts, an interactive map, AI-generated safety guidance, and a one-tap SOS flow β€” plus a responder dashboard for emergency teams to triage incoming requests.

Built with TanStack Start Cloudflare Workers Supabase Tailwind CSS v4


✨ Features

Feature What it does
πŸ—ΊοΈ Live disaster map Leaflet-based map showing alert zones, your location, and a personalized alert radius.
πŸ”” Real-time alerts feed Severity/distance filters, relative timestamps, and live updates via Supabase Realtime β€” no refresh needed.
πŸ†˜ One-tap SOS Signed-in users submit an SOS with severity, message, coordinates, and an optional photo (Supabase Storage).
πŸ€– AI safety guidance Alerts are turned into short, calm, actionable summaries by Groq (Llama 3.3 70B) via a secure server function.
πŸš‘ Responder dashboard Staff-only triage board: Active β†’ Reviewing β†’ Resolved, with AI-written situation notes.
πŸ” Full auth Email/password and Google OAuth through Supabase Auth, with automatic profile + preference creation.
βš™οΈ Personal preferences Alert radius, minimum severity, push/sound toggles, and location sharing β€” stored per user.
πŸ“² PWA notifications Installable web app with a service worker for background disaster notifications, including sound cues.
🌍 Geolocation-aware Distance-sorted alerts and user-position radius filtering everywhere it matters.

🧭 App screens

Route Screen
/ Home β€” live status dashboard
/map Interactive disaster map with alert zones
/alerts Real-time alert feed with filters
/sos Emergency SOS submission flow
/responder Staff-only emergency responder dashboard
/settings Account, preferences, sign out
/auth Sign in / sign up / Google OAuth

πŸ›  Tech stack

  • Framework β€” TanStack Start (React 19, file-based routing, SSR) with TanStack Router + Query
  • Hosting β€” Cloudflare Workers (SSR served from the edge via wrangler)
  • Backend β€” Supabase: Postgres, Auth, Realtime, Storage β€” no custom REST API needed
  • AI β€” Groq llama-3.3-70b-versatile behind a TanStack server function (API key never reaches the browser)
  • UI β€” Tailwind CSS v4, shadcn-style components on Radix primitives, Framer Motion, Lucide icons, Sonner toasts
  • Maps β€” Leaflet + react-leaflet (lazy-loaded client-side)
  • Notifications β€” Service worker (public/alertify-sw.js) + PWA manifest for push-style alerts and sounds

πŸ— How it works

flowchart TB
    subgraph browser [Browser]
        R[TanStack Router + React 19]
        SW[Service worker / PWA]
        SB[Supabase JS client]
    end
    subgraph cf [Cloudflare Worker]
        S[src/server.ts - Worker fetch handler]
        T[TanStack Start SSR]
        AI[Server function β†’ Groq AI]
    end
    subgraph supa [Supabase]
        DB[(Postgres + RLS)]
        RT[Realtime]
        ST[Storage - sos-images]
        AU[Auth]
    end
    User --> R
    R -->|"GET /route"| S --> T --> R
    R --> AI
    R <--> SB
    SB --> DB & RT & ST & AU
    SW -->|"notifications"| R
Loading
  1. The Worker receives GET /… and hands it to TanStack Start for SSR β€” HTML streams back, then the app hydrates.
  2. The browser talks to Supabase directly for reads, writes, auth, storage, and realtime subscriptions β€” protected by Row Level Security.
  3. AI summaries run through a server function so GROQ_API_KEY stays server-side.

πŸš€ Getting started

Prerequisites

  • Node.js 20+
  • A Supabase project
  • (Optional) A Groq API key for AI summaries

1. Clone & install

git clone https://github.com/animatrix01/alertify.ai.git
cd alertify.ai
npm install

2. Set up the Supabase database

Run the migrations against your Supabase project:

supabase link --project-ref <your-project-ref>
supabase db push

This creates all tables, RLS policies, triggers, enums, the sos-images storage bucket, and enables Realtime on disaster_alerts and sos_reports.

In the Supabase dashboard, also enable the Google OAuth provider if you want Google sign-in.

3. Configure environment variables

Create a .env file in the project root:

# Browser (Vite build-time)
VITE_SUPABASE_URL=https://<your-project-ref>.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=<your-anon-key>

# Server (SSR / Cloudflare Worker)
SUPABASE_URL=https://<your-project-ref>.supabase.co
SUPABASE_PUBLISHABLE_KEY=<your-anon-key>
GROQ_API_KEY=<your-groq-api-key>          # optional β€” app degrades gracefully without it

# Local dev only (service worker is disabled in dev by default)
VITE_ENABLE_SW=1

⚠️ SUPABASE_SERVICE_ROLE_KEY is supported for the server-only admin client (src/integrations/supabase/client.server.ts) and bypasses RLS β€” never expose it to the browser.

4. Add sample alerts (optional but recommended)

There is no automated ingestion pipeline yet β€” the disaster_alerts table only contains what you insert. To see the map and alerts feed populated, insert a few test rows (Supabase SQL editor or supabase db execute):

insert into public.disaster_alerts (type, severity, title, description, latitude, longitude, radius_km, source, expires_at) values
  ('flood',     'critical', 'Flash flood warning',       'Rapid water level rise along the river. Move to higher ground immediately.', 28.6139, 77.2090, 15, 'test', now() + interval '12 hours'),
  ('earthquake','warning',  'M5.4 seismic event',        'Moderate shaking reported. Check for structural damage before re-entering buildings.', 35.6895, 139.6917, 50, 'test', now() + interval '6 hours'),
  ('wildfire',  'advisory', 'Wildfire spreading NW',     'Smoke visible from town. Keep windows closed and monitor local guidance.', 37.7749, -122.4194, 25, 'test', now() + interval '24 hours');

They'll appear on the map and feed instantly thanks to the Realtime subscription.

5. Run it

npm run dev        # start the dev server

Open the printed local URL (typically http://localhost:5173) on desktop or a phone β€” the UI is mobile-first.

🧰 Troubleshooting

Symptom Cause & fix
Missing Supabase environment variable(s) thrown at startup One of VITE_SUPABASE_URL / VITE_SUPABASE_PUBLISHABLE_KEY isn't set. Copy .env.example β†’ .env and restart the dev server.
Map page blank or SSR error mentioning window Leaflet only runs in the browser β€” it's lazy-loaded on /map. If you add new map components, keep them client-only (mount after hydration).
No notification prompts / sounds in dev The service worker is disabled in dev so it doesn't fight HMR. Set VITE_ENABLE_SW=1 and restart.
Google sign-in fails or redirects to an error Enable the Google provider in Supabase Auth settings and add your app URL to the allowed redirect URLs.
Alerts feed is empty Nothing ingests alerts automatically β€” see step 4 to insert sample data.
AI summaries show the raw description GROQ_API_KEY isn't set (or is invalid). Without it the app degrades gracefully to the original alert text.

πŸ“¦ Scripts

Command What it does
npm run dev Start the Vite dev server
npm run build Production build (Cloudflare Worker output)
npm run build:dev Production build in development mode
npm run preview Preview the production build locally
npm run lint Run ESLint
npm run format Format with Prettier

☁️ Deploy to Cloudflare Workers

The repo is already wired for Workers (wrangler.jsonc β†’ main: src/server.ts):

npx wrangler deploy

Set your production environment variables (SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY, GROQ_API_KEY) as Worker secrets:

npx wrangler secret put SUPABASE_URL
npx wrangler secret put SUPABASE_PUBLISHABLE_KEY
npx wrangler secret put GROQ_API_KEY

πŸ—‚ Project structure

alertify.ai/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ routes/                 # File-based routes (/, /map, /alerts, /sos, /responder, /settings, /auth)
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ layout/             # AppShell, TopBar, BottomNav
β”‚   β”‚   β”œβ”€β”€ map/                # Leaflet disaster map
β”‚   β”‚   β”œβ”€β”€ notifications/      # Alert notification manager
β”‚   β”‚   β”œβ”€β”€ settings/           # Settings components
β”‚   β”‚   └── ui/                 # shadcn-style UI primitives
β”‚   β”œβ”€β”€ hooks/                  # Auth, geolocation, alerts, preferences, SOS, staff role…
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ ai/                 # Groq AI alert summaries (server function)
β”‚   β”‚   └── notifications/      # Service worker registration, sounds, dedupe, severity priority
β”‚   β”œβ”€β”€ integrations/supabase/  # Typed client, admin client, auth middleware, generated types
β”‚   β”œβ”€β”€ lib/                    # Utilities, SSR error handling
β”‚   β”œβ”€β”€ server.ts               # Cloudflare Worker entry
β”‚   β”œβ”€β”€ start.ts                # TanStack Start instance + server middleware
β”‚   └── styles.css              # Tailwind v4 + theme tokens
β”œβ”€β”€ supabase/migrations/        # SQL schema, RLS policies, triggers, realtime, storage
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ alertify-sw.js          # Service worker for notifications
β”‚   β”œβ”€β”€ manifest.webmanifest    # PWA manifest
β”‚   β”œβ”€β”€ sounds/                 # Alert sound cues
β”‚   └── images/
└── wrangler.jsonc              # Cloudflare Workers config

πŸ—ƒ Data model

Table Purpose Access
disaster_alerts Live disaster alerts (type, severity, location, radius, expiry) Public read, Realtime-enabled
sos_reports Emergency SOS submissions with status lifecycle Owner-only (RLS)
profiles User display name, avatar, phone, role Owner-only
user_preferences Alert radius, min severity, push/sound/location toggles Owner-only
emergency_contacts Personal emergency contact list Owner-only
sos-images (bucket) Optional SOS photo attachments Public read, owner write

Enums: alert_severity (info β†’ advisory β†’ warning β†’ critical), alert_type (earthquake, flood, wildfire, storm, tsunami, heatwave, landslide, other), sos_status (active β†’ acknowledged β†’ resolved / cancelled).

A handle_new_user trigger automatically creates a profile and default preferences for every new signup.

πŸ”’ Security notes

  • Row Level Security is enabled on every table β€” clients only ever read/write their own rows, and alerts are read-only.
  • The Groq API key lives only in a server function; the client gets the generated text back, never the key.
  • The service-role key is never shipped to the browser; use it only for trusted server-side operations.
  • Responder access is checked via the useStaffRole hook (email allow-list for the demo + profiles.role for future RBAC).

πŸ—Ί Roadmap ideas

  • Automated disaster-feed ingestion (USGS, GDACS, etc.) into disaster_alerts
  • Web Push for off-screen disaster notifications
  • Responder assignment + ETA tracking on active SOS reports
  • Emergency contacts integration into the SOS flow
  • Full RBAC UI for responder/admin management

πŸ“„ License

All rights reserved Β© 2026 Alertify.

πŸ“š Deep-dive documentation

For a full tour of how the codebase is wired β€” request flow, auth middleware, HTTP endpoints, and the mental model of every layer β€” see final project overview.md.


Built with ❀️ to help people stay safe when it matters most.

About

Alertify.ai combines real-time disaster alerts, AI-driven risk analysis, and emergency response tools to enable faster, smarter, and safer decision-making.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages