Skip to content

CodersAcademy006/Weather-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌦️ IntelliWeather

A production-grade weather API built with FastAPI, featuring real-time weather data, intelligent caching, user authentication, rate limiting, and horizontal scaling support. Designed as a modern competitor to AccuWeather.

Dashboard

✨ Features

Phase 1 - Core Features

Weather Data

  • Real-time Weather - Current temperature, humidity, wind speed, UV index, and more
  • Hourly Forecasts - 24-hour detailed weather predictions
  • 7-Day Forecast - Extended weather outlook with high/low temperatures
  • Air Quality Index - AQI monitoring with health indicators

UI & UX

  • Royal Theme - Premium purple and gold color scheme
  • Animated Backgrounds - Starfield, floating orbs, aurora effects
  • Responsive Layout - Works on mobile, tablet, and desktop
  • Connection Status - Real-time backend connectivity indicator

Backend Features

  • Multi-tier Caching - In-memory cache with configurable TTL
  • CSV Data Storage - Simple file-based persistence
  • Session Authentication - Secure server-side sessions
  • Rate Limiting - Per-IP rate limiting
  • Health Checks - /healthz endpoint for load balancers

Phase 2 - Advanced Features

Enhanced Weather API

  • Hourly Endpoint V2 - 24/48/72 hour forecasts with CSV export
  • Daily Endpoint V2 - 7/14 day forecasts with CSV export
  • Historical Data - Query weather data up to 1 year back
  • Unit Conversion - Metric and imperial support

Geocoding

  • Location Search - Search cities with autocomplete
  • Reverse Geocoding - Get location from coordinates
  • Caching - 24-hour cache for geocoding results

Weather Alerts

  • Active Alerts - Get severe weather warnings
  • Alert Types - Thunderstorms, high winds, precipitation, winter weather
  • Background Prefetch - Automatic alert updates for popular locations

Downloadable Reports

  • PDF Reports - Formatted weather reports with charts
  • Excel Reports - Structured data with multiple sheets
  • Report Caching - Generated reports are cached

ML Predictions

  • Next-Day Temperature - Linear regression model
  • Confidence Intervals - Prediction uncertainty
  • Model Training - Periodic retraining on historical data

Multi-language Support

  • 5 Languages - English, Hindi, Urdu, Arabic, Spanish
  • UI Translations - Full interface localization
  • Weather Descriptions - Localized condition text

API Key Management

  • Personal API Keys - Create keys for programmatic access
  • Per-Key Rate Limits - Customizable limits per key
  • Usage Tracking - Monitor API key usage

Admin Dashboard

  • Analytics - User counts, cache stats, top locations
  • System Health - Component status monitoring
  • Cache Management - Clear cache from dashboard

πŸ› οΈ Tech Stack

Backend

  • FastAPI - Modern async Python web framework
  • Pydantic - Data validation with type hints
  • Uvicorn/Gunicorn - ASGI server for production
  • Open-Meteo API - Free weather data provider

Frontend

  • HTML5/CSS3 - Royal theme design
  • Vanilla JavaScript - No framework dependencies
  • Playfair Display - Elegant typography

Infrastructure

  • Docker - Containerization
  • NGINX - Load balancing & reverse proxy
  • Redis (optional) - Session storage for scaled deployments

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • pip package manager
  • Docker (optional, for containerized deployment)

Quick Start

  1. Clone the repository

    git clone https://github.com/CodersAcademy006/Weather-API.git
    cd Weather-API
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the server

    uvicorn app:app --host 0.0.0.0 --port 8000 --reload
  4. Open in browser

Docker Deployment

# Build and run with Docker Compose
docker-compose up -d

# Scale to multiple replicas
docker-compose up -d --scale app=3

# View logs
docker-compose logs -f

πŸ“‘ API Endpoints

Phase 1 - Weather Endpoints

Endpoint Method Description
/weather?lat={lat}&lon={lon} GET Current weather
/hourly?lat={lat}&lon={lon} GET 24-hour forecast
/forecast?lat={lat}&lon={lon} GET 7-day forecast
/aqi-alerts?lat={lat}&lon={lon} GET Air quality & alerts

Phase 2 - Enhanced Weather

Endpoint Method Description
/weather/hourly?lat=&lon=&hours= GET Hourly forecast (24/48/72h)
/weather/daily?lat=&lon=&days= GET Daily forecast (7/14 days)
/weather/historical?lat=&lon=&start=&end= GET Historical data
/weather/download?lat=&lon=&type=pdf GET Download report

Phase 2 - Geocoding

Endpoint Method Description
/geocode/search?q={query} GET Search locations
/geocode/reverse?lat=&lon= GET Reverse geocode

Phase 2 - Alerts & Prediction

Endpoint Method Description
/alerts?lat=&lon= GET Weather alerts
/predict/nextday?lat=&lon= GET Next-day prediction

Phase 2 - API Keys & i18n

Endpoint Method Description
/apikeys POST Create API key
/apikeys GET List API keys
/apikeys/{id} DELETE Revoke API key
/i18n/translations?lang= GET Get translations

Authentication

Endpoint Method Description
/auth/signup POST Create account
/auth/login POST Login
/auth/logout POST Logout
/auth/me GET Get current user

Admin & System

Endpoint Method Description
/admin/dashboard GET Admin dashboard
/admin/api/stats GET Dashboard stats
/healthz GET Health check
/metrics GET Application metrics

