# capstone-bau-2025/smart-home-system architecture

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

- Interactive diagram: https://gitdiagram.com/capstone-bau-2025/smart-home-system
- Repository: https://github.com/capstone-bau-2025/smart-home-system

## Overview

##### Main Components
- Mobile Application: Built with React Native (found under the mobileapp directory), this is the front-end interface through which users interact with the system.
- Cloud Server: A Spring Boot application (located in the cloudserver directory) providing a Web API, handling real-time communications with WebSockets, managing authentication/role management, and interfacing with an Oracle database to store user and hub data.
- Central Hub: Also a Spring Boot application (in the centralhub directory) running on a Raspberry Pi. It handles local device communications using Mosquitto MQTT, local database (SQLite), device control logic, automation rules, and connectivity with IoT devices.
- IoT Devices / Device Templates: Represented by the device-template folder. This component serves as a blueprint for integrating and managing various smart devices within the home.
- Supporting Documentation: The docs folder provides protocol and setup details, which can also be referenced to understand integration patterns (e.g., the devices-hub-comm-protocol and mosquitto setup).

##### Relationships and Interactions
- The Mobile App communicates with the Cloud Server for user authentication, sending control commands, retrieving notifications, etc.
- The Cloud Server provides remote access by relaying commands and receiving data. It utilizes WebSocket for real-time communication back to the Mobile App.
- The Cloud Server also interacts with the Central Hub through secure API endpoints (and possibly via token-based authentication mechanisms). This allows the hub to register and exchange status updates.
- The Central Hub communicates with individual IoT devices using MQTT (via Mosquitto) to control devices, process local automation, monitor states, and send notifications.
- In addition, both the Cloud Server and Central Hub contain separate security configurations (via JWT auth filters and security configs) as shown in the file structure.

##### Architectural Patterns & Design Principles
- Layered / MVC Architecture in both Central Hub and Cloud Server (visible through the controllers, services, repositories, and DTOs).
- Use of Microservice-like separation: while each component is a monolith in its own right, the clear separation of responsibilities (local vs. remote, UI vs. backend) advocates a service-oriented architecture.
- Integration using MQTT for IoT device communication and WebSocket/HTTP-based interactions for real-time updates.
- Clear separation of concerns: the mobile app for front-end, Cloud Server for remote access and central coordination, and Central Hub for local device management.

##### Relevant Technologies & Their Roles
- Java Spring Boot: Used for building the Cloud Server and Central Hub.
- Mosquitto MQTT: Enables IoT communications on the Central Hub.
- SQLite & Oracle DB: Represent local (hub) and enterprise (cloud) data storage, respectively.
- React Native & Expo: Underpin the mobile application.
- WebSocket: Handles real-time message exchange in the Cloud Server.
- Gradle (via build files): Indicates build and dependency management setups.
- JWT Authentication: Present in both the hub and cloud, enforcing security.

- Mobile App (with a note about React Native and push notifications)
- Cloud Server (highlight Spring Boot, WebSocket, Oracle DB)
- Central Hub (emphasize Spring Boot, MQTT, SQLite)
- IoT Devices/Device Template (indicate that these follow a standardized protocol that integrates via MQTT)
- Rectangles for application/service components

##### Additional Details
- Mention any intricacies visible in the file tree such as the organization of REST controllers, DTOs, and service layers that imply a clean separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        MA["Mobile Application (React Native)"]:::mobile
    end

    %% Backend Layer
    subgraph "Backend"
        CS["Cloud Server (Spring Boot, WebSocket)"]:::server
        OR["((Oracle DB))"]:::db
        CH["Central Hub (Spring Boot, MQTT)"]:::hub
        SQ["((SQLite))"]:::db
        CS -->|"stores_data"| OR
        CH -->|"stores_data"| SQ
    end

    %% IoT / Device Layer
    subgraph "IoT/Device Layer"
        DT["IoT Devices/Device Templates"]:::device
    end

    %% Documentation
    subgraph "Documentation"
        DOC["Supporting Documentation"]:::docs
    end

    %% Data and Command Flows
    MA -->|"API/WebSocket:Auth,commands,notifications"| CS
    CS -->|"RemoteAccess:HubRegistration"| CH
    CH -->|"LocalControl:MQTT"| DT

    %% Click Events
    click MA "https://github.com/capstone-bau-2025/smart-home-system/tree/main/mobileapp"
    click CS "https://github.com/capstone-bau-2025/smart-home-system/tree/main/cloudserver"
    click CH "https://github.com/capstone-bau-2025/smart-home-system/tree/main/centralhub"
    click DT "https://github.com/capstone-bau-2025/smart-home-system/tree/main/device-template"
    click DOC "https://github.com/capstone-bau-2025/smart-home-system/tree/main/docs"

    %% Styles
    classDef mobile fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef server fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef hub fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef device fill:#F5CBA7,stroke:#C0392B,stroke-width:2px;
    classDef docs fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef db fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
