Weather tracking app with ML-powered insights. Track multiple cities, detect temperature anomalies, analyze trends, and find recurring weather patterns.
Live Demo: https://weather-insight-ml.vercel.app
Tracks weather for multiple cities and runs ML analysis on historical data. Backend collects weather data every hour and stores it for analysis. Frontend shows current weather, 5-day forecasts, and ML insights.
Dashboard
- Add up to 10 favorite cities, set one as primary
- Current weather and 5-day hourly forecast
- Guest mode (stores cities in localStorage, migrates to DB on signup)
- Weather-themed animated backgrounds
ML Insights (requires historical data)
- Anomaly Detection - Flags unusual temperatures using Z-score analysis (needs 10+ days of data)
- Trend Analysis - Predicts next 7 days of temps using linear regression (needs 30+ days)
- Pattern Clustering - Groups similar weather conditions with K-Means (needs 90+ days)
Auth
- JWT tokens with bcrypt password hashing
- Can use the app without login (guest mode)
Performance
- Caches weather data for 10 minutes (no duplicate API calls)
- Background job collects weather every hour for favorited cities
- React.memo and useMemo to prevent unnecessary re-renders
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Frontend (Vite) β
β Dashboard β ML Insights β Auth β City Search β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β REST API (Axios)
βββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β Routes β Services β Repositories β Models β
β + ML Pipeline (NumPy, Pandas, Scikit-learn) β
β + Background Jobs (APScheduler) β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β PostgreSQL Database (SQLAlchemy) β
β Users β Cities β Weather Data β ML Results β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β OpenWeather API β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
For detailed architecture: See ARCHITECTURE.md
- Framework: React 18.3 with Vite
- Routing: React Router v7
- State: React Context API with custom hooks
- Styling: CSS Modules with responsive design (320px+)
- Charts: Recharts for data visualization
- HTTP: Axios with interceptors
- Icons: React Icons
- Framework: FastAPI (Python 3.14)
- Database: PostgreSQL with SQLAlchemy ORM
- Migrations: Alembic
- Auth: JWT tokens with bcrypt (12 salt rounds)
- ML: NumPy, Pandas, Scikit-learn
- Scheduler: APScheduler (hourly data collection, daily cleanup)
- External API: OpenWeather API
- Anomaly Detection: Z-Score statistical method
- Trend Analysis: Linear Regression with confidence intervals
- Pattern Clustering: K-Means with StandardScaler normalization
weather-insight/
βββ src/ # Frontend React app
β βββ components/ # React components
β βββ pages/ # Route pages (Dashboard, MLInsights, Auth)
β βββ context/ # React Context (AuthContext)
β βββ hooks/ # Custom hooks (useCachedWeather)
β βββ api/ # API client modules
β βββ utils/ # Utilities (guestCities, localStorage)
βββ backend/
β βββ app/
β β βββ routes/ # API endpoints
β β βββ services/ # Business logic
β β βββ repositories/ # Data access layer
β β βββ models/ # SQLAlchemy models
β β βββ ml/ # ML algorithms
β β βββ jobs/ # Background jobs
β βββ alembic/ # Database migrations
βββ ARCHITECTURE.md # System architecture details
βββ ML_MODELS.md # ML algorithm explanations
βββ backend/API_ENDPOINTS.md # Complete API reference
- ARCHITECTURE.md - System architecture, database schema, data flow
- ML_MODELS.md - ML algorithms with math formulas
- API_ENDPOINTS.md - API reference with examples
Performance
- Custom React hooks cache weather data for 10 minutes
- Deduplicates simultaneous requests (multiple components requesting same city = 1 API call)
- React.memo on heavy components (WeatherBackground, weather cards)
- Lazy loads pages (Dashboard, MLInsights split into separate bundles)
Data Pipeline
- APScheduler runs hourly job to fetch weather for favorited cities
- Daily cleanup removes old data (180 days for weather, 90 days for ML results)
- Alembic manages database migrations
Security
- bcrypt password hashing (12 salt rounds)
- JWT tokens (24-hour expiration)
- Pydantic validates all API inputs
- CORS only allows specific origins
- Node.js 18+
- Python 3.14+
- PostgreSQL 14+
- OpenWeather API key
npm install
npm run dev # http://localhost:5173cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Configure .env
cp .env.example .env
# Add: DATABASE_URL, SECRET_KEY, OPENWEATHER_API_KEY
# Run migrations
alembic upgrade head
# Start server
python -m app.main # http://localhost:8000- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Caching
- First request fetches from API and caches for 10 minutes
- Subsequent requests use cache (instant load)
- Cache auto-expires after 10 minutes
- Try the app without creating an account
- Cities stored in localStorage (expires after 30 days)
- Data automatically migrates to DB when you sign up
- Anomaly detection needs 10+ days of data
- Trend analysis needs 30+ days
- Pattern clustering needs 90+ days
- Backend collects weather every hour for all favorited cities
Built with React, FastAPI, PostgreSQL, and Scikit-learn. Uses background jobs for hourly data collection and daily cleanup. See ARCHITECTURE.md for system design and ML_MODELS.md for algorithm details.