Example Requests

# Current weather
curl "http://localhost:8000/weather?lat=40.7128&lon=-74.0060"

# Hourly forecast with CSV export
curl "http://localhost:8000/weather/hourly?lat=40.7128&lon=-74.0060&hours=48&format=csv" -o forecast.csv

# Search for a city
curl "http://localhost:8000/geocode/search?q=London&limit=5"

# Get weather alerts
curl "http://localhost:8000/alerts?lat=40.7128&lon=-74.0060"

# Next-day temperature prediction
curl "http://localhost:8000/predict/nextday?lat=40.7128&lon=-74.0060"

# Download PDF report
curl "http://localhost:8000/weather/download?lat=40.7128&lon=-74.0060&type=pdf" -o report.pdf

# Get Hindi translations
curl "http://localhost:8000/i18n/translations?lang=hi"

πŸ—οΈ Project Architecture

Weather-API/
β”œβ”€β”€ app.py                     # Main FastAPI application
β”œβ”€β”€ config.py                  # Centralized configuration
β”œβ”€β”€ cache.py                   # In-memory caching system
β”œβ”€β”€ storage.py                 # CSV-based data storage
β”œβ”€β”€ session_middleware.py      # Session management
β”œβ”€β”€ logging_config.py          # Structured logging
β”œβ”€β”€ metrics.py                 # Health checks & metrics
β”œβ”€β”€ middleware/
β”‚   └── rate_limiter.py        # Rate limiting
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.py                # Authentication
β”‚   β”œβ”€β”€ weather_v2.py          # Enhanced weather endpoints
β”‚   β”œβ”€β”€ geocode.py             # Geocoding
β”‚   β”œβ”€β”€ alerts.py              # Weather alerts
β”‚   β”œβ”€β”€ downloads.py           # Report downloads
β”‚   β”œβ”€β”€ apikeys.py             # API key management
β”‚   β”œβ”€β”€ predict.py             # ML predictions
β”‚   β”œβ”€β”€ admin.py               # Admin dashboard
β”‚   └── i18n.py                # Internationalization
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ geocode.py             # Geocoding service
β”‚   β”œβ”€β”€ api_keys.py            # API key manager
β”‚   β”œβ”€β”€ i18n.py                # Translation service
β”‚   β”œβ”€β”€ prediction.py          # ML prediction service
β”‚   └── reports/
β”‚       β”œβ”€β”€ pdf_report.py      # PDF generation
β”‚       └── xlsx_report.py     # Excel generation
β”œβ”€β”€ schemas/
β”‚   β”œβ”€β”€ weather.py             # Weather models
β”‚   β”œβ”€β”€ geocode.py             # Geocoding models
β”‚   β”œβ”€β”€ alerts.py              # Alert models
β”‚   └── api_keys.py            # API key models
β”œβ”€β”€ workers/
β”‚   β”œβ”€β”€ alerts_prefetch.py     # Alert prefetcher
β”‚   └── train_model.py         # Model trainer
β”œβ”€β”€ static/                    # Frontend files
β”œβ”€β”€ tests/                     # Unit tests
β”œβ”€β”€ data/                      # CSV storage
β”œβ”€β”€ Dockerfile                 # Docker image
β”œβ”€β”€ docker-compose.yml         # Multi-container setup
β”œβ”€β”€ nginx.conf                 # Load balancer
β”œβ”€β”€ requirements.txt           # Dependencies
β”œβ”€β”€ CHANGELOG.md               # Version history
β”œβ”€β”€ QA.md                      # Phase 1 QA checklist
β”œβ”€β”€ QA_PHASE2.md               # Phase 2 QA checklist
β”œβ”€β”€ demo_script.md             # Phase 1 demo guide
└── demo_phase2.md             # Phase 2 demo guide

βš™οΈ Configuration

Core Settings

Variable Default Description
APP_NAME IntelliWeather Application name
APP_PORT 8000 Server port
CACHE_TTL_SECONDS 3600 Cache expiration
SESSION_TIMEOUT_SECONDS 86400 Session expiration
RATE_LIMIT_PER_MIN 60 Requests per minute per IP

Phase 2 Feature Flags

Variable Default Description
FEATURE_WEATHER_V2 true Enable enhanced weather
FEATURE_GEOCODING true Enable geocoding
FEATURE_ALERTS true Enable alerts
FEATURE_DOWNLOADS true Enable downloads
FEATURE_API_KEYS true Enable API keys
FEATURE_ML_PREDICTION true Enable predictions
FEATURE_ADMIN_DASHBOARD true Enable admin
FEATURE_I18N true Enable i18n

Additional Settings

Variable Default Description
GEOCODE_CACHE_TTL_SECONDS 86400 Geocode cache (24h)
API_KEY_RATE_LIMIT_DEFAULT 100 Default key rate limit
ML_HISTORICAL_DAYS 365 Training data days
DEFAULT_LANGUAGE en Default language

πŸ§ͺ Testing

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=. --cov-report=html

# Run Phase 2 specific tests
pytest tests/test_phase2.py -v

🎨 Screenshots

Dashboard Login Sign Up
Dashboard Login Sign Up

🌐 Data Sources

πŸ“„ License

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

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“§ Contact

Created by @CodersAcademy006


⭐ Star this repo if you find it helpful!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •