How kajenthavaraj/smart_mirror_v2 works
Project Type and Purpose
• This is a monolithic full-stack web application built on Java Spring Boot.
• It serves a static front-end (“smart mirror” UI) and provides a REST endpoint to fetch real-time weather data from OpenWeatherMap.
High-Level Architecture Components
a. Frontend (Client)
• Browser running static HTML/CSS/JavaScript (index.html + styles.css)
• Responsible for rendering time, date, and weather UI and periodically calling the backend for updated weather data.
b. Backend (Spring Boot Application)
• Static Resource Handler: serves index.html & styles.css.
• MirrorController: HTTP REST controller exposing endpoints (e.g., GET /api/weather).
• WeatherService: service layer using Spring WebFlux WebClient to call the external API.
• WeatherData Model: POJO mapping JSON response from OpenWeatherMap.
• Application Configuration: application.properties holds API key and app settings.
c. External Dependency
• OpenWeatherMap API: external REST service providing current weather data.
Component Interactions and Data Flow
1. Client loads “/” → Spring Boot static resource handler → index.html & styles.css delivered.
2. Frontend JavaScript issues HTTP GET to /api/weather.
3. MirrorController receives request → invokes WeatherService.
4. WeatherService (via WebFlux WebClient) calls OpenWeatherMap API with configured API key and coordinates.
5. OpenWeatherMap returns JSON → WebClient maps to WeatherData model.
6. WeatherService returns WeatherData → MirrorController serializes to JSON.
7. Response sent back to the browser → UI updates with new weather info.
Architectural Patterns and Design Principles
• Layered Architecture: Controller → Service → External API.
• Separation of Concerns: static assets in resources/static; backend code in controller/service/model packages.
• Reactive HTTP Client: WebFlux WebClient for non-blocking calls to the external API.
Relevant Technologies & Frameworks
• Java 17, Spring Boot 3
• Maven (pom.xml) for build lifecycle
• Spring WebFlux (WebClient) for reactive HTTP
• Static frontend: HTML/CSS/JavaScript
• Application properties: externalized config (weather.api.key)