A full-stack mobile application for health monitoring, fitness tracking, and AI-powered wellness insights.
- Overview
- System Architecture
- Tech Stack
- Features
- Database Schema
- API Documentation
- Authentication Flow
- Frontend Structure
- Key Algorithms
- External Integrations
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.
- 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
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
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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) โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Technology | Purpose |
|---|---|
| Flutter | Cross-platform mobile framework |
| Dart | Programming language |
| SharedPreferences | Local storage & caching |
| HTTP Package | REST API communication |
| Intl Package | Internationalization & date formatting |
| Technology | Purpose |
|---|---|
| Node.js | Runtime environment |
| Express.js | Web application framework |
| MongoDB | NoSQL database |
| Mongoose | MongoDB ODM |
| JWT | Authentication tokens |
| bcrypt | Password hashing |
| Service | Purpose |
|---|---|
| Strava API | Fitness activity synchronization |
| Google Gemini AI | Health insights generation |
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
- 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
How it works:
- Aggregates last 7 days of health data
- Sends to Google Gemini AI with structured prompt
- 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": "..." }
]
}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
| 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 |
- OAuth2 authentication flow
- Automatic activity sync on app open
- Supports: Running, Walking, Cycling, Swimming
- Data mapped to daily health logs
| Language | Code |
|---|---|
| English | en |
| Hindi | hi |
| Marathi | mr |
{
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")
}{
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){
userId: ObjectId (ref: User),
points: Number,
dailyPoints: Number,
level: Number,
badges: Array,
lastUpdatedDate: String (YYYY-MM-DD)
}| 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 |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health/day/:date |
Get health data for specific date |
| POST | /api/health/sync |
Sync daily health data |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/analytics/weekly |
Get weekly aggregated stats |
| GET | /api/analytics/monthly |
Get monthly aggregated stats |
| 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) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/ai/summary |
Get AI-generated health insights |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/strava/auth |
Strava OAuth callback |
| POST | /api/strava/sync |
Sync Strava activities |
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ 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 โ โ
โ<โโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
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
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();
}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();
}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;OAuth2 Flow:
- User clicks "Connect Strava"
- Redirect to Strava authorization page
- User grants permission
- Callback with authorization code
- Exchange code for access/refresh tokens
- 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"
}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());- Node.js v18+
- Flutter SDK 3.0+
- MongoDB Atlas account
- Strava API credentials
- Google Gemini API key
cd server
npm install
cp .env.example .env
# Configure environment variables
npm startcd client
flutter pub get
# Update API base URL in api_service.dart
flutter runPORT=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-keyBuilt with โค๏ธ for HackCrypt Hackathon
This project is licensed under the MIT License.