Full-stack Weatherstack client with a React + Vite frontend and an Express proxy backend. The app keeps the Weatherstack API key on the server while delivering a rich dashboard for multiple locations, current conditions, 5-day forecasts, air quality, and detailed metrics.
git clone <repo-url>Install dependencies separately for backend and frontend.
Backend
cd world-weather
cd backend
npm installFrontend
cd world-weather
cd frontend
npm install- In
backend, copy.env.example→.env. - Set
WEATHERSTACK_API_KEY(required) plus optional overrides likeWEATHERSTACK_BASE_URLandWEATHERSTACK_TIMEOUT_MS. - In
frontend, copy.env.example→.envand setVITE_API_BASE_URL(defaulthttp://localhost:4000).
Backend
cd backend
npm run devFrontend
cd frontend
npm run devVisit http://localhost:5173 (Vite default) with the backend running on http://localhost:4000.
- Queries Weatherstack via backend proxy (
/api/weather/{endpoint}) keeping the API key server-side. - Attempts 5-day forecast first; falls back to current conditions with synthetic forecast generation.
- Graceful degradation to sample data when offline or rate-limited.
- Preset cities plus add/search/remove custom locations.
- LocalStorage persistence and quick switching.
- Current weather snapshot with feels-like, wind, humidity, visibility, UV.
- 5-day forecast strip with icons and highs/lows.
- Air quality breakdown (PM2.5, PM10, O₃) with EPA index status.
- Additional details: sunrise, sunset, moon phase, precipitation, chance of rain.
- Unit toggle (°F/°C) and status messaging (online/partial/sample).
- In-memory cache with TTL to avoid duplicate fetches.
- Inline status/error messaging and sample payload fallback.
- Health check endpoint (
/health) for backend readiness.
- Node.js with Express
- Axios for Weatherstack calls
- CORS enabled for local dev
- React 18 with Hooks
- Vite for dev/build
- Tailwind CSS for styling
GET http://localhost:4000/api/weather/{endpoint}?query={location}&...
Parameters:
endpoint(optional) – defaults tocurrent; supportsforecast,historical, etc.- Other query params are forwarded (e.g.,
query,forecast_days,hourly,units,language).
Response:
- JSON payload from Weatherstack with errors normalized when missing keys.
- User selects or searches a location.
- Frontend requests
/api/weather/forecast(withforecast_days,hourly). - If forecast fails, frontend retries
/api/weather/currentand synthesizes a 5-day forecast. - Results hydrate dashboard cards; cache stores payload for subsequent requests.
- Status bar indicates provider state (online/partial/sample).
- App.jsx – orchestration, caching, fallback logic, unit toggles.
- LocationSidebar – preset/custom locations, search, persistence.
- CurrentWeatherCard – primary conditions and metrics.
- ForecastStrip – 5-day visual forecast.
- AirQualityCard / WeatherDetailsCard – AQI + detailed metrics.
- StatusBar – provider/status messaging.
- src/server.js – Express proxy for Weatherstack with key stripping, timeout control, and 404 handling.
- Backend must run for live data; frontend ships with sample payload for offline fallback.
WEATHERSTACK_API_KEYis mandatory on the server;access_keysent from clients is ignored.- Update
VITE_API_BASE_URLif backend runs on a different host/port.
- Improved loading/progress states and toasts.
- Richer air quality metrics and charts.
- Saved location profiles synced across devices.
- Optional deployment steps/scripts and Docker setup.
world-weather/
├─ frontend/ # React + Vite SPA (UI, caching, formatting helpers)
├─ backend/ # Express proxy that signs Weatherstack requests
└─ _assets/ # Design references and documentation artifacts
For deeper details, see frontend/README.md and backend/README.md.
