# nguyenminhduc163/fire-guard-mobile architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenminhduc163/fire-guard-mobile
- Repository: https://github.com/nguyenminhduc163/fire-guard-mobile

## Overview

##### Main System Components

a) IoT Hardware Layer:
- ESP8266 microcontroller
- Fire sensors
- Gas sensors
- Physical connectivity components

b) Backend Services Layer:
- Firebase services (evident from firebase_service.dart)
- REST API services (shown in api_service directory)
- Remote configuration services
- Notification services

c) Mobile Application Layer (Flutter):
- User Interface (Views)
- Business Logic (ViewModels)
- Data Models
- Service Layer

##### Component Relationships and Data Flow

a) IoT Layer → Backend Services:
- Data flow from sensors to the backend
- Real-time monitoring connections
- Emergency alert pathways

b) Backend Services → Mobile App:
- API communication paths
- Push notification flow
- Authentication flows
- Real-time data streams

c) External Services Integration:
- Google Maps integration
- News API connection
- Emergency services communication
- Weather API integration

##### Detailed Component Breakdown

For the Mobile App (based on the file structure):
**Mobile Application**
- Core Services
- Authentication (auth_model.dart)
- Sensor Management (sensor_model.dart)
- User Management (user_model.dart)
- Home Management (home_model.dart)
- Features
- Fire Detection
- Gas Detection
- Emergency Alerts
- Family Management
- News Feed
- Safety Skills
- External Integrations
- Maps
- Notifications
- Weather Services

##### Key Architectural Patterns to Highlight

- MVVM Architecture (evident from viewModel directory)
- Service-based architecture (service directory structure)
- Repository pattern (for data handling)
- Event-driven architecture (for real-time updates)

##### Implementation Details

- Firebase Authentication flow
- Real-time sensor data processing
- Emergency alert broadcast system
- Local storage implementation
- Multi-language support (shown by translations directory)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef iot fill:#90EE90,stroke:#333,stroke-width:2px
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef mobile fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px
    classDef alert fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% IoT Layer
    subgraph IoT["IoT Hardware Layer"]
        ESP[ESP8266]:::iot
        FireSensor[Fire Sensors]:::iot
        GasSensor[Gas Sensors]:::iot
        ESP --> FireSensor
        ESP --> GasSensor
    end

    %% Backend Services Layer
    subgraph Backend["Backend Services Layer"]
        Firebase["Firebase Service"]:::backend
        NotifService["Notification Service"]:::backend
        RemoteConfig["Remote Configuration"]:::backend
        Network["Network Service"]:::backend
        APIServices["API Services"]:::backend
        
        Firebase --> NotifService
        Firebase --> RemoteConfig
        Network --> APIServices
    end

    %% Mobile Application Layer
    subgraph Mobile["Mobile Application Layer"]
        %% Core Services
        subgraph Core["Core Services"]
            Auth["Authentication"]:::mobile
            SensorMgmt["Sensor Management"]:::mobile
            UserMgmt["User Management"]:::mobile
            HomeMgmt["Home Management"]:::mobile
        end

        %% Features
        subgraph Features["Features"]
            FireDetect["Fire Detection"]:::alert
            GasDetect["Gas Detection"]:::alert
            Emergency["Emergency Alerts"]:::alert
            Family["Family Management"]:::mobile
            News["Fire News"]:::mobile
            Safety["Fire Safety Skills"]:::mobile
        end

        %% ViewModels
        subgraph ViewModels["ViewModels"]
            AuthVM["Auth ViewModel"]:::mobile
            HomeVM["Home ViewModel"]:::mobile
            SensorVM["Sensor ViewModel"]:::mobile
            NewsVM["Fire News ViewModel"]:::mobile
        end
    end

    %% External Services
    subgraph External["External Services"]
        Maps["Google Maps"]:::external
        Weather["Weather Services"]:::external
        EmergencyServices["Emergency Services"]:::external
    end

    %% Connections between layers
    IoT --> Backend
    Backend --> Mobile
    Mobile --> External

    %% Click events for component mapping
    click Firebase "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/service_config/firebase_service.dart"
    click NotifService "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/service_config/notification_service.dart"
    click RemoteConfig "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/service_config/remote_config_service.dart"
    click Network "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/service_config/network_service.dart"
    click APIServices "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/service/api_service/"
    click Auth "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/models/auth_model.dart"
    click SensorMgmt "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/models/sensor_model.dart"
    click UserMgmt "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/models/user_model.dart"
    click HomeMgmt "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/models/home_model.dart"
    click News "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/view/fireNews/"
    click Safety "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/view/fireSafetySkills/"
    click HomeMgmt "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/view/home/"
    click Auth "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/view/userAuth/"
    click UserMgmt "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/tree/main/lib/view/personalProfile/"
    click AuthVM "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/viewModel/auth_view_model.dart"
    click HomeVM "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/viewModel/home_view_model.dart"
    click SensorVM "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/viewModel/sensor_view_model.dart"
    click NewsVM "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/viewModel/fire_news_view_model.dart"
    click Emergency "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/api_service/request/fire_emergency_request.dart"
    click Family "https://github.com/NguyenMinhDuc163/Fire-guard-mobile/blob/main/lib/service/api_service/request/send_family_alert_request.dart"

    %% Legend
    subgraph Legend
        L1[IoT Components]:::iot
        L2[Backend Services]:::backend
        L3[Mobile Components]:::mobile
        L4[External Services]:::external
        L5[Alert Systems]:::alert
    end
```
