HabitFlow — Offline-First Habit Tracking App

Tech Stack Versions
Precise technology versions used in this project
Screenshots
Main feature screens of the project
Home — Daily habit list with swipe-to-complete and streak tracking
AI Coach — Personalized insights based on 30-day habit data
Vocabulary — Spaced repetition system with NEW / FAMILIAR / MASTERED stages
New Habit — Frequency, category, color & icon customization
Settings — Theme toggle, data export, AI provider configuration
Capabilities Demonstrated
Technical and business capabilities demonstrated through this project
- Multi-Provider AI Integration — Strategy Pattern architecture supports OpenAI, Gemini, and Claude with zero SDK dependencies, enabling provider switching without code changes
- AI-Powered Habit Coaching — Analyzes 30-day behavioral data (completion rates, streaks, patterns) to generate personalized improvement suggestions cached in SQLite
- Custom Spaced Repetition System — Three-tier mastery progression (new, familiar, mastered) with automatic demotion on incorrect answers and review debt tracking
- Visual Progress Analytics — GitHub-style SVG contribution heatmap with 5-level intensity coloring and responsive weekly completion bar charts, all rendered with zero third-party chart dependencies
- Privacy-First Local Architecture — All data stored on-device in SQLite with encrypted API key storage via expo-secure-store, no cloud dependency or subscription required
Challenges Faced
Main technical challenges encountered during development
- Integrating 3 AI providers (OpenAI, Gemini, Claude) with different API formats, authentication methods, and response structures without installing any provider SDKs
- Implementing a spaced repetition algorithm that correctly manages mastery transitions, prevents unbounded review debt, and demotes on incorrect answers
- Eliminating N+1 query patterns in statistics calculations where each habit required a separate completion count query
- Handling date comparisons for streak calculation that break during daylight saving time transitions when using millisecond math
- Storing sensitive API keys securely on mobile devices while maintaining a smooth user experience for key management
Solutions
Technical solutions and implementation strategies adopted
- Designed a Strategy Pattern with AIProviderConfig interface — each provider is a pure config object with buildHeaders(), buildBody(), and parseResponse() methods. Adding a new provider requires implementing one object, zero SDK installations.
- Built a finite state machine in markReviewed() with explicit mastery transitions (new→familiar→mastered), automatic demotion rules, and needReview debt capped at 10 via Math.min() to prevent unbounded growth.
- Refactored StatsRepository to execute 2 bulk SQL queries (all habits + all completions in date range) and aggregate results in-memory using a Map, reducing database round-trips from O(n) to O(1).
- Replaced 86400000ms arithmetic with calendar-based comparison using setDate(day+1), which correctly accounts for DST transitions where days may be 23 or 25 hours.
- Used expo-secure-store for encrypted keychain storage with per-provider key naming convention (aiApiKeyStorageKey function), abstracting platform-specific encryption behind a clean API.
Code Snippets
Key implementation code from the project
// services/aiProviders.ts
export interface AIProviderConfig {
id: string;
name: string;
buildHeaders: (apiKey: string) => Record<string, string>;
buildBody: (model: string, messages: ChatMessage[]) => Record<string, unknown>;
parseResponse: (data: unknown) => string;
models: AIModelOption[];
}
export const OPENAI_PROVIDER: AIProviderConfig = {
id: 'openai',
name: 'OpenAI',
buildHeaders: (apiKey) => ({
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
}),
buildBody: (model, messages) => ({ model, messages }),
parseResponse: (data: any) => data.choices[0].message.content,
models: [{ id: 'gpt-4o-mini', label: 'GPT-4o Mini' }],
};Architecture Decisions
Key architectural and technical decisions made during development
Context
HabitFlow integrates 3 AI providers (OpenAI, Gemini, Claude). The choice was between installing each provider's official SDK or using a unified interface with pure fetch().
Options Compared
- Type-safe API calls with auto-complete
- 3 SDK dependencies (+bundle size), different API patterns per provider
- React Native compatibility issues with Node.js-specific SDKs
- Zero dependencies, uniform interface, trivial to add new providers
- Works everywhere fetch() works — no platform compatibility issues
- Must manually handle each provider's request/response format
Decision
Chose Strategy Pattern: AIProviderConfig interface with buildHeaders/buildBody/parseResponse. Each provider is one config object. Adding a 4th provider requires zero new dependencies.
Outcome
3 providers integrated in ~60 lines of config code, zero SDK dependencies, bundle size stays minimal, and the pattern is proven extensible.
Technical Highlights
In-depth technical implementation details and architecture design
Strategy Pattern AI Integration
- AIProviderConfig interface with buildHeaders/buildBody/parseResponse methods enables adding new LLM providers by implementing a single config object — no SDK dependencies, just fetch()
Spaced Repetition State Machine
- Finite state machine in markReviewed() manages mastery transitions (new→familiar→mastered) with automatic demotion and review debt capped at 10 to prevent unbounded growth
N+1 Query Elimination
- StatsRepository uses 2 SQL queries + in-memory Map aggregation instead of per-habit queries, eliminating N+1 patterns in weekly completion rate calculations
DST-Safe Date Handling
- isConsecutiveDay() uses calendar arithmetic (setDate+1) instead of 86400000ms comparison, correctly handling daylight saving time transitions
Key Takeaways
Important lessons and reflections from this project
Zero-Dependency AI Integration Scales Better
Real Impact: Using fetch() with a Strategy Pattern interface instead of provider SDKs eliminated React Native compatibility issues and made adding the 3rd provider (Claude) take under 30 minutes. This pattern is directly reusable in any JavaScript runtime.
Versioned Migrations Are Essential for Mobile
Real Impact: Unlike web apps where you control the database server, mobile apps must handle schema evolution on each user's device. PRAGMA user_version + idempotent guards made the migration from 3 tables to 6 seamless across app updates.
Repository Pattern Enables Test-First Mobile Development
Real Impact: By isolating all SQLite logic in repository classes, 13 tests could be written against pure data operations without mounting React Native components or mocking navigation. This dramatically sped up debugging spaced repetition edge cases.
Interested in this project?
Feel free to reach out to discuss similar technical solutions or how I can help with your project.
Contact Me