Skip to content

captain-KasH/BetterU-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

BetterU - Quit Sugar Coaching App

A comprehensive React Native app built with Expo to help users quit or reduce sugar intake through a structured 90-day program, craving tracking, and AI-powered coaching.

๐Ÿš€ Features

Phase 1 (Current - Mock API)

  • 90-Day Sugar Reset Program: Structured phases (detox, rebalance, sustain)
  • Craving Log: Track triggers, intensity, and outcomes with optimistic updates
  • Food Scanner: Barcode scanning and photo classification with AI swap suggestions
  • Healthy Recipes: Searchable recipe database with nutrition info
  • Insights Dashboard: Streak tracking, craving heatmaps, and weekly AI coaching
  • Local Notifications: Smart scheduling with quiet hours
  • Developer Tools: Mock API configuration and request monitoring

Tech Stack

  • Framework: Expo Managed Workflow (React Native)
  • Language: TypeScript
  • Routing: expo-router
  • State Management: Zustand
  • Data Fetching: React Query
  • Styling: NativeWind (Tailwind CSS)
  • Forms: Formik + Zod validation
  • Database: SQLite with expo-sqlite
  • Storage: expo-secure-store
  • Camera: expo-camera + expo-barcode-scanner
  • Charts: victory-native + react-native-svg
  • Notifications: expo-notifications (local only)
  • Testing: jest-expo + @testing-library/react-native

๐Ÿ“ฑ Installation & Setup

Prerequisites

  • Node.js 18+
  • Expo CLI: npm install -g @expo/cli
  • iOS Simulator (Mac) or Android Emulator

Quick Start

# Clone and install
git clone <repository-url>
cd BetterU
npm install

# Start development server
npm start

# Run on specific platform
npm run ios
npm run android
npm run web

First Launch

The app will automatically:

  1. Initialize SQLite database
  2. Load seed data (recipes, program days, nutrition items)
  3. Navigate to onboarding for new users

๐Ÿ—๏ธ Project Structure

app/                    # Expo Router pages
โ”œโ”€โ”€ (tabs)/            # Main tab navigation
โ”œโ”€โ”€ onboarding/        # User onboarding flow
โ”œโ”€โ”€ dev/               # Developer tools
โ”œโ”€โ”€ scan/              # Camera scanning results
โ”œโ”€โ”€ recipes/           # Recipe details
โ””โ”€โ”€ cravings/          # Craving log forms

src/
โ”œโ”€โ”€ api/               # API client and mock handlers
โ”‚   โ”œโ”€โ”€ mock/handlers/ # Mock API responses
โ”‚   โ”œโ”€โ”€ ApiClient.ts   # Main API client with error simulation
โ”‚   โ””โ”€โ”€ endpoints.ts   # API endpoint constants
โ”œโ”€โ”€ store/             # Zustand state management
โ”œโ”€โ”€ lib/               # Utilities and database
โ”‚   โ”œโ”€โ”€ db/           # SQLite schema and seeds
โ”‚   โ”œโ”€โ”€ notifications.ts
โ”‚   โ””โ”€โ”€ storage.ts
โ”œโ”€โ”€ features/          # Feature-specific components
โ”œโ”€โ”€ assets/seed/       # JSON seed data
โ”œโ”€โ”€ types/             # TypeScript definitions
โ””โ”€โ”€ tests/             # Unit and integration tests

๐Ÿ”ง Configuration

Mock API Settings

The app uses a mock API system for Phase 1. Configure via Developer Tools or app.json:

{
  "expo": {
    "extra": {
      "USE_MOCK_API": true,
      "MOCK_FAIL_RATE": 0.05,
      "MOCK_TIMEOUT_RATE": 0.05
    }
  }
}

Developer Tools Access

Navigate to Settings โ†’ Developer Tools to:

  • Toggle mock API on/off
  • Adjust error simulation rates
  • Reset seed data
  • View API request logs (last 20 requests)

๐Ÿ“Š Data Flow

Mock API Architecture

UI Component โ†’ React Query โ†’ ApiClient โ†’ Mock Handlers โ†’ Local Response
                    โ†“
              Zustand Store โ† SQLite Database

Key Features:

  • Artificial Latency: 350-700ms delays
  • Error Simulation: Configurable fail/timeout rates
  • Request Logging: Track all API calls for debugging
  • Optimistic Updates: Immediate UI updates with rollback on failure

๐Ÿงช Testing

Run Tests

# Unit tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

Test Coverage

  • Unit Tests: Zustand stores, utilities, mock API behaviors
  • Integration Tests: Onboarding flow, craving log, barcode scanning
  • Mocked Dependencies: All Expo modules and external libraries

๐Ÿ“ฑ Key User Flows

1. Onboarding

  1. Goal selection (quit vs reduce sugar)
  2. Dietary restrictions
  3. Craving trigger times
  4. Profile creation via mock API
  5. Navigation to main app

2. Daily Program

  1. View current day's challenge
  2. Complete micro-tasks
  3. Track streak progress
  4. Handle relapses gracefully

3. Craving Management

  1. Log craving with trigger/intensity
  2. Record outcome (resisted/consumed/swapped)
  3. Optimistic UI updates
  4. Rollback on API failure

4. Food Scanning

  1. Camera permission request
  2. Barcode scan or photo capture
  3. Mock nutrition analysis
  4. AI-generated healthy swaps
  5. Detailed nutrition comparison

๐Ÿ”ฎ Phase 2 Integration

The app is designed for easy backend integration:

API Client Modification

// Switch from mock to real API
apiClient.updateConfig({ useMockApi: false });

// Real API implementation
async makeRequest(method, endpoint, data) {
  const response = await fetch(`${API_BASE_URL}${endpoint}`, {
    method,
    headers: { 'Authorization': `Bearer ${token}` },
    body: JSON.stringify(data)
  });
  return response.json();
}

Database Sync

  • SQLite remains for offline capability
  • Add sync mechanisms for server backup
  • Implement conflict resolution

Authentication

  • Add auth screens and flows
  • Integrate with backend auth system
  • Secure token management

๐ŸŽฏ AI System Prompts

Coach System Prompt

"You are BetterU Coach. Be supportive, concise, action-first. Never shame. Suggest hydration, fiber, protein, movement, mindful craving pauses. Prefer affordable, local foods. Keep responses short. If mention health symptoms, add a brief non-medical disclaimer."

Swap Generation

"Generate 3 snacks + 2 drinks low-added-sugar. Include ingredients, <=4 steps, macros (kcal, protein, sugar, fiber), and a one-line reason why it satisfies the craving. Keep โ‰ค260 tokens."

Weekly Summary

"Return 5 bullet insights, a <=60 word motivational paragraph, and 1 small behavior challenge. Reframe lapses as learning."

๐Ÿšจ Troubleshooting

Common Issues

Camera not working

  • Check permissions in device settings
  • Restart Expo development server
  • Clear Expo cache: expo r -c

SQLite errors

  • Reset app data via Developer Tools
  • Check seed data format in src/assets/seed/

Mock API not responding

  • Verify USE_MOCK_API: true in config
  • Check Developer Tools for request logs
  • Ensure mock handlers exist for endpoints

Debug Mode

Enable detailed logging:

// In ApiClient.ts
console.log('API Request:', method, endpoint, data);
console.log('API Response:', response);

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

Development Guidelines

  • Follow TypeScript strict mode
  • Use provided ESLint configuration
  • Write tests for new features
  • Keep functions under 3 parameters
  • Use object parameters for complex functions
  • Maintain mock API compatibility

BetterU - Empowering healthier choices, one day at a time. ๐ŸŒŸ

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors