A reactive Spring Boot application that integrates with Google Gemini AI and WeatherAPI to provide an interactive chat interface and real-time weather information.
✅ Backend (Spring Boot + WebFlux)
- Reactive REST API using Spring WebFlux
- WebClient integration with Google Gemini AI API
- WebClient integration with WeatherAPI.com
- Non-blocking, reactive programming model
- Proper error handling and validation
✅ Frontend
- Modern, responsive single-page application
- Real-time AI chat interface
- Weather lookup with detailed information
- Beautiful gradient UI with animations
- Mobile-friendly design
- Spring Boot 3.5.7
- Spring WebFlux (Reactive web framework)
- WebClient (Reactive HTTP client)
- Java 17
- Maven
- HTML5
- CSS3 (with animations and modern design)
- Vanilla JavaScript (Fetch API)
- Java 17 or higher
- Maven 3.6+
- Google Gemini API Key (free at https://ai.google.dev/)
- WeatherAPI Key (free at https://www.weatherapi.com/)
- Visit https://ai.google.dev/
- Click "Get API Key"
- Create a new project or use existing one
- Copy your API key
- Visit https://www.weatherapi.com/
- Sign up for a free account
- Copy your API key from the dashboard
Open src/main/resources/application.properties and update:
# Gemini API Configuration
GEMINI_API_KEY=YOUR_GEMINI_API_KEY_HERE
GEMINI_API_BASEURL=https://generativelanguage.googleapis.com/v1beta/models
# Weather API Configuration
EXT_API_KEY=YOUR_WEATHER_API_KEY_HERE
EXT_API_BASEURL=https://api.weatherapi.com/v1
# Server Configuration
server.port=8080Important: Replace YOUR_GEMINI_API_KEY_HERE and YOUR_WEATHER_API_KEY_HERE with your actual API keys.
Windows:
mvnw.cmd clean install
mvnw.cmd spring-boot:runLinux/Mac:
./mvnw clean install
./mvnw spring-boot:runmvn clean install
mvn spring-boot:runOnce the application starts, open your browser and navigate to:
http://localhost:8080
You should see the AI & Weather Assistant interface.
- URL:
POST /api/prompt - Request Body:
{ "prompt": "Your question here" } - Response:
{ "response": "AI response text" }
- URL:
GET /weather/current?q={location} - Query Parameters:
q: City name (e.g., "Copenhagen", "London") or coordinates (e.g., "48.8567,2.3508")
- Response: JSON object with weather data
src/
├── main/
│ ├── java/dk/ss/projectai/
│ │ ├── ProjectAiApplication.java # Main application class
│ │ └── app/
│ │ ├── client/
│ │ │ └── GeminiClient.java # Gemini API WebClient
│ │ ├── config/
│ │ │ └── WebClientConfig.java # WebClient configuration
│ │ ├── controller/
│ │ │ ├── PromptController.java # AI chat REST controller
│ │ │ └── WeatherController.java # Weather REST controller
│ │ └── service/
│ │ ├── GeminiService.java # AI service logic
│ │ └── WeatherService.java # Weather service logic
│ └── resources/
│ ├── application.properties # Configuration
│ └── static/ # Frontend files
│ ├── index.html # Main HTML page
│ ├── styles.css # Styling
│ └── app.js # JavaScript logic
- Type your question in the text area
- Click "Send" or press
Ctrl+Enter - Wait for the AI response to appear in the chat
- Continue the conversation as needed
- Enter a city name (e.g., "Copenhagen", "Tokyo", "New York")
- Click "Get Weather" or press
Enter - View detailed weather information including:
- Temperature (current and feels like)
- Weather condition with icon
- Humidity, wind speed, pressure
- Visibility and UV index
You can test the backend APIs directly using curl or Postman:
curl -X POST http://localhost:8080/api/prompt \
-H "Content-Type: application/json" \
-d '{"prompt":"What is Spring WebFlux?"}'curl "http://localhost:8080/weather/current?q=Copenhagen"-
"API key must be provided" error:
- Ensure you've added your API keys to
application.properties - Check there are no extra spaces in the keys
- Ensure you've added your API keys to
-
"401 Unauthorized" error:
- Verify your API keys are valid
- Check if you have API quota remaining
-
Port 8080 already in use:
- Change the port in
application.properties:server.port=8081
- Change the port in
-
Connection timeout:
- Check your internet connection
- Verify the API base URLs are correct
✅ Requirement 1: Backend built with Spring Boot and WebFlux (Reactive web) ✓
✅ Requirement 2: WebClient to call external AI service (Gemini API) ✓
✅ Requirement 3: WebClient to call 3rd party API (WeatherAPI) ✓
✅ Requirement 4: Frontend that communicates with backend and allows user to enter prompts ✓
- Responsive design (mobile, tablet, desktop)
- Loading states and animations
- Error handling with user-friendly messages
- Chat history in the UI
- Beautiful gradient design
- Keyboard shortcuts (Ctrl+Enter to send, Enter for weather)
- Chat history persistence (database)
- User authentication
- Multiple AI model selection
- Weather forecast (7-day)
- Export chat history
- Dark mode toggle
This project is for educational purposes.
- Google Gemini AI
- WeatherAPI.com
- Spring Framework Team