- Project Overview
- Architecture
- Technology Stack
- Project Structure
- Core Features
- API Integration
- State Management
- Components
- Services
- Hooks
- Types & Interfaces
- Configuration
- Development Setup
- Deployment
- Known Issues & Future Improvements
Muscledia is a gamified fitness tracking mobile application built with React Native and Expo. The app combines workout tracking with RPG-style character progression, challenges, achievements, and social features to motivate users to maintain consistent fitness routines.
- Gamification: Users earn XP, level up, unlock badges, and participate in challenges
- Character System: Visual avatar that evolves based on fitness progress
- Workout Tracking: Comprehensive exercise logging with sets, reps, and weights
- Social Features: Leaderboards and public routine sharing
- AI Integration: Personalized workout recommendations using AI
- Primary: Mobile (iOS & Android)
- Framework: Expo (React Native)
- Backend: Spring Boot REST API
┌─────────────────────────────────────────────────────────┐
│ React Native App │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Screens │ │ Components │ │ Hooks │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ ┌──────┴─────────────────┴──────────────────┴──────┐ │
│ │ Services Layer │ │
│ │ (API calls, data transformation, caching) │ │
│ └──────────────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────────────┴─────────────────────────────┐ │
│ │ State Management (Context API) │ │
│ │ - AuthProvider, CharacterProvider, etc. │ │
│ └──────────────────────┬─────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┴─────────────────────────────┐ │
│ │ Storage (AsyncStorage) │ │
│ └────────────────────────────────────────────────────┘ │
└───────────────────────────┬─────────────────────────────┘
│
┌───────┴────────┐
│ Spring Boot │
│ REST API │
└────────────────┘
- Provider Pattern: Context API for global state management
- Service Layer Pattern: Centralized API communication
- Custom Hooks: Reusable business logic
- Component Composition: Modular, reusable UI components
- React Native: 0.81.5
- React: 19.1.0
- Expo SDK: ~54.0.29
- TypeScript: ~5.9.3
expo-router: ~6.0.20 - File-based routing with typed routes@react-navigation/native: ^7.1.8@react-navigation/bottom-tabs: ^7.4.0
@tanstack/react-query: ^5.90.5 - Server state management@tanstack/react-query-devtools: ^5.90.2- React Context API (custom providers)
expo-linear-gradient: ~15.0.8lucide-react-native: ^0.545.0 - Icon libraryreact-native-reanimated: ~4.1.2 - Animationsreact-native-gesture-handler: ~2.28.0
@react-native-async-storage/async-storage: 2.2.0
axios: ^1.12.2axios-retry: ^4.5.0
date-fns: ^4.1.0expo-haptics: ~15.0.8 - Haptic feedbackexpo-notifications: ~0.32.15react-native-confetti-cannon: ^1.5.2
cross-env: ^10.1.0 - Cross-platform environment variables@babel/core: ^7.28.4
Muscledia-Frontend/
├── app/ # Expo Router screens
│ ├── _layout.tsx # Root layout with providers
│ ├── index.tsx # Entry point (redirects to auth/tabs)
│ ├── onboarding.tsx # First-time user onboarding
│ ├── (auth)/ # Authentication screens
│ │ ├── _layout.tsx
│ │ ├── login.tsx
│ │ └── register.tsx
│ ├── (tabs)/ # Main tab navigation
│ │ ├── _layout.tsx # Tab bar configuration
│ │ ├── index.tsx # Home/Dashboard
│ │ ├── challenges.tsx # Challenges screen
│ │ ├── achievements.tsx # Badges/Achievements
│ │ ├── shop.tsx # Equipment shop
│ │ └── exercises/ # Exercise-related screens
│ ├── profile.tsx # User profile
│ ├── profile-settings.tsx # Profile settings
│ ├── workout-plans/ # Workout plan management
│ │ ├── create.tsx
│ │ └── [planId]/
│ ├── workout-session/ # Active workout tracking
│ │ ├── [planId].tsx
│ │ └── log-set.tsx
│ ├── routine-detail/ # Routine details
│ │ └── [id]/
│ ├── public-routines.tsx # Browse public routines
│ ├── ai-recommendation/ # AI workout recommendations
│ ├── leaderboard.tsx # Leaderboards
│ └── personal-records.tsx # Personal records tracking
│
├── components/ # Reusable UI components
│ ├── CharacterAvatar.tsx # Character display
│ ├── CharacterDisplay.tsx # Enhanced character visualization
│ ├── ProgressBar.tsx # Progress indicators
│ ├── StatsCard.tsx # Stat display cards
│ ├── SetTypeSelector.tsx # Set type selection
│ ├── WorkoutAnalytics.tsx # Workout statistics
│ ├── challenges/ # Challenge-related components
│ ├── exercises/ # Exercise components
│ ├── leaderboard/ # Leaderboard components
│ ├── pr/ # Personal records components
│ ├── routines/ # Routine components
│ ├── ui/ # Generic UI components
│
├── hooks/ # Custom React hooks
│ ├── useAuth.tsx # Authentication state
│ ├── useCharacter.tsx # Character state management
│ ├── useWorkouts.tsx # Workout tracking
│ ├── useRoutines.tsx # Routine management
│ ├── useChallenges.tsx # Challenge system
│ ├── useLeaderboard.tsx # Leaderboard data
│ ├── useNotifications.tsx # Push notifications
│ ├── useHaptics.ts # Haptic feedback
│ └── ...
│
├── services/ # API service layer
│ ├── api.ts # Base API client
│ ├── authService.ts # Authentication
│ ├── userService.ts # User management
│ ├── workoutPlanService.ts # Workout plans
│ ├── WorkoutService.ts # Workout sessions
│ ├── exerciseService.ts # Exercise data
│ ├── routineService.ts # Routines
│ ├── challengeService.ts # Challenges
│ ├── gamificationService.ts # Gamification profile
│ ├── badgeService.ts # Badges/achievements
│ ├── leaderboardService.ts # Leaderboards
│ ├── aiService.ts # AI recommendations
│ ├── personalRecordsService.ts # Personal records
│ └── storageService.ts # Local storage wrapper
│
├── types/ # TypeScript type definitions
│ ├── index.ts # Central type exports
│ ├── api.ts # API response types
│ ├── auth.types.ts # Authentication types
│ ├── workout.types.ts # Workout types
│ ├── exercise.types.ts # Exercise types
│ ├── gamification.types.ts # Gamification types
│ ├── ai.types.ts # AI recommendation types
│ └── personalRecords.ts # Personal records types
│
├── config/ # Configuration files
│ └── api.ts # API configuration & endpoints
│
├── constants/ # App constants
│ ├── Colors.ts # Theme colors
│ ├── Assets.ts # Asset paths
│ └── setTypes.ts # Set type definitions
│
├── utils/ # Utility functions
│ └── helpers.ts # Helper functions
│
├── data/ # Static data
│
├── providers/ # React providers
│ └── QueryProvider.tsx # React Query setup
│
├── assets/ # Static assets
│ ├── images/ # Images
│ ├── characters/ # Character sprites
│ ├── clothes/ # Clothing assets
│ ├── equipment/ # Equipment images
│ └── backgrounds/ # Background images
│
├── app.json # Expo configuration
├── package.json # Dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # Project readme
- Login/Register: Email-based authentication
- Token Management: JWT token storage and refresh
- Session Persistence: Automatic login on app restart
- Protected Routes: Route guards for authenticated screens
Implementation: hooks/useAuth.tsx, services/authService.ts
The character is the core gamification element that represents the user's fitness journey.
- Level: Increases with XP gain (starts at 1)
- XP System:
- Base XP requirement: 100 for level 2
- Exponential growth:
100 * (1.2 ^ (level - 1)) - XP gained from workouts, challenges, achievements
- Health System:
- Max health: 50 (base)
- Health consumed during workouts
- Regenerates over time
- Streaks:
- Daily workout streaks
- Weekly streaks
- Monthly streaks
- Stages: Character appearance changes based on level
- Stage 1 (Levels 1-4): Beginner
- Stage 2 (Levels 5-14): Intermediate
- Stage 3 (Levels 15-29): Advanced
- Stage 4 (Levels 30+): Master
- Skin color (3 variants)
- Clothing (shirts, pants)
- Equipment (barbells, dumbbells)
- Accessories
- Backgrounds
Implementation: hooks/useCharacter.tsx, components/CharacterDisplay.tsx
- Create custom workout plans
- Add exercises with sets, reps, weight
- Organize into routine folders
- Public/private sharing
- Start workout from plan
- Log sets in real-time
- Track completion
- Set types: Regular, Drop Set, Super Set, Rest Pause
- Auto-save progress
- Browse exercises by muscle group
- Filter by equipment type
- Search functionality
- Exercise details (instructions, muscle groups)
Implementation:
services/workoutPlanService.tsservices/WorkoutService.tsapp/workout-session/[planId].tsx
- Available daily challenges
- Accept and complete challenges
- XP and point rewards
- Progress tracking
- Longer-term objectives
- Higher rewards
- Weekly reset
- Real-time challenge cards
- Progress visualization
- Completion celebrations
Implementation:
hooks/useDailyChallenges.tshooks/useWeeklyChallenges.tscomponents/challenges/
- Multiple badge types:
- Exercise badges
- Champion badges
- Streak badges
- Personal Record badges
- Badge criteria:
- Workout count
- Level reached
- Streak milestones
- Points earned
- Exercise-specific achievements
- Multiple leaderboard types:
- Points leaderboard
- Level leaderboard
- Weekly streak leaderboard
- Real-time updates
- User ranking display
Implementation:
services/badgeService.tsservices/leaderboardService.ts
- Routine Folders: Organize multiple workout plans
- Public Routines: Browse and save community routines
- Routine Builder: Create custom routines
- Difficulty Levels: Beginner, Intermediate, Advanced
- Equipment Types: Gym, Equipment-Free, Mixed
- Workout Splits: Full Body, Upper/Lower, Push/Pull/Legs, etc.
Implementation: services/routineService.ts, hooks/useRoutines.tsx
- Personalized workout recommendations
- Based on user goals, experience, equipment
- Integration with Ollama AI service
- Customizable parameters
Implementation: services/aiService.ts, app/ai-recommendation/
- Track PRs for exercises
- Weight, reps, volume records
- Historical tracking
- Statistics visualization
Implementation: services/personalRecordsService.ts, components/pr/
- Purchase equipment with coins
- Character customization items
- Backgrounds and accessories
- Economy system (coins earned from workouts)
Implementation: app/(tabs)/shop.tsx
- Push notifications for:
- Challenge reminders
- Streak warnings
- Achievement unlocks
- Daily goals
Implementation: hooks/useNotifications.tsx
Located in config/api.ts
- Development:
- iOS:
http://89.168.117.65:8080 - Android:
http://10.0.2.2:8080 - Web:
http://192.168.1.64:8080
- iOS:
- Production:
http://89.168.117.65:8080 - Environment Variable:
EXPO_PUBLIC_API_URL
POST /api/users/login- User loginPOST /api/users/register- User registration
GET /api/users/me- Get current userPUT /api/users/me- Update user profileGET /api/users/{id}- Get user by ID
GET /api/v1/exercises- Get exercise libraryGET /api/v1/workout-plans- Get workout plansGET /api/v1/workout-plans/{id}- Get workout plan detailsPOST /api/v1/workout-plans- Create workout planPUT /api/v1/workout-plans/{id}- Update workout planDELETE /api/v1/workout-plans/{id}- Delete workout planPOST /api/v1/workout-sessions- Create workout sessionPUT /api/v1/workout-sessions/{id}/sets/{setId}- Update set
GET /api/v1/routine-folders/public- Get public routinesGET /api/v1/routine-folders/{id}- Get routine folderPOST /api/v1/routine-folders/save/{id}- Save routineGET /api/v1/routine-folders/is-saved/{id}- Check if saved
GET /api/gamification/profile- Get gamification profileGET /api/gamification/streaks- Get streak informationGET /api/gamification/achievements- Get achievementsGET /api/gamification/badges- Get badge catalogGET /api/gamification/leaderboard- Get leaderboardGET /api/gamification/leaderboards/points- Points leaderboardGET /api/gamification/leaderboards/levels- Level leaderboardGET /api/gamification/leaderboards/weekly-streak- Weekly streak leaderboard
GET /api/challenges/daily- Get daily challengesGET /api/challenges/weekly- Get weekly challengesGET /api/challenges/active- Get active user challengesPOST /api/challenges/{id}/accept- Accept challengePUT /api/challenges/{id}/progress- Update challenge progress
POST /ollama/getRecommendation- Get AI workout recommendation
- Automatic Retry: 3 attempts with exponential backoff
- Request Timeout: 30 seconds (120 seconds for AI)
- Token Management: Automatic token injection
- Error Handling: Centralized error handling
- Response Caching: Service-level caching (TTL-based)
Implementation: services/api.ts
The app uses React Context API for global state management:
- QueryProvider: React Query setup for server state
- AuthProvider: Authentication state
- CharacterProvider: Character data and progression
- WorkoutsProvider: Workout history and sessions
- RoutineProvider: Routine management
- RaidProvider: Raid/challenge system
- NotificationsProvider: Notification management
Used for:
- Server state caching
- Automatic refetching
- Optimistic updates
- Background synchronization
- Component-level state with
useState - Form state management
- UI state (modals, loading, etc.)
Enhanced character visualization with:
- Stage-based appearance
- Equipment rendering
- Animation support
- Customization display
Location: components/CharacterDisplay.tsx
Reusable progress indicator for:
- XP progress
- Challenge progress
- Health bars
- Custom metrics
Location: components/ProgressBar.tsx
InteractiveChallengeCard: Real-time challenge displayActiveChallengeCard: Active challenge trackingCelebrationScreen: Completion animationsChallengeCompletionModal: Reward display
Location: components/challenges/
- Exercise cards
- Exercise filters
- Exercise details
- Set logging interface
Location: components/exercises/
- Composition: Small, focused components
- Props Interface: Strong TypeScript typing
- Theme Support: Dynamic theming via
getThemeColors() - Accessibility: Proper accessibility labels
All services follow a consistent pattern:
- Static methods for API calls
- Caching with TTL
- Error handling
- Type-safe responses
- Login/register
- Token management
- User session
- CRUD operations for workout plans
- Exercise management
- Plan details
- Session creation
- Set logging
- Progress tracking
- Profile fetching
- Streak information
- Caching (5-minute TTL)
- Badge catalog
- Badge status
- Progress calculation
- Caching (15-minute TTL)
- Daily/weekly challenges
- Challenge acceptance
- Progress updates
- AI recommendations
- Extended timeout (120s)
- Request/response logging
Authentication state and methods:
user: Current user datalogin(email, password): Login functionregister(email, password, username): Registrationlogout(): Logout functionisAuthenticated: Auth status
Character state management:
character: Character dataupdateCharacter(): Update characterincrementXP(): Add XP (with stat modifiers)consumeHealth(): Health managementaddCoins(): Economy functionspurchaseItem(): Shop integration
Workout tracking:
- Workout history
- Active sessions
- Statistics
Routine management:
- User routines
- Public routines
- Save/unsave routines
Challenge data fetching with React Query
Active user challenges with progress tracking
Leaderboard data with multiple types
Haptic feedback wrapper:
impact(): Haptic feedbacknotification(): Notification hapticssuccess(): Success haptics
Push notification management
type Character = {
name: string;
level: number;
xp: number;
xpToNextLevel: number;
totalXP: number;
streak: number;
maxHealth: number;
currentHealth: number;
coins: number;
// ... customization fields
}interface WorkoutPlan {
id: string;
name: string;
description?: string;
exercises: PlannedExercise[];
targetMuscleGroups: string[];
estimatedDuration: number;
difficulty: 'beginner' | 'intermediate' | 'advanced';
}interface GamificationProfile {
id: string;
userId: number;
points: number;
level: number;
streaks: {
workout: WorkoutStreak;
};
earnedBadges: EarnedBadge[];
totalWorkoutsCompleted: number;
// ... more fields
}interface Challenge {
challengeId: string;
name: string;
description: string;
challengeType: 'DAILY' | 'WEEKLY' | 'INTERACTIVE';
pointsReward: number;
xpReward: number;
criteria: ChallengeCriteria;
}Location: types/ directory
- App Name: Muscledia
- Version: 1.0.0
- Orientation: Portrait
- New Architecture: Enabled
- Plugins:
- expo-router
- expo-font
- expo-web-browser
- expo-notifications
- Strict mode enabled
- Path aliases:
@/for./root - React Native types included
EXPO_PUBLIC_API_URL: Backend API URLEXPO_PUBLIC_ENV: Environment (development/production)
- Node.js (v16 or higher)
- npm or yarn
- Expo CLI
- iOS Simulator (Mac) or Android Emulator
- Physical device with Expo Go app (optional)
-
Clone Repository
git clone <repository-url> cd Muscledia-Frontend
-
Install Dependencies
npm install
-
Configure Environment (Optional) Create
.envfile:EXPO_PUBLIC_API_URL=http://your-api-url:8080 EXPO_PUBLIC_ENV=development -
Start Development Server
npm run dev
-
Run on Device/Emulator
- Scan QR code with Expo Go app
- Or press
ifor iOS /afor Android
npm run dev: Start Expo development servernpm run build:web: Build for webnpm run lint: Run ESLint
- Screens: Located in
app/directory (file-based routing) - Components: Reusable components in
components/ - Services: API communication in
services/ - Hooks: Custom hooks in
hooks/ - Types: TypeScript definitions in
types/
eas build --platform ioseas build --platform android- Set
EXPO_PUBLIC_API_URLto production URL - Set
EXPO_PUBLIC_ENV=production
Ensure backend API is:
- Accessible from mobile devices
- CORS configured (for web)
- SSL/TLS enabled (production)
-
Missing Backend Endpoints: Some endpoints return 404 (see
BACKEND_ENDPOINTS_NEEDED.md)GET /api/v1/routine-folders/{id}GET /api/v1/workout-plans/{id}GET /api/v1/routine-folders/is-saved/{id}
-
API URL Configuration: Port handling needs improvement for iOS devices
-
Offline Support: Limited offline functionality
- Offline Mode: Full offline workout tracking with sync
- Social Features: Friend system, workout sharing
- Advanced Analytics: Detailed workout analytics and insights
- Workout Templates: Pre-built workout templates
- Video Integration: Exercise demonstration videos
- Nutrition Tracking: Meal logging and macros
- Wearable Integration: Apple Watch, Fitbit support
- Multi-language Support: Internationalization
- Dark Mode Polish: Enhanced dark mode theming
- Performance Optimization: Code splitting, lazy loading
README.md: Quick start guideBACKEND_ENDPOINTS_NEEDED.md: Missing API endpointsERROR_ANALYSIS.md: Error handling documentation
Muscledia is a comprehensive fitness tracking application that combines workout logging with gamification elements to create an engaging user experience. The app is built with modern React Native and Expo technologies, following best practices for code organization, type safety, and user experience.
The architecture is designed to be scalable and maintainable, with clear separation of concerns between UI, business logic, and data layers. The extensive use of TypeScript ensures type safety throughout the application.
For questions or contributions, please refer to the project repository and follow the established coding patterns and conventions.
Document Version: 1.0
Last Updated: 2025-01-XX
Maintained By: Development Team