Skip to content

Latest commit

ย 

History

54 Commits

Folders and files

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

Repository files navigation

MicroWins ๐Ÿš€

A Flutter habit-tracking app focused on micro-habits (2-5 minutes) with gamification, AI suggestions, and reliable background notifications.

โœจ Features

Core Functionality

  • Habit Management: Create, track, and manage daily micro-habits
  • Smart Notifications: Reliable WorkManager-based reminders (15-min intervals)
  • Offline-First: Full offline support with Hive local storage
  • Cloud Sync: Firebase Firestore synchronization when online
  • AI-Powered: Personalized habit suggestions via secure backend proxy

Gamification System

  • ๐Ÿ”ฅ Streak Tracking: Build momentum with daily consecutive streaks
  • ๐ŸŽฏ Achievement System: Unlock 15+ badges across 5 categories (Streak Master, Consistency Champion, Weekly Warrior, Milestone Master, Perfect Week)
  • ๐Ÿ“Š Progress Dashboard: Interactive charts with weekly trends and comparative statistics
  • โญ Level System: Progress through 10 levels from "Beginner" to "Legend" with experience points
  • ๐Ÿ† Badge Rarity: 5 rarity tiers (Common, Uncommon, Rare, Epic, Legendary) with visual distinctions
  • ๐ŸŽ‰ Celebrations: Confetti animations and notifications on habit completion and achievement unlocks
  • ๐Ÿ“ˆ Statistics: Comprehensive tracking of current streak, best streak, total completions, and weekly progress

Technical Highlights

  • Multi-Process Notifications: WorkManager + Firestore for reliable background tasks
  • Firebase Auth: Email/password and Google Sign-In
  • AdMob Integration: Banner ads for monetization

๐Ÿ› ๏ธ Tech Stack

Category Technology
Framework Flutter 3.19+ / Dart 3.3+
State Management Riverpod (Code Generation)
Navigation GoRouter
Local Storage Hive
Backend Firebase (Auth, Firestore)
Notifications WorkManager + flutter_local_notifications
AI Backend AI proxy (OpenRouter in server-side)
Ads Google Mobile Ads (AdMob)

๐Ÿš€ Getting Started

Prerequisites

  • Flutter SDK 3.19+
  • Firebase Project (Create one)
  • Backend endpoint for AI suggestions (AI_PROXY_URL)
  • Android Studio / Xcode (for mobile development)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/microwins.git
    cd microwins
  2. Install dependencies:

    flutter pub get
  3. Firebase Setup:

    a. Create a Firebase project at console.firebase.google.com

    b. Add Android/iOS apps to your Firebase project

    c. Download configuration files:

    • Android: google-services.json โ†’ android/app/
    • iOS: GoogleService-Info.plist โ†’ ios/Runner/

    d. Enable Authentication methods in Firebase Console:

    • Email/Password
    • Google Sign-In

    e. Create Firestore database (start in test mode)

  4. AI Backend Setup:

    Configure a secure backend endpoint and pass it at runtime:

    flutter run --dart-define=AI_PROXY_URL=https://your-backend.example.com
  5. Code Generation:

    Run build_runner to generate Riverpod and Hive code:

    dart run build_runner build --delete-conflicting-outputs
  6. Run the App:

    # Android
    flutter run
    
    # iOS
    flutter run -d ios
    
    # Specific device
    flutter run -d <device-id>

๐Ÿ“ฑ Architecture

Clean Architecture

lib/
โ”œโ”€โ”€ core/                    # Shared utilities
โ”‚   โ”œโ”€โ”€ notifications/       # WorkManager + Firestore notifications
โ”‚   โ”œโ”€โ”€ sync/               # Firebase sync manager
โ”‚   โ”œโ”€โ”€ local/              # Hive setup and configuration
โ”‚   โ””โ”€โ”€ theme/              # App theming
โ”œโ”€โ”€ features/
โ”‚   โ”œโ”€โ”€ auth/               # Authentication (Firebase)
โ”‚   โ”œโ”€โ”€ habits/             # Habit CRUD operations
โ”‚   โ”œโ”€โ”€ gamification/       # Achievements, levels, and progress tracking
โ”‚   โ”‚   โ”œโ”€โ”€ domain/         # Services (AchievementService, GamificationService)
โ”‚   โ”‚   โ”œโ”€โ”€ data/           # Repository and models (HabitCompletionModel)
โ”‚   โ”‚   โ””โ”€โ”€ presentation/   # UI (ProgressScreen, BadgesScreen)
โ”‚   โ”œโ”€โ”€ ai_suggestions/     # AI backend proxy integration
โ”‚   โ””โ”€โ”€ profile/            # User settings
โ””โ”€โ”€ firebase_options.dart   # Firebase configuration

Notification System

Problem Solved: Android 12+ blocks recurring exact alarms, making traditional notification scheduling unreliable.

Solution: WorkManager + Firestore multi-process architecture

Main App Process              WorkManager Process
================              ===================
User creates habit            (every 15 minutes)
    โ†“                                โ†“
Save to Firestore  โ†โ”€โ”€โ”€โ”€โ”€โ†’  Read from Firestore
    โ†“                                โ†“
Save userId to          Read userId from
SharedPreferences       SharedPreferences
                                     โ†“
                            Check for due habits
                                     โ†“
                            Show notifications

Key Features:

  • โœ… Works across app restarts
  • โœ… Survives phone reboots
  • โœ… Multi-process safe (Firestore + SharedPreferences)
  • โœ… Notifications arrive within 0-15 minutes of scheduled time

Trade-off: Notifications may arrive up to 15 minutes late (Android WorkManager limitation)


