EcoTrack is a Next.js-based web application that helps users plan eco-friendly trips by analyzing and suggesting routes and transport modes with minimal carbon footprint. The system leverages Google Gemini AI for sustainability analysis and integrates with Google Maps for comprehensive route planning.
π Live Demo: EcoTrack on Cloud Run
- π± AI-Powered Route Planning - Gemini AI analyzes transport options for sustainability
- π Carbon Footprint Tracking - Real-time emissions calculations with comparison to car travel
- π° Fare Information - Actual transit ticket prices and cost comparisons
- π Travel Analytics Dashboard - Comprehensive metrics, trends, and insights
- π― AI-Generated Sustainability Targets - Monthly and yearly goals based on your travel patterns
- π± Responsive Neobrutalism Design - Bold, accessible UI that works on all devices
- π Secure Authentication - Google OAuth with NextAuth.js
- π Multi-Modal Transport - Car, train, bus, plane, bike, walking combinations
- πΊοΈ Interactive Maps - Route visualization with clickable polylines
- π Travel History - Save and track your completed trips
- π Real-Time Updates - Dashboard metrics update instantly when trips are saved
EcoTrack follows a modern serverless architecture built on Next.js 14+ with the App Router.
The application consists of three main layers:
- Frontend Layer - React 18 components with TypeScript, styled using Tailwind CSS with a custom Neobrutalism design system
- API Layer - Next.js API routes handling authentication, route planning, and user data management
- Service Layer - Integration services for Google Maps, Gemini AI, carbon calculations, and Firestore database operations
Trip Planning Flow:
User Input β Trip Planner Component β /api/routes/plan
β Gemini Service (orchestrator)
β Google Maps Service (parallel route fetching: driving, transit, walking, biking)
β Carbon Calculation Service (emissions & sustainability scoring)
β Gemini AI (sustainability analysis)
β Route Results Component (display with interactive map)
Save Trip & Analytics Flow:
User Saves Trip β /api/user/history (POST)
β Firestore Service (save trip, update metrics)
β Dashboard Component (GET /api/user/analytics)
β Real-time metric calculations (carbon saved, trips, trends)
β Updated dashboard display
For detailed architecture diagrams including sequence flows and component relationships, see the Mermaid diagrams section below.
- Frontend: React 18 with Next.js 14+ (App Router)
- Backend: Next.js API Routes (serverless)
- AI/ML: Google Gemini API for sustainability analysis
- Maps & Routing: Google Maps API (Routes, Places, Geocoding)
- Database: Cloud Firestore
- Authentication: NextAuth.js with Google OAuth
- Styling: Tailwind CSS with custom Neobrutalism design system
- TypeScript: Full type safety across the stack
- Testing: Jest with React Testing Library
- Deployment: Google Cloud Run with CI/CD
- Secret Management: Google Secret Manager
- Node.js 18+
- npm or yarn
- Google Maps API key
- Gemini API key
-
Clone the repository
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.local.example .env.local
Fill in your API keys in
.env.local:GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here GEMINI_API_KEY=your_gemini_api_key_here NEXTAUTH_SECRET=your_nextauth_secret_here -
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser
npm run build
npm startEcoTrack is designed to be deployed on Google Cloud Run with full CI/CD automation.
# Using the deployment script
./scripts/deploy.shPush to main branch to trigger automatic deployment via:
- β GitHub Actions
- β Google Cloud Build
For detailed deployment instructions, see DEPLOYMENT.md
- All secrets are managed via Google Secret Manager
- API keys must have proper restrictions configured
EcoTrack supports real-time bus/train routing powered by OpenTripPlanner APIs.
To enable:
- Set
OTP_BASE_URLin.env.local:
OTP_BASE_URL=https://your-otp-instance/otp/routers/default- Run
npm run devand use the Transit API:
curl -X POST http://localhost:3001/api/routes/transit \
-H "Content-Type: application/json" \
-d '{
"from": "40.7128,-74.0060",
"to": "40.7580,-73.9855"
}'For detailed setup instructions, see docs/transit-integration.md.
βββ app/ # Next.js App Router
β βββ api/ # API routes
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/ # React components
β βββ icons/ # Icon components
β βββ ui/ # UI components
β βββ TripPlanner.tsx # Trip planning form
β βββ RouteResults.tsx # Route results display
β βββ RouteCard.tsx # Individual route card
βββ lib/ # Utilities and services
β βββ services/ # External service integrations
β βββ constants.ts # App constants
β βββ env.ts # Environment variables
β βββ types.ts # TypeScript types
β βββ utils.ts # Utility functions
βββ next.config.js # Next.js configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
Required environment variables:
GOOGLE_MAPS_API_KEY: Google Maps API key for route planningGEMINI_API_KEY: Google Gemini API key for AI analysisNEXTAUTH_SECRET: Secret for NextAuth.js authentication
Optional environment variables:
FIREBASE_PROJECT_ID: Firebase project ID (for future database features)GOOGLE_CLIENT_ID: Google OAuth client ID (for future authentication)GOOGLE_CLIENT_SECRET: Google OAuth client secret (for future authentication)
GET /api/user/history- Get user's travel history with analyticsPOST /api/user/history- Save a completed tripGET /api/user/history/[tripId]- Get specific trip detailsDELETE /api/user/history/[tripId]- Delete a trip
GET /api/user/analytics- Comprehensive travel analyticsGET /api/user/insights- Personalized sustainability insightsGET /api/user/reports- Detailed sustainability reports
GET /api/user/goals- Get sustainability goals and progressPOST /api/user/goals- Create new sustainability goals
GET /api/user/profile- Get user profile and preferencesPUT /api/user/profile- Update user profile
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverageTest Coverage:
- β 38 passing tests
- API route testing
- Component testing
- Integration testing
EcoTrack uses a custom Neobrutalism design system:
- Bold, flat colors with black borders
- 8px offset shadows (
shadow-brutal) - All-caps typography
- High contrast for accessibility
- Mobile-first responsive design
- DEPLOYMENT.md - Complete deployment guide for Google Cloud Run system documentation
npm run dev- Start development server on http://localhost:3000npm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm test- Run test suitenpm run type-check- Run TypeScript type checking
-
UI disappears on load
- Cause: Missing API keys
- Solution: Check browser console for errors, verify
.env.localhas all required variables
-
"Google Maps API key is required"
- Cause:
NEXT_PUBLIC_GOOGLE_MAPS_API_KEYnot set - Solution: Set in
.env.localfor development or Secret Manager for production
- Cause:
-
Authentication issues
- Cause: OAuth credentials not configured
- Solution: Verify
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET, andNEXTAUTH_SECRET - Ensure redirect URIs include your domain in Google Cloud Console
-
No routes found
- Cause: Google Maps APIs not enabled or billing not set up
- Solution: Enable required APIs in Google Cloud Console and set up billing
-
Build fails with type errors
- Cause: TypeScript errors in code
- Solution: Run
npm run type-checkto identify issues
-
Tests failing
- Cause: API mocks not properly configured
- Solution: Check
jest.setup.jshas all required environment variables
The app includes built-in service status checking at /api/health. Missing configurations will show warnings in the UI rather than crashing.
# Run with debug logging
DEBUG=* npm run dev- Lighthouse Score: 95+ (Performance, Accessibility, Best Practices, SEO)
- Core Web Vitals: Optimized
- Bundle Size: < 500KB (gzipped)
- Time to Interactive: < 3s
- β API keys stored in Google Secret Manager (production)
- β Environment variables never committed to git
- β API key restrictions configured (HTTP referrers, API limits)
- β Secure authentication with NextAuth.js
- β HTTPS only in production
- β Content Security Policy headers
- β Regular dependency updates
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
- Run tests and linting
npm test npm run lint npm run type-check - Commit your changes
Follow Conventional Commits
git commit -m "feat: add amazing feature" - Push to your fork
git push origin feature/amazing-feature
- Open a Pull Request
- Use TypeScript for all new code
- Follow the Neobrutalism design system
- Write tests for new features
- Keep components small and focused
- Use meaningful variable names
- Comment complex logic
- Update documentation
- Google Gemini AI for sustainability analysis
- Google Maps Platform for routing data
- Next.js team for the amazing framework
- Open source community for inspiration
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ and β for a sustainable future π
