MicroTrack is a high-performance, minimalist luxury web application designed for people who want more than just calorie counting. It focuses on micronutrient optimization, helping users identify nutritional gaps, maintain consistency streaks, and reach their biological peak through data-driven nutrition.
| Technology | Purpose | Rationale |
|---|---|---|
| React | Core Framework | Component-based architecture for a highly interactive and modular UI. |
| TypeScript | Type Safety | Ensures reliability in nutrient calculations and data synchronization logic. |
| Vite | Build Tool | Optimized development experience with lightning-fast HMR and build times. |
| Tailwind CSS | Styling | Utility-first styling enabling the "minimal luxury" aesthetic with high flexibility. |
| shadcn/ui | UI Components | Accessible, headless components that maintain design consistency. |
| Zustand | State Management | Lightweight, dev-friendly state logic with built-in persistence and low boilerplate. |
| React Router | Routing | Seamless SPA navigation with protected route management. |
| Supabase | Backend | Rapid integration of Auth, Real-time Database, and API services. |
| PostgreSQL | Database | Relational storage for profiles and history, with JSONB support for flexible nutrient logs. |
| jspdf | PDF Generation | Client-side generation of professional nutrition reports. |
| Recharts | Data Visualization | Dynamic charts for daily and weekly nutrient trend analysis. |
MicroTrack follows a Client-Side First architecture with a robust persistence layer.
- User Input: User adjusts food quantities via sliders on the Dashboard or Detail pages.
- Local State (Zustand): Updates the
foodQuantitiesmap reactively. - UI Sync: Progress bars and daily totals recalculate instantly across all views.
- Cloud Sync (Supabase): Clicking "Save Day" triggers an upsert to the
historytable. - Persistence Loop: The store reloads the history from Supabase, recalculates streaks, and resets daily progress for a fresh start.
src/
├── components/ # Reusable UI parts (Progress bars, Charts, Layouts)
├── data/ # Core datasets (Nutrients, Food Items, Safety Limits)
├── hooks/ # Custom React hooks for Auth and Tracking logic
├── lib/ # External library initializations (Supabase Client)
├── pages/ # Main application views (Dashboard, History, etc.)
├── store/ # Zustand store definitions (The brain of the app)
└── utils/ # Helper functions (Formatting, Date manipulation)
The application state is centralized in trackingStore.ts using Zustand.
userProfile: Stores bio-metric data (Weight, Height, Age, Activity) used for requirement math.foodQuantities: Temporary daily log of consumed foods.history: Array of snapshots for previous days.streaks: Dynamically calculated current and longest consistency records.requirements: Nutrient targets calculated based on the active profile.
Why Centralized? Micronutrient tracking involves many-to-many relationships (one food affects 15+ nutrients). Centralized state ensures that changing a quantity in a sub-page is reflected globally in the dashboard headers and progress indicators without prop drilling.
Targets are not static. MicroTrack calculates them based on:
- Calories: Harris-Benedict BMR formula adjusted by activity level.
- Protein: 0.8g to 1.8g per kg of body weight based on activity.
- Micros: Gender-specific RDA (Recommended Dietary Allowance) values for Iron, Calcium, Zinc, etc.
- Cross-Nutrient Updates: Each
FoodItemcontains a mapping of multiple nutrients. Updating one quantity loops through all nutrient IDs to recalculate totals. - Safety Limits: Each food has
maxQuantityandmaxSuggestionQuantitycaps to prevent the algorithm from suggesting unhealthy intakes. - Duplicate Prevention: The database utilizes a composite unique constraint on
(user_id, date_key)to ensure only one entry exists per calendar day.
- Login/Signup: Managed via Supabase Auth (supports Email/Password and Google OAuth).
- Session Persistence: Auth state is monitored via
onAuthStateChange. - Profile Loading: On initial load, the app fetches the user's profile from the
profilestable and hydrates the Zustand store. - Protected Routes: Unauthorized users are redirected to the Landing page to preserve data privacy.
Stores user configuration and bio-metrics.
id: UUID (Primary Key)height,weight,age,gender,activity_level,country
Stores historical nutrition snapshots.
user_id: UUID (Foreign Key)date_key: TEXT (Unique identifier formatted asYYYY-MM-DD)nutrient_totals: JSONB (Snapshot of all nutrient values at save time)foods: JSONB (Mapping of food IDs to quantities consumed)
- Daily Save System: Atomic upsert operation that preserves history even if a user saves multiple times in one day.
- Streak Algorithm: Scans the sorted history array for consecutive
date_keygaps and determines continuity. - Food Suggestions: A gap-filling algorithm that ranks foods by nutrient density relative to the user's remaining requirement for a specific nutrient.
- PDF Export: Translates internal JSONB history data into a formatted report for doctors or nutritionists.
- Deficiency Insights: Real-time identification of nutrients under 100% target, providing prioritized corrective actions.
Required in .env:
VITE_SUPABASE_URL: Your Supabase project URL.VITE_SUPABASE_ANON_KEY: Your project anonymous API key.
- Supabase: Enable Email and Google providers in the Auth settings.
- Build Process: Run
npm run buildto generate the optimized static bundle in the/distdirectory.
- Clone & Install:
git clone <repo-url> npm install
- Logic Entry Point:
- Modify
src/data/nutrients.tsto add new foods or adjust requirements. - Modify
src/store/trackingStore.tsto add new global state or sync logic.
- Modify
- UI Customization:
- Components are built using
shadcn/ui. Checkcomponents.jsonfor base configurations. - Tailwind theme is located in
tailwind.config.ts.
- Components are built using