Skip to content
VectorNguyenPublic

About

Tagalong — Ephemeral, privacy-first real-time group location & outing companion PWA with adaptive GPS, anti-spam separation alerts, multi-stop AI routes, offline IndexedDB backfill & 24h auto-purge.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

📍 Tagalong

Go out in crowded places. Nobody gets lost.

An ephemeral, privacy-first real-time group location & outing companion PWA — spin up a temporary group with a QR code, walk a shared multi-stop route, get smart anti-spam separation alerts, and watch all raw location data vanish automatically after 24 hours.

Live Demo Next.js 15 React 19 MapLibre GL Supabase PWA Ready TypeScript

Try Live Demo · Product Vision · Features · Engineering & Algorithms · Privacy & RLS · Quickstart & Deploy

SRS Specification · Figma Design · Stitch Project


💡 Why Tagalong?

Walking streets, music festivals, and night markets are electric — until someone lags behind at a street-food stall and disappears into the crowd.

Approach What goes wrong
Group chat apps "Where are you?" gets buried in noisy threads; static pins go stale the moment anyone walks 20 meters.
Always-on family trackers Too invasive for a single evening with friends — nobody wants permanent 24/7 surveillance just to hang out.
📍 Tagalong Ephemeral, session-scoped location sharing: join in 5 seconds with a 6-digit code or QR, stay together on one live dark map, and have every raw GPS coordinate & chat message purged automatically 24 hours after the outing ends.

🎮 Try It in 10 Seconds (Zero Setup)

Open tagalong-one.vercel.app and tap "Xem demo" — no sign-up, GPS permission, or backend required.

Demo group 482915 simulates 9 friends walking a 4-stop itinerary around Nguyễn Huệ Walking Street, Saigon, showcasing real-world edge cases live on the map:

  • 🚶 Separated member — drifts past the group's median radius and triggers a separation alert
  • 📶 Lost signal (stale) — no GPS heartbeat for > 60 seconds, clearly distinguished from live pins
  • 🚪 Left app (left_app) — tab backgrounded/closed without causing false separation spam
  • 🔋 Low battery — live battery status badge surfaced to the rest of the group

Running locally without .env? Open two browser tabs in the same group — Tagalong automatically syncs state across tabs in demo mode.


✨ Feature Deep-Dive

1. Ephemeral Group Sessions

  • Instant lobby & join: Create an outing with configurable auto-end duration (≤ 12 hours) and separation radius (50 m / 100 m / 200 m).
  • Zero-friction onboarding: Share a 6-digit code, QR code (qrcode.react), or direct invite link /s/<code>. Friends join with just a display name via Supabase Anonymous Auth (or optional Google Sign-In).
  • Hard group cap: Supports up to 20 members per session, enforced right inside PostgreSQL Row Level Security.

2. Live Map, Smart Presence & Pocket Mode

  • Dark-mode native map: Powered by MapLibre GL + CARTO Dark Matter vector/raster tiles with the custom "Tagalong Dark Pulse" visual language.
  • Honest presence states: Clearly differentiates live, stale ("Mất sóng" after 60 s), left_app, and hidden (user paused sharing) alongside live Battery Status.
  • Pocket Mode (Battery Saver): Uses the Screen Wake Lock API behind an OLED-friendly pure-black lock screen so GPS tracking stays alive in your pocket. Double-tap to wake.

3. Anti-Spam Separation Alerts

  • Computes the group's true center via the geometric median of live members — a single straggler can never skew the center.
  • Fires only when someone remains beyond the threshold for 30 continuous seconds (filtering out urban GPS jitter).
  • Built-in 5-minute cooldown per member (re-escalating immediately only if they drift +100 m further).
  • Combines an in-app alert banner, Browser Notification, and a "Call Back" nudge that triggers haptic vibration on the drifted member's phone.

