Skip to content

A smart diabetes management app built with Flutter (frontend), PHP & MySQL (backend). Features real-time blood sugar monitoring, instant alerts, medication reminders, and activity tracking.

License

Notifications You must be signed in to change notification settings

tawafmesar/DiabetesAlertSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of Contents

Loading

DiabetesAlertSystem

A smart diabetes management application — cross-platform mobile frontend built with Flutter (Dart) and a lightweight PHP + MySQL backend. Features real-time blood sugar tracking, configurable alerts, medication reminders, activity logs, and simple REST-style endpoints to enable integration with other systems.

This document provides a clear project overview, technical architecture, deployment and development instructions, API references, and contribution guidelines suitable for professional audiences (maintainers, reviewers, and developers).


Project Overview

DiabetesAlertSystem is a cross-platform mobile application for tracking and managing diabetes-related health metrics. The app lets patients record metrics (blood sugar, blood pressure, heart rate), receive alerts, store medication schedules, and view historical metrics. The backend is a lightweight PHP-based API that stores users, metrics, alarms and medication records in a MySQL database.

This repository contains:

  • Flutter app source (src/diabetes_alert_system/)
  • PHP backend API (src/backend/)
  • SQL schema and seed data (src/backend/database/)
  • Supporting scripts and utilities

Before making the repository public, ensure all secrets are removed from source control (see Security & Privacy Notes).


Key Features

  • User authentication endpoints (login/signup flows).
  • Persistent user metrics (blood sugar, blood pressure, heart rate).
  • Alarm management (create/view/remove alarms).
  • Medication records and simple CRUD.
  • A Flutter frontend with organized screens and controllers.
  • Lightweight PHP backend using PDO with JSON responses.
  • Exportable SQL schema to easily initialize a database.

Screenshots

Splash Animation 1 Splash Animation 2 Registration Screen Email Verification Screen Success Registration Screen
Splash Animation1 Splash Animation2 Registration Screen Email Verification Screen Success Registration Screen
Login Screen Forget Password Screen Verification Code Screen Reset Password Screen Password Reset Success Screen
Login Screen Forget Password Screen Verification Code Screen Reset Password Screen Password Reset Success Screen
Bottom Navigation Custom Drawer Open Medication List Screen 1 Medication List Screen 2 Add Medication Bottom Dialog
Bottom Navigation Custom Drawer Open Medication List Screen 1 Medication List Screen Add Medication Bottom Dialog
Delete Confirmation Dialog Health Metrics List — Screen 1 Health Metrics List — Screen 2 Add Medication Dialog (add metric) Result of Adding Metric
Delete Confirmation Dialog Health Metrics List 1 Health Metrics List 2 Add Medication Dialog Result of Adding Metric
Delete Confirmation (metric) Result of Deleting Metric Health Metric Guidance — Pop-up 1 Health Metric Guidance — Pop-up 2 Alarm List 1
Delete Confirmation Metric Result of Deleting Metric Health Metric Guidance 1 Health Metric Guidance 2 Alarm List 1
Alarm List 2 Add Alarm Screen Add Alarm Screen (Time Picker) Ringing Alarm Notification
Alarm List 2 Add Alarm Screen Add Alarm Screen Time Picker Ringing Alarm Notification
Challenge Screen After Finish Challenge Delete Confirmation (alarm) Result of Deleting Alarm Activity List — Screen 1
Challenge Screen After finish Challenge Delete Confirmation Alarm Result of Deleting Alarm Activity List 1
Activity List — Screen 2 Add Activity (before selecting a type) Add Activity Add Activity (Stopwatch) Activity added successfully
Activity List 2 Add Activity before select type Add Activity Add Activity Stopwatch Activity added successfully
Dashboard — Overview Home — Quick Actions opens Home — Scrolling 1 Home — Scrolling 2 Loading
Dashboard Overview Home Quick Actions opens Home Scrolling 1 Home Scrolling 2 Loading

Technology Stack

  • Frontend: Flutter (Dart) — located at src/diabetes_alert_system/ (contains lib/, pubspec.yaml, assets/).
  • Backend: Plain PHP (PDO) — located at src/backend/ (PHP controllers / endpoints).
  • Database: MySQL (schema SQL files in src/backend/database/).
  • Email: PHPMailer (bundled in backend includes).
  • Optional: any third-party API keys are read from environment variables.

Repository structure (high-level)

The repository is organized to separate the mobile app from the server API:

DiabetesAlertSystem/
├─ LICENSE
├─ README.md
├─ .gitignore
└─ src/
   ├─ diabetes_alert_system/   # Flutter app
   │  ├─ lib/                  # Flutter source code (UI, controllers, services)
   │  ├─ pubspec.yaml
   │  └─ assets/
   └─ backend/                  # PHP backend (small REST-style endpoints)
      ├─ auth/                  # authentication endpoints (e.g., login.php)
      ├─ alarms/                # alarm endpoints (view.php, remove.php)
      ├─ metrics/               # metrics endpoints (add.php)
      ├─ database/              # SQL schema and seed files (e.g., medications.sql)
      ├─ includes/              # PHPMailer and helpers
      ├─ connect.php            # DB connection and environment loader
      ├─ env.php                # .env file loader
      └─ .env                   # (DO NOT commit to public repo) environment values

Note: The exact file listing may be larger — inspect the repository UI for a complete file tree.


Quick Start — Local Development

These instructions help contributors run the system locally. They are intentionally explicit to onboard new developers quickly.

Prerequisites

  • Flutter SDK (stable; recommended matching the project channel in .metadata).
  • Android Studio / Xcode or another device/emulator to run the Flutter app.
  • PHP 7.4+ with PDO MySQL extension enabled.
  • MySQL / MariaDB server.
  • A local web server environment (XAMPP, MAMP, LAMP) or Docker for the PHP backend.
  • curl or Postman for testing API endpoints.

Backend (PHP + MySQL)

  1. Place the backend into a web-accessible directory. Example:

    • Linux: /var/www/html/diabetes-backend
    • Windows (XAMPP): C:\xampp\htdocs\diabetes-backend
  2. Import the database schema:

    • Using MySQL CLI:

      mysql -u root -p < src/backend/database/medications.sql
      

      (This imports the medications table and seed data — import any additional .sql files found in src/backend/database/.)

    • Using phpMyAdmin:

      • Create a database (e.g., diabetes_alert_system), set collation to utf8mb4_unicode_ci.
      • Import the .sql files via phpMyAdmin -> Import.
  3. Configure environment variables:

    • Create a .env file in src/backend/ (do NOT commit this to public repo) with the following variables:
      DB_HOST=127.0.0.1
      DB_NAME=diabetes_alert_system
      DB_USER=root
      DB_PASSWORD=your_db_password
      SMTP_USER=your_smtp_user@example.com
      SMTP_PASSWORD=your_smtp_password
      
    • The backend includes env.php to load this file at runtime.
  4. File permissions:

    • Ensure the webserver user can read connect.php, env.php and write to any upload directories if used.
  5. Test an endpoint (adjust URL based on your server):

    curl -X POST "http://localhost/diabetes-backend/auth/login.php" \
      -F "email=alice@example.com" -F "password=secret"
    
  6. Quick PHP built-in server (for small-scale testing):

    cd src/backend
    php -S 0.0.0.0:8000
    # then point your Flutter app API_BASE_URL to http://<host>:8000/
    

Frontend (Flutter)

  1. Open src/diabetes_alert_system/ in your IDE.

  2. Update backend base URL:

    • Locate the code that stores the API base URL (commonly in a lib/linkapi.dart or similar file). Update it to the backend address you configured (local or remote).
    • Example:
      static const String server = "http://YOUR_SERVER_ADDRESS/diabetes-backend/";
  3. (Optional) Add environment variables if used (create .env in src/diabetes_alert_system/ next to pubspec.yaml if the project reads from it):

    API_BASE_URL=http://YOUR_SERVER_ADDRESS/diabetes-backend/
    OTHER_API_KEYS=...
    
  4. Install packages and run:

    cd src/diabetes_alert_system
    flutter pub get
    flutter run
    
  5. For emulator network mapping:

    • Android emulator: host machine is reachable at 10.0.2.2 (if you run PHP server on the same machine).
    • Physical device: use machine LAN IP (e.g., http://192.168.1.10/diabetes-backend/).

Configuration & Environment

  • Backend .env (create locally; DO NOT commit):

    DB_HOST=127.0.0.1
    DB_NAME=diabetes_alert_system
    DB_USER=root
    DB_PASSWORD=your_db_password
    SMTP_USER=youremail@example.com
    SMTP_PASSWORD=your_smtp_password
    
  • Frontend optional .env (next to pubspec.yaml):

    API_BASE_URL=http://YOUR_SERVER_ADDRESS/diabetes-backend/
    OTHER_KEYS=...
    
  • Update any server constants in frontend source (e.g., lib/linkapi.dart) if the project does not read from environment.


Database

  • SQL files are stored under src/backend/database/. Example: medications.sql.
  • Typical tables to expect: users, metrics, alarms (or alarms related views), medications.
  • After import, verify tables and seed data via your database client.

API Reference (summary)

Base URL (example):

http://<your-host>/diabetes-backend/

Note: The backend exposes small PHP endpoint scripts. All POST endpoints accept form-encoded data; file uploads use multipart/form-data. Responses are JSON objects with status and optional data.

Authentication:

  • auth/login.php (POST) — params: email, password (note: password may be hashed with sha1 in current implementation). Returns user record on success.

Alarms / Notifications:

  • alarms/view.php (POST) — params: id (user id) — returns alarms/metrics view for user.
  • alarms/remove.php (POST) — params: id (alarm id) — deletes a single alarm.
  • alarms/removeall.php (POST) — params: id (user id) — remove all alarms for a user.

Metrics:

  • metrics/add.php (POST) — params include id (user id), metric_type (e.g., "Blood Sugar", "Blood Pressure", "Heart Rate"), value1, value2 (optional for BP). Stores a metric and returns status.

Medications:

  • SQL and seed available at src/backend/database/medications.sql. Backend endpoints for CRUD on medications may exist — inspect src/backend/ for specific files.

Utility:

  • connect.php — sets up PDO connection, CORS headers and includes functions.php.
  • functions.php — contains helpers (filterRequest, getData, insertData, getAllData, etc.) and PHPMailer integration.

Important: The above is a summary from repository inspection; for an exhaustive list, browse src/backend/ and grep for <?php endpoints.


Testing

  • Manual testing: Use Postman or curl to call endpoints.
  • E2E: Run Flutter in debug and exercise UI flows (login, add metrics, create alarms).
  • Unit tests: The Flutter project currently does not include unit/widget tests by default. Add tests under src/diabetes_alert_system/test/ for critical logic.
  • Backend tests: None included — consider adding PHPUnit or integration tests that run against a test database.

Building & Release

  • Android: flutter build apk --release or flutter build appbundle
  • iOS: flutter build ios (macOS + Xcode required)
  • Make sure to update frontend API base URL to production endpoint before building release artifacts.

Contributing

Thank you for contributing. Suggested workflow:

  1. Fork the repository and create a feature branch (e.g., feature/metrics-export).
  2. Commit changes in small, testable increments and include descriptive commit messages.
  3. Open a pull request and describe the change, include screenshots for UI updates.
  4. Add or update API contract docs if endpoint behavior changes.

Coding standards:

  • Dart: follow official Dart/Flutter style guidelines.
  • PHP: prefer prepared statements (PDO) and sanitize inputs (already using helpers like filterRequest() in code).

Security & Privacy Notes

  • DO NOT publish .env files or credentials. I found src/backend/.env committed in the repo during inspection. That file includes SMTP credentials — remove it and rotate the exposed credentials immediately before making the repo public.
  • Remove any commits that contain secrets from repository history (use git filter-repo or BFG Repo-Cleaner). Rotate credentials after removal.
  • Add .env to .gitignore.
  • Sanitize and validate all user inputs server-side. The backend uses helper functions but review them for edge cases and injection risks.
  • Use HTTPS for production API endpoints and secure SMTP configuration for email sending.
  • Consider hashing passwords with a stronger algorithm (bcrypt/argon2) instead of sha1.

Suggested commands to scrub secrets:

  • BFG:
    bfg --delete-files .env
    git reflog expire --expire=now --all
    git gc --prune=now --aggressive
    
  • Or use git filter-repo to remove sensitive files/strings.

License

This project is distributed under the MIT License. See LICENSE for full text.


Contact / Maintainers

  • Owner / primary maintainer: GitHub: tawafmesar
  • For issues, feature requests, or security disclosures: open an issue in this repository or contact the maintainer directly (email in AUTHORS/metadata if provided). If you exposed credentials and rotated them, list rotated secrets in a secure channel.

Appendix — Useful commands & tips

  • Import DB:

    mysql -u <user> -p diabetes_alert_system < src/backend/database/medications.sql
    
  • Run PHP built-in server:

    cd src/backend
    php -S 0.0.0.0:8000
    
  • Flutter run:

    cd src/diabetes_alert_system
    flutter pub get
    flutter run
    
  • Remove .env from history (example with BFG):

    bfg --delete-files .env
    git reflog expire --expire=now --all
    git gc --prune=now --aggressive
    
  • Critical: remove and rotate credentials (SMTP, DB passwords) found in src/backend/.env before making the repository public. If you want, I can produce a .gitignore and a short migration plan to remove secrets from history.

About

A smart diabetes management app built with Flutter (frontend), PHP & MySQL (backend). Features real-time blood sugar monitoring, instant alerts, medication reminders, and activity tracking.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages