4.1 KiB
4.1 KiB
Atomic Habits AI - Habit Tracker & Personal Library
Atomic Habits AI is a cross-platform mobile and web application designed to help users build lasting habits through a science-backed tracking system and a personalized AI-powered library. It combines local-first performance with cloud synchronization and AI insights.
🏗 Architecture
The application follows a Local-First, Cloud-Sync architecture.
Frontend
- Framework: Expo (React Native) with Expo Router for file-based routing.
- Language: TypeScript.
- State Management: Local SQLite database for offline-first capabilities, synced with Supabase.
- UI/UX: Custom design system built with
Vanilla CSS(via React Native Stylesheets), utilizingLucide React Nativefor iconography andReanimatedfor smooth transitions.
Backend & Cloud
- Platform: Supabase
- Authentication: Supabase Auth (Email/Password, JWT).
- Database: PostgreSQL (Cloud) + SQLite (Local).
- Storage: Supabase Storage for PDF/Epub books.
- Edge Functions: Supabase Edge Functions (Deno) for AI processing and book parsing.
AI Integration
- Models: Gemini (via Supabase Edge Functions).
- Features: Automated book metadata extraction, AI-generated reading insights/synthesis, and interactive habit coaching.
🔐 Security
Security is integrated at every layer of the stack:
- Authentication: Secure session management using
AsyncStorageand Supabase JWTs. - Row Level Security (RLS): Supabase RLS policies ensure users can only access their own habits, books, and logs.
- Secure Storage: sensitive files are accessed via Signed URLs with limited expiration windows (1 hour) rather than public links.
- Local Encryption: (Optional/Roadmap) Local SQLite data protection.
- Environment Variables: All sensitive keys (Supabase URL, Anon Key) are managed via
.envfiles andEXPO_PUBLIC_prefixes.
🗄 Database Schema
The system uses a mirrored schema between local SQLite and cloud PostgreSQL.
Core Tables:
books: Stores library items (id,user_id,title,author,file_uri,current_page,status).habits: Core habit tracking logic (id,user_id,name,frequency,streak,last_completed).reading_logs: Tracks progress over time (id,book_id,duration_seconds,pages_read).chat_history: Persists AI interactions for context-aware coaching.
🛠 Running the Project
Prerequisites
- Node.js (v18+)
- Expo Go app (for physical device testing) or Android Studio / Xcode (for emulators).
Installation
# Clone the repository
git clone <repo-url>
cd atomichabitsai
# Install dependencies
npm install
Development
# Start the Expo development server
npx expo start
- Press
afor Android emulator. - Press
ifor iOS simulator. - Press
wfor web.
🐞 Debugging Details
Logging
The application uses structured logs for critical paths:
[PdfReader]: WebView lifecycle and file writing logs.[downloadBook]: Sync and storage fetch status.[resolveFileUri]: Path resolution debugging for iOS container changes.
Common Troubleshooting
- Stale iOS Paths: If files don't open on iOS after an update, the
resolveFileUriutility automatically corrects absolute paths that contain outdated container UUIDs. - Sync Failures: Check the
performMutationcalls insync.ts. Ensure the device has internet access for Supabase connectivity. - PDF Reader Crashes: Ensure the library
@bildau/rn-pdf-readeris correctly patched viapatch-packageto handle the Legacy FileSystem API in Expo 54.
🧑💻 Backend Developer Notes
Edge Functions
Located in /supabase/functions/:
process-book-ai: Parses uploaded filenames to suggest titles/authors and generates reading summaries.chat-ai: The core engine for the AI habit coach.
Storage
- Bucket name:
books - Access: Private (accessed via
createSignedUrlinsrc/lib/file-utils.ts).