4. Multi-Stop Route Planning & AI Suggestions

  • Interactive itinerary: Search places via Geoapify (Vietnamese-friendly confidence scoring) with Photon / OpenStreetMap fallback, set planned times & notes, and reorder stops on the fly.
  • One-sentence AI itinerary: Describe your vibe in one sentence → POST /api/suggest-route generates 3–5 geocoded stops using any OpenAI-compatible model (DeepSeek, Kimi/Moonshot, OpenRouter) or Anthropic Claude (gracefully falls back to a curated Saigon route when unconfigured).
  • Arrival geofencing & auto-advance: Tracks live members within 50 m of the active stop and automatically advances to the next stop once ≥ 80% of live members arrive.

5. Offline-First Resilience

  • When signal drops in dense crowds or underground passages, GPS continues recording into IndexedDB (tagalong / pending_locations).
  • Once connectivity returns, queued points are drained in chronological order and backfilled in batches to preserve an unbroken route history.

6. Real-Time Chat, Journey Recap & Installable PWA

  • In-session group chat: Real-time text messages, one-tap quick replies, and automated system event messages.
  • Post-outing Recap (/s/<code>/recap & public /r/<code>): Replay everyone's walked path, inspect outing stats, and export a shareable dark-map recap image (server-proxied via /api/static-map so the canvas stays untainted and API keys never leak).
  • Installable PWA: Full Web App Manifest (src/app/manifest.ts), dynamic SVG/PNG app icons (/icons/[size]), and Service Worker (public/sw.js).

🏗️ System Architecture

flowchart TB
  subgraph Client["Phone / Browser PWA (Next.js 15 + React 19 + MapLibre GL)"]
    UI["Tagalong Dark Pulse UI\n(Lobby · Live Map · Pocket Mode · Chat · Recap)"]
    HOOK["useLiveSession Hook"]
    CORE["Pure Domain Engine (src/lib/)\nadaptive · separation · stops · presence · geo"]
    IDB[("IndexedDB\nOffline GPS Queue")]
    APIS["Browser APIs\nGeolocation · Wake Lock · Battery · Vibration · Notifications"]
  end

  subgraph Server["Next.js App Router API (Vercel)"]
    AI_API["POST /api/suggest-route\n(AI + Geoapify / Photon · 10 req/IP/day)"]
    MAP_API["GET /api/static-map\n(Same-origin Geoapify Dark Proxy · 30 req/IP/day)"]
  end

  subgraph Backend["Supabase Cloud"]
    RT["Supabase Realtime\nLive Broadcast & Presence"]
    PG[("PostgreSQL + 100% RLS\n6 Tables · pg_cron 24h Auto-Purge")]
    AUTH["Supabase Auth\nAnonymous & Google OAuth"]
  end

  APIS --> HOOK
  HOOK <--> CORE
  HOOK <-->|"Offline buffer & backfill"| IDB
  HOOK <--> UI
  HOOK <--> RT
  HOOK <--> PG
  UI --> AUTH
  UI --> AI_API
  UI --> MAP_API
Loading

⚙️ Under the Hood — Geospatial Engine

All core algorithms live as deterministic, UI-independent pure functions under src/lib/ and are covered by 20 Vitest unit tests (src/lib/__tests__/logic.test.ts):

Module Core Algorithm & Constants Why it matters
adaptive.ts 4 s send interval when moving (≥ 0.7 m/s) or near edge (> 70% of threshold); 30 s when stationary; instant send on ≥ 15 m jump (min 2 s gap) Cuts battery & data drain while staying responsive when someone starts drifting
separation.ts Median group center · 30 s dwell debounce · 5 min cooldown · +100 m escalation · ignores stale / left_app / hidden Eliminates noisy false alarms from urban GPS drift and alert fatigue
stops.ts 50 m arrival geofence radius · auto-advance at ≥ 80% live member arrival · immutable moveStop reorder Keeps the itinerary moving smoothly without manual host babysitting
presence.ts 60 s heartbeat timeout (STALE_AFTER_MS) separating live, stale, left_app, hidden, unknown Gives friends honest signal visibility instead of frozen pins
offlineQueue.ts IndexedDB enqueue / chronological drain / pendingCount per session Preserves full outing path through temporary dead zones
placeMatch.ts Confidence-ranked Vietnamese geocoding match (Geoapify primary → Photon/OSM backup) Accurately resolves local landmarks & street-food spots from AI suggestions

