# tuda1921/awakedrive_app_stt architecture

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

- Interactive diagram: https://gitdiagram.com/tuda1921/awakedrive_app_stt
- Repository: https://github.com/tuda1921/awakedrive_app_stt

## Overview

##### Project Type and Purpose
- This is a full-stack federated learning system comprising:
- A native Android mobile application (“mobile_app”) that collects brainwave data, performs local inference/training, and communicates with a remote server.
- A Spring Boot-based federated learning server (“federated_server”) that exposes REST endpoints, aggregates model updates, hosts the global model, and schedules federation rounds.
- The overall goal (“Awake Drive”) appears to be real-time brainwave monitoring and adaptive model training via federated learning across mobile clients.

##### File Structure Analysis
- Top level: two sibling modules:
- federated_server – a Gradle-based Spring Boot service
- mobile_app – a Gradle-based Android application
- federated_server/src/main/java/com/example/federatedserver:
– Controller.java: REST API for model upload/download
– ClassifierNNTrain/Test/AverageWeights.java: ML model training, evaluation, weight aggregation
– ScheduledTasks.java: kicks off federation rounds on schedule
– application.properties: config (port, datasource, scheduling)
- federated_server/src/main/resources/model & dataset:
– Pretrained and client model zips, CSV training/testing data
- mobile_app/app/src/main/java/com/example/brainwave:
– Activities: HomeActivity, AttentionActivity, SleepActivity, ModelsActivity, UpdateActivity, LabeledActivity
– Services/Helpers: AlertService, BluetoothAdapterActivity (connect EEG device), DrawWaveView, TrainModel (local training), LocalDataSet
– Uses libStreamSDK.jar for real-time signal streaming
- mobile_app communicates via HTTP to federated_server; stores models locally; renders UI views in res/layout; applies ProGuard rules.

##### Key Architecture Insights from README
- Very minimal README, but project name (“Awake Drive”) implies a brainwave-driven application leveraging federated learning.

a. Main Components
1) External EEG Sensor Device (via Bluetooth)
2) Android Mobile App
– Bluetooth Adapter Service
– Signal Processing & Visualization (DrawWaveView)
– Local Dataset & Model Training Module
– HTTP Client Module (REST API consumer)
3) Federated Learning Server
– REST API Controller
– Model Aggregation Engine (ScheduledTasks + ClassifierNNAverageWeights)
– Training/Evaluation Modules (ClassifierNNTrain, ClassifierNNTest)
– Model & Dataset Storage (filesystem resources)
4) Data Store (server’s file system holding CSVs and model zips)
b. Relationships & Data Flows
1) EEG Sensor → Bluetooth Adapter → Signal Processing on App
2) App → Local Training (TrainModel) → Local Model .zip
3) App → HTTP POST to Server’s /upload endpoint (Controller)
4) Server ScheduledTasks → fetches all client updates → uses ClassifierNNAverageWeights → produces new global model
5) Server → makes global model available via /download endpoint
6) Mobile App periodically GETs updated model → replaces local model
c. Architectural Patterns & Principles
- Client-Server separation with clear API contract (REST)
- Federated Learning pattern: decentralized local training + centralized aggregation
- Scheduled batch jobs for periodic aggregation (cron style)
- Modularity: distinct packages for training, testing, aggregation
- Android MV* style: Activities + Services + Views + local storage
d. Technologies & Frameworks
- Backend: Java 17+, Spring Boot, Gradle, Scheduled Tasks
- Frontend: Android SDK, Java, libStreamSDK for signal streaming
- Data formats: CSV for datasets, ZIP for model artifacts
- Communication: HTTP/JSON REST

##### Final Recommendations
- Be exhaustive: break down the mobile app into Bluetooth interface, UI Activities, local ML modules.
- Federated learning loop explicitly: training → upload → aggregation → distribution.
- Use consistent iconography and layout: client on left, server on right, data store below server, external sensor above client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Hardware
    Sensor["Bluetooth EEG Sensor"]:::external

    %% Mobile App Container
    subgraph "Mobile App" 
        direction TB
        BT["BluetoothAdapterActivity"]:::client
        Draw["DrawWaveView"]:::client
        DataSet["LocalDataSet"]:::client
        Train["TrainModel"]:::client
        Update["UpdateActivity (HTTP Client)"]:::client
        Home["HomeActivity"]:::client
        Attention["AttentionActivity"]:::client
        Sleep["SleepActivity"]:::client
        Models["ModelsActivity"]:::client
        Labeled["LabeledActivity"]:::client
        Manifest["AndroidManifest.xml"]:::client
        SDK["libStreamSDK.jar"]:::client
    end

    %% Federated Server Container
    subgraph "Federated Server"
        direction TB
        AppEntry["FederatedserverApplication"]:::server
        Controller["Controller (REST API)"]:::server
        Scheduled["ScheduledTasks"]:::server
        Agg["ClassifierNNAverageWeights"]:::server
        TrainSrv["ClassifierNNTrain"]:::server
        TestSrv["ClassifierNNTest"]:::server
        Config["application.properties"]:::server
        subgraph Storage
            direction TB
            Dataset["Dataset CSV Files"]:::storage
            ModelStore["Model ZIP Artifacts"]:::storage
        end
    end

    %% Flows
    Sensor -->|"BLE Stream"| BT
    BT -->|"signal data"| Draw
    Draw -->|"features"| DataSet
    DataSet -->|"local data"| Train
    Train -->|"local model (.zip)"| Update
    Update -->|"POST /upload"| Controller
    Scheduled -->|"trigger aggregation"| Agg
    Agg -->|"uses updates"| ModelStore
    Scheduled -->|"calls"| TrainSrv
    Scheduled -->|"calls"| TestSrv
    Controller -->|"GET /download"| Update

    %% Click Events
    click BT "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/BluetoothAdapterActivity.java"
    click Draw "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/DrawWaveView.java"
    click DataSet "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/LocalDataSet.java"
    click Train "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/TrainModel.java"
    click Update "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/UpdateActivity.java"
    click Home "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/HomeActivity.java"
    click Attention "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/AttentionActivity.java"
    click Sleep "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/SleepActivity.java"
    click Models "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/ModelsActivity.java"
    click Labeled "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/java/com/example/brainwave/LabeledActivity.java"
    click Manifest "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/src/main/AndroidManifest.xml"
    click SDK "https://github.com/tuda1921/awakedrive_app_stt/blob/master/mobile_app/app/libs/libStreamSDK.jar"
    click AppEntry "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/FederatedserverApplication.java"
    click Controller "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/Controller.java"
    click Scheduled "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/ScheduledTasks.java"
    click Agg "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/ClassifierNNAverageWeights.java"
    click TrainSrv "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/ClassifierNNTrain.java"
    click TestSrv "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/java/com/example/federatedserver/ClassifierNNTest.java"
    click Config "https://github.com/tuda1921/awakedrive_app_stt/blob/master/federated_server/src/main/resources/application.properties"

    %% Styles
    classDef external fill:#a2d5f2,stroke:#004e66,color:#000
    classDef client fill:#b2f7ef,stroke:#16817a,color:#000
    classDef server fill:#ffd6a5,stroke:#cc5500,color:#000
    classDef storage fill:#fffa65,stroke:#b58900,color:#000
```
