Skip to content

feat: Road Trip addon clean#268

Open
shanelord01 wants to merge 1 commit intomauriceboe:devfrom
shanelord01:road-trip-addon-clean
Open

feat: Road Trip addon clean#268
shanelord01 wants to merge 1 commit intomauriceboe:devfrom
shanelord01:road-trip-addon-clean

Conversation

@shanelord01
Copy link
Copy Markdown

Replaces #259 — previous PR included unrelated security/CI changes from my fork. This branch is clean: road trip addon only, rebased on current main. All code review feedback from #259 has been addressed.

Road Trip Addon

Adds a new admin-toggleable "Road Trip" addon for vehicle-based trip planning with OSRM road routing, fuel cost tracking, driving constraints, real stop finding, and historical route visualisation.

Route Planning

  • Per-leg and global trip toggle to mark travel as road trip (driven by vehicle)
  • Actual OSRM road routes on the map (solid blue polyline) replacing straight-line dashes
  • Server-side OSRM integration with configurable endpoint (OSRM_API_URL env var)
  • Speed-capped duration calculation using per-segment road speed data and user-configured max speed (e.g. for towing)
  • Turn-by-turn directions (major turns only) stored from OSRM steps data
  • Route recalculation on place reorder (2s debounce)
  • Full trip map button — zoom to fit all route legs across all days

Fuel & Range

  • Fuel cost per leg, per day, and trip totals based on tank size and consumption rate
  • Tank size → vehicle range auto-calculation
  • Range warnings when a leg exceeds vehicle range
  • Per-trip fuel price override (inline editable in summary panel, falls back to user default)
  • Fuel type preference (diesel/petrol) with Overpass query filtering
  • Brand preference (multi-select: Mobil, Ampol, BP, Shell, 7-Eleven) with preferred brand highlighting
  • Auto-sync fuel costs to trip Budget (single auto-managed entry, respects user dismissal)
  • Recalculate button for fuel and speed adjustments without re-calling OSRM

Real Stop Finder

  • Automatic fuel station and rest area search when marking a leg as road trip
  • Smart search points — fuel uses corridor sampling (every 150km), rest uses interval-based points
  • Dual data source: OpenStreetMap Overpass API (free, default) or Google Places (richer data, admin-configured API key)
  • Progressive radius expansion: 15km → 50km → 100km → 200km for remote/outback areas
  • Google → Overpass fallback when Google's 50km radius cap returns no results
  • 2km route polyline filtering — only shows stops actually on the road being travelled
  • Critical vs optional fuel stop classification using greedy range algorithm (only critical stops shown)
  • Overpass queries include amenity=fuel, shop=fuel, fuel:diesel=yes for Australian roadhouse coverage
  • Green markers with name, brand, rating, opening hours, and Google Maps link
  • Refresh button to re-search with updated settings

Driving Constraints

  • Daily driving time limit warnings
  • Rest break recommendations with map markers
  • Daylight driving mode with sunrise/sunset calculation per day/location
  • Recommended departure (sunrise + 30min) and arrival (sunset - 30min) times
  • Smart booking checks — only warns when existing check-out/check-in times are outside the safe window
  • One-click check-out/check-in time adjustment on accommodation bookings
  • Green confirmation when bookings are already within the daylight window
  • Insufficient daylight warnings when drive time exceeds available window

Navigation & Export

  • Turn-by-turn directions in PDF export (major turns with maneuver symbols, omitted for legs >800km)
  • Per-day driving summaries in PDF with leg breakdown, rest breaks, warnings
  • Trip total summary page in PDF
  • Expandable directions in day detail panel
  • Day detail popup includes full driving section with distance, time, fuel, daylight info

Historical Road Trip Atlas

  • New "Road Trips" tab in Atlas addon (requires both Atlas + Road Trip addons enabled)
  • Colour-coded historical routes across all completed trips (8-colour palette)
  • Trip legend with click-to-highlight and zoom-to-fit
  • Aggregate stats: total distance, trips, driving time, fuel spent, longest trip/day

User Settings

  • Unit system (metric/imperial) with dynamic labels throughout
  • Fuel tank size, consumption rate, fuel price and currency
  • Maximum speed (caps road speed estimates for towing/caravans)
  • Fuel type (diesel/petrol/any) and brand preference (multi-select)
  • Max driving hours per day, rest interval and duration
  • Daylight driving mode toggle
  • Stop search source (OpenStreetMap / Google Places)
  • Road preference (sealed/any) — stored for future custom OSRM profiles

