Skip to content

About

This is my Hakethon Project Of hackcript

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

DataPirates

๐Ÿฅ Swasth-Setu - Comprehensive Health & Fitness Tracking Platform

A full-stack mobile application for health monitoring, fitness tracking, and AI-powered wellness insights.


๐Ÿ“‹ Table of Contents

  1. Overview
  2. System Architecture
  3. Tech Stack
  4. Features
  5. Database Schema
  6. API Documentation
  7. Authentication Flow
  8. Frontend Structure
  9. Key Algorithms
  10. External Integrations

๐ŸŽฏ Overview

Swasth-Setu is a comprehensive health and fitness tracking application that combines real-time health monitoring, AI-powered insights, gamification, and social engagement to help users maintain a healthy lifestyle.

Problem Statement

  • People struggle to maintain consistent health tracking habits
  • Lack of personalized, actionable health insights
  • No motivation system to encourage daily health activities
  • Disconnected health data from various sources

Solution

SwasthSetu addresses these challenges by providing:

  • Unified health dashboard with real-time metrics
  • AI-generated personalized health recommendations
  • Gamification with points, levels, and leaderboards
  • Seamless integration with fitness platforms (Strava)
  • Smart notification system for health alerts

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         PRESENTATION LAYER                          โ”‚
โ”‚                        (Flutter Mobile App)                         โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚  โ”‚ Dashboard โ”‚ โ”‚ Analytics โ”‚ โ”‚ AI Summaryโ”‚ โ”‚Gamificationโ”‚           โ”‚
โ”‚  โ”‚  Screen   โ”‚ โ”‚  Screen   โ”‚ โ”‚  Screen   โ”‚ โ”‚  Screen   โ”‚           โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ”‚        โ”‚             โ”‚             โ”‚             โ”‚                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚                    SERVICE LAYER                         โ”‚       โ”‚
โ”‚  โ”‚  ApiService | GamificationService | NotificationService  โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                         REST API (HTTP)
                         JWT Cookie Auth
                                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         BACKEND LAYER                               โ”‚
โ”‚                      (Node.js + Express)                            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚                    ROUTE HANDLERS                        โ”‚       โ”‚
โ”‚  โ”‚  /auth | /health | /analytics | /gamification | /ai     โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚                               โ”‚                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚                    CONTROLLERS                           โ”‚       โ”‚
โ”‚  โ”‚        (Business Logic & Request Processing)             โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ”‚                               โ”‚                                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚                 MIDDLEWARE LAYER                         โ”‚       โ”‚
โ”‚  โ”‚              (Authentication & Validation)               โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                          DATA LAYER                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”‚
โ”‚  โ”‚                  MongoDB (Mongoose ODM)                  โ”‚       โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚       โ”‚
โ”‚  โ”‚  โ”‚  User   โ”‚ โ”‚DailyHealthLogโ”‚ โ”‚GamificationProfileโ”‚      โ”‚       โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚       โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚       โ”‚
โ”‚  โ”‚  โ”‚  Goal   โ”‚ โ”‚MedicalProfileโ”‚ โ”‚    Activity      โ”‚      โ”‚       โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    EXTERNAL SERVICES                                โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚  โ”‚   Strava API    โ”‚    โ”‚ Google Gemini   โ”‚                        โ”‚
โ”‚  โ”‚ (Activity Sync) โ”‚    โ”‚   (AI Insights) โ”‚                        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Tech Stack

Frontend

Technology Purpose
Flutter Cross-platform mobile framework
Dart Programming language
SharedPreferences Local storage & caching
HTTP Package REST API communication
Intl Package Internationalization & date formatting

Backend

Technology Purpose
Node.js Runtime environment
Express.js Web application framework
MongoDB NoSQL database
Mongoose MongoDB ODM
JWT Authentication tokens
bcrypt Password hashing

External Services

Service Purpose
Strava API Fitness activity synchronization
Google Gemini AI Health insights generation

โœจ Features

1. Health Dashboard ๐Ÿ“Š

Real-time Health Score Calculation:

Health Score = (Steps/StepsGoal ร— 40) + (Sleep/SleepGoal ร— 30) + (Distance/DistanceGoal ร— 30)

Dynamic Health Remarks:

Score Range Status Color
90-100 Excellent Condition Teal (#45A191)
70-89 Good Condition Green (#4CAF50)
50-69 Fair Condition Orange (#FFA726)
30-49 Poor Condition Deep Orange (#FF7043)
0-29 Needs Attention Red (#E53935)

Features:

  • Weekly calendar for date-based health viewing
  • Customizable daily goals (steps, sleep, distance)
  • Real-time data sync with backend
  • Offline mode with cached data

2. Analytics Dashboard ๐Ÿ“ˆ

  • Timeframe Selection: Today / Week / Month
  • Activity Level Charts: Bar charts showing daily steps
  • Heart Rate Monitoring: Trend visualization with resting HR calculation
  • Sleep Quality Tracking: Duration and quality assessment
  • Hydration Tracker: Manual water intake logging (2.5L - 4L goals)
  • Calorie & Distance Metrics

3. AI-Powered Health Insights ๐Ÿค–

How it works:

  1. Aggregates last 7 days of health data
  2. Sends to Google Gemini AI with structured prompt
  3. Returns personalized insights in JSON format

AI Response Structure:

{
  "summaryText": "Weekly health summary",
  "sleepAdvice": "Sleep improvement recommendation",
  "status": "Recovered | Improving | Needs Attention",
  "trend": "Positive | Neutral | Negative",
  "recommendations": [
    { "title": "...", "description": "..." }
  ]
}

4. Gamification System ๐ŸŽฎ

Points System:

Activity XP Earned
Daily activity logged +10 XP
8,000+ steps +20 XP
12,000+ steps +10 XP (bonus)
400+ calories burned +20 XP
7+ hours of sleep +20 XP

Level Progression:

  • Level = Total Points รท 100 + 1
  • Visual progress bar shows XP to next level

Badges (12 Total):

Badge Requirement
First Steps Complete 1,000 steps
Step Master Reach 10,000 steps in a day
Marathon Walker Walk 50,000 steps in a week
Sleep Champion 8+ hours sleep for 7 days
Early Bird Log activity before 7 AM
Calorie Crusher Burn 500+ calories in a day
Consistency King Log data for 30 days straight
Heart Healthy Optimal heart rate for a week
Hydration Hero Meet hydration goal for 5 days
Social Butterfly Share progress with friends
Rising Star Reach Level 5
Health Champion Reach Level 10

Leaderboard:

  • Daily rankings based on XP earned
  • Top 10 users displayed
  • Gold/Silver/Bronze highlighting for top 3

5. Smart Notifications ๐Ÿ””

Alert Type Trigger Time Constraint
Low Activity Steps < 3,000 Only after 6 PM
High Heart Rate HR > 120 BPM (resting) 2-hour cooldown
Abnormal Sleep < 5 or > 10 hours 24-hour cooldown
Daily Health Check Scheduled reminder 8 PM daily

6. Strava Integration ๐Ÿƒ

  • OAuth2 authentication flow
  • Automatic activity sync on app open
  • Supports: Running, Walking, Cycling, Swimming
  • Data mapped to daily health logs

7. Multi-language Support ๐ŸŒ

Language Code
English en
Hindi hi
Marathi mr

๐Ÿ—„๏ธ Database Schema

User Model

{
  name: String,
  email: String (unique, lowercase),
  password: String (hashed),
  age: Number,
  gender: "male" | "female" | "other",
  height: Number (cm),
  weight: Number (kg),
  mobile: String,
  strava: {
    accessToken: String,
    refreshToken: String,
    expiresAt: Number
  },
  role: String (default: "user")
}

DailyHealthLog Model

{
  userId: ObjectId (ref: User),
  date: String (YYYY-MM-DD),
  steps: Number,
  distance: Number (km),
  caloriesBurned: Number,
  heartRateAvg: Number,
  sleep: {
    duration: Number (hours),
    quality: "poor" | "average" | "good"
  },
  nutrition: {
    caloriesConsumed: Number,
    waterIntake: Number (liters)
  },
  mood: {
    moodLevel: Number (1-5),
    stressLevel: Number (1-5)
  },
  source: "google_fit" | "manual" | "strava"
}
// Index: { userId: 1, date: 1 } (unique)

GamificationProfile Model

{
  userId: ObjectId (ref: User),
  points: Number,
  dailyPoints: Number,
  level: Number,
  badges: Array,
  lastUpdatedDate: String (YYYY-MM-DD)
}

๐Ÿ“ก API Documentation

Authentication Endpoints

Method Endpoint Description
POST /api/auth/register User registration
POST /api/auth/login User login (returns JWT cookie)
POST /api/auth/logout User logout
GET /api/auth/profile Get current user profile

Health Endpoints

Method Endpoint Description
GET /api/health/day/:date Get health data for specific date
POST /api/health/sync Sync daily health data

Analytics Endpoints

Method Endpoint Description
GET /api/analytics/weekly Get weekly aggregated stats
GET /api/analytics/monthly Get monthly aggregated stats

Gamification Endpoints

Method Endpoint Description
GET /api/gamification/profile Get user's gamification profile
POST /api/gamification/sync Calculate and sync daily points
GET /api/gamification/leaderboard/today Get today's top 10
POST /api/gamification/reset Reset gamification (dev only)

AI Endpoints

Method Endpoint Description
GET /api/ai/summary Get AI-generated health insights

Strava Endpoints

Method Endpoint Description
GET /api/strava/auth Strava OAuth callback
POST /api/strava/sync Sync Strava activities

๐Ÿ” Authentication Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Flutter    โ”‚     โ”‚   Express    โ”‚     โ”‚   MongoDB    โ”‚
โ”‚    Client    โ”‚     โ”‚   Server     โ”‚     โ”‚   Database   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                    โ”‚                    โ”‚
       โ”‚  POST /auth/login  โ”‚                    โ”‚
       โ”‚  {email, password} โ”‚                    โ”‚
       โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚                    โ”‚
       โ”‚                    โ”‚   Find User        โ”‚
       โ”‚                    โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚
       โ”‚                    โ”‚   User Document    โ”‚
       โ”‚                    โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚                    โ”‚  Verify Password   โ”‚
       โ”‚                    โ”‚  (bcrypt.compare)  โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚                    โ”‚  Generate JWT      โ”‚
       โ”‚                    โ”‚  (24h expiry)      โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚  Set-Cookie: token โ”‚                    โ”‚
       โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚                    โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚  Store in          โ”‚                    โ”‚
       โ”‚  SharedPreferences โ”‚                    โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚  GET /health/day   โ”‚                    โ”‚
       โ”‚  Cookie: token=jwt โ”‚                    โ”‚
       โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚                    โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚                    โ”‚  authMiddleware    โ”‚
       โ”‚                    โ”‚  verify(token)     โ”‚
       โ”‚                    โ”‚  req.user = {id}   โ”‚
       โ”‚                    โ”‚                    โ”‚
       โ”‚                    โ”‚  Query by userId   โ”‚
       โ”‚                    โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€>โ”‚
       โ”‚                    โ”‚  Health Data       โ”‚
       โ”‚                    โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚
       โ”‚   JSON Response    โ”‚                    โ”‚
       โ”‚<โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚                    โ”‚
       โ”‚                    โ”‚                    โ”‚

๐Ÿ“ฑ Frontend Structure

client/lib/
โ”œโ”€โ”€ main.dart                    # App entry point
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ api_service.dart         # REST API communication
โ”‚   โ”œโ”€โ”€ gamification_service.dart # Gamification API
โ”‚   โ””โ”€โ”€ notification_service.dart # Local notifications
โ””โ”€โ”€ screens/
    โ”œโ”€โ”€ splash_screen.dart       # App loading screen
    โ”œโ”€โ”€ login_screen.dart        # User authentication
    โ”œโ”€โ”€ registration_screen.dart # New user signup
    โ”œโ”€โ”€ dashboard/
    โ”‚   โ””โ”€โ”€ dashboard_screen.dart # Main health dashboard
    โ”œโ”€โ”€ Analytics/
    โ”‚   โ””โ”€โ”€ analytics_screen.dart # Health analytics
    โ”œโ”€โ”€ Ai_summary/
    โ”‚   โ””โ”€โ”€ summary_screen.dart  # AI health insights
    โ”œโ”€โ”€ gamification/
    โ”‚   โ””โ”€โ”€ gamification_screen.dart # Points, badges, leaderboard
    โ”œโ”€โ”€ History_page/
    โ”‚   โ””โ”€โ”€ history_page.dart    # Historical health data
    โ”œโ”€โ”€ profile_page/
    โ”‚   โ””โ”€โ”€ profile_page.dart    # User profile
    โ””โ”€โ”€ settings_page/
        โ””โ”€โ”€ settings_page.dart   # App settings

๐Ÿงฎ Key Algorithms

Health Score Calculation

int calculateHealthScore(int steps, double sleep, int distance) {
  double score = 
    (steps / stepsGoal * 40) +     // 40% weight
    (sleep / sleepGoal * 30) +     // 30% weight
    (distance / distanceGoal * 30); // 30% weight
  return score.clamp(0, 100).toInt();
}

Resting Heart Rate Estimation

int calculateRestingHeartRate(int avgHR) {
  double multiplier = 0.75; // Base: 75% of avg daily HR
  
  // Adjust for sleep quality
  if (sleepQuality == 'good') multiplier = 0.72;
  if (sleepQuality == 'bad') multiplier = 0.78;
  
  // Adjust for activity level
  if (steps > 8000) multiplier -= 0.02;
  if (steps < 3000) multiplier += 0.02;
  
  return (avgHR * multiplier).clamp(50, 100).round();
}

Gamification Points Calculation

let dailyPoints = 10; // Base activity points

if (steps >= 8000) dailyPoints += 20;
if (steps >= 12000) dailyPoints += 10;
if (caloriesBurned >= 400) dailyPoints += 20;
if (sleep.duration >= 7) dailyPoints += 20;

level = Math.floor(totalPoints / 100) + 1;

๐Ÿ”— External Integrations

Strava API Integration

OAuth2 Flow:

  1. User clicks "Connect Strava"
  2. Redirect to Strava authorization page
  3. User grants permission
  4. Callback with authorization code
  5. Exchange code for access/refresh tokens
  6. Store tokens in User document

Activity Sync:

// Fetch activities from Strava
GET https://www.strava.com/api/v3/athlete/activities
Authorization: Bearer {access_token}

// Map to DailyHealthLog
{
  steps: activity.distance / 0.75,  // Estimate from distance
  caloriesBurned: activity.calories,
  distance: activity.distance / 1000, // Convert to km
  source: "strava"
}

Google Gemini AI Integration

Request Flow:

const prompt = `
User health data (last 7 days):
- Average steps per day: ${avgSteps}
- Average sleep hours: ${avgSleep}

Return ONLY valid JSON with health insights...
`;

const response = await geminiModel.generateContent(prompt);
const insights = JSON.parse(response.text());

๐Ÿš€ Getting Started

Prerequisites

  • Node.js v18+
  • Flutter SDK 3.0+
  • MongoDB Atlas account
  • Strava API credentials
  • Google Gemini API key

Backend Setup

cd server
npm install
cp .env.example .env
# Configure environment variables
npm start

Frontend Setup

cd client
flutter pub get
# Update API base URL in api_service.dart
flutter run

Environment Variables

PORT=4000
MONGODB_URI=mongodb+srv://...
JWT_SECRET=your-secret-key
STRAVA_CLIENT_ID=your-client-id
STRAVA_CLIENT_SECRET=your-secret
GEMINI_API_KEY=your-api-key

๐Ÿ‘ฅ Team - DataPirates

Built with โค๏ธ for HackCrypt Hackathon


๐Ÿ“„ License

This project is licensed under the MIT License.

About

This is my Hakethon Project Of hackcript

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages