This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
CycleAlerts is a crowdsourced bicycle hazard mapping application for the Seattle/Bellevue area. Users can report, flag, and track cycling hazards in real-time using an interactive map interface. The application is built with SvelteKit and Firebase, using Mapbox GL for map visualization.
- Frontend: SvelteKit 2.0 + Svelte 4
- Map: Mapbox GL JS
- Backend: Firebase (Realtime Database + Auth)
- Hosting: Firebase Functions support (currently minimal usage)
- Build Tools: Vite
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm build
# Preview production build
npm run preview
# Format code
npm run format
# Lint code
npm run lintThe functions/ directory contains Firebase Cloud Functions setup, though currently minimal:
cd functions
npm run serve # Start emulator
npm run deploy # Deploy functions
npm run logs # View logsThe entire application is contained in src/routes/+page.svelte. This monolithic component handles:
- Firebase initialization and authentication (Google OAuth)
- Mapbox map initialization and management
- Hazard CRUD operations
- Real-time data synchronization
- Comment system for hazards
- Corridor/trail overlay visualization
Hazard Class (lines 85-103 in +page.svelte):
class Hazard {
constructor(id, longitude, latitude, name, description, status, confirmed, resolved, report_date, corridor, username)
}Hazard States:
status: 1= Active hazard (black marker)status: 0= Flagged/potentially resolved (red marker)confirmed= Vote count for "still present"resolved= Vote count for "not present"
/hazards/{hazardId}
- longitude, latitude
- name, description
- status, confirmed, resolved
- report_date, corridor
- username
/comments/{hazardId}/{commentId}
- username, date, comment
- timestamp
/users/{userId}
- contributions (count)
Required in .env (Vite format with VITE_ prefix):
VITE_FIREBASE_API_KEYVITE_FIREBASE_AUTH_DOMAINVITE_FIREBASE_DATABASE_URLVITE_FIREBASE_PROJECT_IDVITE_FIREBASE_STORAGE_BUCKETVITE_FIREBASE_MESSAGING_SENDER_IDVITE_FIREBASE_APP_IDVITE_FIREBASE_MEASUREMENT_IDVITE_MAPBOX_API_KEY
Located in src/lib/corridor_geojson/, these define bike corridors/trails:
- 520 trail, I-90 trail, Burke-Gilman Trail
- Lake Washington Loop sections
- Downtown Seattle/Bellevue corridors
- Various regional trails
Each corridor is loaded and rendered as a toggleable line layer on the map.
- Adding Hazards: Click map → Creates blue temporary marker → Fill form → Submit
- Viewing Hazards: Click marker → Opens floating window with details
- Flagging: Active hazards can be flagged (turns marker red)
- Voting: Flagged hazards allow "still present" / "not present" voting
- Comments: Authenticated users can add comments to any hazard
- Desktop (>768px): Sidebar on left (25% width), map on right (75% width)
- Mobile (≤768px): Top navigation bar, fullscreen map, bottom floating panels
The app uses Firebase's onValue() for real-time updates:
- Hazards are synced automatically (lines 368-396)
- Individual hazards update when modified (lines 377-390)
- Comments sync per-hazard (lines 180-200)
- User contributions track via reactive listener (lines 52-55)
All state is local to the Svelte component using reactive declarations:
$:reactive statements for derived state (lines 196-200, 471-477)- Window state controlled by
currentWindowOpenvariable - Selected hazard state in
selectedHazard
Markers stored in mapMarkers object keyed by hazard ID:
createMarker()function handles creation and click events (lines 159-178)- Markers removed/recreated on updates (lines 381-387)
- Temporary marker (
tempMarker) for new hazard placement
Predefined hazard types are in hazardTypes array (line 105). Update this to add/remove hazard categories.
- Add GeoJSON file to
src/lib/corridor_geojson/ - Add checkbox in sidebar HTML (around lines 520-547)
- Call
displayCorridor()in map's load event (lines 402-416) - Add to
corridorListarray (line 106)
User must be signed in to:
- Create hazards
- Add comments
- Flag hazards
- Vote on hazard status
- Delete own hazards
Check user variable for auth state throughout component.
Mobile view includes "add marker at current location" button (lines 625-631) that uses browser geolocation API.