Skip to content

mahammadaftab/Weather_Forecast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Global Weather Forecasting Platform

A production-grade, enterprise-level global weather forecasting platform that provides accurate weather insights for every country, state, and major city worldwide.

🌟 Features

  • Real-time Weather Data: Live temperature, AQI, humidity, and more
  • Location Detection: Automatic user location detection (browser geolocation + IP fallback)
  • Comprehensive Forecasts: 24-hour and 7-day forecasts
  • Weather Alerts: Real-time extreme weather notifications
  • Global Coverage: Weather data for cities worldwide
  • Interactive Maps: Visual world weather map
  • Responsive Design: Mobile-first, fully responsive UI
  • Theme Support: Light, dark, and auto themes

πŸ—οΈ Architecture

Backend (Java Spring Boot)

  • Framework: Spring Boot 3.x
  • Database: MongoDB
  • Security: JWT-based authentication
  • Caching: Caffeine Cache
  • APIs: OpenWeatherMap, WeatherAPI integrations

Frontend (React + Vite)

  • Framework: React 18 with TypeScript
  • Build Tool: Vite
  • Styling: TailwindCSS
  • State Management: React Hooks
  • Real-time: WebSocket connections

πŸ“ Project Structure

weather-forecast/
β”œβ”€β”€ backend/                 # Java Spring Boot backend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”‚   β”œβ”€β”€ java/com/weatherforecast/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ controller/     # REST controllers
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ service/        # Business logic
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ repository/     # Database repositories
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ model/          # Data models
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dto/            # Data transfer objects
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ config/         # Configuration classes
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ security/       # Security configurations
β”‚   β”‚   β”‚   β”‚   └── util/           # Utility classes
β”‚   β”‚   β”‚   └── resources/
β”‚   β”‚   └── test/
β”‚   └── pom.xml              # Maven configuration
β”œβ”€β”€ frontend/                # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ contexts/        # React contexts
β”‚   β”‚   β”œβ”€β”€ hooks/           # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ services/        # API services
β”‚   β”‚   └── App.tsx          # Main application component
β”‚   β”œβ”€β”€ index.html           # HTML entry point
β”‚   └── vite.config.js       # Vite configuration
└── README.md                # Project documentation

πŸš€ Getting Started

Prerequisites

  • Java 17+ for backend
  • Node.js 16+ for frontend
  • MongoDB database
  • OpenWeatherMap API key

Backend Setup

  1. Navigate to the backend directory:

    cd backend
  2. Install dependencies:

    mvn clean install
  3. Configure environment variables:

    # Create application.properties or use environment variables
    export SPRING_DATA_MONGODB_URI=mongodb://localhost:27017/weather_forecast
    export OPENWEATHERMAP_API_KEY=your_api_key_here
  4. Run the application:

    mvn spring-boot:run

Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev
  4. Build for production:

    npm run build

πŸ” Security

  • JWT Authentication: Secure user authentication
  • Role-based Access: Different permissions for user roles
  • Input Validation: Backend validation for all inputs
  • CORS Protection: Controlled cross-origin requests
  • Rate Limiting: API rate limiting to prevent abuse

πŸ› οΈ API Endpoints

Authentication

  • POST /api/auth/signin - User login
  • POST /api/auth/signup - User registration

Location

  • GET /api/location/countries - Get all countries
  • GET /api/location/states/{countryId} - Get states by country
  • GET /api/location/cities/state/{stateId} - Get cities by state
  • GET /api/location/cities/search?name={query} - Search cities

Weather

  • GET /api/weather/current/{cityId} - Current weather
  • GET /api/weather/forecast/hourly/{cityId}?hours={n} - Hourly forecast
  • GET /api/weather/forecast/daily/{cityId}?days={n} - Daily forecast
  • GET /api/weather/alerts/{cityId} - Weather alerts

πŸ§ͺ Testing

Backend

  • Unit Tests: JUnit 5 with Mockito
  • Integration Tests: SpringBootTest
  • API Tests: Postman collections

Frontend

  • Component Tests: Vitest + React Testing Library
  • E2E Tests: Cypress (optional)

Run backend tests:

cd backend
mvn test

Run frontend tests:

cd frontend
npm run test

πŸ“Š Performance

  • Caching: In-memory caching with Caffeine
  • Database Indexes: Optimized MongoDB queries
  • Connection Pooling: Efficient database connections
  • Async Processing: Non-blocking operations

🌍 Deployment

Production Build

  1. Build the frontend:

    cd frontend
    npm run build
  2. Package the backend:

    cd backend
    mvn clean package

Environment Variables

Variable Description Required
SPRING_DATA_MONGODB_URI MongoDB connection URI Yes
OPENWEATHERMAP_API_KEY OpenWeatherMap API key Yes
JWT_SECRET Secret for JWT tokens Yes
SERVER_PORT Application port (default: 8080) No

Docker Deployment (Optional)

Create a docker-compose.yml:

version: '3.8'
services:
  mongodb:
    image: mongo:latest
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db

  backend:
    build: ./backend
    ports:
      - "8080:8080"
    environment:
      - SPRING_DATA_MONGODB_URI=mongodb://mongodb:27017/weather_forecast
      - OPENWEATHERMAP_API_KEY=your_api_key_here
    depends_on:
      - mongodb

  frontend:
    build: ./frontend
    ports:
      - "3000:3000"
    depends_on:
      - backend

volumes:
  mongodb_data:

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors