# mohammadfebriyanto/ahuahu_app architecture

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

- Interactive diagram: https://gitdiagram.com/mohammadfebriyanto/ahuahu_app
- Repository: https://github.com/mohammadfebriyanto/ahuahu_app

## Overview

##### Main System Components
- Mobile Client (Android Application):
- Built with Kotlin and Android Studio.
- Follows the MVVM design pattern: it contains UI components (activities/fragments), a ViewModel layer, and a repository that orchestrates both local (Room database) and remote (Retrofit API calls) data sources.
- Uses Dagger-Hilt for dependency injection.
- UI-related resources (layouts, drawables, fonts) are managed under the Android “res” folder.

- Backend API (Python/Flask Service):
- Implemented in the “api” folder.
- Provides endpoints that the mobile app can call to get sports recommendations based on air quality.
- Integrates a pre-trained Machine Learning model (e.g., best_model.h5) and associated prediction scripts (predict.py, request.py).
- Uses libraries like Tensorflow, Numpy, Pandas, Keras, and Scikit-Learn.
- Containerized using Docker (see Dockerfile and docker-compose.yml).

- Data & Model Assets:
- The “model” directory contains dataset files and classification scripts.
- This component is used during the training phase or potentially for updating the API’s model.

##### Relationships and Data Flow
- User Interaction: The user opens the mobile app and interacts with the UI (e.g., tapping the “Get Location” button).
- Mobile App Data Flow:
- The UI layer communicates with the ViewModel.
- The ViewModel calls the Repository, which routes requests to:
▸ The Room database (for local history or caching).
▸ Retrofit API service to send location data to the backend.
- Backend API Processing:
- The Flask API receives location requests.
- It invokes the ML prediction process (using Tensorflow models) to determine if the current air quality makes for an optimal day for outdoor sports.
- Response Flow:
- The API sends back the recommendation result to the Android client via a JSON response.
- The mobile app then updates the UI accordingly.

##### Architectural Patterns and Design Principles
- MVVM Architecture on Android supports separation of concerns.
- Dependency Injection with Dagger-Hilt simplifies component wiring.
- The Repository pattern abstracts data sources (local vs. remote).
- Microservice/cloud containerization for the API enhances scalability and portability.
- Usage of Retrofit for networking abstracts connection details.
- Docker enables efficient deployment of the Flask service.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    User("User"):::user

    %% Mobile Client Subgraph
    subgraph "Mobile Client"
        UI("Android UI"):::mobile
        VM("ViewModel Layer"):::mobile
        HistVM("HistoryViewModel"):::mobile
        ResVM("ResultViewModel"):::mobile
        Repo("Repository & Domain Logic"):::mobile
        RoomDB("Room Database"):::mobile
        ApiClient("Retrofit API Service"):::mobile
        DI("Dagger-Hilt (Dependency Injection)"):::mobile
    end

    %% Backend API Service Subgraph
    subgraph "Backend API Service"
        Flask("Flask API Service"):::backend
        ML("TensorFlow ML Model"):::backend
        Predict("predict.py"):::backend
        Request("request.py"):::backend
        Dockerfile("Dockerfile"):::backend
        DockerCompose("docker-compose.yml"):::backend
    end

    %% Data & Model Assets (Supporting Component)
    DataAssets("Data & Model Assets"):::backend

    %% Connections - Mobile Client Flow
    User -->|"initiates"| UI
    UI -->|"updates"| VM
    VM -->|"queries"| Repo
    Repo -->|"reads/writes"| RoomDB
    Repo -->|"calls"| ApiClient
    DI -.-> Repo

    %% Mobile to Backend Communication
    ApiClient -->|"sendLocationData"| Flask
    Flask -->|"returnRecommendation"| ApiClient
    %% Backend Internal Operations
    Flask -->|"invokes"| ML
    Flask -->|"executes"| Predict
    Flask -->|"executes"| Request

    %% Data Assets used by Backend ML Component
    ML -->|"uses"| DataAssets

    %% Response Flow back to Mobile Client
    ApiClient -->|"sendsResult"| Repo
    Repo -->|"notifies"| VM
    VM -->|"updates"| UI

    %% Styling Classes
    classDef mobile fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef user fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;

    %% Click Events for Mobile Client Components
    click UI "https://github.com/mohammadfebriyanto/ahuahu_app/tree/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/ui"
    click HistVM "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/ui/history/HistoryViewModel.kt"
    click ResVM "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/ui/result/ResultViewModel.kt"
    click Repo "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/domain/repository/Repository.kt"
    click RoomDB "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/data/local/AppDatabase.kt"
    click ApiClient "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/data/remote/ApiService.kt"
    click DI "https://github.com/mohammadfebriyanto/ahuahu_app/tree/main/ahuahu-app.android/app/src/main/java/com/cap0097/ahuahuapp/di"

    %% Click Events for Backend API Components
    click Flask "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/api/api.py"
    click ML "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/api/best_model.h5"
    click Predict "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/api/predict.py"
    click Request "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/api/request.py"
    click Dockerfile "https://github.com/mohammadfebriyanto/ahuahu_app/tree/main/api/Dockerfile"
    click DockerCompose "https://github.com/mohammadfebriyanto/ahuahu_app/blob/main/api/docker-compose.yml"

    %% Click Event for Data & Model Assets
    click DataAssets "https://github.com/mohammadfebriyanto/ahuahu_app/tree/main/model"
```
