# Troubleshooting Guide

Solutions for common issues in both backend and frontend.

---

## 🔧 Backend Issues

See [backend/TROUBLESHOOTING.md](./backend/TROUBLESHOOTING.md) for detailed backend troubleshooting.

### Quick Fixes

**Module Not Found**:
```bash
cd backend
npm install
pm2 restart chitfund-backend
```

**Can't Delete Group**:
- Remove all active members first
- Removed members (status='removed') are OK
- Backend already fixed to count only active members

**Can't Remove Member (404)**:
- Make sure using `member.userId` not `member.id`
- Already fixed in latest code

---

## 📱 Frontend Issues

### Member Numbers Not Showing

**Cause**: Database migration not applied

**Fix**:
```bash
cd backend
node run-member-number-migration.js
pm2 restart chitfund-backend
```

Then restart Flutter app.

---

### API Connection Error

**Cause**: Wrong API URL

**Fix**: Check `luckychit/lib/core/services/api_service.dart`
```dart
static const String baseURL = 'https://chitfund.deepteklabs.com/api';
```

---

### Build Errors

**Module errors**:
```bash
cd luckychit
flutter clean
flutter pub get
flutter run
```

**Gradle errors** (Android):
```bash
cd luckychit/android
./gradlew clean
cd ..
flutter build apk
```

---

## 🎨 UI Issues

### Text Too Small

Already fixed! Theme now uses:
- 30% larger fonts (fontSizeMultiplier = 1.3)
- High contrast colors
- Large buttons

If still small, check device font scaling in system settings.

---

### Member Delete Not Working

Make sure you're passing `member.userId`:
```dart
// ✅ Correct
_service.removeMemberFromGroup(groupId, member.userId);

// ❌ Wrong
_service.removeMemberFromGroup(groupId, member.id);
```

Already fixed in latest code!

---

## 🔄 After Code Updates

Always do these after pulling new code:

### Backend
```bash
npm install                         # Get new dependencies
node run-member-number-migration.js # Apply migrations (if not done)
pm2 restart chitfund-backend        # Restart
pm2 logs chitfund-backend           # Check logs
```

### Frontend
```bash
flutter pub get                     # Get new dependencies
flutter clean                       # Clean build cache
flutter run                         # Run app
```

---

## 📊 Verification

### Check Backend is Healthy
```bash
curl http://localhost:3000/health
# Should return: {"success":true}

curl http://localhost:3000/api/auth/profile -H "Authorization: Bearer YOUR_TOKEN"
# Should return user data
```

### Check Migration Applied
```bash
sudo -u postgres psql -d luckychit -c "SELECT member_number FROM group_members LIMIT 1;"
# Should show a number (1, 2, 3...)
```

### Check Frontend Connects
```bash
# In Flutter app, try to login
# Should connect to backend successfully
```

---

## 🆘 Still Having Issues?

### Backend Issues
→ See [backend/TROUBLESHOOTING.md](./backend/TROUBLESHOOTING.md)

### Deployment Issues
→ See [DEPLOYMENT.md](./DEPLOYMENT.md)

### API Issues
→ See [backend/API_DOCUMENTATION.md](./backend/API_DOCUMENTATION.md)

### Admin Features
→ See [ADMIN_GUIDE.md](./ADMIN_GUIDE.md)

---

## 💡 Common Solutions

**99% of issues are fixed by**:
```bash
# Backend
cd backend
npm install
pm2 restart chitfund-backend

# Frontend
cd luckychit
flutter clean
flutter pub get
flutter run
```

---

**If all else fails, see [DEPLOYMENT.md](./DEPLOYMENT.md) for complete reset procedure.**
