This repository contains a small weather forecast web application built with Next.js and TypeScript. The app shows the current weather and a 5-day forecast for a searched city, supports theme toggling (light/dark), and temperature unit switching (Celsius/Fahrenheit).
Live Demo: Not provided in the repo. To run locally, follow the Installation section.
Stack summary
- Framework:
Next.js(App Router) - Language:
TypeScript - UI / styling:
Tailwind CSS+PostCSS - Icons:
react-icons
Primary features
- Search: Search for a city to view current weather and forecast.
- 5-day forecast: Uses OpenWeatherMap 5-day forecast API.
- Theme toggle: Light and dark themes via
ThemeProvider. - Temperature toggle: Celsius / Fahrenheit persisted in
localStorage. - Loader UI: Global loader via a
LoaderProvider.
Design
- Designer: The UI and visual design were created by
lovable.
Note about API key: The project currently contains an API key hard-coded in src/app/hooks/weatherProvider.tsx. For security best practices you should store any API keys in environment variables (see Environment Variables below).
Compatibility: Node.js 18+ is recommended.
Scripts (package.json)
npm run dev: Runs Next.js in development mode.npm run build: Builds the app for production.npm run start: Starts the production server after build.npm run lint: Runseslint.
Project structure (top-level important files)
-
app/: Next.js App Router directory containing pages, layout and components.globals.css: Global styles (Tailwind + custom styles).layout.tsx: Root layout wrapper.page.tsx: Root page for the app (home).header/: Header UI and controls (theme + temperature toggles).hooks/: React context providers used across the app:weatherProvider.tsx: Fetches weather & forecast data (OpenWeatherMap).themeProvider.tsx: Theme (dark / light) state persisted tolocalStorage.temperatureProvider.tsx: Temperature unit state persisted tolocalStorage.loaderProvider.tsx: Global loading UI controls.
main/: Main app UI and feature pages (forecast, searched city views).forcast/forecastCont/forecast.ts: Forecast rendering logic.searchedCity/infoContainer/tempDetails.ts: Temperature and details components.
search/: City search UI.
-
public/: Static assets (icons, fonts, images). -
.next/: Next.js build output (ignored in source control normally). -
package.json: Scripts and dependencies. -
postcss.config.mjs,tailwind.config(if present): Tailwind/PostCSS configuration.
Dependencies (from package.json)
next— App framework (App Router based project).react,react-dom— UI library.react-icons— Icon library.
Dev dependencies include:
tailwindcss,@tailwindcss/postcss— utility CSS framework and PostCSS plugin.typescript,@types/*— TypeScript and types for Node/React.eslint,eslint-config-next— linting.
Local installation & development
- Install dependencies
cd path\to\weather-app
npm install- Add environment variables (recommended)
Create .env.local and add your OpenWeatherMap API key:
NEXT_PUBLIC_OPENWEATHER_API_KEY=your_openweather_api_key_here
- Run the dev server
npm run devOpen http://localhost:3000 in your browser.
- Build for production
npm run build
npm run startHow the app fetches weather
- The app uses the OpenWeatherMap 5-day forecast API (
/data/2.5/forecast) insideWeatherProviderto fetch a city's forecast. TheWeatherProviderexposescity,setCity,data(current/aggregated weather), anderrorstates via React Context.
Notes & suggestions
- Move the hard-coded API key out of source control and into a
.env.localfile. - Consider fetching via a Next.js API route (server-side) to keep keys private and avoid exposing them to the client.
- Add a
.gitignoreentry for.env.localif missing. - Add a short
CONTRIBUTING.mdandCODE_OF_CONDUCT.mdif you plan to accept contributions.
Troubleshooting
- If the app fails to fetch data, check that your API key is valid and not rate-limited.
- If you get CORS or network errors, verify your network and that the API endpoint (
https://api.openweathermap.org) is reachable.
Contributing
- Fork the repo, make changes on a branch, and open a Pull Request. Describe the change and include steps to reproduce.
License
- This project does not include a license file. Add a
LICENSEif you want to make the terms explicit.
If you'd like, I can:
- Replace the hard-coded API key in
src/app/hooks/weatherProvider.tsxwith an environment variable reference. - Add an
.env.exampleand update code to readprocess.env.NEXT_PUBLIC_OPENWEATHER_API_KEY. - Create a
CONTRIBUTING.mdwith basic contribution instructions.
If you want any of those, tell me which and I'll implement them.