A full-stack hiking trip optimizer that computes calorie expenditure, evaluates weather risk, generates packing lists, and performs gear weight minimization via dynamic programming.
- Trip Analytics: Advanced calorie estimation using modified Naismith's rule + MET-based adjustments
- Weather Risk Engine: Evaluates cold exposure, heat exposure, storm probability, and wind risk
- Auto-Generated Packing Lists: Intelligent gear suggestions based on trip parameters
- Gear Optimization: 0/1 Knapsack DP algorithm to maximize usefulness while minimizing weight
- Visualizations: Charts showing weight breakdown, calorie burn, and gear distribution
- Google OAuth: Secure authentication with NextAuth
- 10 Pre-loaded Trails: Including Yosemite, Inca Trail, John Muir Trail, and more
- Frontend: Next.js 14 (App Router), React, TypeScript, Tailwind CSS, Recharts
- Backend: Next.js API Routes, Node.js, TypeScript
- Database: MongoDB with Mongoose
- Authentication: NextAuth (Auth.js v5) with Google OAuth
- Validation: Zod schemas
- Node.js 18+
- MongoDB (local or Atlas)
- Google OAuth credentials
- Clone the repository:
git clone <repository-url>
cd TrailOpt- Install dependencies:
npm install- Set up environment variables:
cp .env.example .envEdit .env with your values:
MONGODB_URI=mongodb://localhost:27017/trailopt
NEXTAUTH_SECRET=your-secret-key-here
NEXTAUTH_URL=http://localhost:3000
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret- Generate NextAuth secret:
openssl rand -base64 32-
Set up Google OAuth:
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google
-
Start MongoDB (if running locally):
mongod- Run the development server:
npm run devTrailOpt/
├── app/ # Next.js App Router pages
│ ├── api/ # API routes
│ ├── auth/ # Authentication pages
│ ├── dashboard/ # Dashboard page
│ ├── trips/ # Trip management pages
│ └── gear/ # Gear inventory page
├── components/ # React components
│ ├── ui/ # Reusable UI components
│ └── layout/ # Layout components
├── lib/ # Utilities and configurations
│ ├── db/ # Database connection
│ ├── models/ # Mongoose models
│ ├── schemas/ # Zod validation schemas
│ ├── data/ # Static trail data
│ └── utils/ # Core algorithms
└── middleware.ts # Route protection
- Modified Naismith's rule for time estimation
- MET-based adjustments for pack weight and terrain
- Temperature-based energy expenditure adjustments
- Cold exposure scoring based on temperature thresholds
- Heat exposure penalties for high temperatures
- Storm probability based on elevation and location
- Wind risk assessment
- Rule-based gear suggestions
- Temperature-based insulation recommendations
- Distance-based water and food calculations
- Multi-day trip shelter requirements
- 0/1 Knapsack dynamic programming algorithm
- Maximizes priority/usefulness score
- Ensures essential items are always included
- Optimizes within weight constraints
POST /api/analytics- Calculate calorie estimates and fatigue scoresGET /api/weather-risk- Evaluate weather risk for a tripPOST /api/optimize-gear- Run knapsack optimization on gear listGET /api/trips- List user's tripsPOST /api/trips- Create a new tripGET /api/trips/[id]- Get trip detailsDELETE /api/trips/[id]- Delete a tripGET /api/gear- List user's gear itemsPOST /api/gear- Create a gear itemPUT /api/gear/[id]- Update a gear itemDELETE /api/gear/[id]- Delete a gear item
The following routes require authentication (handled by middleware):
/dashboard/trips/*/gear/*/optimize/*
The application follows a comprehensive design system with:
- Primary blue color scheme (#4B6BFF)
- Soft pastel accent colors
- Consistent spacing (4px multiples)
- Rounded corners (12-20px for cards)
- Subtle shadows (z1-z3 elevation)
- Inter font family
npm run build
npm startnpm run lint| Variable | Description | Required |
|---|---|---|
MONGODB_URI |
MongoDB connection string | Yes |
NEXTAUTH_SECRET |
Secret for JWT signing | Yes |
NEXTAUTH_URL |
Base URL of the application | Yes |
GOOGLE_CLIENT_ID |
Google OAuth client ID | Yes |
GOOGLE_CLIENT_SECRET |
Google OAuth client secret | Yes |
OPENWEATHER_API_KEY |
OpenWeather API key (optional) | No |
- GitHub account
- Vercel account
- MongoDB Atlas account (recommended for production)
-
Push to GitHub:
git init git add . git commit -m "Initial commit" git branch -M main git remote add origin https://github.com/yourusername/trailopt.git git push -u origin main
-
Deploy to Vercel:
- Go to vercel.com
- Click "New Project"
- Import your GitHub repository
- Configure environment variables (see below)
- Click "Deploy"
-
Environment Variables in Vercel: Add these in Vercel project settings → Environment Variables:
MONGODB_URI- Your MongoDB Atlas connection stringNEXTAUTH_SECRET- Generate with:openssl rand -base64 32NEXTAUTH_URL- Your Vercel deployment URL (e.g.,https://trailopt.vercel.app)GOOGLE_CLIENT_ID- Your Google OAuth client IDGOOGLE_CLIENT_SECRET- Your Google OAuth client secret
-
Update Google OAuth Redirect URI:
- Go to Google Cloud Console
- Update authorized redirect URI to:
https://your-domain.vercel.app/api/auth/callback/google
-
MongoDB Atlas Setup:
- Create a free cluster at MongoDB Atlas
- Create a database user
- Whitelist Vercel IPs (or use 0.0.0.0/0 for development)
- Copy connection string and use as
MONGODB_URI
Vercel will automatically detect Next.js and use these settings:
- Framework Preset: Next.js
- Build Command:
npm run build - Output Directory:
.next - Install Command:
npm install
MIT
Pranav