Ibtida is a native iOS app built with SwiftUI that encourages consistent prayer, intentional worship, and charitable giving. Users track daily prayers, build streaks, earn credits, and donate to verified charities โ including card payments in CAD via Stripe and donation receipts stored in their profile. Admin features (global requests, credit conversion settings, moderation) are gated by Firebase Auth custom claims and Firestore rules; regular users see only their own data.
Repo layout: iOS app in Ibtida/ (Xcode project); Firebase (Functions, Firestore rules, scripts) in firebase/.
Ibtida (โa beginningโ) connects two acts of worship:
- Prayer (Salah) โ consistency and awareness through daily tracking
- Charity (Sadaqah) โ giving via credits or card (CAD) to verified organizations
By combining prayer tracking with a credit-based system and real card donations, the app helps turn intention into action and build lasting spiritual habits.
- Auth โ Email/password (Firebase Auth); optional Google Sign-In
- Onboarding โ Gender selection (brother/sister) once at sign-up; no redundant popup; gender drives prayer options and credit rules
- Prayer tracking โ Log 5 daily prayers with gender-specific status options:
- Brothers: In masjid (jamat), On time, Qada, Missed, Not logged; Jumuโah replaces Dhuhr on Friday (distinct status options)
- Sisters: At home (on time), Qada, Missed, Not applicable ๐ฉธ (streak-safe)
- Sunnah and Witr (Isha) logged where applicable; status stored as enum raw value in Firestore; legacy values migrated on read (
PrayerStatus.fromFirestore)
- Fasting & Hijri โ Optional fasting prompt (Monday/Thursday, White Days); Hijri date display (Civil or Umm al-Qura); daily log and bonus credits via
CreditRules - Last 5 weeks โ Horizontal progress grid: current week first (left), older weeks to the right; โThis Weekโ highlighted
- Prayer status sheet โ Full-height bottom sheet; first tap opens correctly (no blank screen); Duas tab: Ameen and Done buttons spaced (no overlap)
- Streaks & credits โ Credits per prayer status (see table below); streak calculator; menstrual / โNot applicable ๐ฉธโ does not break streak
- Journey โ Single โJourneyโ title (nav bar); proportions and padding; milestones by total credits; week progress (5 squares); day detail sheet with gender-aware labels
- Ramadan tab (optional) โ Shown when server enables via
app_config/calendar_flagsand date range is set; per-day fasting log (brothers: Yes/No; sisters: Yes / No / Not applicable ๐ฉธ). Seefirebase/RAMADAN_CONFIG.md - Donate tab โ Overview, My Requests (userโs own requests only:
users/{uid}/requests), Charities (by category), Convert Credits; card donations via Stripe PaymentSheet (CAD only). No global community request feed for regular users. - Card donations โ Per-charity intake โ createPaymentIntent (CAD) โ Stripe PaymentSheet โ finalizeDonation โ receipt in
users/{uid}/donations. If finalizeDonation fails after retries, user sees pending receipt state (no misleading โThank Youโ until receipt is persisted). - Donation receipts โ Server-only writes (webhook + finalizeDonation); list and detail in Profile โ Donations; all amounts and storage in CAD
- Credit conversion โ Convert credits to dollar value (100 credits = $1 default); CreditConversionView; userโs conversion requests in Firestore; admin can edit rate in Admin โ Credit Conversion
- Dua wall โ Global community duas; Ameen toggle (tap to add, tap again to remove); submit anonymous or public
- Profile โ Name, email, credits, streak, member since; Donations history; theme; menstrual mode; About, Privacy, Terms; Diagnostics (dev)
- Admin (when isAdmin) โ Admin tab visible; Dashboard (counts), All Requests (global
requests), Credit Conversion (edit rate inadmin/settings), Moderation (reports). Enforced by custom claimadmin: trueand Firestore rules. - Theme โ Warm design system; light/dark/system; muted gold accent; accessible typography
- Network & errors โ Network status banner; centralized error handling; gentle language and time-aware UI
- Role โ Admin is determined only by Firebase Auth custom claim
{ admin: true }. No email or client-side flag in the app for who is admin. - Setting the first admin โ Use the local script (recommended) or deploy the callable and have an existing admin call it:
- Script: From
firebase/functions:
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json node ../scripts/set-admin-claims.js admin@example.com
User must sign out and sign in again for the claim to take effect. - Callable โ Deploy
setAdminRole; an existing admin can call it with{ email: "newadmin@example.com" }.
- Script: From
- What admins can do โ See Admin tab: Dashboard (overview counts), All Requests (global
requests), Credit Conversion (editadmin/settings), Moderation (reports). All admin reads/writes go through Firestore rules that requirerequest.auth.token.admin == true. - What regular users cannot do โ No Admin tab; no read/write to global
requests,admin/*, or other usersโ data. Donate tab shows only My Requests (users/{uid}/requests). - Testing โ See
Ibtida/ADMIN_OVERLAY_TEST_CHECKLIST.mdfor step-by-step checks (non-admin vs admin, token refresh, CAD, privacy).
Credits are earned by logging prayer status and are used for motivation and conversion to donations.
| Status | Credits |
|---|---|
| On Time | 10 |
| Late | 6 |
| Qada (made up) | 4 |
| Missed | 0 |
| Brothers โ Masjid | 18 |
| Sisters โ Home | 12 |
| Sisters โ Not applicable ๐ฉธ | 0 (no streak break) |
- Daily max โ 50 credits (5 ร 10).
- New user bonus โ First 14 days get a 1.5ร multiplier (see
CreditRules). - Conversion โ 100 credits = $1.00 (default; admin can change in Admin โ Credit Conversion).
| Milestone | Arabic | Credits |
|---|---|---|
| Getting Started | ุงูุจุฏุงูุฉ | 0 |
| Consistent | ู ูุงุธุจ | 100 |
| Steady | ุซุงุจุช | 250 |
| Committed | ู ูุชุฒู | 500 |
| Devoted | ู ุชูุงูู | 1,000 |
| Elite | ู ุชู ูุฒ | 2,500 |
| Master | ุฎุจูุฑ | 5,000 |
| Legend | ุฃุณุทูุฑุฉ | 10,000 |
- Currency โ CAD only (client, Cloud Functions, Stripe, Firestore, UI).
- Flow โ Choose charity โ intake form (name, email, amount โฅ $0.50 CAD) โ createPaymentIntent (Cloud Function) โ Stripe PaymentSheet โ on success, finalizeDonation (Cloud Function) โ receipt written to
users/{uid}/donations/{intakeId}. - Receipts โ Server-only writes (webhook
payment_intent.succeeded+ finalizeDonation). Schema:amountCents,currency: "cad",createdAt,organizationId,organizationName,intakeId,paymentIntentId,status, etc. - Pending receipt โ If finalizeDonation fails after retries, the app shows a pending receipt state (e.g. โPayment received; receipt may take a moment โ check Profile โ Donationsโ) instead of a full โThank Youโ so the UX stays honest and transparent.
- Profile โ Donations โ Lists receipts (newest first); tap for detail (reference ID, amount in CAD, receipt URL if present).
Five bottom tabs (fixed): Home, Journey, Donate, Dua, Profile. Profile is also reachable via toolbar button on each tab.
- Regular users: Home, Journey, Donate, Dua, Profile. (Ramadan tab appears when server enables it via
app_config/calendar_flags.) - Admin users: Same 5 tabs plus Admin when
authService.isAdmin(Firebase Auth custom claim).
Tab contents:
- Home โ Todayโs prayers (5 circles; Jumuโah replaces Dhuhr for brothers on Friday), Last 5 Weeks grid (current week left), progress summary; fasting prompt and Sunnah/Witr where applicable.
- Journey โ Milestones, week progress (5 squares), credit summary; single nav title โJourneyโ; day detail sheet; Last 5 Weeks horizontal scroll (current week first).
- Donate โ Overview, My Requests (userโs own requests), Charities (by category), Convert Credits; card donation via Stripe (CAD).
- Dua โ Community dua wall; submit and view duas; Dua of the Day with Ameen toggle (tap to add, tap again to remove).
- Profile โ User info, credits, streak; Donations history; theme; settings; About; Diagnostics (dev).
- Ramadan (optional) โ Visible when server config enables it and date range is set; daily fasting log (brothers: Yes/No; sisters: Yes / No / Not applicable ๐ฉธ).
- Admin (if
isAdmin) โ Dashboard, All Requests, Credit Conversion, Moderation.
- iOS โ SwiftUI, iOS 17+
- Backend โ Firebase (Auth, Firestore, Cloud Functions)
- Payments โ Stripe (PaymentSheet); CAD only; test mode via
pk_test_/ Stripe test cards - Key paths โ All Firestore paths are centralized in
Core/FirestorePaths.swift. Main ones:users/{uid},users/{uid}/donations,users/{uid}/receipts,users/{uid}/requests,users/{uid}/prayerDays,users/{uid}/prayers,users/{uid}/ramadanLogs,users/{uid}/dailyLogs,users/{uid}/journey;organizationIntakes,payments; globalduas,daily_duas,charities,donation_requests;app_config(e.g. calendar_flags); admin-only:admin/*, globalrequests,reports,credit_conversion_requests.
- Users โ Read/write only own
users/{userId}and subcollections (donations,requests,prayers,prayerDays,dailyLogs,ramadanLogs). - Donations โ Read-only for user on
users/{uid}/donations; writes only by backend. - app_config โ Read for authenticated users; write only by admin (e.g. Ramadan calendar flags).
- Global requests โ Read/write only if
request.auth.token.admin == true. - Reports โ Any authenticated user can create; only admin can read/delete.
- credit_conversion_requests โ User can create/read/update/delete only docs where
userId == request.auth.uid; admin can read all. - admin โ Read/write only if
request.auth.token.admin == true.
Full rules in firebase/firestore.rules.
- Requirements โ Xcode 15+, iOS 17+ target.
- Xcode โ Open
Ibtida/Ibtida.xcodeproj; use the Ibtida scheme. - Firebase โ Add
GoogleService-Info.plist; enable Auth (email/password, optional Google) and Firestore. - Stripe โ In Info.plist set
StripePublishableKeyto your test key (pk_test_...). Backend: Stripe secret and webhook secret (Cloud Functions config/secrets). - Cloud Functions โ Deploy from
firebase/functions. Deployed functions: createPaymentIntent (CAD), finalizeDonation, stripeWebhook, health, setAdminRole (callable, admin-only). Set secrets for Stripe. - Firestore rules โ Deploy from
firebase/:firebase deploy --only firestore:rules. - First admin (optional) โ Run from
firebase/functions:
GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json node ../scripts/set-admin-claims.js your-admin@example.com
Then have that user sign out and sign in again.
- Use test card 4242 4242 4242 4242 for success.
- Receipts appear under Profile โ Donations after finalizeDonation (and/or webhook).
Ibtida/Ibtida/Ibtida/ # iOS app (Xcode: Ibtida/Ibtida.xcodeproj)
โโโ IbtidaApp.swift
โโโ Core/
โ โโโ FirestorePaths.swift (single source for all collection/document paths)
โ โโโ BEHAVIOR_LOCK.md (behaviors that must not change; in-code checklist refs)
โ โโโ LoadState.swift (shared loading state for list screens)
โ โโโ StripeConfig.swift, DateUtils.swift, DonationAmountParser.swift
โ โโโ DesignSystem.swift, SemanticDesignSystem.swift, AppTheme.swift
โ โโโ CreditRules.swift, PrayerStatusColors.swift, HijriCalendar.swift
โ โโโ ThemeManager.swift, GentleLanguage.swift, TimeAwareUI.swift, LogLevel.swift
โ โโโ NetworkErrorHandler.swift, PerformanceCache.swift, AppStrings.swift
โโโ Models/
โ โโโ Charity.swift, Donation.swift, DonationError.swift, DonationType.swift
โ โโโ CreditConversionRequest.swift, DailyLog.swift, RamadanConfig.swift, RamadanLog.swift
โ โโโ Prayer.swift (PrayerStatus.fromFirestore, gender-specific lists)
โ โโโ PrayerModels.swift, UserProfile.swift, RequestModel.swift
โ โโโ Dua.swift, DuaRequest.swift
โ โโโ ...
โโโ Services/
โ โโโ AuthService.swift (isAdmin, refreshAdminClaim)
โ โโโ FirestoreService.swift, UserProfileFirestoreService.swift (profile cache 60s, clear on sign-out)
โ โโโ UserRequestsFirestoreService.swift (user requests: load/create)
โ โโโ PrayerLogFirestoreService.swift, PrayerDayFirestoreService.swift, DailyLogFirestoreService.swift
โ โโโ StreakCalculator.swift, CalendarConfigManager.swift, RamadanLogFirestoreService.swift
โ โโโ NetworkMonitor.swift
โ โโโ FirebaseFunctionsService.swift, UserDonationsFirestoreService.swift
โ โโโ OrganizationIntakeService.swift, CharityService.swift, DonationService.swift
โ โโโ CreditConversionService.swift, DuaFirestoreService.swift
โ โโโ LocalStorageService.swift, UIStateFirestoreService.swift
โโโ ViewModels/
โ โโโ HomeViewModel.swift, HomePrayerViewModel.swift
โ โโโ JourneyViewModel.swift, JourneyProgressViewModel.swift, JourneyMilestoneViewModel.swift
โ โโโ RamadanViewModel.swift
โ โโโ DonationViewModel.swift, CreditConversionViewModel.swift, PaymentFlowCoordinator.swift
โ โโโ CategoryCharitiesViewModel.swift, CommunityRequestsViewModel.swift (admin-only use)
โ โโโ DuaViewModel.swift
โโโ Views/
โ โโโ Home/ (HomeView, HomePrayerView โ prayer grid, status sheets)
โ โโโ Journey/ (JourneyView, JourneyHomeView, JourneyMilestoneView)
โ โโโ Ramadan/ (RamadanTabView, RamadanDaySheet โ optional tab)
โ โโโ Donate/ (DonationsPage [My Requests], OrganizationIntakeView, CategoryCharitiesView, CreditConversionView)
โ โโโ Dua/ (DuaWallView)
โ โโโ Profile/ (ProfileView, DonationsHistoryView)
โ โโโ Requests/ (RequestsView โ userโs own requests; LoadState + UserRequestsFirestoreService)
โ โโโ Admin/ (AdminTabView, AdminDashboardView, AdminRequestsView, AdminCreditConversionView, AdminModerationToolsView)
โ โโโ Auth/ (LoginView)
โ โโโ Onboarding/ (GenderOnboardingView)
โ โโโ Settings/ (SettingsView, AppSettingsView, DiagnosticsView)
โ โโโ Components/ (DuaComponents, EmptyStates, ErrorHandling, NetworkStatusBanner)
โ โโโ RootTabView.swift (tab order: Home, Journey, Donate, Duas, Profile; persist selected tab)
โโโ REFACTOR_PLAN.md, QUALITY_GATE_CHECKLIST.md
โโโ Resources/ charities.json; Assets.xcassets
firebase/
โโโ firestore.rules (user-only + admin-only)
โโโ RAMADAN_CONFIG.md (how to enable Ramadan tab via app_config/calendar_flags)
โโโ scripts/
โ โโโ set-admin-claims.js (set admin custom claim by email; run locally)
โโโ functions/
โโโ index.js createPaymentIntent (CAD), finalizeDonation, stripeWebhook, health, setAdminRole (callable)
- Firestore paths โ All collection/document strings live in
Core/FirestorePaths.swift; use these constants instead of literals. No hardcoded collection names in ViewModels or services. - Behavior lock โ
Core/BEHAVIOR_LOCK.mdand in-code comments define behaviors that must stay identical across refactors (navigation, sheets, credits, dates, privacy). Check before changing flows or data. - Loading state โ List screens use
LoadState(idle, loading, loaded, empty, error) andLoadState.showLoadingPlaceholder(loadState, isEmpty)to avoid blank-first-tap and double-fetch. - Logging โ Use
AppLog(error, network, state, verbose) inCore/LogLevel.swiftfor debug output; respectLogLevel.currentto reduce console noise. - Services โ Firestore access is centralized in services (e.g.
UserRequestsFirestoreService,UserProfileFirestoreServicewith optional 60s profile cache). Views/ViewModels orchestrate; services perform reads/writes. - Quality gate โ After changes, run through
Ibtida/QUALITY_GATE_CHECKLIST.md(build, no behavior change, no clipping, no blank first-tap, no fetch loops).
- Credits are for in-app motivation and conversion only; they do not represent religious reward.
- Donation receipts are written only by the backend; client never writes to
users/{uid}/donations. - Prayer status is stored as enum raw value in Firestore; display labels are gender-specific in the UI; legacy strings (e.g.
"later","made up") are mapped on read viaPrayerStatus.fromFirestore. - Last 5 Weeks order: index 0 = current week (left); data from
DateUtils.lastNWeekStarts(5); โThis Weekโ emphasized. - Islamic guidelines โ Prayer terminology (e.g. Jamaโah, Qada, โNot applicable ๐ฉธโ) and donation flows are aligned with mainstream fiqh; โNot applicable ๐ฉธโ does not penalize streaks; donations are transparent (CAD, receipt state, no misleading success until receipt is saved).
- App icon โ Use the same in-app logo for the iOS App Icon (see
Ibtida/JOURNEY_DEBUG_CHECKLIST.mdfor App Icon consistency notes).
Ibtida/Core/BEHAVIOR_LOCK.mdโ Behaviors that must remain identical; module inventory; in-code checklist referencesIbtida/REFACTOR_PLAN.mdโ Refinement passes: path centralization, LoadState, services, profile cache; file-by-file rationaleIbtida/REFINEMENT_PASS_SUMMARY.mdโ Latest refinement pass: FirestorePaths, dead code removal, logging, UI consistencyIbtida/QUALITY_GATE_CHECKLIST.mdโ Post-refactor verification: build, no behavior change, no clipping, no blank first-tap, no fetch loopsIbtida/ADMIN_OVERLAY_TEST_CHECKLIST.mdโ How to set admin, test non-admin vs admin, token refresh, CAD, privacyIbtida/JOURNEY_DEBUG_CHECKLIST.mdโ Production QA checklist, App Icon consistency, Islamic guidelines sectionfirebase/RAMADAN_CONFIG.mdโ Enable Ramadan tab viaapp_config/calendar_flagsfirebase/functions/README.mdโ Cloud Functions setup
Ibtida โ a beginning.