# kajenthavaraj/smart_mirror_v2 architecture

> Architecture diagram of the GitHub repository kajenthavaraj/smart_mirror_v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kajenthavaraj/smart_mirror_v2
- Repository: https://github.com/kajenthavaraj/smart_mirror_v2

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Browser (Frontend)"
        direction TB
        Index["index.html"]:::static
        Styles["styles.css"]:::static
    end

    %% Backend Layer
    subgraph "Spring Boot Application" 
        direction TB
        SmartMirrorApp["SmartMirrorApplication\n(Spring Boot Entry)"]:::component
        StaticHandler["Static Resource Handler\n(serves index.html & styles.css)"]:::component
        Controller["MirrorController\n(GET /api/weather)"]:::component
        Service["WeatherService\n(WebFlux WebClient)"]:::component
        Model["WeatherData Model"]:::component
        AppProps["application.properties\n(weather.api.key)"]:::config
        POM["pom.xml"]:::build
    end

    %% External API
    OpenWeatherMap["OpenWeatherMap API"]:::external

    %% Data Flows
    Index -->|"GET /"| StaticHandler
    Styles --> StaticHandler
    StaticHandler -->|"serves static files"| Browser
    Browser -->|"GET /api/weather"| Controller
    Controller -->|"fetchWeather()"| Service
    Service -->|"HTTP GET with API key & coords"| OpenWeatherMap
    OpenWeatherMap -->|"200 OK JSON"| Service
    Service -->|"maps to WeatherData"| Controller
    Controller -->|"200 OK JSON"| Browser

    %% Click Events
    click Index "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/resources/static/index.html"
    click Styles "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/resources/static/styles.css"
    click StaticHandler "https://github.com/kajenthavaraj/smart_mirror_v2/tree/main/src/main/resources/static"
    click SmartMirrorApp "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/java/com/example/smartmirror/SmartMirrorApplication.java"
    click Controller "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/java/com/example/smartmirror/controller/MirrorController.java"
    click Service "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/java/com/example/smartmirror/service/WeatherService.java"
    click Model "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/java/com/example/smartmirror/model/WeatherData.java"
    click AppProps "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/src/main/resources/application.properties"
    click POM "https://github.com/kajenthavaraj/smart_mirror_v2/blob/main/pom.xml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085
    classDef backend fill:#d4edda,stroke:#155724
    classDef external fill:#ffe5b4,stroke:#ff8500
    classDef component fill:#ffffff,stroke:#6c757d
    classDef config fill:#f8d7da,stroke:#721c24
    classDef build fill:#e2e3e5,stroke:#6c757d

    class Index,Styles frontend
    class SmartMirrorApp,StaticHandler,Controller,Service,Model backend
    class AppProps config
    class POM build
    class OpenWeatherMap external
```
