Skip to content

Latest commit

Β 

History

145 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Weather App

A full-stack weather application that provides real-time weather data for any city. The application features a React frontend and a Node.js/Express backend, and is fully containerized with Docker and configured for deployment on Kubernetes and Render.

🌟 Features

  • City-based Weather Search: Search for current weather conditions by entering a city name
  • Detailed Weather Information: Displays temperature, humidity, wind speed, and weather description
  • Dynamic Weather Icons: Visual representation of current weather conditions
  • Responsive Design: Clean, modern UI that works on both desktop and mobile devices
  • Dark/Light Mode: Toggle between dark and light themes for user comfort
  • Backend API: Simple Express API that proxies requests to OpenWeatherMap

πŸš€ Live Demo

πŸ”— Frontend: https://weather-frontend-7mo5.onrender.com
πŸ”— Backend API: https://weather-backend-dde1.onrender.com

⚠️ Note: First request may take 30+ seconds due to Render's cold start.

πŸ› οΈ Tech Stack

Frontend

  • React 18
  • TypeScript
  • Vite
  • Tailwind CSS
  • Lucide React (icons)

Backend

  • Node.js
  • Express.js
  • CORS
  • node-fetch

DevOps & Deployment

  • Docker & Docker Compose
  • Kubernetes
  • Nginx
  • GitHub Actions (CI/CD)
  • Render
  • SonarCloud (code quality)
  • OWASP Dependency Check
  • Nexus Repository

πŸ“‹ Prerequisites

  • Node.js 18+ (for local development)
  • Docker & Docker Compose (for containerized deployment)
  • OpenWeatherMap API key (Get one free here)

πŸƒ Getting Started

Option 1: Local Development (Recommended for Development)

  1. Clone the repository:

    git clone https://github.com/lavash2310/weather-app.git
    cd weather-app
  2. Install dependencies:

    npm install
  3. Create environment file:

    Create a .env file in the root directory:

    API_KEY=your_openweathermap_api_key_here
    PORT=5001
  4. Run the backend server:

    npm run dev

    Backend will start at http://localhost:5001

  5. Run the frontend (in a separate terminal):

    npm run build
    npm run preview

    Frontend will start at http://localhost:4173

Option 2: Docker Compose (Recommended for Production)

  1. Clone the repository:

    git clone https://github.com/kubezen-stack/weather-app.git
    cd weather-app
  2. Create environment file:

    Create a .env file in the root directory:

    VITE_API_KEY=your_openweathermap_api_key_here
  3. Update docker-compose.yaml:

    Replace the hardcoded API key in docker-compose.yaml:

    environment:
      - VITE_API_KEY=${VITE_API_KEY}
  4. Build and run containers:

    docker-compose up --build
  5. Access the application:

Option 3: Kubernetes Deployment

  1. Setup Minikube (if using locally):

    minikube start
  2. Create Kubernetes secret:

    kubectl create secret generic my-app-secret \
      --from-literal=api-key="your_api_key_here" \
      --from-literal=backend-url="https://weather-backend-dde1.onrender.com"
  3. Apply Kubernetes manifests:

    kubectl apply -f kubernetes/
  4. Check deployment status:

    kubectl get pods,svc,ingress -n default

πŸ”Œ API Endpoints

The backend server provides the following endpoints:

Method Endpoint Description Example
GET / Welcome message and API info -
GET /health Health check with status and uptime -
GET /api/weather?q=<city> Get weather data for specified city /api/weather?q=London

Example API Response:

{
  "temperature": 15,
  "humidity": 72,
  "windSpeed": 20,
  "description": "partly cloudy",
  "city": "London",
  "country": "GB",
  "icon": "02d"
}

πŸ“Š Environment Variables

Backend (.env)

Variable Description Required Default
API_KEY OpenWeatherMap API key βœ… Yes -
PORT Backend server port No 5001
NODE_ENV Environment mode No development

Frontend (Docker build args)

Variable Description Required Default
VITE_BACKEND_URL Backend API URL No http://localhost:5001

πŸ—οΈ Project Structure