🔐 Privacy by Design & Data Lifecycle

Tagalong enforces privacy at the database layer, not just in frontend UI code (supabase/migrations/0001_init.sql):

  • Row Level Security (RLS) enabled on all 6 tables:
    • sessions & stops — readable by code for joining; writable only by the session owner (public.is_owner).
    • members — self-join enforces < 20 active members and blocks joining ended sessions.
    • locations & messages — strictly scoped to verified members of that session (public.is_member).
    • recaps — public read via unique share_slug, containing only aggregated outing stats (never raw PII).
  • Automated 24-Hour Data Purge (pg_cron):
    • Hourly job (tagalong-retention, scheduled at minute :17 every hour) automatically marks expired sessions as ended and permanently deletes raw locations and messages 24 hours after ends_at.
  • Zero Client Secret Exposure:
    • AI keys (AI_API_KEY / ANTHROPIC_API_KEY) and GEOAPIFY_API_KEY exist exclusively in server-side Route Handlers with per-IP daily rate limits.

🗺️ Routes & Server Endpoints

Frontend Routes (src/app/)

Route Purpose
/ Landing screen + instant "Xem demo" entry
/login Display-name anonymous sign-in or Google OAuth
/home Join a session by 6-digit code, view active/recent outings
/create Create a new outing, configure radius/duration & build multi-stop route (with AI assist)
/s/[code] Live session: lobby, MapLibre live view, separation banners, chat & Pocket Mode
/s/[code]/recap Member recap with animated path replay & downloadable dark-map share card
/r/[code] Public read-only recap share page

Server API Routes (src/app/api/)

Method Endpoint Rate Limit Description
POST /api/suggest-route 10 req / IP / day Turns a 1-sentence outing prompt into 3–5 geocoded stops (OpenAI-compatible / Anthropic / Saigon sample fallback)
GET /api/static-map 30 req / IP / day Same-origin proxy to Geoapify Dark Matter Static Maps (24h cache) for untainted canvas recap exports

🛠️ Tech Stack

Layer Technologies
Framework & UI Next.js 15 (App Router) · React 19 · TypeScript (strict) · Tailwind CSS 4 · Zustand · @fontsource-variable/inter
Maps & Geocoding MapLibre GL 6 · CARTO Dark Matter tiles · Geoapify Geocoding & Static Maps · Photon / OpenStreetMap
Backend & Realtime Supabase (PostgreSQL, Realtime, Anonymous & Google Auth, Row Level Security, pg_cron)
AI Route Assistant Any OpenAI-compatible API (DeepSeek, Kimi/Moonshot, OpenRouter) or Anthropic Claude API
Native Web APIs Geolocation · Screen Wake Lock · Battery Status · Web Notifications · Vibration · IndexedDB · Service Worker
Quality & CI Vitest (20 unit tests) · ESLint 9 · TypeScript tsc --noEmit · GitHub Actions CI · Vercel

🚀 Getting Started

Local Development (Instant Demo Mode)

git clone https://github.com/VectorNguyen/tagalong.git
cd tagalong
npm install
npm run dev          # http://localhost:3000

predev and prebuild automatically copy the MapLibre Web Worker via scripts/copy-maplibre-worker.mjs. With no .env configured, demo mode works immediately out of the box.

Quality Checks

npm test                                    # 20 unit tests (geo, separation, stops, adaptive, presence)
npm run lint && npm run typecheck && npm run build

Environment Variables (.env.example)

