A modern, full-stack web application for monitoring real-time environmental data including weather conditions, air quality metrics, and historical trends for cities worldwide.
https://gsoc-assignm.vercel.app/
- User registration and login with JWT authentication
- Protected routes for authenticated users
- MongoDB-based user management
- Email domain validation (Gmail, Yahoo, Outlook, etc.)
- Secure password hashing with bcrypt
- Current Weather Data: Temperature, humidity, wind speed, pressure, visibility
- Air Quality Index (AQI): PM2.5, PM10, NO2, O3, SO2, CO levels
- Weather Forecasts: 24-hour temperature predictions
- Multi-City Support: Search and monitor any city worldwide
- Interactive charts using Chart.js
- Temperature trends over time
- Wind speed analysis
- Air quality metrics visualization
- Responsive metric cards with real-time updates
- Dark/Light Mode: Toggle between themes with persistent preferences
- Auto-Refresh: Configurable automatic data updates
- City Search: Intelligent location search with autocomplete
- Geolocation: Detect user's current location automatically
- Responsive Design: Optimized for desktop, tablet, and mobile devices
- Historical Data: View and analyze past environmental trends
- Custom React hooks for data management
- Context API for global state management
- Error handling with fallback mock data
- API caching for improved performance
- Loading states and error messages
- RESTful API architecture
- React 18.2 - UI library
- React Router 7.9 - Client-side routing
- Vite 5.0 - Build tool and dev server
- TailwindCSS 3.3 - Utility-first CSS framework
- Chart.js 4.4 - Data visualization
- Axios - HTTP client
- Node.js - Runtime environment
- Express 4.18 - Web framework
- MongoDB - NoSQL database
- Mongoose 8.0 - MongoDB ODM
- JWT - Authentication tokens
- bcryptjs - Password hashing
- CORS - Cross-origin resource sharing
- OpenWeatherMap API - Weather data and forecasts
- AQICN API - Air quality information
- Nominatim API - Geocoding and location search (free, no API key required)
- Node.js (v16 or higher)
- npm or yarn
- MongoDB Atlas account (or local MongoDB)
- OpenWeatherMap API key
- AQICN API key
git clone <repository-url>
cd gsoc_assignm_myInstall dependencies for both frontend and backend:
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm install
# Return to project root
cd ..Create environment files for both frontend and backend:
Backend .env file (in backend/ directory):
# MongoDB Connection String
MONGODB_URI=mongodb+srv://username:[email protected]/
# JWT Secret (change this in production)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
# Server Port
PORT=5002Frontend .env file (in frontend/ directory):
# OpenWeatherMap API Key
# Get yours at: https://openweathermap.org/api
VITE_OPENWEATHER_API_KEY=your_openweather_api_key
# AQICN Air Quality API Key
# Get yours at: https://aqicn.org/data-platform/token/
VITE_AQICN_API_KEY=your_aqicn_api_key
# Backend API URL
VITE_API_URL=http://localhost:5002/api
# Optional Configuration
VITE_DEFAULT_CITY=London
VITE_AUTO_REFRESH_INTERVAL=60000- Visit OpenWeatherMap
- Sign up for a free account
- Generate an API key
- Add to
.envfile
- Visit AQICN Data Platform
- Request a free API token
- Add to
.envfile
- Visit MongoDB Atlas
- Create a free cluster
- Get your connection string
- Add to
.envfile
You need to run both the backend and frontend servers. Open two terminal windows:
Terminal 1 - Backend Server:
cd backend
npm startTerminal 2 - Frontend Development Server:
cd frontend
npm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:5002
- API Health Check: http://localhost:5002/api/health
gsoc_assignm_my/
βββ backend/ # Backend server
β βββ server/ # Server source code
β β βββ models/ # MongoDB models
β β β βββ User.js # User schema
β β βββ routes/ # API routes
β β β βββ auth.js # Authentication endpoints
β β βββ index.js # Express server setup
β βββ .env # Backend environment variables
β βββ package.json # Backend dependencies
β βββ node_modules/ # Backend dependencies
βββ frontend/ # Frontend application
β βββ public/ # Static assets
β βββ src/ # Frontend source
β β βββ assets/ # Images and static files
β β βββ components/ # React components
β β β βββ Header.jsx
β β β βββ Navigation.jsx
β β β βββ Footer.jsx
β β β βββ CitySelector.jsx
β β β βββ MetricsGrid.jsx
β β β βββ ChartsGrid.jsx
β β β βββ StatusMessage.jsx
β β β βββ ThemeToggle.jsx
β β β βββ ProtectedRoute.jsx
β β β βββ history/
β β β βββ HistoricalDataPanel.jsx
β β βββ contexts/ # React Context providers
β β β βββ ThemeContext.jsx
β β β βββ AuthContext.jsx
β β β βββ CityContext.jsx
β β βββ hooks/ # Custom React hooks
β β β βββ useDashboardData.js
β β β βββ useHistoricalData.js
β β β βββ useAutoRefresh.js
β β βββ pages/ # Page components
β β β βββ Home.jsx
β β β βββ Login.jsx
β β β βββ Signup.jsx
β β β βββ Dashboard.jsx
β β β βββ HistoricalData.jsx
β β β βββ NotFound.jsx
β β βββ services/ # API services
β β β βββ apiService.js
β β βββ utils/ # Utility functions
β β β βββ mockData.js
β β β βββ historyUtils.js
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β β βββ index.css # Global styles
β βββ .env # Frontend environment variables
β βββ package.json # Frontend dependencies
β βββ vite.config.js # Vite configuration
β βββ tailwind.config.js # Tailwind configuration
β βββ node_modules/ # Frontend dependencies
βββ README.md # Project documentation
POST /api/auth/signup- Register new userPOST /api/auth/login- User loginGET /api/auth/verify- Verify JWT token
GET /api/health- Server status
Backend (run from backend/ directory):
npm start # Start backend serverFrontend (run from frontend/ directory):
npm run dev # Start Vite dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint- Real-time weather metrics display
- Air quality monitoring with color-coded indicators
- Interactive charts for temperature and wind trends
- Manual refresh and auto-refresh options
- City search with autocomplete
- Geolocation support
- View past environmental trends
- Temperature history charts
- Wind speed analysis
- Air quality trends over time
- Date range selection
- User signs up with name, email, and password
- Email domain validation ensures allowed providers
- Password is hashed before storage
- JWT token generated on successful login
- Token stored in localStorage
- Protected routes verify token before access
- Password hashing with bcrypt (10 salt rounds)
- JWT token-based authentication
- Protected API routes
- CORS configuration for allowed origins
- Email domain validation
- Secure password requirements (minimum 6 characters)
| Variable | Description | Required |
|---|---|---|
VITE_OPENWEATHER_API_KEY |
OpenWeatherMap API key | Yes |
VITE_AQICN_API_KEY |
AQICN API key | Yes |
MONGODB_URI |
MongoDB connection string | Yes |
JWT_SECRET |
Secret for JWT signing | Yes |
VITE_API_URL |
Backend API URL | Yes |
VITE_DEFAULT_CITY |
Default city on load | No |
VITE_AUTO_REFRESH_INTERVAL |
Auto-refresh interval (ms) | No |
Error: ERR_CONNECTION_REFUSED on port 5002
Solution: Make sure the backend server is running. Navigate to backend/ directory and run npm start
Warning: API key not configured, using mock data
Solution: Add valid API keys to your frontend/.env file
Error: MongoDB connection error
Solution: Check your MONGODB_URI in backend/.env and ensure your IP is whitelisted in MongoDB Atlas
# Clear cache and reinstall backend
cd backend
rm -rf node_modules package-lock.json
npm install
# Clear cache and reinstall frontend
cd ../frontend
rm -rf node_modules package-lock.json
npm install- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
Built with β€οΈ for smart city monitoring
- OpenWeatherMap for weather data API
- AQICN for air quality data
- Nominatim/OpenStreetMap for geocoding services
- Chart.js for data visualization
- TailwindCSS for styling utilities
For issues and questions:
- Open an issue on GitHub
- Check existing documentation
- Review API provider documentation
Note: This application uses free tier APIs. Rate limits may apply. For production use, consider upgrading to paid API plans.