weather-app/
β”œβ”€β”€ .github/
β”‚   └── workflows/          # CI/CD pipelines
β”‚       β”œβ”€β”€ ci.yaml         # Continuous Integration
β”‚       β”œβ”€β”€ cd.yaml         # Continuous Deployment
β”‚       └── hourly_weather.yaml  # Scheduled weather reports
β”œβ”€β”€ kubernetes/             # Kubernetes manifests
β”‚   β”œβ”€β”€ deployment.yaml     # Pod deployments
β”‚   β”œβ”€β”€ service-backend.yaml
β”‚   β”œβ”€β”€ service-frontend.yaml
β”‚   β”œβ”€β”€ ingress.yaml        # Traffic routing
β”‚   β”œβ”€β”€ role.yaml           # RBAC permissions
β”‚   β”œβ”€β”€ role-binding.yaml
β”‚   └── service-account.yaml
β”œβ”€β”€ src/                    # Frontend source code
β”‚   β”œβ”€β”€ App.tsx            # Main React component
β”‚   β”œβ”€β”€ main.tsx           # Entry point
β”‚   └── index.css          # Global styles
β”œβ”€β”€ index.js               # Backend Express server
β”œβ”€β”€ Dockerfile.backend     # Backend container
β”œβ”€β”€ Dockerfile.frontend    # Frontend container
β”œβ”€β”€ docker-compose.yaml    # Multi-container orchestration
β”œβ”€β”€ nginx.conf            # Nginx configuration
β”œβ”€β”€ package.json          # Dependencies & scripts
└── README.md             # This file

πŸ”„ CI/CD Pipeline

The project uses GitHub Actions for automated CI/CD:

CI Workflow (.github/workflows/ci.yaml)

  • βœ… Dependency installation and build
  • βœ… SonarCloud static code analysis
  • βœ… OWASP dependency vulnerability scanning
  • βœ… NPM package publishing to Nexus

CD Workflow (.github/workflows/cd.yaml)

  • 🐳 Docker image build and push to Docker Hub
  • ☁️ Automatic deployment to Render
  • ☸️ Kubernetes deployment with image updates
  • πŸ“§ Email notifications for deployment status

Hourly Weather Report (.github/workflows/hourly_weather.yaml)

  • πŸ• Runs every hour via cron schedule
  • πŸ“¨ Sends weather report emails for Kyiv, UA

πŸ› οΈ Available Scripts

npm run dev      # Start backend with nodemon (development)
npm run start    # Start backend (production)
npm run build    # Build frontend for production
npm run preview  # Preview production build
npm run lint     # Run ESLint
npm run sonar    # Run SonarQube analysis

πŸ› Troubleshooting

Port Already in Use

If ports 5001 or 8080 are already in use:

# Stop Docker containers
docker-compose down

# Kill process on port (Linux/Mac)
lsof -ti:5001 | xargs kill -9
lsof -ti:8080 | xargs kill -9

# Kill process on port (Windows)
netstat -ano | findstr :5001
taskkill /PID <PID> /F

CORS Errors

Ensure the backend URL in src/App.tsx matches your deployment:

const BACKEND_URL = 'https://weather-backend-dde1.onrender.com';

For local development, update to:

const BACKEND_URL = 'http://localhost:5001';

Docker Build Fails

Clear Docker cache and rebuild:

docker-compose down --volumes
docker system prune -a
docker-compose up --build

API Key Not Working

  1. Verify your API key at OpenWeatherMap
  2. Wait a few hours after creating new API key (activation delay)
  3. Check if API key is properly set in environment variables

⚠️ Known Issues

  • First request to Render deployment may take 30+ seconds (cold start)
  • Docker compose contains hardcoded API key (should use .env file)
  • No automated tests implemented yet

🀝 Contributing

Contributions are welcome! Please follow these steps:

  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

Code Style

  • Use TypeScript for frontend code
  • Follow ESLint configuration
  • Use Prettier for formatting
  • Write meaningful commit messages

πŸ“ License

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

πŸ‘€ Author

Kubezen-stack

πŸ™ Acknowledgments

πŸ“§ Support

If you have any questions or need help, please open an issue on GitHub.


⭐ Star this repository if you find it helpful!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages