A modern weather application built with React, Vite, and Tailwind CSS that demonstrates API integration capabilities. This project showcases real-time weather data fetching, local storage management, and responsive UI design.
- API Integration: Connects to OpenWeatherMap API for real-time weather data
- Mock Data Support: Includes demo mode with simulated weather data for testing
- Search Functionality: Search weather by city name with autocomplete suggestions
- Popular Cities: Quick access to weather for major Indian cities
- Search History: Stores and displays recent searches with local storage
- Temperature Conversion: Toggle between Celsius and Fahrenheit
- Responsive Design: Mobile-first design with Tailwind CSS
- Modern UI: Glass morphism effects and smooth animations
- Error Handling: Graceful error handling with user-friendly messages
User Input โ Search Form โ API Call โ Weather Data โ State Update โ UI Render
โ
Local Storage โ Search History โ Weather Response
App.jsx (Main container)
โโโ SearchForm.jsx (City input and popular cities)
โโโ WeatherCard.jsx (Weather display with temperature conversion)
โโโ LoadingSpinner.jsx (Loading state indicator)
โโโ ErrorMessage.jsx (Error handling display)
โโโ Search History (Stored searches with localStorage)
- Node.js (v16 or higher)
- npm or yarn
- Git
-
Clone the repository
git clone https://github.com/Kanchan3D/weather-app.git cd weather-app -
Install dependencies
npm install
-
Install Tailwind CSS
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
-
Configure Tailwind CSS Update
tailwind.config.js:/** @type {import('tailwindcss').Config} */ export default { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], }
-
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173
To use real weather data instead of mock data:
- Get a free API key from OpenWeatherMap
- Replace the demo API key in
src/App.jsx:const API_KEY = 'your_actual_api_key_here'
Create a .env file in the root directory:
VITE_WEATHER_API_KEY=your_openweathermap_api_keyThen update the API key usage in the code:
const API_KEY = import.meta.env.VITE_WEATHER_API_KEY || 'demo'- Search for Weather: Enter any city name in the search bar
- Quick Access: Click on popular Indian cities for instant weather data
- View Details: See temperature, humidity, wind speed, and pressure
- Convert Temperature: Click the temperature unit toggle (ยฐC/ยฐF)
- Browse History: View and revisit your recent searches
- Clear History: Remove all stored search history
- Endpoint:
https://api.openweathermap.org/data/2.5/weather - Method: GET
- Parameters:
q: City nameappid: API keyunits: metric (for Celsius)
- Realistic temperature ranges (5-35ยฐC)
- Random weather conditions (Clear, Clouds, Rain, Snow, Mist)
- Indian city mapping with proper country names
- Simulated wind speed and pressure data
- Glass Morphism: Modern translucent design elements
- Gradient Backgrounds: Beautiful blue gradient themes
- Responsive Grid: Adaptive layout for all screen sizes
- Smooth Animations: CSS transitions and hover effects
- Loading States: Visual feedback during API calls
- Error States: Clear error messages with retry options
weather-app/
โโโ public/
โ โโโ vite.svg
โ โโโ index.html
โโโ src/
โ โโโ components/
โ โ โโโ WeatherCard.jsx
โ โ โโโ SearchForm.jsx
โ โ โโโ ErrorMessage.jsx
โ โ โโโ LoadingSpinner.jsx
โ โโโ App.jsx
โ โโโ main.jsx
โ โโโ index.css
โโโ package.json
โโโ vite.config.js
โโโ tailwind.config.js
โโโ README.md
Run the application in different scenarios:
- Demo Mode: Default mode with mock data
- Real API: With actual OpenWeatherMap API key
- Error Handling: Try invalid city names
- Responsive Design: Test on different screen sizes
- Local Storage: Verify search history persistence
- Challenge: OpenWeatherMap free tier has request limits
- Solution: Implemented mock data system for development and demo purposes
- Challenge: Managing multiple states (loading, error, data, history)
- Solution: Used React hooks with clear state separation and proper cleanup
- Challenge: Persisting search history across sessions
- Solution: Implemented localStorage with JSON serialization and error handling
- Challenge: Creating a mobile-first responsive layout
- Solution: Used Tailwind CSS utility classes with responsive breakpoints
- Challenge: Real-time temperature unit conversion
- Solution: Implemented client-side conversion with state management
- 5-day weather forecast
- Geolocation-based weather
- Weather maps integration
- Push notifications for weather alerts
- Dark/light theme toggle
- Weather comparison between cities
- Export weather data as PDF/CSV
- Social sharing features
- Frontend Framework: React 18
- Build Tool: Vite
- Styling: Tailwind CSS
- API: OpenWeatherMap API
- Storage: Browser localStorage
- Icons: SVG icons
- Deployment: Ready for Vercel/Netlify
This project is open source and available under the MIT License.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Developer: Kanchan3D
- GitHub: @Kanchan3D
- Repository: weather-app
- OpenWeatherMap for providing the weather API
- Tailwind CSS for the utility-first CSS framework
- Vite for the fast build tool
- React team for the excellent framework
Built with โค๏ธ using React + Vite + Tailwind CSS