Architecture & Code Quality

Addressed all feedback from #259:

  • Service layer: Split 1033-line roadtrip.ts monolith into three focused services (routingService.ts, fuelService.ts, stopSearchService.ts) + thin 250-line route handler
  • Timeouts: AbortController on all external calls — OSRM (15s), Overpass (45s), Google Places (10s)
  • Input validation: Coordinate bounds checking (-90/90, -180/180), parameter validation (legId, tripId, stop_type, search_points array)
  • Rate limiting: Overpass (2s between requests), Google Places (100ms between requests), OSRM (1s, existing)
  • Error handling: All empty catch {} blocks replaced with contextual console.error logging; Maps API key lookup failures logged
  • DRY: parseDirections()/dirSymbol() deduplicated into shared directionFormatters.ts
  • TypeScript: as any casts replaced with proper interfaces (OsrmResponse, OsrmRoute, OsrmStep, OverpassElement, GooglePlaceResult, etc.)
  • Named constants: Magic numbers extracted (SEARCH_RADII, ROUTE_PROXIMITY_THRESHOLD, CORRIDOR_SAMPLE_INTERVAL, OSRM_TIMEOUT_MS, etc.)
  • SQL: All queries parameterised throughout
  • Auth: requireAddon middleware + trip access checks on all endpoints

Implementation Details

  • Follows existing addon pattern: admin Addons panel toggle, isEnabled('roadtrip') gating throughout
  • Data: trip_route_legs table + existing settings key-value store + trip-level fuel price columns
  • No new npm dependencies: inline polyline decoder, solar calculator, Haversine/cross-track distance utilities
  • Server-side OSRM with IPv4 agent for Docker bridge networking
  • CSP updated for router.project-osrm.org and overpass-api.de
  • i18n: all 12 supported languages (en, de, es, fr, hu, nl, pt-BR, cs, ru, zh, it, ar)

New files

  • server/src/routes/roadtrip.ts — Thin route handlers with input validation
  • server/src/services/routingService.ts — OSRM integration, speed caps, directions
  • server/src/services/fuelService.ts — Fuel cost calculation, budget sync
  • server/src/services/stopSearchService.ts — Overpass/Google Places search, corridor search, filtering
  • client/src/store/roadtripStore.ts — Zustand store with route leg management
  • client/src/components/Map/RoadTripRoute.tsx — Route polyline, stop markers, refuel markers
  • client/src/components/Trip/RoadTripSummary.tsx — Summary panel with totals, per-day breakdown, inline fuel price editor
  • client/src/utils/roadtripFormatters.ts — Formatters, vehicle range, daylight driving calculators
  • client/src/utils/solarCalculation.ts — Sunrise/sunset calculator
  • client/src/utils/directionFormatters.ts — Shared direction parsing and symbols

Modified files

  • server/src/db/schema.tstrip_route_legs table + trip fuel price columns
  • server/src/db/seeds.tsroadtrip addon seed
  • server/src/index.ts — route registration + CSP entries
  • server/src/routes/atlas.ts — road trips history endpoint
  • client/src/api/client.tsroadtripApi
  • client/src/types.tsRouteLeg, RouteDirection, FoundStop, Trip interfaces + settings fields
  • client/src/pages/SettingsPage.tsx — Road Trip settings section
  • client/src/pages/TripPlannerPage.tsx — load/cleanup/reorder hooks
  • client/src/pages/AtlasPage.tsx — Road Trips tab
  • client/src/components/Planner/DayPlanSidebar.tsx — per-leg toggle, info, stops, daylight recommendations
  • client/src/components/Trip/DayDetailPanel.tsx — driving section with directions and daylight
  • client/src/components/Trip/TripPDF.tsx — driving summaries and directions in PDF
  • client/src/components/Map/MapView.tsx — per-segment rendering, full trip map button
  • client/src/components/Admin/AddonManager.tsx — Car icon
  • client/src/i18n/translations/*.ts — all 12 language files

Adds admin-toggleable Road Trip addon with OSRM road routing, fuel cost tracking,
driving constraints, real stop finder, and historical route visualisation.

Split into focused services: routingService, fuelService, stopSearchService.
All external calls have timeouts, input validation, and rate limiting.
Full i18n support across all 12 languages.

https://claude.ai/code/session_01Gbv3XcW64sYVptMTmcyW62
@mauriceboe mauriceboe changed the base branch from main to dev April 3, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants