A Next.js application that uses A* pathfinding to plan optimal mountain hiking routes. The app analyzes elevation data, terrain complexity, and trail networks to generate safe, efficient routes with interactive visualization.
Experience the app at: https://legendary-guacamole-dusky.vercel.app
--- Click to expand ---
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend Layer (Next.js 15) β
β βββββββββββββββββ βββββββββββββββββββ βββββββββββββββββ β
β β Browser β β Mobile PWA β β Static Site β β
β β (Desktop) β β (Offline) β β (Export) β β
β βββββββββ¬ββββββββ βββββββββββ¬ββββββββ βββββββββ¬ββββββββ β
ββββββββββββΌβββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββ
β β β
ββββββββββββββββββββββ΄βββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β App Router β
β (src/app/layout.tsx) β
βββββββββββββββ¬ββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββ
β β β
βββββββββΌβββββββββ βββββββββββΌββββββββββ ββββββββββΌβββββββββ
β Main Route β β Dashboard β β Gallery β
β Planner β β /dashboard β β /gallery β
β (src/app/) β β (User Routes) β β (Public Routes) β
βββββββββ¬βββββββββ βββββββββββ¬ββββββββββ ββββββββββ¬βββββββββ
β β β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββ
β UI Components β
β ββββββββββ ββββββββββ ββββββββ β
β β Forms β β Maps β βChartsβ β
β ββββββββββ ββββββββββ ββββββββ β
β ββββββββββ ββββββββββ ββββββββ β
β β Auth β β PWA β β UI β β
β ββββββββββ ββββββββββ ββββββββ β
ββββββββββββββββββ¬βββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β Business Logic β
β β
β ββββββββββββββββββββββββββββ
β β A* Pathfinding Engine ββ
β β (src/lib/algorithms/) ββ
β β ββ
β β βββββββββββ βββββββββββ ββ
β β β Terrain β β Trail β ββ
β β βAnalyzer β βDetector β ββ
β β βββββββββββ βββββββββββ ββ
β ββββββββββββββββββββββββββββ
β β
β ββββββββββββββββββββββββββββ
β β State Management ββ
β β (Auth Context + Local) ββ
β ββββββββββββββββββββββββββββ
ββββββββββββββββ¬βββββββββββββββ
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββ
β β β
βββββββββΌβββββββββ βββββββββββΌββββββββββ ββββββββββΌβββββββββ
β External β β Supabase β β Map Services β
β APIs β β (Database) β β (Mapbox GL) β
β β β β β β
β ββββββββββββββ β β βββββββββββββββββ β β βββββββββββββββ β
β β Open-Meteo β β β β Users β β β β Interactive β β
β β(Elevation) β β β β Routes β β β β Maps β β
β ββββββββββββββ β β β Preferences β β β βββββββββββββββ β
β ββββββββββββββ β β βββββββββββββββββ β β βββββββββββββββ β
β βOpenStreetMapββ β β β β Terrain β β
β β (Trails) β β β βββββββββββββββββ β β β Layers β β
β ββββββββββββββ β β β Auth/Users β β β βββββββββββββββ β
ββββββββββββββββββ β β (Built-in) β β βββββββββββββββββββ
β βββββββββββββββββ β
βββββββββββββββββββββ- A* Algorithm Implementation: Pathfinding with heuristic cost calculation
- Terrain-Aware Routing: Factors in elevation gain, slope steepness, and terrain complexity
- Trail Integration: Uses OpenStreetMap trail data for route planning
- Multi-Modal Options: Support for trails-only, roads-only, or mixed routing
- Modular Architecture: Efficient spatial indexing and organized code structure
- Mapbox GL JS Integration: Interactive terrain maps
- Elevation Profiling: Elevation charts with gradient visualization
- Route Overlay: Color-coded route segments based on elevation and difficulty
- Responsive Design: Works on desktop and mobile
- Fallback Support: Static maps when interactive maps fail
- Authentication System: Secure user registration and login with Supabase
- Route Saving: Save optimized routes to personal collection
- Route Management: Organize routes with custom names, tags, and privacy settings
- Parameter Tuning: Adjustable settings for iterations, waypoints, and trail preferences
- Route Preferences: Configurable penalties and bonuses for different terrain types
- Example Routes: Pre-loaded routes for popular hiking destinations
- Linear Route Detection: Automatic detection and optimization for park/linear trails
- Fallback Strategies: Multiple strategies for robust route generation
- Trail Chaining: Connection of trail segments for optimal paths
- Cost Optimization: Hiking speed calculations using Tobler's function
- Node.js 18+ and npm
- Mapbox access token (free tier available)
-
Clone the repository
git clone <repository-url> cd alpine-route-optimizer
-
Install dependencies
npm install
-
Environment Setup Copy
.env.exampleto.env.localand fill in your values:cp .env.example .env.local
Required environment variables:
# Mapbox (required for maps) NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN=your_mapbox_public_token_here # Supabase (required for authentication and route saving) NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key_here
Get your tokens:
- Mapbox: mapbox.com (free tier available)
- Supabase: supabase.com (free tier available)
-
Start development server
npm run dev
-
Open your browser Navigate to http://localhost:3000
For production deployment, see the comprehensive DEPLOYMENT.md guide.
Quick deployment checklist:
- Configure environment variables in your hosting platform
- Deploy database tables to Supabase
- Test authentication and route saving functionality
Common hosting platforms:
- Vercel: Automatic deployment with GitHub integration
- Netlify: Easy static site deployment
- Railway/Render: Full-stack hosting options
- Framework: Next.js 15 with App Router and TypeScript
- Frontend: React 19 with hooks and context for state management
- Styling: Tailwind CSS v4 with semantic component architecture
- Mapping: Mapbox GL JS for interactive terrain visualization
- Backend: Supabase for authentication, database, and real-time features
- Database: PostgreSQL with Row Level Security (RLS) policies
- Testing: Jest with React Testing Library w/ coverage
- Authentication System: User registration, login, and session management
- Route Input Form: Coordinate input with validation and example routes
- Pathfinding Engine: Modular A* implementation with terrain analysis
- Interactive Map: Mapbox visualization with elevation-colored routes
- Elevation Chart: Profiling with gradient visualization
- Route Summary Card: Metrics display with integrated save functionality
- Save Route Button: Modal-based route saving with privacy controls
- Control Panel: Pathfinding parameter tuning and preferences
- Supabase: User authentication, route persistence, and real-time database
- Open-Meteo Elevation API: High-resolution elevation data for pathfinding
- OpenStreetMap Overpass API: Hiking trails and path network data
- Mapbox APIs: Interactive terrain visualization and geocoding services
npm run dev- Start development server with Turbopacknpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm test- Run Jest unit testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report
src/
βββ app/ # Next.js app router
βββ components/
β βββ forms/ # Input forms and validation
β βββ ui/ # Reusable UI components
β βββ semantic/ # Business logic components
βββ lib/
β βββ algorithms/ # Pathfinding implementation
β β βββ pathfinding/ # Modular pathfinding components
β βββ api/ # External API integrations
βββ types/ # TypeScript interfaces
βββ constants/ # UI text, styles, and colors
- Modular Design: Clean separation of concerns with focused modules
- Type Safety: TypeScript interfaces and strict typing
- Performance: Optimized algorithms with spatial indexing and caching
- Maintainability: Constants-based architecture for easy localization
- Adaptive Step Sizing: Variable resolution based on terrain complexity
- Trail Detection: Automatic snapping to established hiking paths
- Safety Considerations: Exponential penalties for dangerous slopes
- Multi-Objective Optimization: Balance distance, time, safety, and trail preference
- Trail Routes: Prioritize established hiking paths and trails
- Road Routes: Focus on roads and paved surfaces for accessibility
- Mixed Routes: Combination of trails and roads
- Linear Routes: Optimized for park environments and linear paths
- Elevation Gradient: Color-coded segments showing elevation changes
- Interactive Controls: Zoom, pan, and fullscreen map exploration
- Route Metrics: Distance, elevation gain, estimated time, and difficulty
- Core A pathfinding algorithm* with terrain analysis and Tobler's hiking function
- Interactive Mapbox GL JS mapping with elevation visualization and route overlay
- User authentication system with Supabase integration
- Route persistence - save, organize, and manage optimized routes
- Pathfinding controls and parameter tuning for customization
- Trail data integration with OpenStreetMap via Overpass API
- Modular architecture with clean separation of concerns and semantic components
- Responsive UI design with Tailwind CSS and professional styling
- Test coverage across all modules and components
- User dashboard for route management
- Public route gallery for community browsing
- Enhanced terrain analysis with weather integration
- Advanced multi-objective optimization