Variable Scope Required Description
NEXT_PUBLIC_SUPABASE_URL Client + Server Multi-device Supabase Project URL (omit for browser demo mode)
NEXT_PUBLIC_SUPABASE_ANON_KEY Client + Server Multi-device Supabase anon public key
NEXT_PUBLIC_ENABLE_GOOGLE Client Optional Set 1 after enabling Google OAuth in Supabase
AI_API_KEY, AI_BASE_URL, AI_MODEL Server only Optional Any OpenAI-compatible endpoint (DeepSeek, Kimi, OpenRouter…)
ANTHROPIC_API_KEY, ANTHROPIC_MODEL Server only Optional Anthropic Messages API (fallback if AI_API_KEY is unset)
GEOAPIFY_API_KEY Server only Optional Vietnamese geocoding boost & dark basemap for recap image export
NEXT_PUBLIC_MAP_STYLE_URL Client Optional Custom MapLibre style URL (defaults to CARTO Dark Matter)
Step-by-step: Deploy Multi-Device Production (Vercel + Supabase)
  1. Import VectorNguyen/tagalong on Vercel and deploy — demo mode is live immediately.
  2. Create a Supabase project and execute supabase/migrations/0001_init.sql and supabase/migrations/0002_members_select_own.sql in order inside the SQL Editor.
  3. In Supabase → Authentication → Sign In / Providers, enable Anonymous Sign-Ins. Under URL Configuration, set Site URL to your Vercel domain and add https://<your-app>.vercel.app/** to Redirect URLs.
  4. Add NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY in Vercel → Project Settings → Environment Variables, then Redeploy.
  5. (Optional) Enable Google Login in Supabase and set NEXT_PUBLIC_ENABLE_GOOGLE=1.
  6. (Optional) Configure AI_API_KEY + AI_BASE_URL + AI_MODEL (or ANTHROPIC_API_KEY) for real AI route suggestions, and GEOAPIFY_API_KEY (free tier at myprojects.geoapify.com) for high-accuracy Vietnamese place search + dark-map recap exports.

📂 Project Structure

tagalong/
├── src/
│   ├── app/
│   │   ├── page.tsx, login/, home/, create/     # Onboarding & outing setup
│   │   ├── s/[code]/ & s/[code]/recap/          # Live session & member recap
│   │   ├── r/[code]/                            # Public recap share page
│   │   ├── api/suggest-route/ & api/static-map/ # Server-only AI & static map proxies
│   │   └── manifest.ts & icons/[size]/          # PWA manifest & generated app icons
│   ├── components/
│   │   ├── MapView.tsx, RouteEditor.tsx, RecapView.tsx, RegisterSW.tsx
│   │   └── live/                                # LiveScreen, Lobby, Overlays, Panels
│   ├── hooks/                                   # useLiveSession (core orchestrator), useProfile
│   └── lib/                                     # Pure geospatial/domain modules + 20 unit tests
├── supabase/migrations/                         # 6-table schema, RLS policies, 24h pg_cron cleanup
├── public/sw.js                                 # PWA Service Worker
├── scripts/copy-maplibre-worker.mjs             # MapLibre worker asset helper
└── docs/SRS.md                                  # Full Software Requirements Specification

🧭 Known Limitations & Product Roadmap

  • True Background GPS Tracking: Mobile browsers pause geolocation when the screen locks. v1 mitigates this via Pocket Mode (Wake Lock), IndexedDB offline backfill, and honest left_app states; native background tracking is planned via Capacitor (#36).
  • Web Push Notifications: Alert members even when the browser tab is closed (requires Add-to-Home-Screen on iOS Safari).
  • RLS-Scoped Private Realtime Channels: Upgrade from per-code broadcast channels to Supabase Realtime Authorization with private RLS channels.

👤 Author

Thắng Nguyễn · @VectorNguyen
Conceived, designed in Figma, specified (SRS), engineered, and shipped solo.


Map tiles © CARTO · Map data © OpenStreetMap contributors.

About

Tagalong — Ephemeral, privacy-first real-time group location & outing companion PWA with adaptive GPS, anti-spam separation alerts, multi-stop AI routes, offline IndexedDB backfill & 24h auto-purge.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages