# chalindu19/novalith architecture

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

- Interactive diagram: https://gitdiagram.com/chalindu19/novalith
- Repository: https://github.com/chalindu19/novalith

## Overview

##### Project type and purpose
- This is a full-stack IoT healthcare application (“Smart Pregnancy Belly Wrap”) combining:
- Hardware firmware (Arduino/INO sketches for various sensors)
- Machine-learning model development and inference
- A cloud/mobile application (Flutter + Firebase)
- A marketing website (React/Vite/Tailwind)
- Purpose: capture maternal/fetal vital signs, transmit them, store and analyze data, and present insights to caregivers.

##### Top-level architecture components
a. Hardware layer (“Device”)
- Multiple Arduino sketches under Hardware/… (.ino files for blood-pressure, ECG, temperature, fetal movement, heart rate)
- Each sensor board packages raw signals into digital data.
- Connectivity: Bluetooth Low Energy (BLE) and/or Wi-Fi modules relay data to gateway.
b. Mobile/Gateway layer
- Flutter app (Software/novalith/lib + pubspec.yaml, android/ios directories)
- Firebase integration (firebase_options.dart, JSON admin SDK in ML directory)
- Responsibilities:
- Device pairing (BLE API)
- Data ingestion into Firestore/Realtime Database
- User authentication (AuthController.dart)
- Real-time charts (custom_ecg_chart, graph_view)
- Chat interface for caregiver-patient communication
c. Cloud backend
- Firebase services:
- Authentication
- Firestore (Chat, LoggedUser, MessageRequest collections)
- Storage (optionally for raw data, audio recordings in chat)
- Functions (not shown but implied by models/infrastructure)
- ML inference service
- Offline training notebooks (Machine Learning/ML/*.ipynb, Updated_ML/*.ipynb)
- Trained models (best_fetal_model.pkl, best_fetal_model_updated.pkl)
- Inference pipeline (inference_updated.ipynb or deploy as cloud function or local service)
d. Machine-learning training pipeline (offline)
- Jupyter notebooks process fetal_data.csv → train fetal model → export .pkl
- Optionally hosted on a server or Google Colab
e. Public marketing website
- React + TypeScript + Vite project under Marketing Website/
- Static hosting on Netlify/Vercel or Firebase Hosting

##### Data flows & interactions
1. Sensor boards collect biometric signals → MCU packages measurements.
2. MCU → BLE/Wi-Fi → Flutter app on mother’s phone.
3. Flutter app → Firebase Auth → Firestore writes sensor readings.
4. Cloud triggers ML inference (could be Firebase Function or app-embedded interpreter)
→ inference results (risk alerts, patterns) → store back in Firestore.
5. Flutter app → listens for updates via Firestore listeners → UI charts/alerts.
6. Optional: Chat requests → Firestore → caregiver app.

##### Architectural patterns & design principles
- Layered architecture: Device → Gateway → Cloud → Client UI
- Pub/Sub for real-time updates (Firestore listeners)
- MVC/MVVM style in Flutter (Controllers under lib/Controllers, Views under lib/views)
- Microservices / Functions for ML inference (decoupled training vs. inference)
- Componentized frontend on marketing site (atomic UI elements under src/components/ui)

##### Final checklist
- Security/auth flows (Auth → token → Firestore)
- Key architectures (hardware, mobile, cloud, ML, web) are represented

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer" 
        direction TB
        H_BP["Blood Pressure Sensor\n(.ino)"]:::hardware
        H_ECG["ECG Monitoring Sensor\n(.ino)"]:::hardware
        H_FM["Fetal Movement Sensor\n(.ino)"]:::hardware
        H_OX["Oximeter Sensor\n(.ino)"]:::hardware
        H_TEMP["Temperature Sensor\n(.ino)"]:::hardware
        H_MAIN["Device Main Firmware\n(.ino)"]:::hardware
    end

    %% Mobile/Gateway Layer
    subgraph "Mobile/Gateway Layer (Flutter App)" 
        direction TB
        M_CFG["pubspec.yaml\nfirebase_options.dart"]:::mobile
        M_CTRL["AuthController\nChatController"]:::mobile
        M_MODEL["DB Models\nChat, LoggedUser,\nMessageRequest"]:::mobile
        M_VIEW["Views:\nAuth, Chat, Home,\nHistory, Splash"]:::mobile
        M_WID["Widgets:\ncustom_ecg_chart,\ngraph_view"]:::mobile
    end

    %% Cloud Backend & Inference
    subgraph "Cloud Backend & Inference Service"
        direction TB
        C_AUTH["Firebase Auth"]:::cloud
        C_FS["Firestore\n(Chat, LoggedUser,\nMessageRequest)"]:::cloud
        C_ST["Firebase Storage"]:::cloud
        C_FUNC["Firebase Functions"]:::cloud
        C_INF["ML Inference Pipeline"]:::cloud
    end

    %% ML Training Pipeline
    subgraph "ML Training Pipeline (Offline)"
        direction TB
        ML_DATA["fetal_data.csv\nfetal_data_updated.csv"]:::ml
        ML_NOTE["Notebooks:\nfetal_ml.ipynb,\nUpdated.ipynb"]:::ml
        ML_MODEL["Models:\nbest_fetal_model.pkl,\nbest_fetal_model_updated.pkl"]:::ml
    end

    %% Marketing Website
    subgraph "Marketing Website" 
        direction TB
        MK_CFG["package.json\nvite.config.ts\ntailwind.config.ts"]:::marketing
        MK_ENTRY["index.html\nmain.tsx,\nApp.tsx"]:::marketing
        MK_COMP["Components:\nNavigation, Hero,\nFeatures, UI Primitives"]:::marketing
        MK_PG["Pages:\nAbout, FAQ,\nNotFound"]:::marketing
        MK_UTIL["Utils & Hooks"]:::marketing
    end

    %% Data Flows
    H_MAIN -->|BLE/Wi-Fi| M_CFG
    M_CFG -->|Firestore SDK\nHTTPS| C_FS
    M_CFG -->|Auth API| C_AUTH
    C_FS -->|Triggers| C_INF
    C_INF -->|Inference Results| C_FS
    C_FS -->|Listeners| M_VIEW
    M_CTRL -->|User Chat| C_FS
    ML_DATA --> ML_NOTE
    ML_NOTE --> ML_MODEL
    ML_MODEL -.-> C_INF

    %% Marketing site external
    MK_ENTRY -.->|Static Hosting| MK_COMP

    %% Click Events Hardware
    click H_BP "https://github.com/chalindu19/novalith/blob/main/Hardware/Blood_Pressure/bp_sensor.ino"
    click H_ECG "https://github.com/chalindu19/novalith/blob/main/Hardware/ECG_Monitoring/ECG_AD8232.ino"
    click H_FM "https://github.com/chalindu19/novalith/blob/main/Hardware/Fetal_Movement/ThinfilmPressure.ino"
    click H_OX "https://github.com/chalindu19/novalith/blob/main/Hardware/Maternal_HeartRate/Oximeter_sensor.ino"
    click H_TEMP "https://github.com/chalindu19/novalith/blob/main/Hardware/Maternal_Temprature/Temperature.ino"
    click H_MAIN "https://github.com/chalindu19/novalith/blob/main/Hardware/Device_Main/device.ino"

    %% Click Events Mobile
    click M_CFG "https://github.com/chalindu19/novalith/blob/main/Software/novalith/pubspec.yaml"
    click M_CFG "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/firebase_options.dart"
    click M_CTRL "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/Controllers/AuthController.dart"
    click M_CTRL "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/Controllers/ChatController.dart"
    click M_MODEL "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/Models/DB/Chat.dart"
    click M_MODEL "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/Models/DB/LoggedUser.dart"
    click M_MODEL "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/Models/DB/MessageRequest.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Auth/login.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Auth/register.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Auth/forget_password.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Chat/chat.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Contents/Home/home.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Contents/Home/drawer.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Contents/History/history.dart"
    click M_VIEW "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Contents/Init/splash_screen.dart"
    click M_WID "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Widgets/custom_ecg_chart.dart"
    click M_WID "https://github.com/chalindu19/novalith/blob/main/Software/novalith/lib/views/Widgets/graph_view.dart"

    %% Click Events ML Training
    click ML_NOTE "https://github.com/chalindu19/novalith/blob/main/Machine Learning/ML/fetal_ml.ipynb"
    click ML_NOTE "https://github.com/chalindu19/novalith/blob/main/Machine Learning/Updated_ML/Updated_ML/Updated.ipynb"
    click ML_DATA "https://github.com/chalindu19/novalith/blob/main/Machine Learning/ML/fetal_data.csv"
    click ML_DATA "https://github.com/chalindu19/novalith/blob/main/Machine Learning/Updated_ML/Updated_ML/fetal_data_updated.csv"
    click ML_MODEL "https://github.com/chalindu19/novalith/blob/main/Machine Learning/ML/best_fetal_model.pkl"
    click ML_MODEL "https://github.com/chalindu19/novalith/blob/main/Machine Learning/Updated_ML/Updated_ML/best_fetal_model_updated.pkl"
    click ML_NOTE "https://github.com/chalindu19/novalith/blob/main/Machine Learning/Updated_ML/Updated_ML/inference_updated.ipynb"
    click ML_MODEL "https://github.com/chalindu19/novalith/blob/main/Machine Learning/Updated_ML/Updated_ML/novalith-c49fb-firebase-adminsdk-fbsvc-ad5eb615de.json"

    %% Click Events Marketing
    click MK_CFG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/package.json"
    click MK_CFG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/vite.config.ts"
    click MK_CFG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/tailwind.config.ts"
    click MK_ENTRY "https://github.com/chalindu19/novalith/blob/main/Marketing Website/index.html"
    click MK_ENTRY "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/main.tsx"
    click MK_ENTRY "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/App.tsx"
    click MK_COMP "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/components/Navigation.tsx"
    click MK_COMP "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/components/landing/HeroSection.tsx"
    click MK_COMP "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/components/landing/FeaturesSection.tsx"
    click MK_COMP "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/components/ui/button.tsx"
    click MK_PG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/pages/About.tsx"
    click MK_PG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/pages/FAQ.tsx"
    click MK_PG "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/pages/NotFound.tsx"
    click MK_UTIL "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/lib/utils.ts"
    click MK_UTIL "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/hooks/use-mobile.tsx"
    click MK_UTIL "https://github.com/chalindu19/novalith/blob/main/Marketing Website/src/hooks/use-toast.ts"

    %% Styles
    classDef hardware fill:#a8e6cf,stroke:#379683,color:#05386b;
    classDef mobile fill:#d0e1f9,stroke:#4a90e2,color:#05386b;
    classDef cloud fill:#ffe0b2,stroke:#f57c00,color:#05386b;
    classDef ml fill:#e2c1f9,stroke:#8e44ad,color:#05386b;
    classDef marketing fill:#e0e0e0,stroke:#9e9e9e,color:#05386b;
```