๐ŸŽฎ Gamification System

Overview

MicroWins features a comprehensive gamification system designed to maximize user engagement and habit consistency through psychological reinforcement mechanics.

Achievement Categories

Category Icon Focus Badges
Streak Master ๐Ÿ”ฅ Daily consecutive completions 4 badges (3, 7, 30, 100 days)
Consistency Champion ๐Ÿ“… Monthly completion frequency 3 badges (7, 20, 28+ days/month)
Weekly Warrior ๐Ÿ“ˆ Weekly volume 3 badges (5, 10, 20 habits/week)
Milestone Master ๐Ÿ† Cumulative achievements 4 badges (10, 50, 100, 500 total)
Perfect Week โญ Weekly perfection 2 badges (3+, 5+ habits)

Level Progression

  • 10 Levels: Principiante โ†’ Novato โ†’ Aprendiz โ†’ Practicante โ†’ Dedicado โ†’ Comprometido โ†’ Experto โ†’ Maestro โ†’ Gran Maestro โ†’ Leyenda
  • EXP Formula: Each level requires 100 * level additional EXP
  • Bonuses: Streak bonuses (+5 to +20 EXP), first of day (+5 EXP), perfect week (+15 EXP)

๐Ÿ”” Notification Behavior

Scenario Behavior
App open Notification arrives 0-15 min after scheduled time
App closed WorkManager continues checking every 15 min
Phone restart WorkManager resumes automatically
No internet Works offline (reads from Firestore cache)

Why 15 minutes?

  • Android restricts background tasks to save battery
  • WorkManager is the only reliable solution on Android 12+
  • Same approach used by Todoist, Microsoft To-Do, Google Keep

๐Ÿงช Testing

Unit Tests

flutter test

Integration Tests

flutter test integration_test/

Testing Notifications

  1. Sign in to the app (saves userId to SharedPreferences)
  2. Create a habit with a reminder time 5-10 minutes from now
  3. Close the app completely
  4. Wait for the notification (arrives within 15 min)

View logs:

flutter logs --device-id=<device-id> | grep -i "workmanager\|flutter"

Expected output:

๐Ÿ”” WorkManager: Checking for due notifications...
๐Ÿ“ฆ Found 1 habits in Firestore
โœ… Showed notification for: [habit name]

๐Ÿ”ง Configuration

Firebase

  • android/app/google-services.json - Android config
  • ios/Runner/GoogleService-Info.plist - iOS config
  • lib/firebase_options.dart - Generated by FlutterFire CLI

Runtime Configuration

  • AI_PROXY_URL (--dart-define) - Backend endpoint for AI suggestions

Secure AI Backend (Cloud Functions)

  1. Install dependencies:
cd functions
npm install
cd ..
  1. Set the OpenRouter secret in Firebase Secret Manager:
firebase functions:secrets:set OPENROUTER_API_KEY
  1. Deploy functions:
firebase deploy --only functions
  1. Configure app runtime with your function base URL:
flutter run --dart-define=AI_PROXY_URL=https://europe-west1-<your-project-id>.cloudfunctions.net/api

The app calls POST /ai/habits on that backend URL.

Android Permissions

Required permissions in AndroidManifest.xml:

  • INTERNET - Network access
  • POST_NOTIFICATIONS - Show notifications (Android 13+)
  • RECEIVE_BOOT_COMPLETED - Restart WorkManager after reboot
  • WAKE_LOCK - Keep WorkManager running

๐Ÿ“ฆ Dependencies

Core

  • flutter_riverpod - State management
  • riverpod_annotation - Code generation
  • go_router - Navigation
  • hive_flutter - Local storage

Firebase

  • firebase_core - Firebase initialization
  • firebase_auth - Authentication
  • cloud_firestore - Cloud database
  • google_sign_in - Google OAuth

Notifications

  • flutter_local_notifications - Show notifications
  • workmanager - Background task scheduling
  • shared_preferences - Multi-process data sharing
  • permission_handler - Runtime permissions

AI & Ads

  • http - Backend AI proxy calls
  • google_mobile_ads - AdMob integration

๐Ÿšข Deployment

Android

  1. Build release APK:

    flutter build apk --release
  2. Build App Bundle (for Play Store):

    flutter build appbundle --release
  3. Install on device:

    flutter install --device-id=<device-id>

iOS

  1. Build for iOS:

    flutter build ios --release
  2. Archive in Xcode for App Store submission


๐Ÿ› Troubleshooting

Notifications not arriving

Issue: "Found 0 habits in Firestore" in logs

Solution:

  1. Sign out and sign in again (saves userId to SharedPreferences)
  2. Verify habit has a reminderTime set
  3. Check Firestore rules allow read access

Issue: Notifications delayed more than 15 minutes

Solution:

  • Check battery optimization settings (Settings โ†’ Apps โ†’ MicroWins โ†’ Battery โ†’ Unrestricted)
  • Verify WorkManager is running: adb shell dumpsys jobscheduler | grep microwins

Firebase connection issues

Issue: "No user logged in" in WorkManager logs

Solution:

  • Ensure user is signed in before creating habits
  • Check SharedPreferences has current_user_id key

๐Ÿ“„ License

MIT License - see LICENSE file for details


๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Follow Conventional Commits
  4. Submit a pull request

๐Ÿ“ž Support

For issues or questions:

  • Open an issue on GitHub
  • Check existing documentation in /docs

Built with โค๏ธ using Flutter

About

Minimalist, gamified habit tracker focused on micro-routines of 2 to 30 minutes. Create, complete, and track habits with a simple interface, smart reminders, and optional cloud sync

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages